/* -----------------------------------------------
   Floating layer - v.1
   (c) 2006 www.haan.net
   contact: jeroen@haan.net
   You may use this script but please leave the credits on top intact.
   Please inform us of any improvements made.
   When usefull we will add your credits.
  ------------------------------------------------ */

var isNN = document.layers ? true : false;
var isIE = document.all ? true : false;
var mouseX = 0;
var mouseY = 0;
var currentlyVisible = "";

function mouseInit() {
	if ( isNN )
		document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = updateMouseLocation;
}

function updateMouseLocation(evt) {
	mouseX = isIE ? window.event.clientX : evt.clientX;
	mouseY = isIE ? window.event.clientY  : evt.clientY;
	return false;
}
 
function setVisible(objname)
{
	if(currentlyVisible != ""){
		setInvisible(currentlyVisible);
	}
	
	obj = document.getElementById(objname);
	obj.style.display = '';
	obj.style.zIndex = 10000;
	
	currentlyVisible = objname;
}

function setInvisible(objname)
{
	obj = document.getElementById(objname);
	if(obj.style.display == ''){
		obj.style.display = 'none';
		obj.style.zIndex = -1;
	}
	currentlyVisible = "";
	toggleSelect(obj);
}

//sets an object visible and places it at the mouse position
function placeIt(obj)
{
	var thisMouseX = 0;
	var thisMouseY = 0;
	var pushX, pushY;
	var curHeight = 0;
	var curWidth = 0;
	
	//setting visible
	setVisible(obj);

	//setting up location where div is needed
	if (self.pageYOffset) // all except Explorer
	{
		pushX = self.pageXOffset;
		pushY = self.pageYOffset;
	}else if (document.documentElement && document.documentElement.scrollTop){ //IE6 only
		pushX = document.documentElement.scrollLeft;
		pushY = document.documentElement.scrollTop;
	}else if (document.body){  //all other IE
		pushX = document.body.scrollLeft;
		pushY = document.body.scrollTop;
	}
	thisMouseX += parseInt(pushX) + parseInt(mouseX);
	thisMouseY += parseInt(pushY) + parseInt(mouseY);
	
	//alert("Position is thisMouseX:" + thisMouseX + ", thisMouseY:" + thisMouseY);
	
	obj = document.getElementById(obj);
	
	curHeight = obj.offsetHeight;
	curWidth = obj.offsetWidth;
	
	obj.style.left = (thisMouseX - curWidth - 30) + 'px' ;
	obj.style.top = (thisMouseY - (curHeight / 2)) + 'px' ;
	//setTimeout("placeIt('layer1')",500);
	
	//clearing any SELECT elements under the div
	toggleSelect(obj);
}

//this function toggles on or off all the items underneath the element being sent in
function toggleSelect(obj){
	
	var appVer = navigator.appVersion.toLowerCase();
	var iePos = appVer.indexOf('msie');
	if (iePos !=-1) {
		var is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
		var is_major = parseInt(is_minor);
	}
	if (navigator.appName.substring(0,9) == "Microsoft")
	{ // Check if IE version is 6 or older
		if (is_major <= 6) {
			var selx,sely,selw,selh,i, objx, objy, objh, objw, visibility
			var sel=document.getElementsByTagName("SELECT")
			var hidden = false;
			for(i=0;i<sel.length;i++){
				selx=docjslib_getRealLeft(sel[i]);
				sely=docjslib_getRealTop(sel[i]);
				selw=sel[i].offsetWidth;
				selh=sel[i].offsetHeight;
				selxoff=(selx + selw);
				selyoff=(sely + selh);
				objx=docjslib_getRealLeft(obj);
				objy=docjslib_getRealTop(obj);
				objw=obj.offsetWidth;
				objh=obj.offsetHeight;
				if((objx < selx) && (selx < (objx + objw)) && (objy < sely) && (sely < (objy + objh))){
					if(sel[i].style.visibility!="hidden"){
						sel[i].style.visibility="hidden";
					}else{
						sel[i].style.visibility="visible";
					}
				}else if((objx < selxoff) && (selxoff < (objx + objw)) && (objy < selyoff) && (selyoff < (objy + objh))) {
					if(sel[i].style.visibility!="hidden"){
						sel[i].style.visibility="hidden";
					}else{
						sel[i].style.visibility="visible";
					}
				}else{
					if(sel[i].style.visibility=="hidden"){
						sel[i].style.visibility="visible";
					}
				}
				visibility = sel[i].style.visibility;
			}
		}
	}
} 

//gets the X position of the element in question
function docjslib_getRealLeft(imgElem) {
	xPos = eval(imgElem).offsetLeft;
	tempEl = eval(imgElem).offsetParent;
  	while (tempEl != null) {
  		xPos += tempEl.offsetLeft;
  		tempEl = tempEl.offsetParent;
  	}
	return xPos;
}

//gets the Y position of the element in question
function docjslib_getRealTop(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}





//matches the size of something, objToResize is the object of the item to change, objToMatch is the object of the item to match
function matchObjectSize(objToResize, objToMatch){
	objToResize.style.width = objToMatch.offsetWidth.toString() + 'px';
	objToResize.style.height = objToMatch.offsetHeight.toString() + 'px';
}

//matches the location of something, objToResize is the object of the item to change, objToMatch is the object of the item to match
function matchObjectLocation(objToResize, objToMatch){
	objToResize.style.left = objToMatch.style.left + 'px';
	objToResize.style.top = objToMatch.style.top + 'px';
}
