function startTime()	{
	var JSclock=document.getElementById('JSclock');
	if (JSclock) {
		var today=new Date();
		var h=today.getHours();
		var m=today.getMinutes();
		var s=today.getSeconds();
		m=addZero(m);
		s=addZero(s);
		JSclock.innerHTML=h+":"+m+":"+s;
		setTimeout('startTime()',1000);
	}
}

function addZero(i)	{ 
	if (i<10) i="0" + i; 
	return i; 
}

function getCookie(c_name)	{
	if (document.cookie.length>0)	{
		var c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)	{ 
			c_start=c_start + c_name.length+1 ;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

function setCookie(c_name,value,expiredays)	{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";path=/; expires="+exdate.toGMTString());
}

Slimbox.scanPage = function() {
	var links = $$("a").filter(function(el) {
		return el.rel && el.rel.test(/^lightbox/i);
	});
	$$(links).slimbox({
			counterText: "{x}/{y}"
		}
		, null
		, function(el) {
			return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));	
//			return (this == el) || (this.rel.length > 8);
	});
};

var cur_lang;
window.addEvent("domready", function () {
	Slimbox.scanPage();
	
	document.body.className = document.body.className.replace(/jsOFF/gi, "jsON");
	cur_lang = document.getElementsByTagName('html')[0].lang;
	
	switch (document.body.id) {
		case 'home':
		break;
		case 'contacts-form':
		break;
		case 'contacts':
		break;
	}
	
	var ContTopHeught;
	(function(){
		ContTopHeught = getCookie('content_top_height') || 456;
		if (Browser.Engine.trident4) return false;
		var cur_op, css_class;
		if (ContTopHeught == 456) {
			cur_op = 1;
			css_class = 'opened';
		} else {
			cur_op = 0
			css_class = 'closed';
		}
		
		var ctop_fx = new Fx.Morph('content_top', {
			duration: 600
		  , transition: Fx.Transitions.Cubic.easeOut
		});
		var fbox_fx = new  Fx.Morph('feetbox', {
			duration: 600
		  , transition: Fx.Transitions.Cubic.easeOut
		});
		ctop_fx.set({'height':ContTopHeught});
		if (Browser.Engine.trident) fbox_fx.set({'opacity':cur_op});
		
		var arrw = $('feetbox_arrow');
		arrw.className=css_class;
		$('toggler_fbox').addEvent('click', function(){
			
			if (ContTopHeught==35) {
				ContTopHeught =  456; cur_op = 1; css_class = 'opened';
			} else {
				ContTopHeught = 35 ; cur_op = 0; css_class = 'closed';
			}
			arrw.className=css_class;
			setCookie('content_top_height',ContTopHeught,1)
			ctop_fx.cancel();
			ctop_fx.start({'height':ContTopHeught});
			if (Browser.Engine.trident) {
				fbox_fx.cancel();
				fbox_fx.start({'opacity':cur_op});
			}
		}).setStyle('visibility', 'visible');
	})();
	
	(function () {
		var tabs = $('tabs');
		if (!tabs) return false;
		var curTab = 0;
		var curTabId = '';
		var tinfoHeights = [];

		var tHeight_fx = new Fx.Morph(tabs);

		var pairs = $$('#tabs li.tpair');
		var tbtns = [];
		if (location.search && location.search.search("city_id=")>-1) curTabId = 'tbranches';
		pairs.each(function(pair,num){
			tbtns[num] = pair.getChildren('a.tbtn')[0];
			if (!tbtns[num]) return false;
			tinfoHeights[num] = pair.getSize().y + pair.getChildren('.tinfo')[0].getSize().y+5;
			if (location.hash == '#'+pair.id || curTabId==pair.id) curTab = num;
			
			tbtns[num].addEvent('click', function(ev){
				pairs[curTab].removeClass('tget');
				curTab=num;
				pairs[curTab].addClass('tget');
				tHeight_fx.cancel();
				tHeight_fx.start({'height':tinfoHeights[num]});
				ev.stop();
			});
			return true;
		});
		pairs[curTab].addClass('tget');
		tHeight_fx.cancel();
		tHeight_fx.start({'height':tinfoHeights[curTab]});
		return true;

	})();

	(function (){
		var feetbox = $('feetbox');
		feetbox.style.overflow='hidden';
		var boxes = $$('#feetbox .feet');
		var tlrs=[]; // togglers
		var tles=[]; // togglies
		var curBox=-1, hovered=false, clckd=false, delayInt;
		
		var myFx = new Fx.Tween(undefined, {
			  duration: 1500
			, transition: Fx.Transitions.Elastic.easeOut
		});
		
		function SelectBox(numSel){
			if (numSel == curBox) return false; // Do nothing
			tles.each(function(el, num){
				if (num==numSel) {
					myFx.cancel();
					myFx.element = myFx.subject = el;
					el.style.zIndex='7';
					tlrs[num].addClass('toggler_on');
					myFx.start('left',-700, 0);
				} else if (num == curBox) {
					el.style.zIndex='6';
					el.style.left='0px';
					tlrs[num].removeClass('toggler_on');
				} else {
					el.style.left='-700px';
					el.style.zIndex='5';
					tlrs[num].removeClass('toggler_on');
				}
			});
			curBox = numSel;
			return true;
		}

		boxes.each(function(el, num){
			var chld = el.getChildren();
			tlrs[num]=chld[0];
			tles[num]=chld[1];
			if (!tles[num] || !tlrs[num]) return false;
			tles[num].style.visibility="visible";
			tles[num].style.left="-700px";
			el.addEvent('mouseover', function(ev){
				hovered=true;
			}).addEvent('mouseleave', function(ev){
				hovered=false;
			}).addEvent('click', function(ev){
				SelectBox(num);
			});
		})
		
		function loopFbox (){
			var newBox = (curBox<3 ) ? curBox+1 : 0 ;
			if (!hovered && ContTopHeught>100 ) SelectBox(newBox);
			delayInt = loopFbox.delay(5000);
		}
		delayInt = loopFbox.delay(1000);
		
	})()
/**	
	var fixed_box = $('fixed_box');
	if (fixed_box && !Browser.Engine.trident4) {
		(function checkScroll() {
			var scry = window.getScroll()['y'];
			var posy = $('content_rpt').getPosition()['y'];
			if (scry-posy > 0) fixed_box.addClass('floted')
			else fixed_box.removeClass('floted')
			//alert('scry:'+scry+' ;' + 'posy:'+posy+' ;' + '('+(scry-posy)+')');
		}).periodical(100);
	}
/**/	
	if (Browser.Engine.trident4) {
	
		$$('#nav li').addEvent("mouseover", function() {
			this.className += ' IEover';
		}).addEvent("mouseout", function() {
			this.className = this.className.replace(/ IEover/g, "");
		})

	}

});