/**
 * JS for top menu
 */
 
function topMenu() {

	this.init = function() {
		this.menu = $('topMenu');
		this.topLinks = this.menu.getElementsByTagName('a');
		this.subLinksContainer = this.menu.getElementsByTagName('ul');
		this.activeBranch = null;
		
		this.foldMenu = false;
		this.activeMenuObj = null;
		_parent = this;
		
		for(var i= 0;i < this.topLinks.length;i++) {
			
			if(this.topLinks[i].className == 'link') {
				if(this.topLinks[i].parentNode.getElementsByTagName('li').length > 1) {
					this.topLinks[i].onmouseover = function() {
						var dropdown = this.parentNode.getElementsByTagName('ul')[0];
						if(_parent.activeBranch != null)
							_parent.activeBranch.style.display = 'none';
							
						dropdown.style.display = 'block';			
						_parent.activeBranch = dropdown;
						_parent.foldMenu = false;
					}
					
					this.topLinks[i].onmouseout = function() {
						_parent.foldMenu = true;
						_parent.activeMenuObj = this.parentNode.getElementsByTagName('ul')[0];
						setTimeout("TopMenu.hideMenu()",1000);
					}
				}
			}
		}
		
		for(var i= 0;i < this.subLinksContainer.length;i++) {
			this.subLinksContainer[i].onmouseout = function() {
				_parent.foldMenu = true;
				_parent.activeMenuObj = this;
				setTimeout("TopMenu.hideMenu()",1000);
			}
			
			this.subLinksContainer[i].onmouseover = function() {
				_parent.activeMenuObj = this;
				_parent.foldMenu = false;
			}
		}
		
		this.hideMenu = function(index) {
			if(this.foldMenu) {
				this.activeMenuObj.style.display = 'none';
			}
		}
	}
	
}

var TopMenu =  new topMenu();



