/*
The ultimate DHTML drop-down code
Nick Nettleton
www.computerarts.co.uk || www.fluid7.co.uk
--
This must be the single most requested bit of code in the history of Computer Arts, so we've decided to make it user-friendly and adaptable for everyone. Stacks more goodies to come too - head to one of the above sites for regular infoa nd updates.
Works with v4 and v5 browsers - both IE and NS. Update for NS6 coming. Also, be aware there's no way to automatically centre layers in the window - a JS for this coming soon. In the meantime, stick with left-aligned.
Keep an eye out for update for NS6.
--
You can adapt, use and distribute this code under GNU public licence, as long as:
(1) You leave all the comment and credit lines in, including these ones
(2) You don't sell it for profit
--
If you want to tweak the code yourself, use the f7_droplayer to set the names of the dropdowns, and just call f7_showdrop(n) and f7_hdidedrop from onmouseover, onmouseout and other events. Swap n for the number of the layer as in the array.
--
Enjoy!!!
*/

//names of dropdowns stored here
f7_droplayer=new Array()
f7_droplayer[0]="drop0";
f7_droplayer[1]="drop1";
f7_droplayer[2]="drop2";
f7_droplayer[3]="drop3";
f7_droplayer[4]="drop4";
f7_droplayer[5]="drop5";
f7_droplayer[6]="drop6";
f7_droplayer[7]="drop7";
f7_droplayer[8]="drop8";
f7_droplayer[9]="drop9";
f7_droplayer[10]="drop10";
f7_droplayer[11]="drop11";
f7_droplayer[12]="drop12";


//simple browser check
f7_v4=(parseInt(navigator.appVersion)>=4 && parseInt(navigator.appVersion)<=5)?1:0
f7_ie=(document.all && f7_v4)?1:0
f7_ns=(document.layers && f7_v4)?1:0


//code for drops

function f7_showdrop(thelayer,theref){
	f7_keep=thelayer; f7_hideall(); f7_showitnow=1
	f7_showit(thelayer,theref)
}

function movemenu (id, x, y) {

	if (f7_ns) obj = document.layers[id];
	if (f7_ie) obj = document.all[id].style;
	obj.xpos = parseInt(x);
	obj.ypos = parseInt(y);
	obj.left = obj.xpos;
	obj.top = obj.ypos;

}


function f7_showit(thelayer,theref){
	var top;
	var left;
	
	top	= eval(getElementTop(theref) + 22)
	left = getElementLeft(theref)
	

	if(f7_ie){ eval(f7_droplayer[thelayer]+'.style.visibility="visible"') }
	if(f7_ns){ eval('document.'+f7_droplayer[thelayer]+'.visibility="show"');}

	movemenu('drop0', left, top);
	movemenu('drop1', left, top);
	movemenu('drop2', left, top);
	movemenu('drop3', left, top);
	movemenu('drop4', left, top);
	movemenu('drop5', left, top);
	movemenu('drop6', left, top);
	movemenu('drop7', left, top);
	movemenu('drop8', left, top);
	movemenu('drop9', left, top);
	movemenu('drop10', left, top);
	movemenu('drop11', left, top);
	movemenu('drop12', left, top);
		
}

function f7_hidedrop(){
	f7_keep=-1; setTimeout('f7_hideall()',500)
	}

f7_keep=-1

function f7_hideall(){
	for(i=0;i<f7_droplayer.length;i++){  
		f7_hideit=0; f7_checkmousepos(i)
		if(f7_ie && f7_keep!=i){ 
			if(f7_hideit){ eval(f7_droplayer[i]+'.style.visibility="hidden"') } 
			}
		if(f7_ns && f7_keep!=i){ 
			if(f7_hideit){ eval('document.'+f7_droplayer[i]+'.visibility="hide"') }
			}
		}
	}

//deal with cursor over layer
document.onmousemove = f7_getmousepos
if (f7_ns) document.captureEvents(Event.MOUSEMOVE)

function f7_getmousepos(e){
	if(f7_ns){f7_mousex=e.pageX; f7_mousey=e.pageY}
	if(f7_ie){f7_mousex=event.clientX; f7_mousey=event.clientY;}
	}

function f7_checkmousepos(i){          
	if(f7_ns){     
		f7_x_min=eval('document.'+f7_droplayer[i]+'.left')
		f7_x_max=f7_x_min+eval('document.'+f7_droplayer[i]+'.clip.width')
		f7_y_min=eval('document.'+f7_droplayer[i]+'.top')
		f7_y_max=f7_y_min+eval('document.'+f7_droplayer[i]+'.clip.height')
		}    
	if(f7_ie){     
		f7_x_min=eval(f7_droplayer[i]+'.style.pixelLeft')
		f7_x_max=f7_x_min+eval(f7_droplayer[i]+'.scrollWidth')
		f7_y_min=eval(f7_droplayer[i]+'.style.pixelTop')
		f7_y_max=f7_y_min+eval(f7_droplayer[i]+'.scrollHeight')
		}
	if (f7_mousex>=f7_x_min && f7_mousex<=f7_x_max && f7_mousey>=f7_y_min && f7_mousey<=f7_y_max){
		f7_hideit=0; setTimeout('f7_hideall()',500)
		}
	else { f7_hideit=1 }
	return f7_hideit
	}

function getElementLeft(Elem) {		
			var elem;
			if(document.getElementById) {
				var elem = document.getElementById(Elem);
			} else if (document.all){
				var elem = document.all[Elem];
			}
			xPos = elem.offsetLeft;
			tempEl = elem.offsetParent;
  			while (tempEl != null) {
  				xPos += tempEl.offsetLeft;
	  			tempEl = tempEl.offsetParent;
  			}
			return xPos;
	}
function getElementTop(Elem) {
	
		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
	
}

	