$(document).ready(function(){
	
	var aClock2 = $('#clock2');
	var clockWidthHeight2 = aClock2.width();//width and height of the clock
	
	function startClock2(){
		
		aClock2.css({"height":clockWidthHeight2 +"px"});//sets the height if .js is enabled. If not, height = 0;
		aClock2.show();//fade it in
		
		//call rotatehands function
		setInterval(function(){
		
			rotateHands2();
			
		}, 200);//1000 = 1 second
			
		rotateHands2();//make sure they start in the right position
		
	}
		
	function rotateHands2(){
		
		//get current time/date from local computer
		var now2 = new Date();
		var london = now2.toGMTString();
		var curdate = new Date();
		var offset = curdate.getTimezoneOffset()/60;
		var london = now2.getHours() +offset ;
		
		// helle Uhr oder dunkle Uhr
		var stunde2 = london;
		 if (stunde2 > 6 && stunde2 < 18) {
			 $("#bg2").attr("src","img/clockBg_tag.png"); 
			 $("#hourHand2").attr("src","img/hourHand_tag.png"); 
			 $("#minuteHand2").attr("src","img/minuteHand_tag.png"); 
		 }
		 else {
		     $("#bg2").attr("src","img/clockBg_nacht.png"); 
			 $("#hourHand2").attr("src","img/hourHand_nacht.png"); 
			 $("#minuteHand2").attr("src","img/minuteHand_nacht.png"); 
		 }

		/*//set the second hand
		var secondAngle2 = 360/60 * now2.getSeconds();//turn the time into angle
		$('#secondHand2').rotate(secondAngle2, 'abs');//set the hand angle
		$('#secondHand2').css( { "left": (clockWidthHeight2 - $('#secondHand2').width())/2 + "px", "top":(clockWidthHeight2 - $('#secondHand2').height())/2 + "px" });//set x and y pos*/

		//set the minute hand
		var minuteAngle2 = 360/60 * now2.getMinutes();//turn the time into angle
		$('#minuteHand2').rotate(minuteAngle2, 'abs');//set the hand angle
		$('#minuteHand2').css( { "left": (clockWidthHeight2 - $('#minuteHand2').width())/2 + "px", "top":(clockWidthHeight2 - $('#minuteHand2').height())/2 + "px" });//set x and y pos
		
		//set the hour hand
		var hourAngle2 = 360/12 * london;//turn the time into angle
		$('#hourHand2').rotate((hourAngle2 + minuteAngle2/12)%360, 'abs');//set the hand angle
		$('#hourHand2').css( { "left": (clockWidthHeight2 - $('#hourHand2').width())/2 + "px", "top":(clockWidthHeight2 - $('#hourHand2').height())/2 + "px" });//set x and y pos

	};
	
	startClock2();
	
	
});

