// JavaScript Document
var currentMenu = null;
var timer = null;

function initMenu(id) {
	if (document.getElementById) {
		var root = document.getElementById(id);
		var el = root.childNodes;
		var e = 0;

		for (var i=0; i < el.length; i++) {
			if (el[i].nodeType == 1) {
				if (menu[e]) {
					el[i].innerHTML += createMenu(menu[e]);
				}
				e++;
			}
		}
	}
}

function createMenu(arr) {
	var sb = new Array();

	if (arr.length > 0) {
		sb.push('<ul class="menu">');

		for (var i=0; i < arr.length; i++) {
			sb.push(createItem(arr[i])); 
		}

		sb.push('</ul>');
	}
	
	return sb.join("");
}

function createItem(arr) {
	var childCount = arr["children"].length;
	var sb = new Array();
	sb.push('<li')

	if (childCount > 0) sb.push(' class="mother"');

	sb.push(' onmouseover="mouseOver(this)" onmouseout="mouseOut(this)"><a href="' + arr["href"] + '">' + arr["title"] + '</a>');
	
	if (childCount > 0) {
		sb.push('<ul>');
		for (var i=0; i < childCount; i++) {
			sb.push(createItem(arr["children"][i])); 
		}
		sb.push('</ul>');
	}
	sb.push('</li>');
	return sb.join("");
}

function mouseOver(el) {
	if (timer) {
		window.clearTimeout(timer);
		hideMenu();
	}
	el.className += " hover";
	if (el.getElementsByTagName("ul").length > 0)
		hideSelects();
}

function mouseOut(el) {
	if (el.getElementsByTagName("ul").length > 0) {
		currentMenu = el;
		timer = window.setTimeout(hideMenu, 500)
	}
	else {
		el.className = el.className.replace(/ ?hover/, "");
	}
}

function hideMenu() {
	if (currentMenu) {
		var el = currentMenu;
		el.className = el.className.replace(/ ?hover/, "");
		showSelects();
		currentMenu = null;
	}
}

function hideSelects() {
	var selects = document.getElementsByTagName("select");
	var flash = document.getElementById("flashLayer");
	
	for (var i=0; i < selects.length; i++) {
		selects[i].style.visibility = "hidden";	
	}

	// Hide Flash object when menu is activated and show static image there.
	if (flash) {
		flash.style.display = "none";
		document.getElementById('flashHide').style.display = "block";
	}
}

function showSelects() {
	var selects = document.getElementsByTagName("select");
	var flash = document.getElementById("flashLayer");
		
	for (var i=0; i < selects.length; i++) {
		selects[i].style.visibility = "visible";	
	}

	if (flash) {
		flash.style.display = "block";
		document.getElementById('flashHide').style.display = "none";
	}
}


//Array push for ie 5

if( typeof Array.prototype.push == "undefined") {
	Array.prototype.push=function(){
		b = this.length,
		a = arguments;
		for (var i = 0; i < a.length; i++)
			this[b+i] = a[i];

		return this.length
	};
}