//////////////////////////////////////////////////////////////
// menu.js - A simple JS drop Down menu
// Inspired by Ronak and Pulkit
// ----------------------------------------------------------
// Please Read the Terms of use at http://www.anelectron.com
// ----------------------------------------------------------
// (c)Electron Inc.
//////////////////////////////////////////////////////////////

//Shows the menu
function dropmenu(ele, divid){
	//To prevent errors
	try{ $_(divid).style;}catch(e){ return false;};	
	//If it is visible means he is on the drop down list
	if($_(divid).style.display=="block"){
		clearTimeout(hider);
		return;
	}
	//Get the position
	var pos = $(ele).position();
	//Get the callers left and top
	x = pos.left;
	x = x+10;
	y = pos.top+ele.offsetHeight;//Add the height
		
	//If extremely right adjust
	// if((screen.width - 40) < (x + $_(divid).offsetWidth)){
	// 	extra = $_(divid).offsetWidth - ele.offsetWidth;
	// 	x = x - extra;
	// }

	//Set the drop down div to that point
	$_(divid).style.left=x+"px";
	$_(divid).style.top=y+"px";
	
	//Make the div visble
	$_(divid).style.display="block";
	smoothopaque(divid, 0, 100, 5);
};

//Hides the menu
function pullmenu(hidedivid){
	hider = setTimeout("puller('"+hidedivid+"')", 100);
};

function puller(pid){
	try{ $_(pid).style;}catch(e){ return false;};
	$_(pid).style.display="none";
};

function clearhider(){
	try{ clearTimeout(hider);}catch(e){ return false;};	
}

function createmenu(id, array){
	if(!array){
		return false;
	}
	var t = '<div id="'+id+'" onmouseover="clearTimeout(hider)" onmouseout="pullmenu(\''+id+'\')" class="ddopt row w-auto">';	
	var o;
	for(o in array){		
		t += '<div onmouseover="this.className=\'ddmon col-12 p-2\'" onmouseout="this.className=\'ddmnor col-12 p-2\'" class="ddmnor col-12 p-2">'+array[o]+'</div>';		
	}
	
	t += '</div></div>';
	document.write(t);
};