var id;
var imgurl;
var clockTimeoutID;

function popup(ID,IMGURL)
{
    id = ID;
    imgurl = IMGURL;
    clearTimeout(clockTimeoutID);
    clockTimeoutID = setTimeout("delayProcess()",0);
   
}

function delayProcess()
{
   setImgPosition(id);
   document.getElementById('popup'+id).style.display="block";
   LoadImage(id,imgurl);
}

function setImgPosition(id)
{
    var Element = document.getElementById('popup'+id);                                
    Element.style.top = parseFloat(getImgRealTop(id))+parseFloat(25)+"px";
                
    var left = parseFloat(getImgRealLeft(id)) - parseFloat(0);
    if((parseFloat(left)+parseFloat(document.getElementById('popup'+id).style.width)) >screen.width)
    {
        Element.style.left =parseFloat(parseFloat(getImgRealLeft(id)) -parseFloat(document.getElementById('popup'+id).style.width))+"px";
    }
    else
    {
        Element.style.left = parseFloat(parseFloat(getImgRealLeft(id)) + parseFloat(10))+"px";
    }

}

 function getImgRealTop(el){

    var yPos = document.getElementById(el).offsetTop;
    var tempEl = document.getElementById(el).offsetParent;
    
    while (tempEl != null) {
    yPos += tempEl.offsetTop;
    tempEl = tempEl.offsetParent;
    }
    return yPos;
}
function getImgRealLeft(el){
    var xPos = document.getElementById(el).offsetLeft;
    var tempEl = document.getElementById(el).offsetParent;
    while (tempEl != null) {
    xPos += tempEl.offsetLeft;
    tempEl = tempEl.offsetParent;
    }
    return xPos;
 }
 function LoadImage(id,url)
 {
    var Element = document.getElementById('regimg'+id); 
    Element.src = url;
 }
 function CloseImgDiv(id)
 {
    clearTimeout(clockTimeoutID);
    document.getElementById('popup'+id).style.display="none";
 }
 function OpenLargeProductImage(path,width,height)
{
		var MsgWindow;
		var URL = "include/LargeProductImage.aspx?path=" + path;
		MsgWindow = window.open(URL,"MsgWindow","scrollbars=1,width="+ (width)+"px,height="+ (height)+"px,menubar=0,resizable=1");
}
