// 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("1 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("31 December 2010 23:59:59 GMT-1000"); // IMPOR TANT: Remember to set this date/time for end of promo
var expireDay = expireDate.getDate();
var expireHour = expireDate.getHours();


// IF running consecutive promotions back to back
// set start date for alternate promo
var altstartDate = new Date("1 August 2009 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("12 November 2009 23:59:00 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 ((now > startDate) && (now < expireDate) && (now > altstartDate) && (now < altexpireDate)) {
	var subpromospace;
	var selector = Math.round(Math.random()*1);
		//PROMO 1
		subpromospace = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="189" height="97"><param name="movie" value="amc-badge_rotation_v5.swf"><param name="quality" value="high"><embed src="amc-badge_rotation_v5.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="189" height="97"></embed></object>';
	
	 if (selector == 1) {
		 // ALTERNAMTE PROMO:
		 subpromospace = '<a href="http://alamoanacenter.com/hoursdirs.htm" target="_self"><img src="images/badge-newhours07.gif" alt="Click here for details" width="189" 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 "31 December 2009 23:59:00 GMT-1000" <-- set this date for now because they don't know when they want to take it down yet
	var subpromospace = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="189" height="97"><param name="movie" value="swf/badge-giftcard02.swf"><param name="quality" value="high"><embed src="swf/badge-giftcard02.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="189" height="97"></embed></object>';	// current promo

}
else {
	if ((now > altstartDate) && (now < altexpireDate)) {
		// ALTERNATE PROMO: promo 1 has ended
		//	expire: "27 August 2007 9:00:00 GMT-1000"
		var subpromospace = '<a href="http://viewer.zmags.com/publication/590902a7" target="_blank"><img src="bnr/bnr-50thanni_static.jpg" alt="Click here for details" width="189" height="97" border="0"></a>';	// current promo
	} else {
		// DEFAULT: promos have expired use default banner
		var subpromospace = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="189" height="97"><param name="movie" value="swf/badge-giftcard10.swf""><param name="quality" value="high"><embed src="swf/badge-giftcard10.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="189" height="97"></embed></object>';	// default promo
		//var subpromospace = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="189" height="97"><param name="movie" value="swf/amc-badge_static.swf""><param name="quality" value="high"><embed src="swf/amc-badge_static.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="189" height="97"></embed></object>';	// default promo
	}
}
}
document.write(subpromospace);
// IF using Flash banners, use the detector file fpi-swappromo.js

//alert(now + '::' + expireDate);