var timerID=null ; // global timer for expiring rollovers
var timeoutValue=720 ; // global timeout value - how long after mouseout do thumbnails persist

function initDropBoxes(timeout)
{
	var boxes=findObj('dropBoxes') ;
	var droppers ;
	var dropBoxID ;
	var dropperID ;
	var box ;

	droppers = findDroppers(boxes) ;

	if (timeout != null)
		document.timeoutValue=timeout ;

	for(var i=0;i < droppers.length;i++)
	{	dropBoxID=droppers[i].getAttribute('box') ;
		dropperID=droppers[i].getAttribute('id') ;
		box=findObj(dropBoxID) ;
		box.style.visibility = "hidden" ;
		droppers[i].onmouseover = new Function("showBox('"+dropperID+"')") ;
		droppers[i].onmouseout = new Function("startTimer()") ;
		box.onmouseover = new Function("killTimer()") ;
		box.onmouseout = new Function("startTimer()") ;
		// alert('init dropper('+i+')-'+dropperID+" drops:"+dropBoxID+"-"+box) ;
	}
}

function findObj(theObj, theDoc)
{
	var p, i, foundObj;
	if(!theDoc) theDoc = document;
	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
	for (i=0; !foundObj && i < theDoc.forms.length; i++) 
		foundObj = theDoc.forms[i][theObj];
	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
		foundObj = findObj(theObj,theDoc.layers[i].document);
	if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

	return foundObj;
}

function findDroppers(parentObj,droppers) // recurses 'till it finds em all
{
	if (!droppers)
		var droppers=new Array() ;
	if(parentObj.hasChildNodes()==true)
	{	if(parentObj.children)
			var ch=parentObj.children ;
		if(parentObj.childNodes)
			var ch=parentObj.childNodes ;
		for(var i=0, d=droppers.length; i < ch.length; i++)
		{	if (ch[i].attributes)
			{	if (ch[i].getAttribute('box') != null)
				{	droppers[d++]=ch[i] ;
				}
			}
			if (ch[i].hasChildNodes())
				droppers=findDroppers(ch[i],droppers);
		}
	}
	return droppers ;
}

function getObjMetrics(obj)
{
	var objBox=new Object(); 
	if (document.getBoxObjectFor)
	{	var bo = document.getBoxObjectFor(obj); 
		objBox.x = bo.x; 
		objBox.w = bo.width;
		objBox.y = bo.y;
		objBox.h = bo.height;
	} 
	else if (obj.getBoundingClientRect)
	{	var rect = obj.getBoundingClientRect(); 
		objBox.x = rect.left; 
		objBox.w = rect.right - rect.left;
		objBox.y = rect.top;
		objBox.h = rect.bottom - rect.top;
	} 
	return objBox ;
}

function calcDropBox(boxID)
{
	return ;
}

function hideBoxes()
{
	obj=findObj('dropBoxes') ;
	var droppers = new Array() ;
	droppers=findDroppers(obj) ;
	for(var i =0;i<droppers.length;i++)
	{	var dropBox = findObj(droppers[i].getAttribute('box')) ;
		dropBox.style.visibility = "hidden" ;
	}
}

function showBox(dropperID)
{	hideBoxes() ;
	var dropper=findObj(dropperID) ;
	var dropBox=findObj(dropper.getAttribute('box')) ;
	var offsetX=0, offsetY=0 ;
	if ((x=dropper.getAttribute('offsetX')) != null)
		offsetX=1*x ;
	if ((y=dropper.getAttribute('offsetY')) != null)
		offsetY=1*y ;
	if (dropBox)
	{	killTimer() ;
		boxMetrics=getObjMetrics(dropper) ; 	// x=boxMetrics.x ; y=boxMetrics.y ; w=boxMetrics.w ; h=boxMetrics.h
		newX = boxMetrics.x + offsetX;
		newY = boxMetrics.y + boxMetrics.h + offsetY;
		setPosition(dropBox,newX,newY)
		dropBox.style.visibility = "visible" ;
	}
}

function setPosition(obj,x,y)
{
	var addScroll=(navigator.userAgent.toLowerCase().indexOf('msie') != -1)
	if (addScroll)
	{	if(document.body.scrollLeft != null)
		{	x+=document.body.scrollLeft ;
			y+=document.body.scrollTop ;
		}
	}

	if(obj.style.pixelLeft != null) // IE
	{	obj.style.pixelLeft = x;
		obj.style.pixelTop = y;
	} else if (obj.style.left != null) { //DOM 2.0
		obj.style.left = x;
		obj.style.top = y;
	} else if (obj.left != null) { // N4
		obj.left = x;
		obj.top = y;
	}
}

function killTimer() { // kill timer if you get over a thumbnail
	if (timerID) {
		clearTimeout(timerID) ;
		timerID = null ;
	}
	return true ;
}

function startTimer()  { // (re)set timer 
	killTimer() ; // if any
	timerID = setTimeout("timedOut()", timeoutValue) ;
	return true ;
}

function timedOut()  { // hide layerShown
	killTimer() ;
	hideBoxes() ;
	return true ;
}
