$(document).ready(function(){

	// function to calculate local time
	// in a different city
	// given the city's UTC offset
	function calcTime(offset) {

		// create Date object for current location
		d = new Date();
		
		// convert to msec
		// add local time zone offset 
		// get UTC time in msec
		utc = d.getTime() + (d.getTimezoneOffset() * 60000);
		
		// create new Date object for different city
		// using supplied offset
		nd = new Date(utc + (3600000*offset));
 
		//return "The local time in " + nd.toLocaleString();
		//return new Date();
		return nd ;

	}


	
	//clock 1
	var aClock = $('#analog-clock');
	var clockWidthHeight = aClock.width();//width and height of the clock
	
	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 = calcTime( '+8') //Mylay Time new
		
		//set the second hand
		var secondAngle = 360/60 * now.getSeconds();//turn the time into angle
		$('#analog-clock #secondHand').rotate(secondAngle, 'abs');//set the hand angle
		$('#analog-clock #secondHand').css( { "left": (clockWidthHeight - $('#secondHand').width())/2 + "px", "top":(clockWidthHeight - $('#analog-clock #secondHand').height())/2 + "px" });
		//set x and y pos

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

	};
	
	startClock();
	
	
	/*
	analog-clock-2
	************************/
	//clock 2
	var bClock = $('#analog-clock-2');
	var bclockWidthHeight = bClock.width();//width and height of the clock
	
	function bstartClock(){
		
		bClock.css({"height":bclockWidthHeight +"px"});//sets the height if .js is enabled. If not, height = 0;
		bClock.fadeIn();//fade it in
		
		//call rotatehands function
		setInterval(function()
		{
		
			brotateHands();
			
		}, 200);//1000 = 1 second
			
		brotateHands();//make sure they start in the right position
		
	}
		
	function brotateHands(){
		
		//get current time/date from local computer
		var bnow = calcTime( '+6.5') //Myanmar Time
		
		//set the second hand
		var bsecondAngle = 360/60 * bnow.getSeconds();//turn the time into angle
		$('#analog-clock-2 #secondHand').rotate(bsecondAngle, 'abs');//set the hand angle
		$('#analog-clock-2 #secondHand').css( { "left": (bclockWidthHeight - $('#analog-clock-2 #secondHand').width())/2 + "px", "top":(bclockWidthHeight - $('#analog-clock-2 #secondHand').height())/2 + "px" });
		//set x and y pos

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

	};
	
	bstartClock();
	
	
	/*
	analog-clock-3
	************************/
	//clock 3
	var cClock = $('#analog-clock-3');
	var cclockWidthHeight = cClock.width();//width and height of the clock
	
	function cstartClock(){
		
		cClock.css({"height":cclockWidthHeight +"px"});//sets the height if .js is enabled. If not, height = 0;
		cClock.fadeIn();//fade it in
		
		//call rotatehands function
		setInterval(function()
		{
		
			crotateHands();
			
		}, 200);//1000 = 1 second
			
		crotateHands();//make sure they start in the right position
		
	}
		
	function crotateHands(){
		
		//get current time/date from local computer
		var cnow = calcTime( '+7') //Bangkok Time
		
		//set the second hand
		var csecondAngle = 360/60 * cnow.getSeconds();//turn the time into angle
		$('#analog-clock-3 #secondHand').rotate(csecondAngle, 'abs');//set the hand angle
		$('#analog-clock-3 #secondHand').css( { "left": (cclockWidthHeight - $('#analog-clock-3 #secondHand').width())/2 + "px", "top":(cclockWidthHeight - $('#analog-clock-3 #secondHand').height())/2 + "px" });
		//set x and y pos

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

	};
	
	cstartClock();	
	
});
