﻿function __getPosX(obj){
	var curleft = 0;
	if (obj.offsetParent)
		while (obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	else if (obj.x) 
		curleft = obj.x;
	return curleft;
}

window.onload = function(){
	var menu = document.getElementById('menu')
	for(var i=0;i<menu.childNodes.length;i++){
		if(menu.childNodes[i].tagName!=''){
			menu.childNodes[i].onmouseover = function(){								
				if(this.className!='sel'){
					this.style.background = 'url(../i/mbs.gif) repeat-x';
					this.childNodes[0].style.color = '#2E75C7';
					this.childNodes[0].style.background = 'url(../i/mbrs.gif) no-repeat right';
					this.childNodes[0].childNodes[0].style.background = 'url(../i/mbls.gif) no-repeat left';
				}	
				if(document.getElementById('submenu_' + this.id)){
					var subMenu = document.getElementById('submenu_' + this.id);
					subMenu.style.display = 'block';
					subMenu.style.left = __getPosX(this) + 'px';
					subMenu.onmouseover = function(){
						var menu = document.getElementById(this.id.substring(8, this.id.length));
						menu.childNodes[0].style.color = '#2E75C7';
						menu.childNodes[0].style.background = 'url(../i/mbrs.gif) no-repeat right';
						menu.childNodes[0].childNodes[0].style.background = 'url(../i/mbls.gif) no-repeat left';
					}
					subMenu.onmouseout = function(){
						var menu = document.getElementById(this.id.substring(8, this.id.length));
						menu.childNodes[0].style.color = '#FFFFFF';
						menu.childNodes[0].style.background = 'url(../i/mbr.gif) no-repeat right';
						menu.childNodes[0].childNodes[0].style.background = 'url(../i/mbl.gif) no-repeat left';
					}
				}
			}
			menu.childNodes[i].onmouseout = function(){						
				if(this.className!='sel'){
					this.style.background = 'url(../i/mb.gif) repeat-x';
					this.childNodes[0].style.color = '#FFFFFF';
					this.childNodes[0].style.background = 'url(../i/mbr.gif) no-repeat right';
					this.childNodes[0].childNodes[0].style.background = 'url(../i/mbl.gif) no-repeat left';
				}	
				if(document.getElementById('submenu_' + this.id)){
					var subMenu = document.getElementById('submenu_' + this.id);
					subMenu.style.display = 'none';
					
				}
			}
		}
	}
}