/* =========================================================================================================================
   greataupairs.co.uk | event bound page clock and other events
   ==========================================================================================================================
   Event binding is used in this script so that no javascript needs to be embeded into the page */

var elClock;      //Object reference to the clock element
var flipflop = 0; //Used to blink the colon

var nths = new Array("th","st","nd","rd","th","th","th","th","th","th","th","th","th","th");
var weekday = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var monthname = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

function updateClock() {
	var tDate = new Date();
	var hours = (tDate.getHours()<13 ? tDate.getHours() : tDate.getHours() - 12);
	if (hours==0) hours=12;
	var minutes = tDate.getMinutes();
	minutes = ((minutes < 10) ? "0" : "") + minutes;
	
	tBlinken = (flipflop==0 ? ":" : " ");
	flipflop = 1 - flipflop;
	tMeridian = (tDate.getHours()<12 ? "AM" : "PM");
	
	var nth = (tDate.getDate()<14 ? nths[tDate.getDate()] : nths[tDate.getDate()%10]);
	elClock.innerHTML = weekday[tDate.getDay()] + " " + tDate.getDate() + "<small>" + nth + "<\/small> " + monthname[tDate.getMonth()] + " " + hours + tBlinken + minutes + " " + tMeridian;
}

function callPrint() {
	if(window.print) window.print();
	return true;
}

window.onload = function(){
	//Bind the Clock to the page if it exists
	elClock = document.getElementById("PageClock");
	if (elClock) {
		setInterval("updateClock()", 500);
		updateClock();
	}
	
	var a = document.getElementsByTagName("a");
	for (var i=0; i<a.length; i++) {
 		//Hyperlinks with rev="alternate" cause a javascript window.print();
 		if (a[i].getAttribute("rev")=="alternate") {
 			a[i].onclick = function(){callPrint(); return false;};
 		}
 	}
};
/* === END ====================================================================================== */