/* -----------------------------------------------
	written by Annie @ CaryTagawaOnline.com
	do not use without permission
	thanks!
-------------------------------------------------*/
var image_day = "/_graphics/images/time_day.jpg";
var image_trans = "/_graphics/images/time_trans.jpg";
var image_night = "/_graphics/images/time_night.jpg";
var image_xmas = "/_graphics/images/time_xmas.jpg";

//#########################################################

function displayTimeImage(imgName) {
	var now = new Date;
	if (document.images) {
		thisImage = document.images[imgName];
	} else {
		thisImage = eval('document.' + imgName);
	}
	if (now.getMonth() == 11) {
		thisImage.src = image_xmas;
	} else if ((now.getHours() <= 4) || (now.getHours() >= 21)) {
		thisImage.src = image_night;
	} else if ((now.getHours() <= 6) || (now.getHours() >= 19)) {
		thisImage.src = image_trans;
	} else {
		thisImage.src = image_day;
	}
}

//#########################################################

function ShowChatMsg(){
	/* 	display a message if chat is coming up!
		according to UTC time, chat time of Tuesday 10pm EST 
		is UTC Date of Wednesday, 2am  */
	/*-------------------------------------------------------------------*/
	chatDay = 3; 					// 3 (wednesday) ... tuesday EST
	chatTime = 2; 					// 2:00 am ... 10:00 pm EST
	chatURL = "aim:GoChat?RoomName=carytagawaonlinechat";	
	/*-------------------------------------------------------------------*/
	dayName = new Array ("Sun.","Mon.","Tues.","Wed.","Thurs.","Fri.","Sat.");
	oneHour = 60 * 60 * 1000;   	// one hour, in milliseconds
	oneDay = oneHour * 24;   		// one day, in milliseconds
	now = new Date;
	GMTDate = new Date(now.getUTCFullYear(),now.getUTCMonth(),now.getUTCDate(),now.getUTCHours(),now.getUTCMinutes());
	hourDifference = (now.valueOf() - GMTDate.valueOf());
	chatDate = new Date(now.getUTCFullYear(),now.getUTCMonth(),now.getUTCDate(),chatTime);
	while (chatDate.getDay() != chatDay) {
		chatDate = new Date(chatDate.valueOf() + oneDay);
	}
	// translate the chat date back to user's time
	chatDateTranslated = new Date(chatDate.valueOf() + hourDifference);
	chatDateEST = new Date(chatDate.valueOf() + (oneHour * -4));
	message = "";
	timeDifference = (GMTDate.valueOf() - chatDate.valueOf());
	// if it is between 1 day before chat and 2 hours after, show msg
	if ((timeDifference < 0) && (Math.abs(timeDifference) < oneDay)) {
		if (Math.abs(timeDifference) < (oneHour * 2)) {
			message = "<b>Reminder:</b> <a href=\"" + chatURL + "\" target='_blank'\">Weekly Chat in ";
			message += Math.round(100*Math.abs((timeDifference/oneHour)))/100 + " hour";
			if (Math.abs(timeDifference/oneHour) != 1) message += "s";
			message += "</a>";
		} else {
		message = "<b>Reminder:</b> Weekly Chat " + dayName[chatDateTranslated.getDay()] + ", " + (chatDateTranslated.getMonth() + 1) + "/" + chatDateTranslated.getDate() + " @ " + chatDateTranslated.getHours() + ":00";
		if (chatDateTranslated.getHours() != chatDateEST.getHours()) {
			message += "<br>(" + dayName[chatDateEST.getDay()] + " " + chatDateEST.getHours() + ":00 EST)";
			}
		}
	} else if ((timeDifference > 0) && (timeDifference <= (oneHour * 2))) {
		message = "<a href=\"" + chatURL + "\" target='_blank'\">Weekly chat in progress!</a>";
	}
	if (message != "") displayText = "<div class='Notice'>" + message + "</div>";
	else displayText = "";
	document.writeln(displayText);
}

//#########################################################

function Start(page) {
	OpenWin = this.open(page, "CtrlWindow", "height=460,width=570,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes");
} 

//#########################################################


// End 
