jQuery(function(){

	// Datepicker
	
	jQuery('#start-date').datepicker({
		inline: true,
		minDate:0,
		changeMonth: true,
		//changeYear: true,
		dateFormat: 'yy-mm-dd',
		altField: '#datefrom',
		closeText: 'Lukk',
        prevText: '&laquo;Forrige',
		nextText: 'Neste&raquo;',
		currentText: 'I dag',
		buttonImage: 'images/system/cal.gif',
		showOn: 'both', 
		buttonImageOnly: true,
        monthNames: ['Januar','Februar','Mars','April','Mai','Juni',
        'Juli','August','September','Oktober','November','Desember'],
        monthNamesShort: ['Jan','Feb','Mar','Apr','Mai','Jun',
        'Jul','Aug','Sep','Okt','Nov','Des'],
		dayNamesShort: ['Søn','Man','Tir','Ons','Tor','Fre','Lør'],
		dayNames: ['Søndag','Mandag','Tirsdag','Onsdag','Torsdag','Fredag','Lørdag'],
		dayNamesMin: ['Sø','Ma','Ti','On','To','Fr','Lø'],
		onSelect: function() 
		{ 
			var minDate = new Date($('#start-date').datepicker('getDate'));
			$('#end-date').datepicker('option', 'minDate', minDate);
			minDate.setDate(minDate.getDate() + 3);
			$('#end-date').datepicker('setDate', minDate);
			minDate = new Date($('#start-date').datepicker('getDate'));
			$('#end-date').datepicker('option', 'minDate', minDate);
			//$('#end-date').datepicker('setDate', +3);
		}
	});
	
	jQuery('#end-date').datepicker({
		inline: true,
		minDate:0,
		changeMonth: true,
		//changeYear: true,
		dateFormat: 'yy-mm-dd',
		buttonImage: 'images/system/cal.gif',
		showOn: 'both', 
		buttonImageOnly: true,
		altField: '#dateto',
		closeText: 'Lukk',
        prevText: '&laquo;Forrige',
		nextText: 'Neste&raquo;',
		currentText: 'I dag',
        monthNames: ['Januar','Februar','Mars','April','Mai','Juni',
        'Juli','August','September','Oktober','November','Desember'],
        monthNamesShort: ['Jan','Feb','Mar','Apr','Mai','Jun',
        'Jul','Aug','Sep','Okt','Nov','Des'],
		dayNamesShort: ['Søn','Man','Tir','Ons','Tor','Fre','Lør'],
		dayNames: ['Søndag','Mandag','Tirsdag','Onsdag','Torsdag','Fredag','Lørdag'],
		dayNamesMin: ['Sø','Ma','Ti','On','To','Fr','Lø']
	});
	
	//$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['']));
	//$("#start-date").datepicker($.datepicker.regional['no']);
	
	//var minDate = $('.selector').datepicker('option', 'minDate');
	//setter
	//$('.selector').datepicker('option', 'minDate', new Date(2007, 1 - 1, 1));

	//hover states on the static widgets
	jQuery('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);
	
	var timeout = 10000;
	var effect_duration = 1500;
	var now_class = 'article_1';
	var next_class = 'article_2';
	
	//callback function to bring a hidden box back
	$(document).ready(function(){ setTimeout(function(){runEffect();}, timeout); });
	
	//run the currently selected effect
	function runEffect()
	{
		//most effect types need no options passed by default
		var options = {};
		//check if it's scale or size - they need options explicitly set
		//if(selectedEffect == 'scale'){  options = {percent: 100}; }
		//else if(selectedEffect == 'size'){ options = { to: {width: 280,height: 185} }; }
		
		//run the effect
		$("#top_article ."+now_class).hide('drop',options,effect_duration);

		$("#top_article ."+now_class).addClass('nosee');
		$("#top_article ."+now_class).removeClass('see');
		
		$("#top_article ."+next_class).removeClass('nosee');
		$("#top_article ."+next_class).addClass('see');

		$("#top_article_selectors ."+now_class).addClass('nosee');
		$("#top_article_selectors ."+now_class).removeClass('see');
		
		$("#top_article_selectors ."+next_class).removeClass('nosee');
		$("#top_article_selectors ."+next_class).addClass('see');
		
		setTimeout(function(){$("#top_article ."+next_class).show('drop',options,effect_duration,callback());}, effect_duration);
	};
	
	
	function getElementExists(selector)
	{
		if($(selector).length > 0 )
		{ return true; }
		else
		{ return false; }
	}
	
	//callback function to bring a hidden box back
	function callback()
	{ 
		var i=1;
		var nc = '';
		var nxc = '';
		
		var nowc = '';
		var nxtc = '';
		var nxtc2 = '';
		
		while (i < 50)
		{
			nowc = 'article_'+i;
			nxtc = 'article_'+(i+1);
			nxtc2 = 'article_'+(i+2);

			if(now_class == nowc)
			{
				nc = nowc;
				if(getElementExists('.'+nxtc2)) //(article1) = article 3 exists
				{
					now_class = nxtc;
					next_class = nxtc2;
				}
				else
				{
					if(getElementExists('.'+nxtc)) //(article2) = article 3 exists / article 4 not exists
					{
						now_class = nxtc;
						next_class = 'article_1';
					}
					else //(article3) = article 4 not exists
					{
						now_class = 'article_1';
						next_class = 'article_2';
					}
				}
				i = 100;
				break;
			}
			
			i++;
		}
		setTimeout(function(){runEffect();}, timeout);
	};
});

function fnActivateTab(tabid)
{
	var psLiActiveSelector = 'div#tab_box li.'+tabid;
	
	//alert(psLiActiveSelector);
	
	jQuery('div#tab_box td').removeClass('active');
	jQuery('div#tab_box td.'+tabid).addClass('active');
	
	jQuery('div#tab_box div.tab_container').removeClass('active');
	jQuery('div#tab_box div#'+tabid).addClass('active');
}

/*
var params = '';

function frmLoad()
{
var t = document.getElementById('ticker');
var frm = document.getElementById('frm');

if (t == null || frm == null)
return;

t.style.display = 'none';
frm.style.display = '';
}

function renderFrame(url, style)
{
var fu = url + params;
if (navigator.userAgent.indexOf('Safari') != -1)
{
document.write('<iframe id="frm" name="frm" style="display: none; ' + style + '" frameborder="0" allowtransparency="true"></iframe>');
document.getElementById('frm').onload = frmLoad;
var f = document.createElement('FORM');
document.body.appendChild(f);
f.method = 'POST';
f.action = fu;
f.target = 'frm';
f.submit();
}
else
{
document.write('<iframe id="frm" src="' + fu + '" style="display: none; ' + style + '" frameborder="0" allowtransparency="true" onload="frmLoad()"></iframe>');
}
}
*/

