// calen.js
// djm+pga 2005
// dampjg (norwegian j)
var n = (document.layers) ? 1:0
var n6 = (parseInt(navigator.appVersion) >= 5) ? 1:0
var ie = (document.all) ? 1:0
var milissince = new Date();
var eventday = new Date(2005, 11, 25);
var diffdays = eventday - milissince;
var days = Math.round(diffdays / (1000*3600*24) + 0.5, 0);

function changeV(name,v) {
	if(n6){ document.getElementById(name).style.visibility=(v) ? "visible":"hidden";
        	document.getElementById(name).style.display=(v) ? "block":"none"; }
	if(n) { document.layers[name].visibility=(v) ? "show":"hide";
        	document.layers[name].display=(v) ? "block":"none"; }
	if(ie){ document.all[name].style.visibility=(v) ? "visible":"hidden";
        	document.all[name].style.display=(v) ? "block":"none"; }
}
function WriteDoors() {
	var dTopArray = new Array();
	var dLeftArray = new Array();
	dTopArray = ["0","184","240","222","160","86","265","350","104","351","335","275","274","228","235","181","132","165","222","290","355","269","133","397","313","168"];
	dLeftArray = ["0","252","104","546","465","382","216","378","249","507","292","684","149","503","297","210","337","553","173","462","184","588","420","438","548","335"];
	for (var xmas = 1;xmas < 25; xmas++) {
		document.write('<div id="door_'+xmas+'" class="door" style="top:'+dTopArray[xmas]+'; left:'+dLeftArray[xmas]+';"><img'+
		' src="door_'+xmas+'.gif" alt="door '+xmas+' closed" title="door '+xmas+' closed" /></div>'+
		'<div id="door_open_'+xmas+'" class="door open" style="top:'+dTopArray[xmas]+'; left:'+dLeftArray[xmas]+';"><img'+
		' src="door_open_'+xmas+'.gif" alt="door '+xmas+' open" title="door '+xmas+' open" /></div>'+
		'<div id="door_anim_'+xmas+'" class="door anim" style="top:'+dTopArray[xmas]+'; left:'+dLeftArray[xmas]+';"><img'+
		' id="door_anim_img_'+xmas+'" src="door_anim_'+xmas+'.gif" alt="door '+xmas+' open" title="door '+xmas+' open" /></div>');
	}
	var xmas = 25;
	document.write ('<div id="door_'+xmas+'" class="doorlast" style="top:'+dTopArray[xmas]+'; left:'+dLeftArray[xmas]+';"><img'+
		' src="door_'+xmas+'.gif" alt="door '+xmas+' closed" title="door '+xmas+' closed" /></div>'+
		'<div id="door_open_'+xmas+'" class="doorlast anim" style="top:'+dTopArray[xmas]+'; left:'+dLeftArray[xmas]+';"><img'+
		' src="door_open_'+xmas+'.gif" alt="door '+xmas+' open" title="door '+xmas+' open" /></div>'+
		'<div id="door_anim_'+xmas+'" class="doorlast open" style="top:'+dTopArray[xmas]+'; left:'+dLeftArray[xmas]+';"><img'+
		' id="door_anim_img_'+xmas+'" src="door_anim_'+xmas+'.gif" alt="door '+xmas+' open" title="door '+xmas+' open" /></div>');
	document.write ('<div class="door" style="top:307; left:193;"><a href="Javascript:OpenAll();"><img'+
		' src="white.gif" alt="open all" title="open all" /></a></div>');

}
function OpenDoors() {
	if (days > 0) {
		if (days <= 25) {
			for (i = 1; i <= 25-days; i++) {
				changeV("door_open_"+i, 1);
				document.images['door_anim_img_'+i].src = "door_anim_"+i+".gif";
				changeV("door_anim_"+i, 1);
				if (i == 25) changeV("door_"+i, 0);
			}
		} else {
			alert ("No doors to open yet!");
		}	
	} else {
		OpenAll();
	}
}
function WriteDaysToGo() {
	if (days > 0) {
		document.write("Check back over the next <b>" + days + "</b> days  to see more doors being opened.");
	} else {
		document.write("<b>" + (0 - days) + "</b> days <b>since</b> Christmas.");
	}
}
function OpenAll() {
	for (i=1; i < 26; i++) {
		changeV("door_open_"+i, 1);
		document.images['door_anim_img_'+i].src = "door_anim_"+i+".gif";
		changeV("door_anim_"+i, 1);
		if (i == 25) changeV("door_"+i, 0);
	}
}
function Getoday() {
	var dayno = milissince.getDay();
		if (dayno == 0) this_day = "Sunday";
		if (dayno == 1) this_day = "Monday";
		if (dayno == 2) this_day = "Tuesday";
		if (dayno == 3) this_day = "Wednesday";
		if (dayno == 4) this_day = "Thursday";
		if (dayno == 5) this_day = "Friday";
		if (dayno == 6) this_day = "Saturday";
	var monthno = milissince.getMonth();
		if (monthno == 0) this_month = "January";
		if (monthno == 1) this_month = "February";
		if (monthno == 2) this_month = "March";
		if (monthno == 3) this_month = "April";
		if (monthno == 4) this_month = "May";
		if (monthno == 5) this_month = "June";
		if (monthno == 6) this_month = "July";
		if (monthno == 7) this_month = "August";
		if (monthno == 8) this_month = "September";
		if (monthno == 9) this_month = "October";
		if (monthno == 10) this_month = "November";
		if (monthno == 11) this_month = "December";
	var monthday = milissince.getDate();
		var xtra = "th";
		if (monthday == 1) xtra = "st";
		if (monthday == 21) xtra = "st";
		if (monthday == 31) xtra = "st";
		if (monthday == 2) xtra = "nd";
		if (monthday == 22) xtra = "nd";
		if (monthday == 3) xtra = "rd";
		if (monthday == 23) xtra = "rd";

	document.write("Today is " + this_day + ", the ");
	document.write(monthday);
	document.write(xtra + " of " + this_month + ". ");
}
