var ie/*@cc_on=1@*/;

// перерисовка страницы - чтобы браузеры не перло при динамическом изменении контента
function reloadPage() {
	document.body.style.display="inline";
	document.body.style.display="block";
}

// выбор страниц для отображения
function selectPage(current) {
	if (current.parentNode.className!="active") {
		var pos = current.href.lastIndexOf("#");
		where = current.href.slice(pos+1);
		where = document.getElementById(where);

		var nav = current.parentNode.parentNode.getElementsByTagName('li');
		for(var i=0; i<nav.length; i++) nav[i].className="";
		current.parentNode.className="active";

		nav = document.getElementById("switch").getElementsByTagName('div');
		for(var i=0; i<nav.length; i++) {
			var navClass=nav[i].className;
			if (navClass.indexOf("switch-content")!=-1) if(navClass.indexOf("on")!=-1) nav[i].className=navClass.replace(" on", "");
			if (nav[i].id==where.id) where.className+=" on";
		}
		reloadPage();
	}
	return false;
}


// показать попап
function showPopup(current) {
	showShadow();
	document.getElementById(current).style.display = "block";
	reloadPage();
	return false;
}
// спратать попап
function hidePopup(current) {
	hideShadow();
	document.getElementById(current).style.display = "none";
	reloadPage();
	return false;
}

// показать тень
function showShadow() {
	var shadow = document.getElementById("shadow");
	shadow.style.display = "block";

	if(ie) {document.body.className += " hideselects";}

	var bodyHeight = document.body.clientHeight;
	var wrapHeight = document.getElementById("wrap").clientHeight;

	if (wrapHeight > bodyHeight) shadowHeight = wrapHeight;
	else shadowHeight = bodyHeight;
	shadow.style.height = shadowHeight + "px";
	return false;
}

// спрятать тень
function hideShadow() {
	var shadow = document.getElementById("shadow");
	shadow.style.display = "none";
	if(ie) {document.body.className = document.body.className.replace(" hideselects", "");}
	return false;
}


function toggleToolbarPopup(current) {
	var m = current.parentNode.getElementsByTagName('div')[0];
	if (m.className.indexOf("toolbar-popup")>=0) {
		if (m.style.display == "none" || !m.style.display) {
			m.style.display="block";
		} else {
			m.style.display="none";
		}
	}
	return false;
}


function init() {
	if (document.getElementById("map1")) {
		var tmp;var coords;
		var metroCur = document.getElementById("metroCur");
		var arr = document.getElementById("map1").getElementsByTagName("area");
		var inp = document.getElementById("inpopup");
		for (var i=0; i<arr.length; i++) {
			arr[i].onmouseover = function() {
				for( var x = 0; x < this.attributes.length; x++ ) {
					if(this.attributes[x].nodeName.toLowerCase() == 'coords') {
						coords = this.attributes[x].nodeValue.split(",");
						metroCur.style.left=parseInt(coords[0])+25+"px";
						metroCur.style.top=(parseInt(coords[1])+(parseInt(coords[3])-parseInt(coords[1])+45))+"px";
						metroCur.style.width=(parseInt(coords[2])-parseInt(coords[0]))+"px";
						metroCur.style.display="block";
					}
				}
			}
			arr[i].onmouseout = function() {
				metroCur.style.display="none";
			}
		}
	}
}

function showIn(current,intext) {
	var coords;
	var inp = document.getElementById("inpopup");
	var inpс = document.getElementById("incontent");
	for( var x = 0; x < current.attributes.length; x++ ) {
		if(current.attributes[x].nodeName.toLowerCase() == 'coords') {
			coords = current.attributes[x].nodeValue.split(",");
			//alert(coords);
			inp.style.left=parseInt(coords[2])+25+"px";
			inp.style.top=(parseInt(coords[1])+(parseInt(coords[3])-parseInt(coords[1])+45))+"px";
			inpс.innerHTML=intext+"<p class=\"inclose\"><a href=\"#\" onclick=\"return hideInPopup('inpopup');\">свернуть</a></p>";
			showInPopup('inpopup');
		}
	}
	return false;
}


// показать попап
function showInPopup(current) {
	document.getElementById(current).style.display = "block";
	reloadPage();
	return false;
}
function hideInPopup(current) {
	document.getElementById(current).style.display = "none";
	reloadPage();
	return false;
}

window.onload = init;