// AUTHOR: Devin Panquites
// DATE: 01/14/2005
// PURPOSE: File switching scheduler
// MODIFICATION LOG:
// DATE        AUTHOR		VERSION		MODIFICATION
// ====        ======		=======		============
// 01/14/2005	dp			1.0			Initial Generation
// 02/01/2005	dp			1.1			Changed the IF statement *1
// 04/15/2005	dp			1.2			Added an alternate promotion *2
// 05/25/2005	tb			1.3			Added a start date to promotions *3
// 10/2/2006	es			1.4			Added banner rotation
//
// USE:
//		Built for Ala Moana Center to automate switching out the Flash movies on the
// 		homepage. These Flash movies contain promotions that end on certain dates and
//		need to be switched out at inconvenient times.
//
// *1	The IF statement was changed from '(theDay < expireDay)' to '(now < expireDate)'
//		The previous statement only accounted for the day which didn't function properly
//		once the next month came along.
//
// *2	The purpose of the altpromo is to run back to back promotions. The first promotion
// 		will end, then the alternate promotion will begin.
// 		NOTE: Should be rewritten to be more flexible and interchangeable. The code will
// 		look for promo 1 first. If that is expired it will move on to the alt promo, then
// 		to the default promo. Promo 1 and alt promo should be interchangeable based on date
// 		of promo.
//
// *3	Start date variables were added to so that the promotion banner can be set to automatically go live.
//		The IF statement was changed from '(now < expireDate)' to '((now > startDate) && (now < expireDate))'.
//		The changes were also made to the alternate promotion.
//
// *4	If both banners are set to run, banners will be randomly displayed in first IF statement.
//

var Hawaii = -10;

now = new Date();
var ar1 = now.toGMTString().split(" ");
var ar2 = ar1[4].split(":");
var GMThour = parseInt(ar2[0]);
now = new Date();

var hourCheck = GMThour + Hawaii;
if (hourCheck < 0) {
  hourCheck = 24 + hourCheck;
}

now.setHours(hourCheck);

var theDay = now.getDate();
var theHour = now.getHours();


// set start date for promo
var startDate = new Date("9 March 2010 00:00:00 GMT-1000"); // IMPORTANT: Remember to set this date/time for start of promo
var startDay = startDate.getDate();
var startHour = startDate.getHours();

// set expiration date for promo
var expireDate = new Date("25 March 2010 23:59:59 GMT-1000"); // IMPORTANT: Remember to set this date/time for end of promo
var expireDay = expireDate.getDate();
var expireHour = expireDate.getHours();

//1 September 2007 01:00:01 GMT-1000
// IF running consecutive promotions back to back
// set start date for alternate promo
var altstartDate = new Date("26 March 2010 00:00:00 GMT-1000"); // IMPORTANT: Remember to set this date/time for start of promo
var altstartDay = altstartDate.getDate();
var latstartHour = altstartDate.getHours();

// set expiration date for alternate promo
var altexpireDate = new Date("1 January 2011 23:59:59 GMT-1000"); // IMPORTANT: Remember to set this date/time for end of promo
var altexpireDay = altexpireDate.getDate();
var altexpireHour = altexpireDate.getHours();


// document.write(now + ': ' + theDay + '/' + theHour + '<br>' +
//			   expireDate + ': ' + expireDay + '/' + expireHour + '<br>');

// banner rotation -----------------------------------------------------------------------------------------
// if banners running simultaneously
if ((now > startDate) && (now < expireDate) && (now > altstartDate) && (now < altexpireDate)) {
	var promospace;
	var selector = Math.round(Math.random()*1);
		//PROMO 1
		var promospace = '<a href="http://www.alamoanacenter.com/hawaii_restaurants.htm" target="_self"><img src="images/hookipaterrace.gif" alt="Click here for details" width="377" height="97" border="0"></a>';

	 if (selector == 1) {
		 // ALTERNAMTE PROMO:
		 var promospace = '<a href="http://www.alamoanacenter.com/diningentertainment.htm" target="_self"><img src="images/banner_r_f3.gif" alt="Click here for details" width="377" height="97" border="0"></a>';
    }
}
// if two banners are NOT running at same time, then proceed with checks
else {
if ((now > startDate) && (now < expireDate)) {
	// PROMO 1: run this banner
	// expires on "25 March 2010 23:59:59 GMT-1000"
	var promospace = '<a href="http://www.alamoanacenter.com/shopaleagiveaway.htm" target="_self"><img src="bnr/bnr-shopping_serenades.gif" alt="Click here for details" width="377" height="97" border="0"></a>';	// current promo

}
else {
	if ((now > altstartDate) && (now < altexpireDate)) {
		// ALTERNATE PROMO: promo 1 has ended
		//	expire: "leave up after promo 1 ends until further notice. Set to January 1, 2011 for now."
		var promospace = '<a href="http://www.alamoanacenter.com/connect.htm" target="_self"><img src="bnr/bnr-connect.jpg" alt="Click here for details" width="377" height="97" border="0"></a>';	// current promo
	} else {
		// DEFAULT: promos have expired use default banner
		var promospace = '<a href="http://www.alamoanacenter.com/trendwatch.htm" target="_self"><img src="images/trendwatch.jpg" alt="Click here for details" width="377" height="97" border="0"></a>';	// default promo
		// var promospace = '<a href="mallmap.htm?iid=2007_9_Mall_Map"><img src="images/banner-mallmap.gif" alt="Ala Moana Center Mall Map" width="377" height="97" border="0"></a>';
	}
}
}
// IF using Flash banners, use the detector file fpi-swappromo.js

//alert(now + '::' + expireDate);