// Image par produit 
// Copyright echoppe.biz/songeur.com
floatingdiv = false;
currentimg = null;
thedelay = null;
preloads = new Object;
// Futur use window.onerror = function() { return true; }
// Futur use window.onload = function(e) { if (document.getElementById && document.createElement) tooltip.define(); }
function init_preview() {
	document.onmousemove = document_onmousemove;
	if (window.onscroll) window.onscroll = hide_div();
	document.write('<div class="floating" id="div_200" style="left: -3000px; background: #ffffff;"><img id="img_200" width="250" height="250" alt=""></div>'); 
	setInterval("changer();",333);
	for (var i = 4; i <= 4+7; i += 1)  {
	var rnd_200 = i; rnd_200 = (rnd_200 < 10) ? '0' + rnd_200 : rnd_200;
	preloads['loader_'+i] = new Image;
	preloads['loader_'+i].src = rnd_200;
	preloads['loader_'+i].width = 0;
	preloads['loader_'+i].height = 0;
	}
}

function get_obj(id_name) {
   if (document.getElementById) {
      return document.getElementById(id_name);
   } else if (document.all) {
      return document.all[id_name];
   } else {
      return null;
   }
}

function document_onmousemove(e) {

   if ( !floatingdiv ) return;

   var pos_X = 0, pos_Y = 0;
   if ( !e ) e = window.event;
   if ( e ) {
      if ( typeof(e.pageX) == 'number' ) {
         pos_X = e.pageX; pos_Y = e.pageY;
      } else if ( typeof(e.clientX) == 'number' ) {
         pos_X = e.clientX; pos_Y = e.clientY;
         if ( document.body && ( document.body.scrollTop || document.body.scrollLeft ) && !( window.opera || window.debug || navigator.vendor == 'KDE' ) ) {
            pos_X += document.body.scrollLeft; pos_Y += document.body.scrollTop;
         } else if ( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) && !( window.opera || window.debug || navigator.vendor == 'KDE' ) ) {
            pos_X += document.documentElement.scrollLeft; pos_Y += document.documentElement.scrollTop;
         }
      }
   }
 
   var scroll_X = 0, scroll_Y = 0;
   if ( document.body && ( document.body.scrollTop || document.body.scrollLeft ) && !( window.debug || navigator.vendor == 'KDE' ) ) {
      scroll_X = document.body.scrollLeft; scroll_Y = document.body.scrollTop;
   } else if ( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) && !( window.debug || navigator.vendor == 'KDE' ) ) {
      scroll_X = document.documentElement.scrollLeft; scroll_Y = document.documentElement.scrollTop;
   }
 
   var win_size_X = 0, win_size_Y = 0;
   if (window.innerWidth && window.innerHeight) {
      win_size_X = window.innerWidth; win_size_Y = window.innerHeight;
   } else if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) {
      win_size_X = document.documentElement.clientWidth; win_size_Y = document.documentElement.clientHeight;
   } else if (document.body && document.body.clientWidth && document.body.clientHeight) {
      win_size_X = document.body.clientWidth; win_size_Y = document.body.clientHeight;
   }
 
   pos_X += 15; pos_Y += 15;
 
   if (floatingdiv.offsetWidth && floatingdiv.offsetHeight) {
      if (pos_X - scroll_X + floatingdiv.offsetWidth + 5 > win_size_X) pos_X -= (floatingdiv.offsetWidth + 25);
      if (pos_Y - scroll_Y + floatingdiv.offsetHeight + 5 > win_size_Y) pos_Y -= (floatingdiv.offsetHeight + 20);
   }

   floatingdiv.style.left = pos_X + "px"; floatingdiv.style.top = pos_Y + "px";
 
}

function show_200(img_src,wp_id,img_w,img_h) {
   if (thedelay) {
      clearTimeout(thedelay); thedelay = null;
   } else {
      floatingdiv = get_obj('div_200');
      thedelay = setTimeout('show_200("' + img_src + '","' + wp_id + '",' + img_w + ',' + img_h+ ');', 50);
      return;
   }
   var img_mark = 'img_wp_id_' + wp_id;
   currentimg = img_mark;
   if (preloads[img_mark] && preloads[img_mark].complete) {
      swap_img(img_mark);
   } else {
      var rnd_200 = Math.round(Math.random()*4) + 7;
      swap_img('loader_' + rnd_200);
   }
   if ( ! preloads[img_mark] ) {
      preloads[img_mark] = new Image;
      preloads[img_mark].src =  img_src;
      preloads[img_mark].width = img_w;
      preloads[img_mark].height = img_h;
   }
   show_div('div_200');
}

function changer() {
   if ( !floatingdiv || !preloads[currentimg] || !get_obj('img_200')) return;
   if ( get_obj('img_200').src != preloads[currentimg].src && preloads[currentimg].complete ) swap_img(currentimg);
}

function swap_img(img_mark) {
   var obj_base_img = get_obj('img_200');
   if (!obj_base_img) return;
   obj_base_img.src    = preloads[img_mark].src;
   obj_base_img.width  = preloads[img_mark].width;
   obj_base_img.height = preloads[img_mark].height;
}

function show_div(div_mark) {
   if (thedelay) {
      clearTimeout(thedelay); thedelay = null;
   } else {
      floatingdiv = get_obj(div_mark);
      thedelay = setTimeout('show_div("' + div_mark + '");', 400);
      return;
   }
   if ( ! floatingdiv ) return;
   if (floatingdiv.offsetWidth) {
      floatingdiv.style.width = "auto";
      floatingdiv.style.height = "auto";
      if (floatingdiv.offsetWidth > 300) floatingdiv.style.width = "300px";
   }
   document_onmousemove;
   floatingdiv.style.visibility = 'visible';
}

function hide_div() {
   clearTimeout(thedelay); thedelay = null;
   if ( ! floatingdiv ) return;
   floatingdiv.style.visibility = 'hidden';
   floatingdiv.style.left = "-3000px";
   floatingdiv = false;
}

function append_to_div(div_mark,doc) {
   var obj_box = get_obj(div_mark);
   if ( obj_box && typeof(obj_box.innerHTML) == 'string' ) obj_box.innerHTML += doc;
}
// -----------------
function Image500(chemin)
{
   html = '<html><head><title>Cliquez pour me fermer</title></head><body onBlur="top.close()" onclick="top.close()"><img alt="" src="'+chemin+'" border="0" name="image500" onLoad="window.resizeTo(document.image500.width+10, document.image500.height+30)"></body></html>';
   popupImage = window.open('','_blank','toolbar=0, location=0, directories=0, menuBar=0, scrollbars=0, resizable=1, width=500, height=500');
   popupImage.document.open();
   popupImage.document.write(html);
   popupImage.document.close()
}; 
