// главная функция вызова: function getTimer(timname) . редактировать ее для установки нужных таймеров
function calcage(secs, num1, num2)
{
	s = ((Math.floor(secs/num1))%num2).toString();
	if (LeadingZero && s.length < 2) s = "0" + s;
	return "<b>" + s + "</b>";
}

function CountBack(secs, span_id_element)
{
	if (secs < 0)
	{
		document.getElementById(span_id_element).innerHTML = FinishMessage;
		return;
	}
	DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
	DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
	DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
	DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));
	
	document.getElementById(span_id_element).innerHTML = DisplayStr;
	if (CountActive) setTimeout("CountBack(" + (secs+CountStepper) + ", '"+span_id_element+"')", SetTimeOutPeriod);
}

function putspan(span_id_element, id_element, text_string, link)
{
	document.getElementById(id_element).innerHTML=text_string+'<br><a style="color:white;" href="'+link+'"><span id="'+span_id_element+'"></span></a>';
}

function Counter(id_element,text_string,link)
{
	if (typeof(TargetDate) == "undefined") TargetDate = "12/31/2020 5:00 AM";
	if (typeof(DisplayFormat) == "undefined") DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
	if (typeof(CountActive) == "undefined") CountActive = true;
	if (typeof(FinishMessage) == "undefined") FinishMessage = "";
	if (typeof(CountStepper) != "number") CountStepper = -1;
	if (typeof(LeadingZero) == "undefined") LeadingZero = true;

	var dnow = new Date();
	if (typeof(NowDate) != "undefined")
		dnow = new Date(NowDate);
	
	CountStepper = Math.ceil(CountStepper);
	if (CountStepper == 0) CountActive = false;
	SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990;
	
	span_id_element = id_element+Math.round(Math.random()*10000);
	putspan(span_id_element,id_element,text_string,link);
	
	var dthen = new Date(TargetDate);
	if(CountStepper > 0) ddiff = new Date(dnow - dthen);
	else ddiff = new Date(dthen - dnow);
	gsecs = Math.floor(ddiff.valueOf()/1000);
	CountBack(gsecs, span_id_element);
}
function getTimer(timname) {
 if(timname){
  switch(timname){
/*   case 'ny-2012':
    r=decodeURI('%D0%A0%D0%B5%D0%B3%D0%B8%D1%81%D1%82%D1%80%D0%B0%D1%86%D0%B8%D1%8F%20%D0%BE%D1%82%D0%BA%D1%80%D1%8B%D1%82%D0%B0!%3Cbr%3E%D0%9A%D1%83%D0%BF%D0%B8%D1%82%D1%8C%20%D1%81%D0%B5%D0%BC%D0%B8%D0%BD%D0%B0%D1%80%20%D0%BC%D0%BE%D0%B6%D0%BD%D0%BE%20%D0%B5%D1%89%D0%B5%20%D0%B2%20%D1%82%D0%B5%D1%87%D0%B5%D0%BD%D0%B8%D0%B5:');
    TargetDate = (12)+'/'+(15)+'/'+2011+' 23:59:59';
	link='http://marina-shevchenko.ru/news/ny-2012';
    break;
  case 'main': // для показа везде на всех страницах
    r=decodeURI('%D0%A0%D0%B5%D0%B3%D0%B8%D1%81%D1%82%D1%80%D0%B0%D1%86%D0%B8%D1%8F%20%D0%BE%D1%82%D0%BA%D1%80%D1%8B%D1%82%D0%B0!%3Cbr%3E%D0%9A%D1%83%D0%BF%D0%B8%D1%82%D1%8C%20%D1%81%D0%B5%D0%BC%D0%B8%D0%BD%D0%B0%D1%80%20%D0%BC%D0%BE%D0%B6%D0%BD%D0%BE%20%D0%B5%D1%89%D0%B5%20%D0%B2%20%D1%82%D0%B5%D1%87%D0%B5%D0%BD%D0%B8%D0%B5:');
    TargetDate = (12)+'/'+(15)+'/'+2011+' 23:59:59';
	link='http://marina-shevchenko.ru/news/ny-2012';
    break;*/
   default:
    r='none';
  }
  if(r!='none'){
   id='timerbody'+Math.floor(Math.random()*8999+1000)
   s='<div style="border:#a20204 3px solid; cursor:pointer" onclick="location.href=\''+link+'\'"><div style="border:#fff 3px solid;padding:5px;background:#a20204;text-align:center;font-size:20px;color:#fff;" id="'+id+'"></div></div>';
   document.write(s)
   NowDateD = new Date();
   NowDate = (NowDateD.getMonth()+1)+'/'+NowDateD.getDate()+'/'+NowDateD.getFullYear()+' '+NowDateD.getHours()+':'+NowDateD.getMinutes()+':'+NowDateD.getSeconds();
   DisplayFormat = decodeURI("%25%25D%25%25%20%D0%B4%D0%BD.%20%25%25H%25%25%20%D1%87.%20%25%25M%25%25%20%D0%BC%D0%B8%D0%BD.%20%D0%B8%20%25%25S%25%25%20%D1%81%D0%B5%D0%BA.");
   FinishMessage = decodeURI("%D0%9F%D0%BE%D0%BA%D1%83%D0%BF%D0%BA%D0%B0%20%D0%BE%D1%82%D0%BA%D1%80%D1%8B%D1%82%D0%B0!");
   Counter(id,r,link);
  }
 }
}
