$(function()
{	
	// makes links out of plaintext email addresses in the staff list
	if ($('#tabs').length) { Tabs(); }
	$('#search_text').originalValue();

	$("div.thumbnails").scrollable(); 

	// Image Loop
	ImageLoopStart('.img-banner li'); 

	// Colorbox media links
	$('#column-wrapper div.imgFrame a').colorbox();

	//------------------------------------------------------//
	// ie6 fix fyrir header-controls
	var bName = navigator.appName;
	var bVer = Math.floor(navigator.appVersion);
	if (bName == "Microsoft Internet Explorer" && bVer == 6)
		$("#header-controls").css('right','0px');
	//------------------------------------------------------//

});


function ImageLoopStart( CSS )
{
	var elements = $(CSS);
	if( elements.length > 1 )
	{
		setInterval(  "ImageLoop('"+CSS+"')", 7000 );
	};
};

function ImageLoop( CSS )
{
	var Now = $(CSS+':visible').fadeOut( 2000 );
	var Next = ( Now.next().is(CSS) && Now.next() ) || $(CSS+':first' );
	Next.fadeIn( 2000 );
};	

jQuery.fn.extend(
	{
		originalValue:function( originalValue )
		{
			this.each(function()
				{
					if( originalValue )
					{
						$(this).val( originalValue );
					}
					$(this).attr( 'originalValue', $(this).val() );
				}
			).blur(function()
				{
					if( !$(this).val() )
					{
						$(this).val( $(this).attr('originalValue') );
					}
				}
			).focus(function()
				{
					if( $(this).val() === $(this).attr('originalValue') )
					{
						$(this).val('');
					}
				}
			);
		}
	}
);


function Tabs() {
	$('#tabs div.tab').hide(); // Hide all divs
	$('#tabs div:first').show(); // Show the first div
	$('#tabs ul li:first').addClass('active'); // Set the class of the first link to active
	$('#tabs ul.switches li a').click(function(){ //When any link is clicked
	$('#tabs ul li').removeClass('active'); // Remove active class from all links
	$(this).parent().addClass('active'); //Set clicked link class to active
	var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
	$('#tabs div.tab').hide(); // Hide all divs
	$(currentTab).fadeIn("slow"); // Show div with id equal to variable currentTab
	return false;
});
}

function fncCheckSearchDates() {
	var strFromDay = $('#DateFrom_Day').val();
	var strFromMonth = $('#DateFrom_Month').val();
	var strFromYear = $('#DateFrom_Year').val();

	var dtmFrom = new Date(strFromYear,strFromMonth-1,strFromDay);
	var dtmTo = DateAdd(dtmFrom,0,1,0);
	var strTo = dtmTo.getDate() + '.' + ( dtmTo.getMonth() + 1 ) + '.' + dtmTo.getFullYear();

	$('#DateTo').val(strTo);
}

function DateAdd(startDate, numDays, numMonths, numYears) {
	var returnDate = new Date(startDate.getTime());
	var yearsToAdd = numYears;
	
	var month = returnDate.getMonth() + numMonths;
	if (month > 11) {
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += numYears;
	}
	returnDate.setMonth(month);
	returnDate.setFullYear(returnDate.getFullYear()	+ yearsToAdd);
	returnDate.setTime(returnDate.getTime() + 60000 * 60 * 24 * numDays);
	return returnDate;
}

function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}
