var iDateModifier = 0;
var bFoundToday = false;
var iToday = iDateModifier;
var d		= new Date();
var iMonth	= d.getMonth() + 1;
var iDate	= d.getDate();			// Day of month.
var iYear	= d.getYear();			// Year 4 digit format.
var bSlideshowOn = false;
var hSlideshowTimer = -1;
	
if (iYear < 1000)
	iYear += 1900;
	
function RefreshStrip()
{
	var dDate = new Date();
 dDate.setDate( dDate.getDate() + iDateModifier);
 	iMonth	= dDate.getMonth() + 1;
    iDate	= dDate.getDate();
	iYear	= dDate.getYear();
	if (iYear < 1000)
		iYear += 1900;
		
	document.getElementById("dateToday").innerHTML = iDate + "." + iMonth + "." + iYear;
	var sTest = getYYMMDD(iMonth, iDate, iYear)
	document.getElementById("gaimg").src = "http://images.ucomics.com/comics/ga/" + iYear + "/ga" + sTest;
	}
		
	// Notifier for garfieldload. ERROR WHEN LOADING.
	function onError_Garfield()
	{
	// Try yesterday.
		loadPrev();
	}
	
	function onLoad_Garfield()
	{
		if (bFoundToday == false)
		{
			bFoundToday = true;
			iToday = iDateModifier;
		}
		
		if (iDateModifier == iToday)
		{
			// Disable next button
			document.getElementById("btnNextDay").style.color = "gray";
			document.getElementById("btnNextDay").style.cursor = "default";
		}
		else
		{
			document.getElementById("btnNextDay").style.color = "blue";
			document.getElementById("btnNextDay").style.cursor = "hand";
		}
		
	}

	function slideshowOnOff()
	{
		if (bSlideshowOn)
		{
			bSlideshowOn = false;
			if (hSlideshowTimer >= 0)
			{
				window.clearTimeout(hSlideshowTimer);
				hSlideshowTimer = -1;
			}
			document.getElementById("btnSlideshow").innerHTML = "SlÃÆÃâÃâÃÂ¥ pÃÆÃâÃâÃÂ¥ slideshow";
		}
		else
		{
 			bSlideshowOn = true;
			hSlideshowTimer = window.setTimeout("loadPrev();", 1000);
			document.getElementById("btnSlideshow").innerHTML = "SlÃÆÃâÃâÃÂ¥ av slideshow";
		}
	}

	function loadNext()
	{
		if (iDateModifier == iToday)
			return;
			
		iDateModifier++;
		RefreshStrip();
	}

	function loadPrevWeek()
	{
		iDateModifier = iDateModifier - 7;
		RefreshStrip();
	}
	
	function loadPrev()
	{
		iDateModifier--;
		RefreshStrip();

		if (bSlideshowOn == true)
		{
			// A timer is ready to fire.
			if (hSlideshowTimer >= 0)
			{
				window.clearTimeout(hSlideshowTimer);
				hSlideshowTimer = -1;
			}
			hSlideshowTimer = window.setTimeout("loadPrev();", 8000);
		}
	}

	
	function getYYMMDD(month, date, year4)
	{
		var sTemp = year4.toString();
		var aTemp = sTemp.split("");
		var year2 = aTemp[2] + aTemp[3];		// Year 2 digit format.

		// Add leading zeros. f.ex. before jan = 1 after jan = 01
		if (date.toString().length <= 1)
		date = "0" + date.toString();
		if (month.toString().length <= 1)
		month = "0" + month.toString()

		// yymmdd has the format yymmdd.gif
		return "" + year2.toString() + month.toString() + date.toString() + ".gif";
	}

	// ----------------------------------------------------------------------------------------------------
	// NOW LOAD THE COMIC STRIPS.

	// Stripe 2. Garfield.
	document.getElementById("dateToday").innerHTML = iDate + "." + iMonth + "." + iYear;
