// JavaScript Document
// This JavaScript provides functions to give "date-driven" themes to my website
// It simply looks at the system date, and returns an image string for the appropriate
// date / period that you're in.  This allows me to automatically generate different 
// themes for various holidays.

function determineHolidayComingUp() {
	/*
	 Java Script Calendar is a small script for web pages which displays current Day of the week, Month, Date and Year along with Holidays notification. Just like this working demo below. It will work with Netscape 2++, Microsoft 3++ and Opera 3++ web browsers.
	
										Tuesday, November 24, 1998    
	
	About 70 holidays from all over the world are displayed by Calendar (if you know other ones, let me know, I will add them). It even calculates Easter Sunday date! To see how it works change the date on your computer to January, 1,
	for example and re-load the page.
	
	Installation is very simple. Just copy the script below, everything between SCRIPT and SCRIPT tags (including tags themselves) and paste in the place you want it to appear on your page. You can customize the way
	 it looks by changing document.write function arguments just after month names definitions. Java Script Calendar is free without any limitations. Copyright © Eugene Vassiltsov. But please, let me know if you will use it.
	*/
	
	 var debug = false;
	 var holidayName = "NONE";
	 var season = "NONE";
	 
	 calendar = new Date();
	 /*calendar = new Date("April 3, 2007");*/
	 day = calendar.getDay(); // Returns the day of the week from a Date object (from 0-6), 0=Sunday
	 month = calendar.getMonth();  //Returns the month from a Date object (from 0-11)
	 date = calendar.getDate(); //  	Returns the day of the month from a Date object (from 1-31)
	 year = calendar.getYear(); //Returns the year, as a two-digit or a four-digit number, from a Date object. Use getFullYear() instead !! 
	 if (year < 1000) year+=1900;
	 
	 cent = parseInt(year/100);
	 g = year % 19;
	 k = parseInt((cent - 17)/25);
	 i = (cent - parseInt(cent/4) - parseInt((cent - k)/3) + 19*g + 15) % 30;
	 i = i - parseInt(i/28)*(1 - parseInt(i/28)*parseInt(29/(i+1))*parseInt((21-g)/11));
	 j = (year + parseInt(year/4) + i + 2 - cent + parseInt(cent/4)) % 7;
	 l = i - j;
	 emonth = 3 + parseInt((l + 40)/44);
	 edate = l + 28 - 31*parseInt((emonth/4));
	 emonth--;
	 
	 var dayname = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
	 var monthname = 
	 new Array ("January","February","March","April","May","June","July","August","September","October","November","December" );
	 // the document.writes are for testing only
	 if (debug) {
		 
		 document.write("<font face=verdana,arial size=2>");
		 document.write("day = " + day + "<br>");
		 document.write("date = " + date + "<br>");
		 document.write("month = " + month + "<br><br>");
		 document.write(dayname[day] + ", ");
		 document.write(monthname[month] + " ");
		 if (date< 10) document.write("0" + date + ", ");
				 else document.write(date + ", ");
		 document.write(year + "    <font color=FF0000>");
	 }
	 
	 // determine season - season is overridden by special holidays - just doing a ballpark by month. Not using equinoxes/solstics or anything fancy like that
	 // These seasons are for Calgary, Alberta
	 if ((month == 0) || (month == 1) || ((month == 2) && (date < 21)) || (month == 10) || (month == 11)) holidayName = "SEASON- WINTER";
	 if (((month == 2) && (date >= 21)) || (month == 3) || (month == 4) ) holidayName = "SEASON- SPRING";
	 if ((month == 5) || (month == 6) || (month == 7)|| (month == 8)  ) holidayName = "SEASON- SUMMER";
	 if ((month == 9)) holidayName = "SEASON- FALL";
	 
	 
	 // For the dates, most are actually date RANGES.  I wanted to look forward a bit to see what the next holiday
	 // is that is coming.  The REAL date of the holiday is the END of the range, the number that is after the <=
	 // Generally I use a look ahead of 7 days, but it can vary depending on the holiday.
	 // Some are just single dates (like April Fools Day)
	 
	 // Easter
	 if ((month == emonth) && (date > edate-4) && (date <= edate)) holidayName ="Easter";
	 // January
	 //if ((month == 0) && (date == 1)) holidayName ="New Year's Day";
	 //if ((month == 0) && (date == 15)) holidayName ="Adults Day (Japan)";
	 //if ((month == 0) && (date == 27)) holidayName ="Wolfgang Amadeus Mozart born (1756)";
	 //if ((month == 0) && (day == 1) && (date > 14) && (date< 22)) holidayName ="Martin Luther King's Birthday";
	 // February
	 //if ((month == 1) && (date == 2)) holidayName ="Groundhog Day";
	 //if ((month == 1) && (date == 8)) holidayName ="Jules Verne born (1828)";
	 //if ((month == 1) && (date == 11)) holidayName ="National Foundation Day (Japan)";
	 //if ((month == 1) && (date== 12)) holidayName ="Lincoln's Birthday";
	 if((month == 1) && (date > 8) && (date <= 14)) holidayName ="Valentine's Day";
	 //if ((month == 1) && (date == 15)) holidayName ="Galileo Galilei born (1564)";
	 //if ((month == 1) && (date == 22)) holidayName ="Washington's Birthday";
	 //if ((month == 1) && (date == 29)) holidayName ="Leap Day";
	 // March
	 //if ((month == 2) && (date == 3)) holidayName ="Girl's Day (Japan)";
	 if ((month == 2) && (date > 7) && (date <= 17)) holidayName ="St. Patrick's Day";
	 //if ((month == 2) && (date == 21)) holidayName ="J.S. Bach born (1685)";
	 // April
	 //if ((month == 3) && (date == 1)) holidayName ="April Fools' Day";
	 //if ((month == 3) && (date == 8)) holidayName ="Buddha born";
	 //if ((month == 3) && (date == 15) && (day != 0)) holidayName ="Income Tax Day (USA),   ";
	 //if ((month == 3) && (date == 16) && (day == 1)) holidayName ="Income Tax Day (USA) ";
	 //if ((month == 3) && (date == 15)) holidayName ="Leonardo da Vinci born (1452)";
	 //if ((month == 3) && (date == 22)) holidayName ="Earth Day";
	// if ((month == 3) && (date == 29)) holidayName ="Emperor's Birthday (Japan)";
	 //if ((month == 3) && (day == 0) && (date > 0) && (date< 8)) holidayName ="Daylight Savings Time Begins";
	 // May
	 //if ((month == 4) && (date == 1)) holidayName ="May Day,   Boy's Day (Japan)";
	 //if ((month == 4) && (date == 2)) holidayName ="Constitution Day (Japan)";
	 //if ((month == 4) && (date == 5)) holidayName ="Cinco de Mayo (Mexico),   Children's Day (Japan)";
	 //if ((month == 4) && (date == 14)) holidayName ="Independence Day (Paraguay)";
	 //if ((month == 4) && (day == 0) && (date > 7) && (date< 16)) holidayName ="Mother's Day";
	 //if ((month == 4) && (day == 1) && (date > 24)) holidayName ="Memorial Day";
	 // June
	 //if ((month == 5) && (date == 5)) holidayName ="Constitution Day (Denmark)";
	 //if ((month == 5) && (date == 6)) holidayName ="D-Day (USA)";
	 //if ((month == 5) && (date == 11)) holidayName ="Kamehameha (Hawaii)";
	 //if ((month == 5) && (date == 14)) holidayName ="FlagDay (USA)";
	 //if ((month == 5) && (date == 21)) holidayName ="Summer Solstice";
	 //if((month == 5) && (date == 24)) holidayName ="St. Jean Baptiste Day (Canada)";
	 //if ((month == 5) && (date == 30)) holidayName ="Independence Day (Zaire)";
	 //if ((month == 5) && (day == 0) && (date > 15) && (date< 24)) holidayName ="Father's Day";
	 // July
	 if ( ((month == 5) && (date > 25)) || ((month == 6) && (date <= 1)) ) holidayName ="Canada Day";
	 if ( (month == 6) && ( (date > 6) && (date < 16) ) ) holidayName ="Stampede";

	 //if ((month == 6) && (date == 4)) holidayName ="Independence Day (USA)";
	 //if ((month == 6) && (date == 14)) holidayName ="Bastille Day (France)";
	 // August
	 //if ((month == 7) && (date == 1)) holidayName ="Confederation Day (Switzerland)";
	 //if ((month == 7) && (date == 10)) holidayName ="Independence Day (Ecuador)";
	 //if ((month == 7) && (date == 15)) holidayName ="Independence Day (India)";
	 // September
	 //if ((month == 8) && (date == 7)) holidayName ="Independence Day (Brazil)";
	 //if ((month == 8) && (date == 15)) holidayName ="Respect for the Aged Day (Japan)";
	 //if ((month == 8) && (date == 16)) holidayName ="Independence Day (Mexico)";
	 //if ((month == 8) && (day== 1)&& (date > 0) && (date< 8)) holidayName ="Labor Day (USA)";
	 // October
	 //if ( (month == 9) && (day == 1) && (date > 7) && (date < 15) )  holidayName ="Thanksgiving (Canada)"; // 2nd monday of October
	 //if ((month == 9) && (date == 1)) holidayName ="German Reunufication (1990)";
	 //if ((month == 9) && (date == 10)) holidayName ="Health-Sports Day (Japan)";
	 //if ((month == 9) && (day == 1) && (date > 7) && (date< 16)) holidayName ="Columbus Day (USA)";
	 //if ((month == 9) && (day == 0) && (date > 24) && (date< 31)) holidayName ="Daylight Savings Time Ends";
	 //if ((month == 9) && (day == 0) && (date == 31)) holidayName ="Daylight Savings Time Ends<BR>";
	 //if ((month == 9) && (date == 24)) holidayName ="United Nations Day";
	 if ((month == 9) && (date > 23) && (date <= 31)) holidayName ="Halloween";
	 // November
	 //if ((month == 10) && (date == 1)) holidayName ="All Saints Day";
	 //if ((month == 10) && (date == 2)) holidayName ="All Souls Day";
	 //if ((month == 10) && (date == 3)) holidayName ="Culture Day (Japan)";
	 if ((month == 10) && (date > 5) && (date <= 11)) holidayName ="Remembrance Day (Canada)";
	 //if ((month == 10) && (date ==20)) holidayName ="Revolution Day (Mexico)";
	 //if ((month == 10) && (date == 23)) holidayName ="Labor Thanksgiving Day (Japan)";
	 
	 //if ((month == 10) && (day == 4) && (date > 23) && (date< 30)) holidayName ="Thanksgiving (USA)";
	 //if ((month == 10) && (date == 30) && (day == 4)) holidayName ="Thanksgiving (USA)";  // 4th Thursday of November
	 // December
	 //if ((month == 11) && (date == 10)) holidayName ="Human Rights Day";
	 //if ((month == 11) && (date == 21)) holidayName ="Winter Solstice";
	 //if ((month == 11) && (date <= 24)) holidayName ="Christmas Eve";
	 if ((month == 11) && (date > 11) && (date <= 25)) holidayName ="Christmas";
	 //if ((month == 11) && (date == 26)) holidayName ="Boxing Day";
	 if ((month == 11) && (date == 31) ||(month == 0) && (date == 1) ) holidayName ="New Years";
	 
	 
	 if (debug) {
		document.write("holidayName = ");
		document.write(holidayName);
	 	document.write("<br></font>");
	 }
	 
	 return(holidayName);

}

function setBackgroundImage (id, imageURL) {
  if (document.layers)
    document[id].background.src = imageURL == 'none' ? null : imageURL;
  else if (document.all)
    document.all[id].style.backgroundImage = imageURL == 'none' ? 'none' 
: 'url(' + imageURL + ')';
  else if (document.getElementById)
    document.getElementById(id).style.backgroundImage = imageURL == 
'none' ? 'none' : 'url(' + imageURL + ')';
}


function setBgColor (id, color) {
  if (document.layers)
    document[id].bgColor = color == 'transparent' ? null : color;
  else if (document.all)
    document.all[id].style.backgroundColor = color;
  else if (document.getElementById)
    document.getElementById(id).style.backgroundColor = color;
}


function setTheme() {
	var debug = false;
	var bkgImgRoot = "http://www.coreyhallisey.com/images/backgrounds/";
	//var retVal = bkgImgRoot + "black.jpg";  // default value is black.jpg
	
	// defaults
	var bkgImg = bkgImgRoot + "rocks.jpg";  // default value is black.jpg
	var bkgAltImg = bkgImgRoot + "rocks_darker.jpg";  // default value is black.jpg
	//var foreColor = "#333333";
	//var backColor = "#666666";

	var holidayName = determineHolidayComingUp();
// override holidayName if required
	//var holidayName = "HITMEN";
	//alert("holidayName=" + holidayName);
	//var holidayName = "greensand";
	
	if (debug) document.write("<font color=#FFFFFF>");
	if (debug) document.write(holidayName + "<br>");
	
	// This arrays index values must match the output values os the determineHolidayComingUp
	var bkg_images = new Array ("SEASON- WINTER", "SEASON- FALL", "SEASON- SPRING", "SEASON- SUMMER", "Easter", "Valentine's Day", "St. Patrick's Day", "Canada Day", "Halloween", "Remembrance Day (Canada)", "Christmas", "New Years", "HITMEN");
	var bkg_alt_images = new Array ("SEASON- WINTER", "SEASON- FALL", "SEASON- SPRING", "SEASON- SUMMER", "Easter", "Valentine's Day", "St. Patrick's Day", "Canada Day", "Halloween", "Remembrance Day (Canada)", "Christmas", "New Years", "HITMEN");
	
	// have to determine bkg_images and dark_bkg_images for each theme
	bkg_images["NONE"] = bkgImgRoot + "rocks.jpg";
	bkg_images["SEASON- WINTER"] = bkgImgRoot + "snow_bg2.jpg";
	bkg_images["SEASON- FALL"]= bkgImgRoot + "fall2.jpg" ;
	//bkg_images["SEASON- SPRING"]= bkgImgRoot + "spring_thaw_bg1.jpg" ;
	bkg_images["SEASON- SPRING"]= bkgImgRoot + "spring_bg2.jpg" ;
	bkg_images["SEASON- SUMMER"]= bkgImgRoot + "summer_sunset_bg1.jpg" ; 
	bkg_images["Easter"]= bkgImgRoot + "easter_eggs_bg4.jpg" ; 
	bkg_images["Valentine's Day"]= bkgImgRoot + "valentines_hearts_bg1.jpg" ;
	bkg_images["St. Patrick's Day"]= bkgImgRoot + "shamrock.jpg" ; ;
	bkg_images["Canada Day"]= bkgImgRoot + "mapletile2.gif" ;
	bkg_images["Stampede"]= bkgImgRoot + "stampede_logo_neon.jpg" ;
	bkg_images["Halloween"]= bkgImgRoot + "halloween_bg3.jpg" ;
	bkg_images["Remembrance Day (Canada)"]= bkgImgRoot + "remembrance_day_bg2.jpg" ;
	bkg_images["Christmas"]= bkgImgRoot + "christmas.jpg" ; 
	bkg_images["New Years"]= bkgImgRoot + "new_years_fireworks_bg" ; 
	bkg_images["HITMEN"] = bkgImgRoot + "hitmen_texture3.jpg";
	bkg_images["WINTERGAMES"] = bkgImgRoot + "WINTERGAMES_MEDALS.jpg";
	bkg_images["greensand"] = bkgImgRoot + "green_sand.jpg";
	
	//retVal = bkg_images[holidayName];
	
	bkgImg = bkg_images[holidayName];
	//alert(bkgImg);
	
	if (debug) document.write("retVal = " + bkgImg);
	
	if (document.body) {
   		document.body.background = bkgImg;
	}
	
	// NOTE: the ids here must exist in the HTML that your'e testing with.
	// Otherwise you'll get a javascript error.
	//if (document.getElementById)  {
		//elem = document.getElementById("tagboard_table");
		// adjust the background images
		//setBackgroundImage("tagboard_table", bkgAltImg);
		//setBackgroundImage("flickr_footer_table", bkgAltImg);
		// adjust the row colours on the tagboard
		//setBgColor("altColor1", foreColor);
		//setBGColor("altColor2", backColor);
	//}

	if (debug) document.write("</font>");

	
}


//getTheme_bkg_image();