var onZoomButton=-1;
var reqZoom;

function getMouseXY(evt) 
{
	var tooltip = document.getElementById('iframeZoomBox');
	standardbody=document.body;
	mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
	mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;    
	winWd = (ns5)? window.innerWidth-20+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
	winWd = 905+(winWd - 905)/2;
	//winHt = (ns5)? window.innerHeight-20+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;
    winHt = (ns5)? window.innerHeight-20+window.pageYOffset: document.documentElement.clientHeight+document.documentElement.scrollTop;
    
    
    
    
}


function PositionIFrame(iframeCtrl)
{

	var tpWd =(ie)? iframeCtrl.clientWidth: iframeCtrl.offsetWidth;
	var tpHt = (ie)? iframeCtrl.clientHeight: iframeCtrl.offsetHeight;

	//Below 100 is to allow for right banner width
	if ((mouseX+offX+tpWd+90)>winWd) 
		iframeCtrl.style.left = mouseX-(tpWd+offX)+"px";
	else iframeCtrl.style.left = mouseX+offX+"px";
    
    mouseY = (ie)? mouseY+document.documentElement.scrollTop:mouseY;
    
	if ((mouseY+offY+tpHt)>winHt) 
	{        
        
		iframeCtrl.style.top = winHt-(tpHt+offY)+"px";
	}
	else 
	{   
        
	    iframeCtrl.style.top = mouseY+offY+"px";		          
	}

}


function TriggerProductZoom(productId,documentId,price)
{  

	//-- Construct URL for zoom box iframe --//
    var port ="";
    if(location.port!="")
    {
        port=":"+location.port;
    }
    var url =  "http://" + document.domain + port + "/popups/productdescription.aspx";
            	
	url = url + "?productid=" + productId;
	url = url + "&documentid=" + documentId;
	url = url + "&price=" + price;
	url = url + "&rand=" + Math.random();   //-- required to disable request cache --//
    
	if(zoomBoxTimerId==0)
	{        
	    //document.getElementById("iframeZoomBox").src=url;	    
	    //zoomBoxTimerId = setTimeout('document.getElementById("iframeZoomBox").style.display="";PositionIFrame(document.getElementById("iframeZoomBox"));', 0); //Show the iframe 1 second later
	    setTimeout('document.getElementById("iframeZoomBox").style.display=""',10);
	    PositionIFrame(document.getElementById("iframeZoomBox"));
	    reqZoom = getAjaxRequest(); //-- master.js --//
	    reqZoom.onreadystatechange = function () { ShowProductZoom(productId); };
        reqZoom.open("GET",url);
        reqZoom.send(null);

	}
	else
	{
	    PositionIFrame(document.getElementById("iframeZoomBox"));
	}        

}


function HideProductZoom(productId)
{
    //if(document.getElementById("Zoom_"+productId).style.display=="none")
    if(onZoomButton != productId)
    {
	    document.getElementById("iframeZoomBox").style.display="none";
	    document.getElementById("iframeZoomBox").innerHTML="";
	    document.getElementById("Zoom_"+productId).style.display="none";

	    clearTimeout(zoomBoxTimerId);
	    zoomBoxTimerId=0;
	}

}


function ShowProductZoom(productId)
{

	if (reqZoom)
	{       
	    if (reqZoom.readyState==4 && reqZoom.status==200) 
	    {
		    var zoomBox = document.getElementById("iframeZoomBox");
		    if(zoomBox!=null)
		    {
		        zoomBox.innerHTML = reqZoom.responseText;   		        
		    }
	    }
	}

}

var hideZoomTimer;
var hideZoomProductId;
function InitializeZoomButton(productId,documentId,price)
{
    
    var zoomBtn = document.getElementById('Zoom_'+productId);
    zoomBtn.style.display='';
    zoomBtn.onmouseover= function()
    {
        this.className='ZoomButtonOn';
        onZoomButton=productId;
        TriggerProductZoom(productId,documentId,price);        
    }
    zoomBtn.onmouseout= function()
    {
        
		this.className='ZoomButton';
        this.style.display='none';
        onZoomButton=-1;
        hideZoomTimer = setTimeout('HideProductZoom('+productId+');',50);
		hideZoomProductId = productId;
    }
    zoomBtn.onmousemove= function()
    {
        //HideProductZoom(productId);        
        //(!ie)?PositionIFrame(document.getElementById("iframeZoomBox")):function(){};        
		if(productId==hideZoomProductId)
		{			
			if(hideZoomTimer!=null)
			{
				clearTimeout(hideZoomTimer);
			}
		}				
        PositionIFrame(document.getElementById("iframeZoomBox"))
    }
}

function HideZoomButton(productId)
{
    setTimeout("if(onZoomButton!="+productId+"){document.getElementById('Zoom_"+productId+"').style.display='none';}",100);
}
