$(document).ready(function()
{
	//use javascript to close the divs so if deactivated the divs will still be visible
	$("#services dd").hide();

	//set the background to display the +
	$("#services dt").css('cursor','pointer');

	url = ""+window.location;
	
	url = url.split('#');
	
	if(anchor = url[1])
	{
		$("#" + anchor).parent().next().show();
		$("#" + anchor).parent().css('cursor','auto').css('background-position', 'top left');
	}
	else
	{
		//Show the first dd on page opening
		$("#services dd:first").show();

		//set the background to open
		$("#services dt:first").css('cursor','auto').css('background-position', 'top left');

		//when click on the dt: close every previous opened dd, change their style, open the next children (dd), change its background.
	}
	
	$("#services dt").click(function()
	{
		if(!$(this).next().is(':visible')) {
			$("#services dd").hide();
			$("#services dt").css('cursor','pointer').css('background-position', 'bottom left');
		}
		$(this).css('background-position', 'top left').css('cursor','auto').next().show();
	});
	
	UpdateTime();
	
});

$(window).unload( function () { 
		if(clock) 
		{
			clearTimeout(clock);
			clock = 0;
		} 
	} 
);


var clock = 0;
var tDate = 0;

function UpdateTime() 
{
	tDate = 0;

	if(clock) 
	{
		clearTimeout(clock);
		clock  = 0;
	}
	
	tDate = new Date();
	
	hours = tDate.getHours();
	minutes = (tDate.getMinutes() < 10) ? "0"+tDate.getMinutes() : tDate.getMinutes();

	yourTime = hours+":" +minutes;

	$.get("/wp-content/themes/closeup/clock.php", function(data){
		mineTime = data;
		updateDisplay(mineTime, yourTime);
	});

	clock = setTimeout("UpdateTime()", 30000);
}

function updateDisplay(mineTime, yourTime)
{
	$('#yours').html(yourTime);
	$('#mine').html(mineTime);
	
	if(parseFloat(mineTime) < 8 || parseFloat(mineTime) > 19)
	{
		$('#clock').css('background-position', 'bottom right');
	}
	
}













