//This clock steals timing relations from the famous pardusclock by Spoilerhead
//http://stud3.tuwien.ac.at/~e0326004/pardus/pardusclock/onlineclock/clock.html
//
//Spoilerheads script is licenced under GPL2, so I guess this is also ;)
//
// - Shingouz Team
//
//Usage:
/*
<script type="text/javascript" src="clock.js"></script>
<script type="text/javascript">
function startShingouzClock(){
	var c = new ShingouzClock;
  	document.getElementById("my_tim").innerHTML = c.getTime();
  	document.getElementById("my_gmt").innerHTML = c.getGMT();
  	document.getElementById("my_ap").innerHTML = c.getAPS();
	document.getElementById("my_bui").innerHTML = c.getBuildingTime();
	document.getElementById("my_pl").innerHTML = c.getPLTime();
	document.getElementById("my_sb").innerHTML = c.getStarbaseTime();

	setTimeout("startShingouzClock()",1000)
}
</script>
<body onload="startShingouzClock()">
*/

function ShingouzClock(){
	this.time = new Date;
	this.pardus_time = this.getPardusTime();
}

ShingouzClock.prototype.prettyTime = function(h,m,s){
	//pad with zeroes if needed
	hours = (h > 9) ? "" + h : "0" + h;
	minutes = (m > 9) ? "" + m : "0" + m;
	seconds = (s > 9) ? "" + s : "0" + s;

	return hours + ":" + minutes + ":" + seconds;
}

ShingouzClock.prototype.getPardusTime = function(){
	// Return the pardus-time, which is 25 minutes late
	var my_time = new Date;
	var hours = my_time.getHours();
	var minutes = my_time.getMinutes();

	var min = minutes - 25;
	if( min < 0 )
	{
		min += 60;
		hours--;
	}

	if( hours < 0 )
	{
		hours = 23;
	}

	my_time.setMinutes(min);
	my_time.setHours(hours);

	return my_time;
}

ShingouzClock.prototype.getTime = function(){
	var hours = this.time.getHours() % 24;
	var minutes = this.time.getMinutes();
	var seconds = this.time.getSeconds();

	return this.prettyTime(hours, minutes, seconds);
}

ShingouzClock.prototype.getGMT = function(){
	var gmtHours = this.time.getTimezoneOffset()/60;
	var hours = (this.time.getHours()+gmtHours) % 24;
	var minutes = this.time.getMinutes();
	var seconds = this.time.getSeconds();

	return this.prettyTime(hours, minutes, seconds);
}

ShingouzClock.prototype.getAPS = function(){
	var hours = 0;
	var minutes = 5 - this.time.getMinutes() % 6;
	var seconds = 59 - this.time.getSeconds();

	return this.prettyTime(hours, minutes, seconds);
}

ShingouzClock.prototype.getBuildingTime = function(){
	var gmtHours = this.pardus_time.getTimezoneOffset()/60;
	var hours = this.pardus_time.getHours();
	var minutes = 59 - this.pardus_time.getMinutes();
	var seconds = 59 - this.pardus_time.getSeconds();

	hours += (gmtHours + 5);
	hours = 5 - (hours % 6);

	return this.prettyTime(hours, minutes, seconds);
}

ShingouzClock.prototype.getPLTime = function(){
	var gmtHours = this.pardus_time.getTimezoneOffset()/60;
	var hours = this.pardus_time.getHours();
	var minutes = 59 - this.pardus_time.getMinutes();
	var seconds = 59 - this.pardus_time.getSeconds();

	hours += (gmtHours + 5);
	hours = 2 - ((hours + 2) % 3);

	return this.prettyTime(hours, minutes, seconds);
}

ShingouzClock.prototype.getStarbaseTime = function(){
	var gmtHours = this.pardus_time.getTimezoneOffset()/60;
	var hours = this.pardus_time.getHours();
	var minutes = 59 - this.pardus_time.getMinutes();
	var seconds = 59 - this.pardus_time.getSeconds();

	hours += (gmtHours + 5);
	hours = 2 - ((hours + 1) % 3);

	return this.prettyTime(hours, minutes, seconds);
}
