// config:
var zoomer_width = 440;
var zoomer_height = 440;
var zoomer_top = 225;
var zoomer_left = 41; // décalage par rapport au centre de la page
var zoomer_border = "#0062AB 1px solid";
var zoomer_bgc = "#ffffff";
var aZ_img_out = "OUT";


var aZ_src, aZ_width, aZ_height, aZ_img, aZ_border, aZ_cursor, aZ_zoom, aZ_mini, aZ_imref, aZ_class;
var aZ_td = 0;
var aZ_zoomdiv = 0;
var aZ_img_out;

function ART_zoom2(aZ_img){
    aZ_img_out = "";
    if(aZ_td==0){
        ART_getOffset();
        aZ_td = aZ_img.parentNode;
        aZ_td.id="aZ_td";
        aZ_src = aZ_img.src.toString();
        aZ_width = aZ_img.width;
        aZ_height = aZ_img.height;
        aZ_imref = aZ_img.alt;
        aZ_alt = aZ_img.alt;
        aZ_border = aZ_img.style.border;
        aZ_cursor = aZ_img.style.cursor;
        aZ_class = aZ_img.className;
        aZ_td.style.backgroundImage = "url('"+aZ_src+"')";
        
        aZ_zoom = new Image();
        aZ_src = aZ_src.replace('petit','grand');
        aZ_src = aZ_src.replace('moyenne','grand'); 
        aZ_zoom.src = aZ_src;
        ART_load_img();
    }
}
var aZ_timer = 0;
function ART_load_img(){
    if(aZ_timer==50) aZ_timer="FORCER";
    // préload de l'image 
    if(aZ_zoom.complete || aZ_timer=="FORCER"){
        // création du div de zoom
        if(aZ_zoomdiv==0){
            aZ_zoomdiv = document.createElement("div");
            aZ_zoomdiv.id = "aZ_zoomdiv";
            aZ_zoomdiv.className = aZ_class; 
            aZ_zoomdiv.style.position = "absolute";
            aZ_zoomdiv.style.zIndex = 1000;
            aZ_zoomdiv.style.top = (zoomer_top)+"px";
            aZ_zoomdiv.style.left = (page.width/2 + zoomer_left)+"px";
            aZ_zoomdiv.style.width = zoomer_width+"px";
            aZ_zoomdiv.style.height = zoomer_height+"px";
            aZ_zoomdiv.style.border = zoomer_border;
            document.body.appendChild(aZ_zoomdiv);
        }else{
            aZ_zoomdiv.style.visibility="visible";  
        }
        aZ_td.innerHTML = "";
        aZ_td.style.width = aZ_width;
        aZ_td.style.height = aZ_height;
        aZ_td.className = aZ_class;
        aZ_td.style.cursor = aZ_cursor;
        // affichage 
        aZ_zoomdiv.style.backgroundImage = "url('"+aZ_imref+"')";
        ART_zoom_pos();
    }else{
        aZ_timer++;
        setTimeout('ART_load_img();', 10);
    }  
}
var aZP_w, aZP_h;
function ART_zoom_pos(){
    var aZd = new Date();
    aZ_zoom.width=800;
    aZ_zoom.height=800; 
    aZP_w = Math.floor(zoomer_width / aZ_zoom.width * aZ_width);
    aZP_h = Math.floor(zoomer_height / aZ_zoom.height * aZ_height);
    aZ_mini = document.createElement("div");
    aZ_mini.style.backgroundImage = "url('./theme/defaut/image/zomm_zone.php?w="+aZP_w+"&h="+aZP_h+"&t="+aZd.getTime()+"')";
    aZ_mini.style.backgroundRepeat = "no-repeat";
    aZ_mini.style.width = aZ_width+"px";
    aZ_mini.style.height  = aZ_height+"px";
    aZ_mini.style.position  = "relative";
    aZ_mini.style.top  = "0px";
    aZ_mini.style.left  = "0px";
    
    aZ_mini.id="aZ_mini";
    aZ_td.appendChild(aZ_mini);
    aZ_td.style.position="relative";
    aZ_td.style.top  = "0px";
    aZ_td.style.left  = "0px";
    aZ_td.onmousemove = getMouseXY;
    aZ_td.onmouseout = ART_hide_zoomer;
    aZ_td.onmouseover = ART_show_zoomer;
    setTimeout('ART_checkIn();',500);
}

function ART_checkIn(){
    if(aZ_img_out=="OUT"){ 
        ART_hide_zoomer();
    }else{
       aZ_img_out = "OUT";
       setTimeout('ART_checkIn();',50); 
    }
}

function ART_hide_zoomer(){
    aZ_mini.style.visibility="hidden";
    aZ_zoomdiv.style.visibility="hidden";
}

function ART_show_zoomer(){
    aZ_mini.style.visibility="visible";
    aZ_zoomdiv.style.visibility="visible";
}

var IE = false;
var Op = false;
if (navigator.appName == "Opera") Op = true;
if (navigator.appName == "Microsoft Internet Explorer") IE = true;
if (!IE)document.captureEvents(Event.MOUSEMOVE);

if(IE) {
    zoomer_left -= 2;
    zoomer_top += 7; 
}

var aZDx, aZDy;                                                                      
aZPx=0;
aZPy=0; 
function getMouseXY(m){
    aZ_img_out = "IN";
    if(IE || Op){
        var tmpX = event.offsetX;
        var tmpY = event.offsetY;
    }else{
        var tmpX = m.layerX;
        var tmpY = m.layerY;
    }
    //document.getElementById('debug').innerHTML=tmpX+" "+tmpY;  
    aZDx = tmpX-aZP_w/2;
    aZDy = tmpY-aZP_h/2;  
    if(aZDx<0){   
        aZPx=0;
    }else if(aZDx>aZ_width-aZP_w){
         aZPx=aZ_width-aZP_w;
    }else{
        aZPx = aZDx;
    }
    if(aZDy<0){   
        aZPy=0;
    }else if(aZDy>aZ_height-aZP_h){
         aZPy=aZ_height-aZP_h;
    }else{
        aZPy = aZDy;
    }
    aZ_mini.style.backgroundPosition = aZPx+'px '+aZPy+'px'; //document.getElementById('debug').innerHTML=aZ_mini.style.backgroundPosition;
    aZPx = -aZPx * aZ_zoom.width / aZ_width;
    aZPy = -aZPy * aZ_zoom.height /aZ_height;
    aZ_zoomdiv.style.backgroundPosition = aZPx+'px '+aZPy+'px';
}

var page = Object();
function ART_getOffset(){
    var browserName=(navigator.appName);
    var userAgen=(navigator.userAgent);
    var locMSIE=userAgen.indexOf("MSIE");
    var locNS=userAgen.indexOf("Netscape");
    var locOpera=userAgen.indexOf("Opera");
    var locFirefox=userAgen.indexOf("Firefox");
    var locMozilla=userAgen.indexOf("rv");
    var offsety, height, width, nav;
        
    if (navigator.appName=="Microsoft Internet Explorer"){
        page.offsety = document.documentElement.scrollTop;
        page.height = document.documentElement.clientHeight;
        page.width = document.documentElement.clientWidth;
        page.nav = "IE";
    }else if (locFirefox != -1){
        page.offsety = window.pageYOffset;
        page.height = window.innerHeight;
        page.width = window.innerWidth-20;
        page.nav = "FF";
    }else{        
        page.offsety = window.pageYOffset;
        page.height = window.innerHeight;
        page.width = window.innerWidth;
        page.nav = "OTHER";
    }
}

