function CC_noErrors() {return true;}window.onerror = CC_noErrors;
//initial time
	var d1_current = -1;
	var d2_current = -1;
	var h1_current = -1;
	var h2_current = -1;
	var m1_current = -1;
	var m2_current = -1;
	var s1_current = -1;
	var s2_current= -1;


decCache = [],
    decCases = [2, 0, 1, 1, 1, 2];
function decOfNum(number, titles)
{
    if(!decCache[number]) decCache[number] = number % 100 > 4 && number % 100 < 20 ? 2 : decCases[Math.min(number % 10, 5)];
    return titles[decCache[number]];
}	
	
	//----------------------задаем время жизни куки в минутах
function SetCookieForNMinuts(name, value, minuts, path, domain, secure){
 var today = new Date();
 expires = new Date(today.getTime() + minuts * 60 * 1000);
 document.cookie = name + "=" + escape(value) +
 "; expires=" +
 expires.toGMTString() +
 ((path) ? "; path=" + path : "") +
 ((domain) ? "; domain=" + domain : "") +
 ((secure) ? "; secure" : "");
}
 
//возвращает значение параметра на основании его имени
function GetCookieValueByName(name){
 var beg = document.cookie.indexOf(name + "=");
 if (beg == -1)
 return false;
 
 var end = document.cookie.indexOf(";", beg + name.length);
 if (end == -1)
 end = document.cookie.length;
 
 return unescape(document.cookie.substring(beg + name.length + 1, end));
}
	
	
		
	function flip (upperId, lowerId, changeNumber, pathUpper, pathLower){
		
		var hostus = 'http://www.plastika-okon.ru/fileadmin/templates/plastika/css/img/';
		var uperA = $(upperId);
		var lowerB = $(lowerId);
	
		var upperBackId = upperId+"Back";
		var upperBackBB = $(upperBackId);
		
		uperA.attr('src', upperBackBB.attr('src'));
		uperA.css("height", "52px");
		uperA.css("visibility", "visible");
		if($.browser.msie && $.browser.version == '6.0'){
 			var formats = ".gif";
		} else {
			var formats = ".png";
		}
		upperBackBB.attr('src', hostus+pathUpper+parseInt(changeNumber)+formats);
		
		lowerB.attr('src', hostus+pathLower+parseInt(changeNumber)+formats);
		lowerB.css("height", "0px");
		lowerB.css("visibility", "visible");
		
		
		
	
	uperA.stop().animate({height: "0px"}, 200, function(){
			lowerB.stop().animate({height: "52px"}, 200, function(){
				lowerBackId = lowerId+"Back";				
				$(lowerBackId).attr('src', lowerB.attr('src'));
				lowerB.css("visibility", "hidden");
				uperA.css("visibility", "hidden");
			});
			
		});


		
		if($.browser.msie && $.browser.version == '6.0'){
 			DD_belatedPNG.fix('.b-time img');
		}
		
	}//flip
				
	
	function retroClock(yr, m, d, nnn, bbb){
		


var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

    cdyear = yr;
    cdmonth = m;
    cdday = d;
    var today = new Date();
    var todayy = today.getYear();
    if (todayy < 1000) todayy += 1900;
    var todaym = today.getMonth();
    var todayd = today.getDate();
    var todayh = today.getHours();
    var todaymin = today.getMinutes();
    var todaysec = today.getSeconds();
    var todaystring = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec;
    futurestring = montharray[m - 1] + " " + d + ", " + yr
    dd = Date.parse(futurestring) - Date.parse(todaystring);
    dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1);
    dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
    dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
    dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);

		d1 = Math.floor(dday / 10);
		 d2 = Math.floor(dday % 10);
		h1 = Math.floor(dhour / 10);
		 h2 = Math.floor(dhour % 10);
		 m1 = Math.floor(dmin / 10);
		 m2 = Math.floor(dmin % 10);
		 s1 = Math.floor(dsec / 10);
		 s2 = Math.floor(dsec % 10);
		 
		 if(GetCookieValueByName('kolokonfull') !== false && GetCookieValueByName('kolokonfull') !== '0'){
		 	var kolokonfull = GetCookieValueByName('kolokonfull');
		 }	else {
		 	var kolokonfull = dday * 12;
		 	SetCookieForNMinuts('kolokonfull', kolokonfull,30);
		 }
		 
		var okonvar = decOfNum(parseInt(kolokonfull), ['0', '1', '2']);
		if(okonvar == '2'){
			bbb.css('visibility', 'visible');
		} else {
			bbb.css('visibility', 'hidden');
		}
		nnn.text(kolokonfull); 
		Cufon.replace('.n-okna', {textShadow: '0px 1px #ff8a40'});
		
		 //change pads
		 
		  if( d2 != d2_current){
			flip('#daysUpRight', '#daysDownRight', d2, 'double/Up/Right/', 'double/Down/Right/');
			d2_current = d2;
			
			flip('#daysUpLeft', '#daysDownLeft', d1, 'double/Up/Left/', 'double/Down/Left/');
			d1_current = d1;
		}
		 
		 if( h2 != h2_current){
			flip('#hoursUpRight', '#hoursDownRight', h2, 'double/Up/Right/', 'double/Down/Right/');
			h2_current = h2;
			
			flip('#hoursUpLeft', '#hoursDownLeft', h1, 'double/Up/Left/', 'double/Down/Left/');
			h1_current = h1;
		}
		
		if( m2 != m2_current){
			flip('#minutesUpRight', '#minutesDownRight', m2, 'double/Up/Right/', 'double/Down/Right/');
			m2_current = m2;
			
			flip('#minutesUpLeft', '#minutesDownLeft', m1, 'double/Up/Left/', 'double/Down/Left/');
			m1_current = m1;
		}
		
		 if (s2 != s2_current){
			flip('#secondsUpRight', '#secondsDownRight', s2, 'double/Up/Right/', 'double/Down/Right/');
			s2_current = s2;
			
			flip('#secondsUpLeft', '#secondsDownLeft', s1, 'double/Up/Left/', 'double/Down/Left/');
			s1_current = s1;
		}
		
		
		
			
		
	}



$(document).ready(function(){
	
		colishokon = $('.okon');
		nnnokna = $('.n-okna');
		setInterval('retroClock(2012, 01, 01, nnnokna, colishokon)', 1000);
	
			
});	
