/* script for the hover on the products */
function initProductHover()
{
	if(typeof totalProducts != "null")
	{
		if(totalProducts>0)
		{//2007.03.16: check op <= i.p.v. <
			for(i=1;i<=totalProducts;i++)
			{
				imgEl=$("productCounter_"+i);
				if(imgEl)
				{
					
					
					imgEl.hover_counter=i;
					imgEl.onmouseover=function()
					{						
						showBox(this.hover_counter,(findPosY(this))+10,(findPosX(this)+this.width));						
					} 
					
					imgEl.onmouseout=function()
					{
						hideBox(this.hover_counter);
					}
					
										
					linkEl=$("productCounterLink_"+i);
					if(linkEl)
					{
						linkEl.hover_counter=i;
						linkEl.onmouseover=function()
						{						
							showBox(this.hover_counter,(findPosY($("productCounter_"+this.hover_counter)))+10,(findPosX($("productCounter_"+this.hover_counter))+$("productCounter_"+this.hover_counter).width));						
						} 
						
						linkEl.onmouseout=function()
						{
							hideBox(this.hover_counter);
						}
					}
				}
				
			}
		}
	}
}


var doHideBox=true;

function showBox(id,x,y)
{
	if(typeof id != "null")
	{
		boxEl=$("box_" + id);
		
		if(boxEl)
		{						
			fillHooverBox("box_" + id);
			if(y>900) y-=400;
			if(y<0) y=251;
			
			boxEl.style.position="absolute";						
			boxEl.style.left=y + "px";
			boxEl.style.top=x + "px";
			
			boxEl.zIndex=0;
						
			Effect.Appear("box_" + id, { duration: 0.5 });			
		}
	}
}

/*----------------------------------------------------------
gx.2007.03.29 Additional function by GX:
problem: performance issue, because rendering the productlist is too slow
solution: show tooltip using AJAX
----------------------------------------------------------*/
function fillHooverBox(strDivId)
{
	if (strDivId)
	{
		boxEl=$(strDivId);
		if (boxEl && boxEl.innerHTML == "")
		{		
			var strSep = "&";
			if (ajaxURI.indexOf("?") == -1)
			{
				strSep = "?";
			}
			myAjax=new Ajax.Updater(strDivId, ajaxURIhoover + "?dbid="+boxEl.getAttribute("name"), { asynchronous:true,evalScripts:true,onComplete:doneLoadingAjaxContent,method:'get' });
		}
	}
}


function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
	    while(1) 
	    {
	      curleft += obj.offsetLeft;
	      if(!obj.offsetParent)
	        break;
	      obj = obj.offsetParent;
	    }
	else if(obj.x)
	    curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	    while(1)
	    {
	      curtop += obj.offsetTop;
	      if(!obj.offsetParent)
	        break;
	      obj = obj.offsetParent;
	    }
	else if(obj.y)
	    curtop += obj.y;
	return curtop;
}


function hideBox(id)
{
	if(typeof id != "null")
	{
		boxEl=$("box_" + id);
		if(boxEl)
		{
			Effect.Fade("box_" + id, { duration: 0.1 });			
		}
	}
}


currentMouseX=0;
currentMouseY=0;
function getMouseCoordinates(event)
{
	ev = event || window.event;
	currentMouseX=ev.pageX;
	currentMouseY=ev.pageY;
}

document.onmousemove=getMouseCoordinates;