// Exceptions in menu
var menuExceptions = new Array();

menuExceptions[0] = new Array();
menuExceptions[0][0] = "dovesiamooverview";
menuExceptions[0][1] = "dovesiamo";
menuExceptions[1] = new Array();
menuExceptions[1][0] = "prenotazioneoverview";
menuExceptions[1][1] = "prenotazione";
menuExceptions[2] = new Array();
menuExceptions[2][0] = "faq_igr";
menuExceptions[2][1] = "faq";
menuExceptions[3] = new Array();
menuExceptions[3][0] = "faq_irp";
menuExceptions[3][1] = "faq";
menuExceptions[4] = new Array();
menuExceptions[4][0] = "faq_ira";
menuExceptions[4][1] = "faq";
menuExceptions[5] = new Array();
menuExceptions[5][0] = "offertespecialilastminute";
menuExceptions[5][1] = "appartamentiprezzi";

// END of exceptions listing

function checkMenuExceptions(text) {
	for (var i = 0; i < menuExceptions.length; i++) {
		if (menuExceptions[i][0] == text)
			text = menuExceptions[i][1];
	}
	return text;
}

function loadMenuStyles(obj) {
	for (var i = 0; i < obj.childNodes.length; i++) {
		switchDivStyles(obj.childNodes[i]);
	}
}

function doMenuAction(obj,link) {
	if (obj.parentNode.className == "menuMainOpen")
		switchDivStyles(obj.parentNode.parentNode);
	else
		document.location.href = link;
}

function switchDivStyles(obj) {
	var k = 0;
	var menuContainsItem = false;
	
	for (var j = 0; j < obj.childNodes.length; j++) {
		if (obj.childNodes[j].nodeName == "DIV") {
			if (k==0) {
				if (obj.childNodes[j].className == "")
					obj.childNodes[j].className = "menuMainClose";
				else if (obj.childNodes[j].className == "menuMainClose")
					obj.childNodes[j].className = "menuMainOpen";
				else if (obj.childNodes[j].className == "menuMainOpen")
					obj.childNodes[j].className = "menuMainClose";
			}
			else {
				if (obj.childNodes[j].className == "") {
					obj.childNodes[j].className = "menuItemNone";
					if (getDocumentURL("") == getDocumentURL(obj.childNodes[j].childNodes[0].getAttribute("href")))
						menuContainsItem = true;
				}
				else if (obj.childNodes[j].className == "menuItemNone")
					obj.childNodes[j].className = "menuItemBlock";
				else if (obj.childNodes[j].className == "menuItemBlock")
					obj.childNodes[j].className = "menuItemNone";
			}
			k++;
		}
	}
	
	if (menuContainsItem)
		switchDivStyles(obj);
}

function getDocumentURL(link) {
	var url = "";
	if (link=="")
		url += document.location;
	else
		url += link;
		
	pos1 = url.lastIndexOf ("/")+1;
	pos2 = url.indexOf(".", pos1);
	url = url.substring(pos1,pos2);
	urlall = ""+document.location;
	if (url == "RenderTable" && urlall.indexOf("&") == -1) {
		var url = ""+document.location;
		pos = url.indexOf("TabRef=")+7;
		url = url.substring(pos);
	} else if (url == "RenderTable" && urlall.indexOf("&") != -1) {
		var url = ""+document.location;
		pos = url.indexOf("TabRef=")+7;
		url = url.substring(pos);
		pos = url.indexOf("&");
		url = url.substring(0,pos);
	}
	
	url = checkMenuExceptions(url) + ".tab.aspx";
	return url;
}
