// JavaScript Document
var proDropdown = {
	init: function(){
		var drops = proDropdown.getElementsByClassName("dropm");
		if (drops.length > 0){
			//Aqui implementar os drops
			for (d = 0; d < drops.length; d++){
				var drop = drops[d].parentNode.getElementsByTagName('ul')[0];
				drop.style.position = 'absolute';
				drop.style.display = 'none';
				drop.style.left = drops[d].offsetLeft+'px';
				drop.style.top = eval(drops[d].offsetTop+drops[d].offsetHeight)+'px';
				drops[d].onmouseover = drops[d].onclick = function(){
													proDropdown.hideDrop(this);
													this.parentNode.getElementsByTagName('ul')[0].style.display = 'block';
												 }
			}
			
			var menu = drops[0].parentNode.parentNode.childNodes;

			for (m = 0; m < menu.length; m++){
				var mitem = menu[m].getElementsByTagName('a')[0];
				if (mitem.className == 'dropm'){ continue;}
				mitem.onmouseover = function(){ proDropdown.hideDrop(this);}
			}
		}
		document.body.onclick = function(){ 
			var drops = proDropdown.getElementsByClassName("dropm");
			var menu = drops[0].parentNode.parentNode.childNodes;

			for (m = 0; m < menu.length; m++){
				var mitem = menu[m];
				var tmpDrop = mitem.getElementsByTagName('ul')[0];
				
				if (tmpDrop){ tmpDrop.style.display = 'none';}
			}
		}
	},
	hideDrop: function(current){
		var curMenu = current.parentNode;
		
		if (curMenu.tagName != 'LI'){ return;}

		if (current.tagName != 'BODY'){
			var curDrop = curMenu.getElementsByTagName('ul')[0];
			if (current.className == 'dropm' && curDrop.style.display != 'none'){ return;}	
		}
		
		var drops = proDropdown.getElementsByClassName("dropm");
		var menu = drops[0].parentNode.parentNode.childNodes;
		
		for (m = 0; m < menu.length; m++){
			var mitem = menu[m];
			var tmpDrop = mitem.getElementsByTagName('ul')[0];
			
			if (tmpDrop){ tmpDrop.style.display = 'none';}
		}
	},
	getElementsByClassName: function(className){
		var regClass = new RegExp("(^|\\s)" + className + "(\\s|$)");	
		var allElements = (document.all)? document.all : document.getElementsByTagName('*');
		var classElements = [];
		
		for (e = 0; e < allElements.length; e++){
			var current = allElements[e];
			
			if (!current.className){ continue;}

			if (regClass.test(current.className)){ classElements.push(current);}
		}
		return classElements;	
	}
}

if(window.addEventListener){
	window.addEventListener('load', proDropdown.init, false);
	window.addEventListener('resize', proDropdown.init, false);
} else {
	window.attachEvent('onload', proDropdown.init);
	window.attachEvent('onresize', proDropdown.init);
}
