function fix(id,min,max){
	//alert(window.navigator.userAgent);
	if(document.getElementById("fake")&&document.getElementById(id)){
		if(window.navigator.userAgent.indexOf("MSIE")<0)return;
		var ss=document.getElementById("fake").offsetWidth;
		document.getElementById(id).style.width=((ss>min)?((ss<max)?"100%":max+"px"):min+"px");
	}
}

function showHide(block){
	if(document.getElementById(block)){
		if(document.getElementById(block).style.display!='block'){
			document.getElementById(block).style.display='block';
		}
		else{
			document.getElementById(block).style.display='none';
		}
	}
}

function dropCont(){	
	if(document.getElementById("poster0") && document.getElementById("poster1") && document.getElementById("poster2")){
		dropdowncontent.init("poster0", "right-bottom", 500, "mouseover");
		dropdowncontent.init("poster1", "right-bottom", 500, "mouseover");
		dropdowncontent.init("poster2", "right-bottom", 500, "mouseover");
	}
	if(document.getElementById("trail0") && document.getElementById("trail1") && document.getElementById("trail2")){
		dropdowncontent.init("trail0", "right-bottom", 500, "mouseover");
		dropdowncontent.init("trail1", "right-bottom", 500, "mouseover");
		dropdowncontent.init("trail2", "right-bottom", 500, "mouseover");
	}
	animatedcollapse.addDiv('fine', 'fade=1,hide=1');
	animatedcollapse.init();
	var descriptions = [0, 1, 2];
	for (i = 0; i < descriptions.length; i++){
		if(document.getElementById('description'+descriptions[i])){
			if(window.navigator.userAgent.indexOf("Opera")>=0 || window.navigator.userAgent.indexOf("WebKit")>=0 || window.navigator.userAgent.indexOf("Firefox/3")>=0 || window.navigator.userAgent.indexOf("Konqueror")>=0){
				document.getElementById('description'+descriptions[i]).style.marginTop = "-214px";	
				document.getElementById('description'+descriptions[i]).style.marginLeft = "-4px";
			}
		}
	}
}

function borderColor(shema){
	for (i=0; i<underground.childNodes.length; i++){
		node = underground.childNodes[i]; 
		if(node.nodeName=="DIV"){
			source = node;
			for (a=0; a<source.childNodes.length; a++){
				image = source.childNodes[a];
				if(image.nodeName == "IMG"){
					image.style.border = shema;				
				}
			}
		}
	}
}

status = 'null';
active = 'null';
color = 'null';
function collapseDiv(id, human, colorSection){
	underground = document.getElementById(colorSection);
	pers = document.getElementById(human);
	if(status == 'null'){
		if(window.navigator.userAgent.indexOf("Konqueror")>=0){
			document.getElementById(id).style.display = 'block';
		}
		else{	
			animatedcollapse.show(id);
		}
		status = id;
	}
	if(active == 'null'){
		pers.style.display = 'block';	
		underground.style.backgroundColor = 'rgb(215, 224, 228)';
		borderColor('4px solid #ffffff');
		active = human;
		color = colorSection;
	}
	else if(id == 'quit'){
		if(window.navigator.userAgent.indexOf("Konqueror")>=0){
			document.getElementById('fine').style.display = 'none';
		}
		else{
			animatedcollapse.hide('fine');
		}		
		document.getElementById(human).style.display = 'none';
		underground.style.backgroundColor = 'transparent';
		borderColor('4px solid #BDC1CD');
		status = 'null';
		active = 'null';
		color = 'null';
	}
	else if(active != human){
		document.getElementById(active).style.display = 'none';
		document.getElementById(color).style.backgroundColor = 'transparent';
		userpic = document.getElementById(color);
		for (i=0; i<userpic.childNodes.length; i++){
			node = userpic.childNodes[i]; 
			if(node.nodeName=="DIV"){
				source = node;
				for (a=0; a<source.childNodes.length; a++){
					image = source.childNodes[a];
					if(image.nodeName == "IMG"){
						image.style.border = "4px solid #BDC1CD";				
					}
				}
			}
		}
		pers.style.display = 'block';	
		underground.style.backgroundColor = 'rgb(215, 224, 228)';
		borderColor('4px solid #ffffff');
		active = human;
		color = colorSection;
	}
}

function ratio(mark){
	document.getElementById('rate' + mark).style.backgroundPosition = "0 0";
	for(i = 0; i < mark; i++){
		document.getElementById('rate' + i).style.backgroundPosition = "0 -40px";
	}
}
function hideRatio(mark){
	document.getElementById('rate' +mark).style.backgroundPosition = "0 -20px";
	for(i = 0; i < 5; i++){
		document.getElementById('rate' + i).style.backgroundPosition = "0 -20px";
	}
}

function mshover(tabHover) { 
	if (document.all&&document.getElementById(tabHover)) { 
		navRoot = document.getElementById(tabHover); 
		for (i=0; i<navRoot.childNodes.length; i++) { 
			node = navRoot.childNodes[i]; 
			//alert(node.nodeName);
			if (node.nodeName=="TR") { 
				node.onmouseover=function() {
					this.className+=" over"; 
				} 
				node.onmouseout=function() { 
					this.className=this.className.replace
					(" over", ""); 
				}
				
			}
		}
	}
}

function startMsIeHover() {
	if(window.navigator.userAgent.indexOf("Gecko")>=0 && window.navigator.userAgent.indexOf("/2.0")<0){
		$(".loginLine form label").css({ marginTop: "1px"});
		$("#rememberme").css({ position:"relative", top: "2px" });
		if(window.navigator.userAgent.indexOf("Linux")>=0){
			$(".loginLine form > a").css({ paddingTop: "2px" });
		}
	}
	if(window.navigator.userAgent.indexOf("MSIE")<0)return;
	for (t=0; document.getElementById("aphTable" + t); t++){
		mshover("aphTable" + t);	
	}
}

var activeDay;
var count = 'false';
function lightShow(day, status){
	/* added by kooler*/
	if (day == 'monday') dayNum = 0;
	else if (day == 'tuesday') dayNum = 1;
	else if (day == 'wednesday') dayNum = 2;
	else if (day == 'thursday') dayNum = 3;
	else if (day == 'friday') dayNum = 4;
	else if (day == 'saturday') dayNum = 5;
	else if (day == 'sunday') dayNum = 6;
	
	$('#recName').html(recData[dayNum][0]);
	$('#recType').html(recData[dayNum][1]);
	$('#recPlace').html(recData[dayNum][2]);
	$('#recTime').html(recData[dayNum][3]);
	$('#recPrice').html(recData[dayNum][4]);
	$('#recAddress').html(recData[dayNum][5]);
	$('#recPhone').html(recData[dayNum][6]);
	$.get('/getdata.php?operation=getRecText&id='+recData[dayNum][5], function(data){
		$('#recText').html(data);
	});
	
	//alert(status);
	if(count == 'false'){
		week = document.getElementById("week");
		for (i=0; i<week.childNodes.length; i++) {
			weekDay = week.childNodes[i];
			if(weekDay.className == "recToDay"){
				today = week.childNodes[i];
			}
		}
	}
	if(status == 'otherday'){
		overClass = " sleep";
	}
	else{
		overClass = " light";
	}
	work = document.getElementById(day);
	if(count == 'true'){
		//alert(status + "      " + post);
		if(post == 'otherday'){
			activeDay.className=activeDay.className.replace(" sleep", "");
		}
		else{
			activeDay.className=activeDay.className.replace(" light", "");
		}
	}
	work.className+=overClass;
	today.className+=" tohide";
	activeDay = work;
	post = status;
	count = 'true';
}
//страдаем херней
function fuckwidth(){
	if (document.getElementById('tuesday')) 	bla1 = parseInt(document.getElementById('tuesday').offsetWidth);
	if (document.getElementById('wednesday')) 	bla2 = parseInt(document.getElementById('wednesday').offsetWidth);
	if (document.getElementById('thursday')) 	bla3 = parseInt(document.getElementById('thursday').offsetWidth);
	if (document.getElementById('friday')) 		bla4 = parseInt(document.getElementById('friday').offsetWidth);
	if (document.getElementById('saturday')) 	bla5 = parseInt(document.getElementById('saturday').offsetWidth);
	if (document.getElementById('sunday')) 		bla6 = parseInt(document.getElementById('sunday').offsetWidth);
	if (document.getElementById('monday')) 		bla7 = parseInt(document.getElementById('monday').offsetWidth);
	//alert(bla1);
	
}
/*
 * 
var activeDay;
var count = 'false';
function variant(){
	var week = ['tuesday','wednesday','thursday','friday','saturday','sunday','monday'];
	workWeek = document.getElementById("week");
	todayElem = document.getElementById("today");
	
	for (i=0; i<workWeek.childNodes.length; i++) { 
		weekDay = workWeek.childNodes[i];
		if(weekDay.className == "recDay"){
			weekDay.onmouseover=function(){
				if(count == 'true'){
					activeDay.className=this.className.replace(" light", "");					
				}
				this.className+=" light"
				todayElem.style.backgroundColor="transparent";
				activeDay = this;
				count = 'true';
			}
			todayElem.onmouseover=function(){
				todayElem.style.backgroundColor="#C8D5DC";
				activeDay.className=this.className.replace(" light", "");
			}
		}
	}
	
}
*/
// Сначала был init...
function init() {
	if (arguments.callee.done) return;
	arguments.callee.done = true;
	if (_timer) {
		clearInterval(_timer);
		_timer = null;
	}
	fix('less',1004,1280);
	dropCont();
	startMsIeHover();
	fuckwidth();
	//variant();
	//colsHeight('person0','person1','person2','person3');
};
/* for Mozilla */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			init(); // call the onload handler"
		}
	};
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 50);
}


/* for other browsers */
window.onload = init;
