$(document).ready(function(){
	
	var aClock = $('#analog-clock');
	var clockWidthHeight = 120; // hardcode for safety reasons aClock.width();//width and height of the clock
	if (clockWidthHeight == null)
		return;
			
	function startClock(){
		
		aClock.css({"height":clockWidthHeight +"px"});//sets the height if .js is enabled. If not, height = 0;
		aClock.fadeIn();//fade it in
		
		//call rotatehands function
		setInterval(function(){
		
			rotateHands();
			
		}, 200);//1000 = 1 second
			
		rotateHands();//make sure they start in the right position
	}
		
	function rotateHands(){
		
		//get current time/date from local computer
		var now = new Date();
		
		//set the second hand
		var secondAngle = 360/60 * now.getSeconds();//turn the time into angle
		$('#secondHand').rotate(secondAngle, 'abs');//set the hand angle
		$('#secondHand').css( { "left": (clockWidthHeight - $('#secondHand').width())/2 + "px", "top":(clockWidthHeight - $('#secondHand').height())/2 + "px" });//set x and y pos

		//set the minute hand
		var minuteAngle = 360/60 * now.getMinutes();//turn the time into angle
		$('#minuteHand').rotate(minuteAngle, 'abs');//set the hand angle
		$('#minuteHand').css( { "left": (clockWidthHeight - $('#minuteHand').width())/2 + "px", "top":(clockWidthHeight - $('#minuteHand').height())/2 + "px" });//set x and y pos
		
		//set the hour hand
		var hourAngle = 360/12 * now.getHours();//turn the time into angle
		$('#hourHand').rotate((hourAngle + minuteAngle/12)%360, 'abs');//set the hand angle
		$('#hourHand').css( { "left": (clockWidthHeight - $('#hourHand').width())/2 + "px", "top":(clockWidthHeight - $('#hourHand').height())/2 + "px" });//set x and y pos

		fix_side_bars();
	};
	
	function startDate() {
		
		var days = ["Nedelja", "Ponedeljak", "Utorak", "Sreda", "Četvrtak", "Petak", "Subota", "Nedelja"];

		var today	= new Date();
		var day		= today.getDate();
		var month	= today.getMonth() + 1;
		var year	= today.getYear();
		var weekday = today.getDay();
		var hour 	= today.getHours();
		var minute	= today.getMinutes();
		var second	= today.getSeconds();

		if (year < 2000) // Y2K Fix, Isaac Powell - http://onyx.idbsu.edu/~ipowell
			year = year + 1900;

		if (month	<= 9) month = "0" + month;
		if (day		<= 9) day = "0" + day;
		if (hour	<= 9) hour = "0" + hour;
		if (minute	<= 9) minute = "0" + minute;
		if (second	<= 9) second = "0" + second;

		time = days[weekday] + ", " + day + "." + month + "." + year;

		document.getElementById("time_text").innerHTML=time;
		//~ window.setTimeout("startDate();", 500);
	}	
	
	startClock();
	startDate();
});
