var currentSecsR = 0;
var currentMinR = 0;
var currentHourR = 0;

function rotateObject(obj, deg) {
	$(obj).rotate(deg);
}

function updateTime() {
	// setup new date object, and get current time in hours, minutes and seconds
	currentTime = new Date();
	currentHours = currentTime.getHours();
	if (currentHours > 12) currentHours -= 12;
	currentMins = currentTime.getMinutes();
	currentSecs = currentTime.getSeconds();
	// write it to a div so we can see the time
	//document.getElementById('theTime').innerHTML = currentHours+':'+currentMins+':'+currentSecs;
	
	// calculate rotations for the hands based on current time
	currentSecsR = currentSecs*6; // set rotation for second hand
	currentMinR = currentMins*6; // set rotation for minute hand
	currentHourR = currentHours*30; // set rotation for hour hand (12 hour clock)
	
	// call the function to rotate the hands rotate the hands
	rotateObject('#second', currentSecsR);
	rotateObject('#minute', currentMinR);
	rotateObject('#hour', currentHourR);
	
	// run the function again after 1 second
	setTimeout(updateTime, 1000);
}

$(document).ready(function() {
	updateTime();
});
