function resolutionX() {
  return (screen.width-10)
}
function resolutionY() {
  return (screen.height-85);
}
function MM_openWindow(theURL, winName) {
  features = 'resizable=no,scrollbars=no,directories=no,width=' + resolutionX() + ',height=' + resolutionY() + ',top=0,left=0,location=no,menubar=no,status=no,toolbar=no,titlebar=yes,fullscreen=no'
  winZoom=window.open(theURL,winName,features);
  winZoom.focus();
}
function MM_openWindow_pk(theURL, winName,v_index) {
  features = 'resizable=no,scrollbars=yes,directories=no,width=' + resolutionX() + ',height=' + resolutionY() + ',top=0,left=0,location=no,menubar=no,status=no,toolbar=no,titlebar=yes,fullscreen=no'
  theURL = theURL + "&pk=" + tabpk[v_index][0];
  winZoom=window.open(theURL,winName,features);
  winZoom.focus();
}

function MM_showHideLayers() { //v6.0
 var i,p,v,obj,args=MM_showHideLayers.arguments;
 for (i=0; i<1; i+=3) if ((obj=MM_findObj(args[i]))!=null) { 
   // Basculer Visible | Hidden
   if(obj.style.visibility == "visible") {v = "hidden"; }
   else {v = "visible"; }
   obj.style.visibility=v; }
   return v;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function changeImgJpg(v_index,v_style){
  v_max=tabpk.length;

  // PREVIOUS
  if(v_index=='P'){
    v_index = parseInt(i_index.value)-1;
    if(parseInt(v_index)<0){v_index=v_max-1;}
  }
  // NEXT
  if(v_index=='N'){
    v_index = parseInt(i_index.value)+1;
    if(parseInt(v_index)>v_max-1){v_index=0;}
  }

  // UPDATER VALEUR DU INPUT
  document.getElementById("i_index").value = v_index;

  // CHANGER LA PHOTO
  document.getElementById("la_photo").src='images/produits/photos_medium/' + tabpk[v_index][0] + '.jpg';

  //CHANGER les LIENS
  document.getElementById("link_description").href = "produits_description.asp?style=" + v_style + "&pk=" + tabpk[v_index][0];
  document.getElementById("link_previous").href = "produits_description.asp?style=" + v_style + "&pk=" + tabpk[v_index][0];
  document.getElementById("link_next").href = "produits_description.asp?style=" + v_style + "&pk=" + tabpk[v_index][0];
  document.getElementById("link_zoom_img").href = "produits_zoom.asp?style=" + v_style + "&pk=" + tabpk[v_index][0];
  document.getElementById("link_zoom_bt").href = "produits_zoom.asp?style=" + v_style + "&pk=" + tabpk[v_index][0];
  
  // CHANGER le texte du paragraphe sous la photo
  document.getElementById("txtparagraphepic").value = tabpk[v_index][3];
}

function SetDescription(){   
  if(facebox_visible==false) {facebox_visible = true;}
  else {jQuery.facebox.close();facebox_visible = false;}
}

// Variable utilisée dans function click_handler() et close() du fichier facebox.js
var facebox_visible = false;


// Animation produits photo medium
play_gallery = true;
function GalleryContinuInit(v_style){
   if(play_gallery==true)timeout2 = setTimeout(function() { GalleryContinu(v_style); }, 9000);
   else document.bt_pause.src='images/bt_play.gif';
}
function GalleryContinu(v_style){
   changeImgJpg('N',v_style);
   timeout2 = setTimeout(function() { GalleryContinu(v_style); }, 8000);
}
function ArretGallery(v_style,img_lang){
  if(play_gallery==true){
   play_gallery=false;
   document.bt_pause.src='images/bt_play'+img_lang+'.gif';
   if(img_lang=='_fr') document.bt_pause.setAttribute('alt','> Défilement automatique');
   else document.bt_pause.setAttribute('alt','> Play');
   clearTimeout(timeout2);
  }
}
function SwitchGallery(v_style,img_lang){
   if(facebox_visible!=true){
     if(play_gallery==true){
       play_gallery=false;
       document.bt_pause.src='images/bt_play'+img_lang+'.gif';
       if(img_lang=='_fr') document.bt_pause.setAttribute('alt','> Défilement automatique');
       else document.bt_pause.setAttribute('alt','> Play');
       clearTimeout(timeout2);
     }
     else {
       play_gallery=true;
       document.bt_pause.src='images/bt_pause'+img_lang+'.gif';
       if(img_lang=='_fr') document.bt_pause.setAttribute('alt','|| Arrêter le défilement');
       else document.bt_pause.setAttribute('alt','|| Pause');
       GalleryContinu(v_style);
     }
   }
}

// Others views
var max = 3;
var ImageEnCours = 0;
var pkEnCours = 0;
var Vitesse = 2000;
var play = true;

function ImageSuivante(){
   ImageEnCours++;
   if (ImageEnCours > max){
     ImageEnCours = 1;
   }
   ChargeImage(ImageEnCours)
}
function ChargeImage(NumImage){
  if(NumImage==2)document.la_photo.src = path+pkEnCours+"_2.jpg";
  else if(NumImage==3)document.la_photo.src = path+pkEnCours+"_3.jpg";
  else document.la_photo.src = path+pkEnCours+".jpg";
}
function ImageContinu(){
   ImageSuivante();
   timeout1 = setTimeout("ImageContinu()", Vitesse);
}
function Arret(){
   clearTimeout(timeout1)
}
