﻿var subMenus =
 [
  {"id":"sub0", "url": ["algarve_about.htm", "algarve_weather.htm", "algarve_map.htm", "algarve_food_drink.htm", "algarve_recipes.htm", "algarve_wine_drink.htm", "algarve_golf.htm", "algarve_sportleisure.htm", "sports_[a-z]+.aspx"] },
  {"id":"sub1", "url": ["car_rental_prices.htm", "car_rental.htm"] },
  {"id":"sub2", "url": ["how_to_book.htm", "terms_conditions.htm", "booking_form.aspx", "availability_check.aspx"] },
 ]

var tid = 0;
var menuTimeout = 1250;
var defaultIndex = -1;

function SmShow(smIndex) {
	if (tid != 0)
		ResetTID();

	for (i=0; i<subMenus.length; i++) {
		
		/*
			Workaround for a special case where (subMenus.length != subMenus.length)
			Hint: IE7.0
		//*/
		if (subMenus[i] == null)
			continue;

		var obj = document.getElementById(subMenus[i]["id"]);
		if (i != smIndex)
			obj.style.display = "none";
		else {
			obj.style.display = "block";
			obj.onmouseover = ResetTID;
			obj.onmouseout = SmHide;
		}
	}
}

function SmHide() { 
	tid = window.setTimeout(SmHideAll, menuTimeout); 
}

function ResetTID(e) {
	window.clearTimeout(tid);
	tid=0;
}

function SmHideAll() {
	for (i=0; i<subMenus.length; i++) {

		/*
			Workaround for a special case where (subMenus.length != subMenus.length)
			Hint: IE7.0
		//*/
		if (subMenus[i] == null)
			continue;

		if (i == defaultIndex)
			showSubItem(i);
		else
			hideSubItem(i);
	}
}

function SmStart() {
	var currentUrl = window.location.href;
	var foundUrl = false;
	var i = -1;

	while (!foundUrl && ++i < subMenus.length) {

		/*
			Workaround for a special case where (subMenus.length != subMenus.length)
			Hint: IE7.0
		//*/
		if (subMenus[i] == null)
			continue;
			
		var urlArray = subMenus[i]["url"];
		var j = -1;

		while (!foundUrl && ++j < urlArray.length) {
			var rx = new RegExp(urlArray[j], "i");
			
			try {
				if (currentUrl.match(rx)) {
					showSubItem(i);
					defaultIndex = i;
					smAllowHide = false;
					foundUrl = true;
				}
			}
			catch(x) {
			};

		}// while j
	}// while i
	
	
}


function showSubItem(index) {
	document.getElementById(subMenus[index]["id"]).style.display = "block";
}

function hideSubItem(index) {
	document.getElementById(subMenus[index]["id"]).style.display = "none";
}


function openPopupWindow(url, width, height)
{
	var w = window.open(url, "POPUP", "width="+width+",height="+height+",status=0,menubar=0,scrollbars=0,toolbar=0");
	if (w) w.focus();
	return false;
}

window.onload = SmStart;

