var lastlen = 0;

// Get later time
$(document).ready(function() {
	$.get("/check.php?p=getTimer", function(data){
		getTime(parseFloat(data));
	});
	window.setTimeout("updateFeatured();", 10000);
	
	$("#facebook").hover(
	function(){
		$(this).animate({ right: "0" }, {queue:false, duration:"normal"} );
	},
	function(){
		$(this).animate({ right: "-197" }, {queue:false, duration:"normal"} );
	});
	
});


function getTime(later) {

if(later % 300 == 0 && later > 0)
{
	$.get("/check.php?p=getTimer", function(data){
		later = parseFloat(data);
	});
}

if(later >= 0){
		window.setTimeout("getTime(" + (later - 1) + ");", 1000);
}

var days = later / 60 / 60 / 24;
var daysRound = Math.floor(days);

var hours = later / 60 / 60;
var hoursRound = Math.floor(hours);

var hours2 = later / 60 / 60 - (24 * daysRound);
var hoursRound2 = Math.floor(hours2);

var minutes = later / 60 - (24 * 60 * daysRound) - (60 * hoursRound2);
var minutesRound = Math.floor(minutes);
var seconds = later - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound2) - (60 * minutesRound);
var secondsRound = Math.round(seconds);

if(hoursRound < 0 || minutesRound < 0 || secondsRound < 0){
	document.getElementById('hours').innerHTML = "0";
	document.getElementById('minutes').innerHTML = "0";
	document.getElementById('seconds').innerHTML = "0";
}else{
	document.getElementById('hours').innerHTML = hoursRound;
	document.getElementById('minutes').innerHTML = minutesRound;
	document.getElementById('seconds').innerHTML = secondsRound;
}

}



// Featured
function updateFeatured()
{
	$.get("/check.php?p=getRandFeatured", function(data){
		if(lastlen != data.length)
		{
			$('#server').fadeOut(500, function(){
				$('#server').html(data);
				$('#server').fadeIn(500);
			});
			
			lastlen = data.length;
		}
		
		window.setTimeout("updateFeatured();", 10000);
	});
}

function showDialog()
{
	$('#dialogBox').attr("title", "OtsList.eu Ads");
	$('#dialogBox').dialog({ width: 800, resizable: false });
	$('#dialogBox').html('<center><h1>Loading...</h1><img src="http://otslist.eu/images/ajax_loader.gif"/></center>');
	$('#dialogBox').load("http://otslist.eu/check.php?p=showDialog");
}

function showCreator(id)
{
	$('#otslist_aac').attr("title", "OtsList.eu Account Creator");
	$('#otslist_aac').dialog({ resizable: false, width: 400, height: 150, position: 'center' });
	$('#otslist_aac').html('<center><h3>Loading...</h3><img src="http://otslist.eu/images/ajax_loader.gif"/></center>');
	$('#otslist_aac').load("http://otslist.eu/check.php?p=initAacCreator&ots=" + id );
}

function showTimerBuy()
{
	$('#dialogBox').attr("title", "Purchase Countdown on OtsList.eu");
	$('#dialogBox').dialog({ resizable: false, width: 420, height: 450, position: 'center' });
	$('#dialogBox').html('<center><h3>Loading...</h3><img src="http://otslist.eu/images/ajax_loader.gif"/></center>');
	$('#dialogBox').load("http://otslist.eu/check.php?p=initPurchaseCountdown");
}

jQuery.fn.swap = function(b){
    b = jQuery(b)[0];
    var a = this[0];
    var t = a.parentNode.insertBefore(document.createTextNode(''), a);
    b.parentNode.insertBefore(a, b);
    t.parentNode.insertBefore(b, t);
    t.parentNode.removeChild(t);
    return this;
};

function zamien(id1, id2)
{
	// $('#ots_' + id1).quicksand( $('#ots_' + id2 + ' div'));
	$('#ots_8150').swap( $('#ots_7680') );
}

//  End -->