// JavaScript Document
var cestparti, coefficient_opacite, ici_image, ici_zoom, ici_cache, produit_courant;
var id_zoom = new Array();
var titre_zoom = new Array();
var prix_zoom = new Array();
var descriptif_zoom = new Array();
var nb_zoom = new Array();
var test_favori = new Array();
var seuil_opacite = 6;
var zoom_visible = 0;

function init_zoom() {
	ici_image = document.getElementById("id_zoom_produit");
	ici_zoom = document.getElementById("calque_zoom");
	ici_cache = document.getElementById("calque_cache");
	ici_description = document.getElementById("description-zoom-produit-left");
	ici_titre = document.getElementById("id_zoom_titre");
	ici_prix = document.getElementById("id_zoom_prix");
	ici_nb = document.getElementById("id_zoom_nb");
}

function zoom_produit(numero_produit, avec_opacite) {
	clearInterval(cestparti);
	ici_zoom.style.top = "5px";
	var point_x = Math.round((largeur_page() - 1000) / 2) + deroule_x_page() + 58;
	if(point_x < 0)
		point_x = 0;
	ici_zoom.style.left = point_x + "px";
	ici_cache.style.height = hauteur_page() + "px";
	produit_courant = numero_produit;
	if(test_favori[produit_courant] == 1) {
		document.getElementById("id_favori_zoom").style.backgroundImage = "url(../img/pop/btn_favori_over.jpg)";
		document.getElementById("id_favori_zoom").title = "clic: retirer des favoris";
	}	
	else {
		document.getElementById("id_favori_zoom").style.backgroundImage = "url(../img/new/favorizoom.png)";
		document.getElementById("id_favori_zoom").title = "clic: ajouter aux favoris";
	}
	if(produit_courant == 1)
		document.getElementById("btn_zoom_precedent").style.visibility = "hidden";
	else
		document.getElementById("btn_zoom_precedent").style.visibility = "inherit";
	if(produit_courant == id_zoom.length - 1)
		document.getElementById("btn_zoom_suivant").style.visibility = "hidden";
	else
		document.getElementById("btn_zoom_suivant").style.visibility = "inherit";
	ici_zoom.style.visibility = "visible";
	ici_cache.style.visibility = "visible";
	ici_image.src = "img/produits/produit" + id_zoom[numero_produit] + "_zoom.jpg";
	ici_titre.innerHTML = titre_zoom[numero_produit];
	ici_description.innerHTML = descriptif_zoom[numero_produit];
	ici_prix.innerHTML = prix_zoom[numero_produit];
	if(nb_zoom[numero_produit] > 1)
		ici_nb.innerHTML = "(" + nb_zoom[numero_produit] + " pièces)";
	zoom_visible = 1;
	if(avec_opacite == 1) {
		coefficient_opacite = 0;
		cestparti = setInterval("opacite()", 5);
	}
}

function ajuster_cache() {
	if(zoom_visible == 1) {
		ici_cache.style.height = (hauteur_page() + deroule_y_page()) + "px";
	}
}

function zoom_precedent() {
	if(produit_courant > 1)
		zoom_produit((produit_courant - 1), 0);
}

function zoom_suivant() {
	if(produit_courant < (id_zoom.length - 1))
		zoom_produit((produit_courant + 1), 0);
}

function zoom_panier(zoom_categorie, zoom_recherche) {
	var page_destination = "panier_action.php?id_produit=" + id_zoom[produit_courant] + "&action=plus";
	if(zoom_categorie != "0")
		page_destination += "&id_categorie=" + zoom_categorie;
	if(zoom_recherche != "0")
		page_destination += "&recherche=" + zoom_recherche;
	window.location = page_destination;
}

function zoom_favori(zoom_categorie, zoom_recherche) {
	var page_destination = "favori_action.php?id_produit=" + id_zoom[produit_courant];
	if(test_favori[produit_courant] == 1)
		page_destination += "&action=supprimer";
	else
		page_destination += "&action=ajouter";
	if(zoom_categorie != "0")
		page_destination += "&id_categorie=" + zoom_categorie;
	if(zoom_recherche != "0")
		page_destination += "&recherche=" + zoom_recherche;
	window.location = page_destination;
}

function opacite() {
	if(coefficient_opacite < seuil_opacite) {
		if(document.all) {
			coefficient_opacite += 0.3;
			ici_cache.style.filter = 'alpha(opacity=' + (coefficient_opacite * 10) + ')';
		}	
		else {
			coefficient_opacite += 0.2;
			ici_cache.style.opacity = coefficient_opacite / 10;
		}
	}
	else {
		clearInterval(cestparti);
	}
}

function fermer_zoom() {
	if(cestparti)
		clearInterval(cestparti);
	ici_zoom.style.visibility = "hidden";
	ici_cache.style.visibility = "hidden";
	ici_image.src = "img/common/z.gif";
	ici_cache.style.height = "10px";
	if(document.all)
		ici_cache.style.filter = 'alpha(opacity=0)';
	else
		ici_cache.style.opacity = 0;
	coefficient_opacite = 0;
	zoom_visible = 0;
}

function deroule_x_page() {
  var scrOfX = 0;
  if(typeof(window.pageYOffset) == 'number') {
    //Netscape compliant
    scrOfX = window.pageXOffset;
  } else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
    //DOM compliant
    scrOfX = document.body.scrollLeft;
  } else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
    //IE6 standards compliant mode
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfX;
}

function deroule_y_page() {
  var scrOfY = 0;
  if( typeof(window.pageYOffset) == 'number') {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function largeur_page() {
  var myWidth = 0;
  if(typeof(window.innerWidth) == 'number') {
    //Non-IE
    myWidth = window.innerWidth;
  } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function hauteur_page() {
  var myHeight = 0;
  if(typeof(window.innerWidth) == 'number') {
    //Non-IE
    myHeight = window.innerHeight;
  } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

window.onscroll = ajuster_cache;