// starting the script on page load
$(document).ready(function(){
	tooltip();
});
/*
 * Tooltip script powered by jQuery (http://www.jquery.com)
 * written by Alen Grakalic (http://cssglobe.com)
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 */
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};
$(function () {
	var remt = new Date();
	remt = new Date(remt.valueOf()+($('#next_update').attr("title"))*1000);
	$('#next_update').countdown({until: remt, compact: true, format: 'MS', description: '', onExpiry: next_update_ok});
	for(i = 1; i <= 8; i++)
		if ($('#call_timeleft_'+i).length)
		{
			var remtime = new Date();
			remtime = new Date(remtime.valueOf()+($('#call_timeleft_'+i).attr("title"))*1000);
			if (i == 1) $('#call_timeleft_'+i).countdown({until: remtime, compact: true, format: 'MS', description: '', onExpiry: call_ok_1});
			if (i == 2) $('#call_timeleft_'+i).countdown({until: remtime, compact: true, format: 'MS', description: '', onExpiry: call_ok_2});
			if (i == 3) $('#call_timeleft_'+i).countdown({until: remtime, compact: true, format: 'MS', description: '', onExpiry: call_ok_3});
			if (i == 4) $('#call_timeleft_'+i).countdown({until: remtime, compact: true, format: 'MS', description: '', onExpiry: call_ok_4});
			if (i == 5) $('#call_timeleft_'+i).countdown({until: remtime, compact: true, format: 'MS', description: '', onExpiry: call_ok_5});
			if (i == 6) $('#call_timeleft_'+i).countdown({until: remtime, compact: true, format: 'MS', description: '', onExpiry: call_ok_6});
			if (i == 7) $('#call_timeleft_'+i).countdown({until: remtime, compact: true, format: 'MS', description: '', onExpiry: call_ok_7});
			if (i == 8) $('#call_timeleft_'+i).countdown({until: remtime, compact: true, format: 'MS', description: '', onExpiry: call_ok_8});
		}
});
function next_update_ok() { var remt = new Date(); remt = new Date(remt.valueOf()+300*1000); $('#next_update').countdown('change', {until: remt}); }
function call_ok_1() { $("#call_time_1").remove(); $("#call_button_1").toggle(); }
function call_ok_2() { $("#call_time_2").remove(); $("#call_button_2").toggle(); }
function call_ok_3() { $("#call_time_3").remove(); $("#call_button_3").toggle(); }
function call_ok_4() { $("#call_time_4").remove(); $("#call_button_4").toggle(); }
function call_ok_5() { $("#call_time_5").remove(); $("#call_button_5").toggle(); }
function call_ok_6() { $("#call_time_6").remove(); $("#call_button_6").toggle(); }
function call_ok_7() { $("#call_time_7").remove(); $("#call_button_7").toggle(); }
function call_ok_8() { $("#call_time_8").remove(); $("#call_button_8").toggle(); }