$(document).ready(function(){
	
	// увлекательный элемент
	//var timeout = 10; // время до сокрытия
	$('#close').click(function(){hideOffer()});
	hideOffer = function() {
		var offer_top = $('#offer').height()+10;
		$('#offer').animate({top: '-'+offer_top+'px'}, 500);
		$('aside').animate({'margin-top': '89px'}, 500);
	}
	// таймер обратного отсчёта
	var d1 = new Date (),
		d2 = new Date (d1);
	d2.setSeconds(d1.getSeconds() + timeout);
	StartCountDown('clock', d2);
	
});


function StartCountDown(obj,myTargetDate) {
	var dthen = new Date(myTargetDate);
	var dnow = new Date();
	ddiff = new Date(dthen-dnow);
	gsecs = Math.floor(ddiff.valueOf()/1000);
	CountBack(obj,gsecs);
}

function Calcage(secs, num1, num2) {
	s = ((Math.floor(secs/num1))%num2).toString();
	if (s.length < 2)
		s = "0" + s;
	return (s);
}

function CountBack(obj, secs) {
	if(secs > 0) {
		$('#'+obj).text(Calcage(secs,1,60));
		setTimeout("CountBack('" + obj + "'," + (secs-1) + ");", 990);
	} else
		hideOffer ();
}
