var curSwap,curMenu,curMenuX,curMenuH;
var menuWidth=150;
var menuY = 110;
var labelHeight=25;
var labelWidth=150;

var isNav, isIE;
if( parseInt( navigator.appVersion ) >= 4 ){
	if( navigator.appName == "Netscape" ) isNav = true;
	else isIE = true;
}

function findObj(n, d){
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// Load images for rollovers
function load() {
	var imgs = load.arguments;
	if (document.images) {
		document.preload = new Array();
		for (var j = 0; j < imgs.length; j++){ document.preload[j] = new Image();document.preload[j].src = imgs[j];}
	}
}

function openW(url,name,w,h) {
	var windowprops = "width=" + w + ",height=" + h + ",scrollbars,toolbar,menubar";
	popup = window.open(url, name, windowprops);
	setTimeout('popup.focus();',250);
}

// Restore currently swapped image to original state
function restore(){ 
	if(curSwap != null) if(curSwap.oldSrc) curSwap.src=curSwap.oldSrc;
	curSwap=null;
}

function swap(img,file){ 
	img=findObj(img);
	if(img != null){
		curSwap=img;
		img.oldSrc=img.src;
		img.src=file;
	}
}

function restoreMenu(){
	if(curMenu != null){
		if(curMenu.style) curMenu.style.visibility='hidden';
		else curMenu.visibility='hide';
	}
	curMenu = null;
}

function trackMouse(evt){
	var x,y;
	if( isNav ){	x = evt.pageX; y = evt.pageY; }
	else { x = window.event.clientX + document.body.scrollLeft;	y = window.event.clientY + document.body.scrollTop; }
	if( !chkBox(x,y,curMenuX,menuY,labelWidth,labelHeight) && !chkBox(x,y,curMenuX,menuY+labelHeight-1,menuWidth,menuHeight) ){
		restoreMenu();
		if(isNav) document.releaseEvents( Event.MOUSEMOVE );
		document.onmousemove = null;
	}
}

function chkBox(x,y,bx,by,bw,bh){
	if(x > bx && x < (bx+bw) && y > by && y < (by+bh)) return true
	else return false;
}

function showMenu(obj,x){
	restoreMenu();
	curMenuX = x; obj = findObj(obj);
	if(obj != null){
		if(obj.style) obj.style.visibility='visible';
		else obj.visibility='show';
		curMenu=obj;
	}
	if(isNav){ 
		menuHeight=150;
		document.captureEvents(Event.MOUSEMOVE);
	} else {
		menuHeight=obj.clientHeight+10;
	}
	
	document.onmousemove=trackMouse;
}

