function makeTime (resultArray, diff, dir)
{
	var currentHours = resultArray[0];
	var currentMinutes = resultArray[1];
	
	if(dir == "+")
	{
		currentHours = parseInt(currentHours) + parseInt(diff);
		if(currentHours > 23)
			currentHours = currentHours - 24 ;
	}	
	else if(dir == "-")
	{
		currentHours = parseInt(currentHours) - parseInt(diff);	
		if(currentHours < 0)
			currentHours = currentHours + 24 ;
	}
	currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
	currentHours = ( currentHours < 10 ? "0" : "" ) + currentHours;
	var currentTimeString = currentHours + ":" + currentMinutes ;
	return currentTimeString ;
}

function setClocks ()
{	
	var scriptUrl = "http://www.union-transport.com/gettime.php";
	var result = null; 			// Result of AJAX
	var clocksArray = new Array(9);		// Clock array
	
	$.ajax({
		url: scriptUrl,
		type: 'get',
		cache: false,
		dataType: 'html',
		async: false,
		success: function(data) { result = data.split(":"); }
	});
	
	clocksArray[0] = makeTime(result, 5, "-");		// New York
	clocksArray[1] = makeTime(result, 0, "+");		// London
	clocksArray[2] = makeTime(result, 1, "+");		// Amsterdam
	clocksArray[3] = makeTime(result, 3, "+");		// Moscow
	clocksArray[4] = makeTime(result, 3, "+");		// Dubai
	clocksArray[5] = makeTime(result, 4, "+");		// India
	clocksArray[6] = makeTime(result, 7, "+");		// Singapore
	clocksArray[7] = makeTime(result, 8, "+");		// Tokyo
	clocksArray[8] = makeTime(result, 9, "+");		// Sydney
	
	return clocksArray;
 }
function makeClocks()
{
	var clockArray = setClocks();
	$('#newyork').html('NEW YORK '+clockArray[0]);
	$('#london').html('LONDON '+clockArray[1]);
	$('#amsterdam').html('AMSTERDAM '+clockArray[2]);
	$('#moscow').html('MOSCOW '+clockArray[3]);
	$('#dubai').html('DUBAI '+clockArray[4]);
	$('#india').html('INDIA '+clockArray[5]);
	$('#singapore').html('SINGAPORE '+clockArray[6]);
	$('#tokyo').html('TOKYO '+clockArray[7]);
	$('#sydney').html('SYDNEY '+clockArray[8]);
	
	
}
$(document).ready(function()
{
	makeClocks();
	setInterval(makeClocks,10000);
})
