function clockTimer()
{
	if( (window.clockValue == 0) || (window.clockTicks == 120) ) {
		$.ajaxSetup({
		  url: "clock_sync",
		  type: "GET",
		  async: false
		});
		$.ajax({
			success: function(data){
				window.clockValue = data;
			}
		});
		/*
		$.get('clock_sync',{},
		function (data, textStatus) {
			
		});*/
	}
	var newDate = new Date( );
	newDate.setTime( parseInt(window.clockValue) * 1000 );
	dateString = newDate.toUTCString();
	
	//ALL +1 for summer time
	var offset_ny = -4*3600;
	var offset_hk = 8*3600;
	var offset_ld = 1*3600;
	var offset_tk = 9*3600;
	var offset_dj = 4*3600;
	var offset_fr = 2*3600;
	var offset_wr = 2*3600;
	

	newDate.setTime( (parseInt(window.clockValue) + offset_ny) * 1000 );
	var time_ny = (newDate.getUTCHours() < 10 ?"0":"") + newDate.getUTCHours() + ":" + (newDate.getUTCMinutes() < 10?"0":"") + newDate.getUTCMinutes() + ":" + (newDate.getUTCSeconds() < 10?"0":"") + newDate.getUTCSeconds();
	
	newDate.setTime( (parseInt(window.clockValue) + offset_hk) * 1000 );
	var time_hk = (newDate.getUTCHours() < 10 ?"0":"") + newDate.getUTCHours() + ":" + (newDate.getUTCMinutes() < 10?"0":"") + newDate.getUTCMinutes() + ":" + (newDate.getUTCSeconds() < 10?"0":"") + newDate.getUTCSeconds();
	
	newDate.setTime( (parseInt(window.clockValue) + offset_ld) * 1000 );
	var time_ld = (newDate.getUTCHours() < 10 ?"0":"") + newDate.getUTCHours() + ":" + (newDate.getUTCMinutes() < 10?"0":"") + newDate.getUTCMinutes() + ":" + (newDate.getUTCSeconds() < 10?"0":"") + newDate.getUTCSeconds();
	
	newDate.setTime( (parseInt(window.clockValue) + offset_tk) * 1000 );
	var time_tk = (newDate.getUTCHours() < 10 ?"0":"") + newDate.getUTCHours() + ":" + (newDate.getUTCMinutes() < 10?"0":"") + newDate.getUTCMinutes() + ":" + (newDate.getUTCSeconds() < 10?"0":"") + newDate.getUTCSeconds();
	
	newDate.setTime( (parseInt(window.clockValue) + offset_dj) * 1000 );
	var time_dj = (newDate.getUTCHours() < 10 ?"0":"") + newDate.getUTCHours() + ":" + (newDate.getUTCMinutes() < 10?"0":"") + newDate.getUTCMinutes() + ":" + (newDate.getUTCSeconds() < 10?"0":"") + newDate.getUTCSeconds();
	
	newDate.setTime( (parseInt(window.clockValue) + offset_fr) * 1000 );
	var time_fr = (newDate.getUTCHours() < 10 ?"0":"") + newDate.getUTCHours() + ":" + (newDate.getUTCMinutes() < 10?"0":"") + newDate.getUTCMinutes() + ":" + (newDate.getUTCSeconds() < 10?"0":"") + newDate.getUTCSeconds();
	
	newDate.setTime( (parseInt(window.clockValue) + offset_wr) * 1000 );
	var time_wr = (newDate.getUTCHours() < 10 ?"0":"") + newDate.getUTCHours() + ":" + (newDate.getUTCMinutes() < 10?"0":"") + newDate.getUTCMinutes() + ":" + (newDate.getUTCSeconds() < 10?"0":"") + newDate.getUTCSeconds();
	
	$('#ny').html(time_ny);
	$('#hk').html(time_hk);
	$('#ld').html(time_ld);
	$('#tk').html(time_tk);
	$('#dj').html(time_dj);
	$('#fr').html(time_fr);
	$('#wr').html(time_wr);
	
	window.clockValue = parseInt(window.clockValue) + 1;
	window.clockTicks = parseInt(window.clockTicks) + 1;;
	
	t=setTimeout("clockTimer()",1000);
}

$(function($) {
	window.clockValue = 0;
	window.clockTicks = 0;
	clockTimer();
	
	

/*
    var options_ny={
        utc: true,
        utc_offset: -4
    };
    var options_hk={
        utc: true,
        utc_offset: 8
    };var options_ld={
        utc: true,
        utc_offset: 1
    };var options_tk={
        utc: true,
        utc_offset: 9
    };var options_dj={
        utc: true,
        utc_offset: 4
    };var options_fr={
        utc: true,
        utc_offset: 2
    };var options_wr={
        utc: true,
        utc_offset: 2
    };
    $('#ny').jclock(options_ny);
    $('#hk').jclock(options_hk);
    $('#ld').jclock(options_ld);
    $('#tk').jclock(options_tk);
    $('#dj').jclock(options_dj);
    $('#fr').jclock(options_fr);
    $('#wr').jclock(options_wr);
*/
});
