$(document).ready(function(){
	
	var clockWidth = 100;//width and height of the clock
	
	//add all the images to the page
	$('#analog-clock').append("<img id='bg' src='images/clockBg.png' width='100px' height='100px' alt='clock face' /><img id='hourHand' src='images/hourHand.png' alt='hour hand' /><img id='minuteHand' src='images/minuteHand.png' alt='minute hand' /><img id='secondHand' src='images/secondHand.png'  alt='second hand' />");
	
	var secondHand = $('#secondHand');
	
	//call rotatehands function every second (1000 ms)
	setInterval(function(){
	
		rotateHands();
		
	}, 1000);
		
	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": (clockWidth - $('#secondHand').width())/2 + "px", "top":(clockWidth - $('#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": (clockWidth - $('#minuteHand').width())/2 + "px", "top":(clockWidth - $('#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": (clockWidth - $('#hourHand').width())/2 + "px", "top":(clockWidth - $('#hourHand').height())/2 + "px" });//set x and y pos

	};
	
	
});
