﻿function lp_getrealtop(oObj) {
var sTag = "";
var i = 0;
while ((sTag != "body") && (oObj != null))   {
i += oObj.offsetTop;
oObj = oObj.offsetParent;
if (oObj != null) sTag = oObj.tagName.toLowerCase();
}
return(i);
}
function lp_getrealleft(oObj) {
var sTag = "";
var i = 0;
while ((sTag != "body") && (oObj != null))   {
i += oObj.offsetLeft;
oObj = oObj.offsetParent;
if (oObj != null) sTag = oObj.tagName.toLowerCase();
}
return(i);
}
var zoomRatio = 2.2;
var zoomDepth = 2;
var ratio = 1 / zoomRatio;

function showClip(e) {
    if (!e) e = window.event;
    var imgT = document.getElementById("ctl00_ContentPlaceHolder1_imgPhoto");
    var clip = document.getElementById("divClip");
    var scrollX = window.scrollX || document.body.parentNode.scrollLeft || document.body.scrollLeft; 
    var scrollY =window.scrollY || document.body.parentNode.scrollTop || document.body.scrollTop;
    var l =  lp_getrealleft(imgT) - scrollX; //document.documentElement.scrollLeft;
    var t =  lp_getrealtop(imgT) - scrollY; //document.documentElement.scrollTop;
    var clipWidth = Math.round((imgT.width * ratio) / zoomDepth);
    var clipHeight = Math.round((imgT.height * ratio) / zoomDepth);
    var x = e.clientX - l - (clipWidth/2);
    var y = e.clientY - t - (clipHeight/2);
    if (x < 0) x = 0;
    if (y < 0) y = 0;
    if ((x + clipWidth) > imgT.width) x = imgT.width - clipWidth;
    if ((y + clipHeight) > imgT.height) y = imgT.height - clipHeight;
    x += imgT.offsetLeft;
    y += imgT.offsetTop;
    clip.style.width = clipWidth + "px";
    clip.style.height = clipHeight + "px";
    clip.style.left = x + "px";
    clip.style.top = y + "px";
    clip.style.visibility = "visible";
}
function hideClip(e) {
    if (!e) e = window.event;
    var clip = document.getElementById("divClip");
    clip.style.visibility = "hidden";
}
    
function getZoomImg(e) {
    if (!e) e = window.event;
    var imgT = document.getElementById("ctl00_ContentPlaceHolder1_imgPhoto");
    var imgZ = document.getElementById("imgZoom");
    var scrollX = window.scrollX || document.body.parentNode.scrollLeft || document.body.scrollLeft; 
    var scrollY =window.scrollY || document.body.parentNode.scrollTop || document.body.scrollTop;
    var l = lp_getrealleft(imgT) - scrollX; // document.body.scrollLeft; //document.documentElement.scrollLeft;
    var t = lp_getrealtop(imgT) - scrollY; // document.body.scrollTop; //document.documentElement.scrollTop;
    var x = e.clientX - l;
    var y = e.clientY - t;
    var currentZoomRatio = Math.pow(zoomRatio, zoomDepth - 1);
    var clipWidth = Math.round((imgT.width * ratio) / zoomDepth);
    var clipHeight = Math.round((imgT.height * ratio) / zoomDepth);
    var clipX = x - (clipWidth/2);
    if (clipX < 0) clipX = 0;
    if ((clipX + clipWidth) > imgT.width) clipX = imgT.width - clipWidth;
    var clipY = y - (clipHeight/2);
    if (clipY < 0) clipY = 0;
    if ((clipY + clipHeight) > imgT.height) clipY = imgT.height-clipHeight;
    var baseX = (clipX + (clipWidth / 2));
    var baseY = (clipY + (clipHeight / 2));
    document.getElementById('imgLoading').style.display="inline";
    imgZ.src = 'http://download.fotolia.com/Content/Zoom/' + (zoomRatio * currentZoomRatio) + '/' + baseX + '/' + baseY + '/?path=' + escape(imgT.src);
}

addLoadEvent(function () {
    var imgT = document.getElementById("ctl00_ContentPlaceHolder1_imgPhoto");
    var clip = document.getElementById("divClip");
    if (imgT.getAttribute('lp_zoomable') == 1) {
        //imgT.onclick = getZoomImg; //IE
        imgT.onmousemove = showClip; //IE
        imgT.onmouseover = showClip; 
        imgT.onmouseout = hideClip; //IE
        clip.onclick = getZoomImg;
        clip.onmousemove = showClip;
        clip.onmouseout = hideClip;
        document.getElementById("imgZoom").onload = function () {document.getElementById('imgLoading').style.display="none";}
    } else {
        var info = document.getElementById("clickInfo");
        info.style.display = "none";
    }
});
