
var millisec = 250;
var timeoutId;
var visiblePopup = null;
var imgArrow_on = "/searchResults/resultListMoreInfo-over.jpg";
var imgArrow = "/searchResults/resultListMoreInfo.jpg";
var imgArrowClassName = "moreInfoImage";

/*
 * handleover() 
 * parameter
 *		imageServerPath - arrow images's server path
 *		divObj - div object that triggers popup
 *		popdivId - targeted popup div id
 */  
function handleover(imageServerPath, divObj, popdivId)
{
	
	if(popdivId == visiblePopup)
		clearpopup();
	
	var elmImgs = divObj.getElementsByTagName("img");	
	imageServerPath += imgArrow_on;	
	for(var i=0; i<elmImgs.length; i++)
	{
		if(elmImgs[i].className == imgArrowClassName)
			elmImgs[i].setAttribute("src", imageServerPath);
	}

	//create onlcick event on this target
	divObj.onclick = function()
	{
		showHidePopup(popdivId)
	}
}

/*
 * handleover() 
 * parameter
 *		imageServerPath - arrow images's server path
 *		divObj - div object that triggers popup

 */ 
function handleout(imageServerPath, divObj) 
{
	var elmImgs = divObj.getElementsByTagName("img");	
	imageServerPath += imgArrow;	
	for(var i=0; i<elmImgs.length; i++)
	{
		if(elmImgs[i].className == imgArrowClassName)
			elmImgs[i].setAttribute("src", imageServerPath);
	}
	delayhide()
}

/*
 * showHidePopup()
 * parameter
 * 		popupdivId - targeted popup div id
 */
function showHidePopup(popdivId)
{
	if(document.getElementById)
	{
		var obj = document.getElementById(popdivId);
		if(obj.style.visibility == "hidden" || obj.style.visibility == "")
		{
			obj.style.visibility = "visible";
    		hidepopup();
			visiblePopup=popdivId;
		}
		else
			hidepopup();
	}
	return false;
}

/*
 * delayhide() 
 * 		delays popup closing timing.
 */
function delayhide()
{
	clearpopup();
	timeoutId = setTimeout(function(){hidepopup()}, millisec);
}

/*
 * hidepopup() 
 * 		close the targetd popup when a user click the "x".
 */
function hidepopup()
{
	clearpopup();
	if(visiblePopup!=null)
	{
		var o = document.getElementById(visiblePopup);		
		visiblePopup=null;
		o.style.visibility = "hidden";
	}
	return false;
}

/*
 * clearpopup() 
 * 		cancel the setTimeout(), so when a user mouseover the popup,
 * it will not disappeared. 
 */
function clearpopup()
{
	if(typeof timeoutId != "undefined")
	{
		clearTimeout(timeoutId);
	}
}
