var dob = new Date(1966, 0, 28, 0, 10, 0);
var daysIn = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var tob = dob.getTime();
var intervalID = -1;

var isIE = (navigator.userAgent.indexOf("MSIE")    != -1);
var isNS = !isIE && (navigator.userAgent.indexOf("Mozilla")    != -1);

function GetAge()
{
	var theDate = new Date();
	var tAge = theDate.getTime() - tob;

	var secs = tAge % 60000;
	tAge -= secs;
	tAge /= 60000;
	secs /= 1000;

	var minutes = tAge % 60;
	tAge -= minutes;
	tAge /= 60;

	var hours = tAge % 24;
	tAge -= hours;
	tAge /= 24;

	var days = tAge;
	var year = 1966;
	var years = 0;
	var daysInYear = 365;

	while (days >= daysInYear) {
		days -= daysInYear;
		if (++year % 4 == 0)
			daysInYear = 366;
		else
			daysInYear = 365;
		years++;
	}

	var months = 0;
	var mon = 1;
	if (year % 4 == 0) daysIn[mon] = 29;
	
	while (days >= daysIn[mon]) {
		days -= daysIn[mon++];
		mon %= 12;
		months++;
	}

	var sAge = years + " Years";

	var sLineFeed = "<BR>";
	
	if (isIE) {
		sLineFeed = "\n";
	}
	else {
		sLineFeed = "<BR>";
	}

	if (months > 0)		sAge += sLineFeed + months + " Months";
	if (days > 0)		sAge += sLineFeed + days + " Days";
	if (hours > 0)		sAge += sLineFeed + hours + " Hours";
	if (minutes > 0)	sAge += sLineFeed + minutes + " Minutes";
	if (secs > 0)		sAge += sLineFeed + secs + " secs";

	return sAge;
}

function GetNSText() 
{
	var s = "";
	
	s += "<head>";
	s += "<link rel=stylesheet href='pagestyle.css' type='text/css'>";
	s += "<link rel=stylesheet href='styles.css' type='text/css'>";
	s += "<SCRIPT SRC='frontpage.js' LANGUAGE='JavaScript1.2'></SCRIPT>";
	s += "</head>";

	s += "<body onLoad='Init();' onResize='Init();' STYLE='background-color:white;'>";
	
	s += "<CENTER><TABLE HEIGHT=100% WIDTH=100%><TR WIDTH=100% HEIGHT=66% VALIGN=MIDDLE>";
	s += "<TD WIDTH=25% ALIGN=LEFT VALIGN=MIDDLE><FONT FACE='Arial' SIZE=2>";

	s += "<CENTER>";
	s += "<A ID='Age' STYLE='position:absolute;'>";
	s += GetAge();
	s += "</A>";
	s += "</CENTER>";
	s += "</FONT></TD><TD ALIGN=MIDDLE VALIGN=MIDDLE>";

	s += "<IMG SRC='portrait.jpg' ALT=\"Yo. This is me. If you don't have a browser capable of loading this picture, think yourself lucky. If you do, \ndon't.\"";
	s += "HSPACE = 20 ALIGN=MIDDLE WIDTH=";
	s += window.innerWidth / 3;
	s += "></TD>";
	s += "<TD WIDTH=10% ALIGN=RIGHT VALIGN=MIDDLE><FONT FACE='Arial' SIZE=2><B>DOB</B></FONT></TD>";
	s += "<TD WIDTH=15% ALIGN=LEFT VALIGN=MIDDLE>: 28/01/66</TD></TR>";
	s += "<TR VALIGN=MIDDLE HEIGHT=33%><TD COLSPAN=4 ALIGN=MIDDLE VALIGN=MIDDLE>";
	s += "This site has scored <img SRC='/cgi-bin/count' ALT='(Theres a hit counter here)' ";
	s += "ALIGN=MIDDLE VSPACE=15> hits to date.	</TD></TR></TABLE>";

	s += "</body>";

	return s;
}

function tick()  {

	clearInterval(intervalID);

	if (navigator.appName.indexOf("Netscape") == -1) {
		var a = self.document.anchors[0];
		a.innerText = GetAge();
	}
	else {
	
		//var s = GetNSText();

		//document.getElementById("Age").firstChild.data = s;
		//document.open();
		//document.write(s);
		//document.close();

		MoveCounter();
	}

	if (isIE) {
		intervalID = window.setInterval("tick()", 100);
	}
	else if (isNS) {
		intervalID = window.setInterval("tick()", 100);
	}
}

function MoveCounter() 
{
	if (isNS) {

		//document.getElementById("Age").left = window.innerWidth / 10;
		//document.getElementById("Age").top = (window.innerHeight * 2/3 - 100) / 2;
	}
}

function Init() {

	if (navigator.appName.indexOf("Netscape") == -1) {
		document.all["portrait"].width = document.body.clientWidth / 2;
	}
	else {
	
	    document.open();
		document.write(GetNSText());
	    document.close();
	}
	
	if (isIE) {
		intervalID = window.setInterval("tick()", 50);
	}
	else if (isNS) {
		intervalID = window.setInterval("tick()", 250);
	}
}
