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;
	}
	
	(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 myFx = new Fx.Tween('fade', { duration: 1000});
		var CurOpac=1;
		function loopFbox (){
			CurOpac = CurOpac >0 ? 0 : 1 ;
			myFx.cancel();
			myFx.start('opacity',CurOpac);
			loopFbox.delay(5000);
		}
		loopFbox.delay(3000);
	})();
/**	
	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, "");
		})

	}

});
