﻿

function BCzoom(obj, highres) {

    BCzoomratio = BCzoomheight / BCzoomwidth;

    if (BCzoomoffsetx > 1) {

        BCzoomoffset = 'dumb';

        BCzoomoffsetx = BCzoomoffsetx / BCzoomwidth;

        BCzoomoffsety = BCzoomoffsety / BCzoomheight;

    }

    if (!obj.style.width) {

        if (obj.width > 0) {

          

            obj.style.width = obj.width + 'px';

            obj.style.height = obj.height + 'px';

        }

    }

    if (typeof (highres) != typeof ('')) { highres = obj.src }

    var BCstage = document.createElement("div");

    BCstage.style.width = obj.style.width;

    BCstage.style.height = obj.style.height;

    BCstage.style.overflow = 'hidden';

    BCstage.style.position = 'absolute';

    if (typeof (BCstage.style.filter) != typeof (nosuchthing)) {

       

        if (navigator.appVersion.indexOf('Mac') == -1) {

            BCstage.style.filter = 'alpha(opacity=0)';

            BCstage.style.backgroundColor = '#ffffff';

        }

    } else {

       

        BCstage.style.backgroundImage = 'transparent';

    }

    BCstage.setAttribute('onmousemove', 'BChandlemouse(event,this);');

    BCstage.setAttribute('onmousedown', 'BChandlemouse(event,this);');

    BCstage.setAttribute('onmouseup', 'BChandlemouse(event,this);');

    BCstage.setAttribute('onmouseout', 'BChandlemouse(event,this);');

    if (navigator.userAgent.indexOf('MSIE') > -1) {

        BCstage.onmousemove = function() { BChandlemouse(event, this); }

        BCstage.onmousedown = function() { BChandlemouse(event, this); }

        BCstage.onmouseup = function() { BChandlemouse(event, this); }

        BCstage.onmouseout = function() { BChandlemouse(event, this); }

    }

    obj.parentNode.insertBefore(BCstage, obj);



    BCwin = document.createElement("div");

    BCwin.style.width = '0px';

    BCwin.style.height = '0px';

    BCwin.style.overflow = 'hidden';

    BCwin.style.position = 'absolute';

    BCwin.style.display = 'none';

    tw1 = '<div style="position:absolute;overflow:hidden;margin:';

    BCwin.innerHTML =

 tw1 + '0 0 0 0; background-color:' + BCbordercolor + '; width:' + BCzoomwidth + 'px;height:' + BCzoomheight + 'px"></div>' +

 tw1 + BCborderthick + 'px 0 0 ' + BCborderthick + 'px; width:' + (BCzoomwidth - BCborderthick * 2) + 'px;height:' + (BCzoomheight - BCborderthick * 2) + 'px;"><img src="' + obj.src + '" style="position:absolute;margin:0;padding:0;border:0; width:' + (BCzoomamount * parseInt(obj.style.width)) + 'px;height:' + (BCzoomamount * parseInt(obj.style.height)) + 'px;" />' + ((obj.src != highres) ? ('<img src="' + highres + '" style="position:absolute;margin:0;padding:0;border:0; width:' + (BCzoomamount * parseInt(obj.style.width)) + 'px;height:' + (BCzoomamount * parseInt(obj.style.height)) + 'px;" onload="if(this.parentNode) {this.parentNode.parentNode.getElementsByTagName(\'div\')[2].style.display=\'none\';}" />') : ('')) + '</div>';

    if (highres != obj.src) {

        BCwin.innerHTML += '<div style="position:absolute; margin:' + BCborderthick + 'px 0 0 ' + BCborderthick + 'px;">' + BCloading + '</div>';

    }

   

    obj.parentNode.insertBefore(BCwin, BCstage);

    BCresize(obj);

}

function BCresize(obj) {

    sbr = 0; sbl = 0;

    if (BCzoomwidth - 2 * BCborderthick < 22) { sbr = 1 }

    if (BCzoomheight - 2 * BCborderthick < 22) { sbr = 1 }

    if (BCzoomwidth > parseFloat(obj.style.width)) { sbl = 1; }

    if (BCzoomheight > parseFloat(obj.style.height)) { sbl = 1 }



    if (sbr == 1 && sbl == 1) {

        BCzoomwidth = parseFloat(obj.style.width) / 2;

        BCzoomheight = parseFloat(obj.style.height) / 2;

        BCzoomratio = BCzoomheight / BCzoomwidth;

    }

    if (sbr == 1) {

        if (BCzoomwidth < BCzoomheight) {

            BCzoomheight = BCzoomheight / BCzoomwidth * (22 + 2 * BCborderthick); BCzoomwidth = 22 + 2 * BCborderthick;

        } else {

            BCzoomwidth = BCzoomwidth / BCzoomheight * (22 + 2 * BCborderthick); BCzoomheight = 22 + 2 * BCborderthick;

        }

    }



    if (sbl == 1) {

        if (parseFloat(obj.style.width) / parseFloat(obj.style.height) > BCzoomwidth / BCzoomheight) {

            BCzoomheight = parseFloat(obj.style.height);

            BCzoomwidth = BCzoomheight / BCzoomratio;

        } else {

            BCzoomwidth = parseFloat(obj.style.width);

            BCzoomheight = BCzoomratio * BCzoomwidth;

        }

    }

    BCzoomwidth = Math.floor(BCzoomwidth / 2) * 2;

    BCzoomheight = Math.floor(BCzoomheight / 2) * 2;

    ww = obj.parentNode.getElementsByTagName('div')[0];

    ww.style.width = BCzoomwidth + 'px';

    ww.style.height = BCzoomheight + 'px';

    w = ww.getElementsByTagName('div')[0];

    w.style.width = BCzoomwidth + 'px';

    w.style.height = BCzoomheight + 'px';

    w = ww.getElementsByTagName('div')[1];

    w.style.width = BCzoomwidth - BCborderthick * 2 + 'px';

    w.style.height = BCzoomheight - BCborderthick * 2 + 'px';

}

function BCfindposy(obj) {

    var curtop = 0;

    if (!obj) { return 0; }

    if (obj.offsetParent) {

        while (obj.offsetParent) {

            curtop += obj.offsetTop

            obj = obj.offsetParent;

        }

    } else if (obj.y) {

        curtop += obj.y;

    }

    return curtop;

}

function BCfindposx(obj) {

    var curleft = 0;

    if (!obj) { return 0; }

    if (obj && obj.offsetParent) {

        while (obj.offsetParent) {

            curleft += obj.offsetLeft

            obj = obj.offsetParent;

        }

    } else if (obj.x) {

        curleft += obj.x;

    }

    return curleft;

}

function BChandlemouse(evt, obj) {

    var evt = evt ? evt : window.event ? window.event : null; if (!evt) { return false; }

    if (evt.pageX) {

        nowx = evt.pageX - BCfindposx(obj) - BCadjustx;

        nowy = evt.pageY - BCfindposy(obj) - BCadjusty;

    } else {

        if (document.documentElement && document.documentElement.scrollTop) {

            nowx = evt.clientX + document.documentElement.scrollLeft - BCfindposx(obj) - BCadjustx;

            nowy = evt.clientY + document.documentElement.scrollTop - BCfindposy(obj) - BCadjusty;

        } else {

            nowx = evt.x + document.body.scrollLeft - BCfindposx(obj) - BCadjustx;

            nowy = evt.y + document.body.scrollTop - BCfindposy(obj) - BCadjusty;

        }

    }

    if (evt.type == 'mousemove') {

        BCsetwin(obj, nowx, nowy);

    } else if (evt.type == 'mousedown') {

        BCmouse = 1; //left: 1, middle: 2, right: 3

        BCmousey = nowy;

        BCmousex = nowx;

    } else if (evt.type == 'mouseup') {

        BCmouse = 0;

    } else if (evt.type == 'mouseout') {

        BCmouse = 0;

        if (navigator.appVersion.indexOf('Mac') == -1 || navigator.appVersion.indexOf('MSIE') == -1) { //hi Mac IE

            x = obj.parentNode;

            x.removeChild(x.getElementsByTagName('div')[0]);

            x.removeChild(x.getElementsByTagName('div')[0]);

        }

    }

}

function BCsetwin(obj, nowx, nowy) {

    obj.parentNode.getElementsByTagName('div')[0].style.display = 'block';

    if (BCzoomoffset == 'smart') {

        BCzoomoffsetx = .1 + .8 * nowx / parseFloat(obj.style.width);

        BCzoomoffsety = .1 + .8 * nowy / parseFloat(obj.style.height);

    }

    stage = obj.parentNode.getElementsByTagName('div')[0];

    if (BCmouse == 1) {

        if (Math.abs(nowy - BCmousey) >= 1) {

            BCzoomamount *= ((nowy > BCmousey) ? (0.909) : (1.1));

            BCmousey = nowy;

            if (BCzoomamount < BCzoomamountmin) { BCzoomamount = BCzoomamountmin; }

            if (BCzoomamount > BCzoomamountmax) { BCzoomamount = BCzoomamountmax; }

            stage.getElementsByTagName('div')[1].getElementsByTagName('img')[0].style.width = parseInt(obj.style.width) * BCzoomamount + 'px';

            stage.getElementsByTagName('div')[1].getElementsByTagName('img')[0].style.height = parseInt(obj.style.height) * BCzoomamount + 'px';

            if (stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1]) {

                stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1].style.width = stage.getElementsByTagName('div')[1].getElementsByTagName('img')[0].style.width;

                stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1].style.height = stage.getElementsByTagName('div')[1].getElementsByTagName('img')[0].style.height;

            }

        }

        if (Math.abs(nowx - BCmousex) >= 12 && BCzoomwindowlock == 0) {

            BCzoomwidth *= ((nowx > BCmousex) ? (1.1) : (0.909));

            BCzoomheight = BCzoomwidth * BCzoomratio;

            BCresize(obj);

            BCmousex = nowx;

        }

    }

    stage.style.marginLeft = nowx - (BCzoomwidth - 2 * BCborderthick) * BCzoomoffsetx - BCborderthick + 'px';

    stage.style.marginTop = nowy - (BCzoomheight - 2 * BCborderthick) * BCzoomoffsety - BCborderthick + 'px';

    clip1 = 0; clip2 = BCzoomwidth; clip3 = BCzoomheight; clip4 = 0;

    nwidth = BCzoomwidth; nheight = BCzoomheight;

    tmp = (1 - 2 * BCzoomoffsetx) * BCborderthick;



    if (nowx - BCzoomwidth * BCzoomoffsetx < tmp) {

        clip4 = BCzoomwidth * BCzoomoffsetx - nowx + tmp;

    } else if (parseFloat(nowx - BCzoomwidth * BCzoomoffsetx + BCzoomwidth) > parseFloat(obj.style.width) + tmp) {

        clip2 = BCzoomwidth * BCzoomoffsetx - nowx + parseFloat(obj.style.width) + tmp;

        nwidth = BCzoomwidth * BCzoomoffsetx - nowx + parseInt(obj.style.width) + BCborderthick;

    }



    tmp = (1 - 2 * BCzoomoffsety) * BCborderthick;



    if (nowy - BCzoomheight * BCzoomoffsety < tmp) {

        clip1 = BCzoomheight * BCzoomoffsety - nowy + tmp;

    } else if (parseFloat(nowy - BCzoomheight * BCzoomoffsety + BCzoomheight) > parseFloat(obj.style.height) + tmp) {

        clip3 = BCzoomheight * BCzoomoffsety - nowy + parseFloat(obj.style.height) + tmp;

        nheight = BCzoomheight * BCzoomoffsety - nowy + parseFloat(obj.style.height) + BCborderthick;

    }

    stage.style.width = nwidth + 'px';

    if (nheight < 0) {

        nheight = 0;

    }

    stage.style.height = nheight + 'px';

    stage.style.clip = 'rect(' + clip1 + 'px,' + clip2 + 'px,' + clip3 + 'px,' + clip4 + 'px)';

    if (nowy - BCzoomoffsety * (BCzoomheight - 2 * BCborderthick) < 0) { t = -(nowy - BCzoomoffsety * (BCzoomheight - 2 * BCborderthick)) }

    else if (nowy - BCzoomoffsety * (BCzoomheight - 2 * BCborderthick) > parseFloat(obj.style.height) - BCzoomheight + BCborderthick * 2) { t = -BCzoomamount * parseFloat(obj.style.height) + BCzoomheight - BCborderthick * 2 - ((nowy - BCzoomoffsety * (BCzoomheight - 2 * BCborderthick)) - (parseFloat(obj.style.height) - BCzoomheight + BCborderthick * 2)); }

    else { t = (-BCzoomamount * parseFloat(obj.style.height) + BCzoomheight - BCborderthick * 2) / (parseFloat(obj.style.height) - BCzoomheight + BCborderthick * 2) * (nowy - BCzoomoffsety * (BCzoomheight - 2 * BCborderthick)) }

    stage.getElementsByTagName('div')[1].getElementsByTagName('img')[0].style.marginTop = t + 'px';

    if (stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1]) {

        stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1].style.marginTop = t + 'px';

    }

    if (nowx - BCzoomoffsetx * (BCzoomwidth - 2 * BCborderthick) < 0) { t = -(nowx - BCzoomoffsetx * (BCzoomwidth - 2 * BCborderthick)) }

    else if (nowx - BCzoomoffsetx * (BCzoomwidth - 2 * BCborderthick) > parseFloat(obj.style.width) - BCzoomwidth + BCborderthick * 2) { t = -BCzoomamount * parseFloat(obj.style.width) + BCzoomwidth - BCborderthick * 2 - ((nowx - BCzoomoffsetx * (BCzoomwidth - 2 * BCborderthick)) - (parseFloat(obj.style.width) - BCzoomwidth + BCborderthick * 2)); }

    else { t = (-BCzoomamount * parseFloat(obj.style.width) + BCzoomwidth - BCborderthick * 2) / (parseFloat(obj.style.width) - BCzoomwidth + BCborderthick * 2) * (nowx - BCzoomoffsetx * (BCzoomwidth - 2 * BCborderthick)) }

    stage.getElementsByTagName('div')[1].getElementsByTagName('img')[0].style.marginLeft = t + 'px';

    if (stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1]) {

        stage.getElementsByTagName('div')[1].getElementsByTagName('img')[1].style.marginLeft = t + 'px';

    }

}

function BCinit() {

    BCadjustx = 0; BCadjusty = 0;

    if (navigator.userAgent.indexOf('MSIE') > -1) { BCadjustx = 2; BCadjusty = 2; }

    if (navigator.userAgent.indexOf('Opera') > -1) { BCadjustx = 0; BCadjusty = 0; }

    if (navigator.userAgent.indexOf('Safari') > -1) { BCadjustx = 1; BCadjusty = 2; }

}



var BCon = new Array();

var BCadjustx, BCadjusty;

var BCmouse = 0; var BCmousey; var BCmousex;

var BCloading = '<div style="background-color: #fff; color: #333333; padding:2px; font-family: verdana,arial,helvetica; font-size: 10px;">Loading...</div>';

var BCzoomwidth = 200;

var BCzoomheight = 180;

var BCzoomratio;

var BCzoomwindowlock = 0;

var BCzoomoffsetx = .5;

var BCzoomoffsety = .5;

var BCzoomoffset;

var BCzoomamount = 2;

var BCzoomamountmax = 5;

var BCzoomamountmin = 1;

var BCborderthick = 5;

var BCbordercolor = '#f7f7f7';

var BCshadow = 'dropshadow/';

BCinit();
