//////////////////////////////////////////////////////////////
// menu.js - A simple JS drop Down menu
// ----------------------------------------------------------
// Please Read the Terms of use at http://www.iScript4u.com
// ----------------------------------------------------------
// (c)iScript4u - Making the NextGen Scripts!
//////////////////////////////////////////////////////////////

//Element referencer - We use $ because we love PHP
function $(id){
	//DOM
	if(document.getElementById){
		return document.getElementById(id);
	//IE
	}else if(document.all){
		return document.all[id];
	//NS4
	}else if(document.layers){
		return document.layers[id];
	}
};


//Changes the opacity
function setopacity(el, opacity){
	el.style.opacity = (opacity/100);
	el.style.filter = 'alpha(opacity=' + opacity + ')';
};

//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.visibility=="visible"){
		clearTimeout(hider);
		return;
	}
	//Get the position
	var pos = findelpos(ele);
	//Get the callers left and top
	x = pos[0]-5;
	y = pos[1]+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.visibility="visible";
	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.visibility="hidden";
};

function createmenu(id, array){
	if(!array || $(id) != null){
		return false;
	}
	var t = '<table id="'+id+'" onmouseover="clearTimeout(hider)" onmouseout="pullmenu(\''+id+'\')" class="ddopt" cellpadding="5" cellspacing="1">';	
	var o;
	for(o in array){		
		t += '<tr><td onmouseover="this.className=\'ddmon\'" onmouseout="this.className=\'ddmnor\'" class="ddmnor">'+array[o]+'</td></tr>';		
	}
	
	t += '</table>';
	document.write(t);
};

//Finds the position of the element
function findelpos(ele){
	var curleft = 0;
	var curtop = 0;
	if(ele.offsetParent){
		while(1){
			curleft += ele.offsetLeft;
			curtop += ele.offsetTop;
			if(!ele.offsetParent){
				break;
			}
			ele = ele.offsetParent;
		}
	}else if(ele.x){
		curleft += ele.x;
		curtop += ele.y;
	}
	return [curleft,curtop];
};

//Gradually increases the opacity
function smoothopaque(elid, startop, endop, inc){
	if(typeof(elid) == 'object'){
		var el = elid;
	}else{
		var el = $(elid);
	}
	op = startop;
	//Initial opacity
	setopacity(el, op);
	//Start the opacity timeout that makes it more visible
	setTimeout(slowopacity, 1);
	function slowopacity(){
		if(startop < endop){
			op = op + inc;
			if(op < endop){
				setTimeout(slowopacity, 1);
			}
		}else{
			op = op - inc;
			if(op > endop){
				setTimeout(slowopacity, 1);
			}
		}
		setopacity(el, op);		
	};
};

//The style
document.write('<style>'+"\n"+'.ddopt{background-color:#FFFFFF;min-width:70px;border:1px solid #DEDCD1;margin-top:2px;visibility:hidden;position:absolute;top:0px;left:0px;}'+"\n"+'.ddmnor, .ddopt a:link, .ddopt a:visited, .ddopt a:active{text-decoration: none;text-align:left;}'+"\n"+'.ddmon{background-color:#DAEBFE;color: #FFF;text-align:left;}</style>');