var timeout_time = 100;
var shadow_width = 12;
var shadow_height = 12;

var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);
var main_nav;
var menu_hide_timout;

function menu_arrange() {
	main_nav = document.getElementById('mainnav');
	
	var children = main_nav.getElementsByTagName('li');
	var shadow_bottom = document.createElement('div');
		shadow_bottom.className = 'shadow_bottom';
	var shadow_right = document.createElement('div');
		shadow_right.className = 'shadow_right';
	var iframe = document.createElement('iframe');
	
	for (var i = 0; i < children.length; i++) {
		var list = children[i].getElementsByTagName('ul')[0];
		//menu for ie6
		if ((version >= 5.5 && version < 7) && (document.body.filters)) {
			children[i].onmouseover = menu_show;
			children[i].onmouseout = function() {
				clearTimeout(menu_hide_timout); menu_hide_timout = setTimeout('menu_hide();', timeout_time);
			}
		}
		if (list != undefined){
			//shadows
			list.style.padding = '0 ' + shadow_width + 'px ' + shadow_height + 'px 0';
			var this_shadow_bottom = shadow_bottom.cloneNode(true);
			var this_shadow_right = shadow_right.cloneNode(true);
			list.appendChild(this_shadow_bottom);
			list.appendChild(this_shadow_right);
			this_shadow_right.style.height = (list.offsetHeight-shadow_height)+'px';
			//iframe
			if ((version >= 5.5 && version < 7) && (document.body.filters)) {
				this_iframe = iframe.cloneNode(true);
				this_iframe.style.width = (parseInt(list.offsetWidth, 10) - shadow_width)+'px';
				this_iframe.style.height = (parseInt(list.offsetHeight, 10) - shadow_height)+'px';
				list.appendChild(this_iframe);
			}
		}
		
	}
}

function menu_show(event) {
	clearTimeout(menu_hide_timout);
	menu_hide();
	var children = this.getElementsByTagName('ul');
	for (var i = 0; i < children.length; i++) {
		children[i].className = 'visible';
	}
}
function menu_hide(event){
	children_l1 = main_nav.getElementsByTagName('li');
	for (var i = 0; i < children_l1.length; i++) {
		children_l2 = children_l1[i].getElementsByTagName('ul');
		for (var k = 0; k < children_l2.length; k++) {
			children_l2[k].className = '';
		}
	}
}

function attachEventOnLoad(event) {
	if (window.addEventListener) {
		window.addEventListener("load", event, false);
	} else if (window.attachEvent) {
		window.attachEvent("onload", event);
	} else if (document.getElementById) {
		window.onload = event;
	}
}

attachEventOnLoad(menu_arrange);