//maxRating
function showIt(item,i,j,max){var id;actualItem=item;for(var x=1;x<=i;x++){id=item+"_"+x;document.getElementById(id).src="aa/b.png";}
for(var x=i+1;x<=max;x++){id=item+"_"+x;if(x<=j)document.getElementById(id).src="aa/y.png";else document.getElementById(id).src="aa/w.png";}}
function showOriginal(i,max){for(var x=1;x<=max;x++){id=actualItem+"_"+x;if(x<=i)document.getElementById(id).src="aa/b2.png";else document.getElementById(id).src="aa/w.png";}}
function showOriginal2(i,max){for(var x=1;x<=max;x++){id=actualItem+"_"+x;if(x<=i)document.getElementById(id).src="aa/b2.png";else document.getElementById(id).src="aa/w.png";}}
function getHTTPObject(){if(window.ActiveXObject)return new ActiveXObject("Microsoft.XMLHTTP");else if(window.XMLHttpRequest)return new XMLHttpRequest();else{alert("Your browser does not support AJAX.");return null;}}
function setOutput(){var result;var data;var rating;var totalRates;var max;if(httpObject.readyState==4){result=httpObject.responseText;data=result.split(':::');rating=data[0];totalRates=data[1];max=data[2];removeActions(Math.round(rating),max);updateTextRating(actualItem,rating,totalRates);}}
function removeActions(rating,max){showOriginal(rating,max);var t;for(var x=1;x<=max;x++){id=actualItem+"_"+x;t=document.getElementById(id);t.onmouseover=null;t.onmouseout=null;t.onclick=null;}}
function updateTextRating(item,rating,total){var itemRating;var totalRating;var id;id=item+"_ir";itemRating=document.getElementById(id);id=item+"_tr";totalRating=document.getElementById(id);if(itemRating!=null)itemRating.innerHTML=rating;if(totalRating!=null)totalRating.innerHTML=total;}
function submitRating(item,rate,max){httpObject=getHTTPObject();actualItem=item;if(httpObject!=null){httpObject.open("GET","submitRating.php?item="+item+"&rating="+rate+"&max="+max,true);httpObject.send(null);httpObject.onreadystatechange=setOutput;}}
var httpObject=null;var actualItem=null;
//hoverzoom:
(function($){$.fn.hoverzoom=function(oSettings){var oSettings=$.extend({preload:false,previewCursor:"simple",customPreviewElt:'<div class="hoverzoom-preview"></div>',loadingClass:"hoverzoom-loading",customInsert:function(jPreview,jLink){jLink.after(jPreview);},onMouseEnter:function(){},onMouseLeave:function(){}},oSettings);var bUseCursor=(!!oSettings.previewCursor&&(oSettings.previewCursor=="simple"||oSettings.previewCursor=="mask"));return this.each(function(){var jLink=$(this);var jThumb=jLink.find("img:first");var jPreview=$(oSettings.customPreviewElt);var jPreload;var jCursor;var bIsLoaded=false;var hover=false;var nWidthRatio,nHeightRatio,nPreviewWidth,nPreviewHeight,nImgWidth,nImgHeight,nThumbWidth,nThumbHeight,nCursorWidth,nCursorHeight,nThumbPosX,nThumbPosY,nMouseX,nMouseY=0;oSettings.customInsert(jPreview,jLink);jPreview.addClass(oSettings.loadingClass).hide();jLink.click(function(e){e.preventDefault()});if(oSettings.preload)initLoading();$(window).load(function(){nThumbWidth=jThumb.width();nThumbHeight=jThumb.height();jThumb.css("display","block");jLink.css({position:"relative",display:"block",width:nThumbWidth+"px",overflow:"hidden"}).hover(function(){hover=true;jThumb.addClass("hover");nThumbPosX=jThumb.offset().left;nThumbPosY=jThumb.offset().top;if(bUseCursor&&bIsLoaded){jCursor.show();}else if(!oSettings.preload&&!bIsLoaded){initLoading();}
jLink.bind("mousemove",onMouseMove);oSettings.onMouseEnter({"link":jLink,"thumb":jThumb,"preview":jPreview,"cursor":jCursor,"preload":jPreload});jPreview.show();},function(){hover=false;jLink.unbind("mousemove");if(bUseCursor&&bIsLoaded)jCursor.hide();jThumb.removeClass("hover");jPreview.hide();oSettings.onMouseLeave({"link":jLink,"thumb":jThumb,"preview":jPreview,"cursor":jCursor,"preload":jPreload});});});function onMouseMove(e){nMouseX=e.pageX||nMouseX;nMouseY=e.pageY||nMouseY;var nPreviewPosX=-(((nMouseX-nThumbPosX)*nWidthRatio)-nPreviewWidth/2);var nPreviewPosY=-(((nMouseY-nThumbPosY)*nHeightRatio)-nPreviewHeight/2);if(bUseCursor){var nCursorPosX=e.pageX-nThumbPosX-nCursorWidth/2;var nCursorPosY=e.pageY-nThumbPosY-nCursorHeight/2;}
if(nPreviewPosX>0){nPreviewPosX=nCursorPosX=0;}else if(nPreviewPosX<(nPreviewWidth-nImgWidth)){nPreviewPosX=-nImgWidth+nPreviewWidth;if(bUseCursor)nCursorPosX=Math.ceil(nThumbWidth-nCursorWidth);}
if(nPreviewPosY>0){nPreviewPosY=nCursorPosY=0;}else if(nPreviewPosY<(nPreviewHeight-nImgHeight)){nPreviewPosY=-nImgHeight+nPreviewHeight;if(bUseCursor)nCursorPosY=Math.ceil(nThumbHeight-nCursorHeight);}
jPreview.css("backgroundPosition",nPreviewPosX+"px "+nPreviewPosY+"px");if(bIsLoaded&&bUseCursor){if(oSettings.previewCursor=="simple"){jCursor.css({left:nCursorPosX+"px",top:nCursorPosY+"px"});}else if(oSettings.previewCursor=="mask"){jCursor.css("clip","rect("+nCursorPosY+"px "+(nCursorPosX+nCursorWidth)+"px "+(nCursorPosY+nCursorHeight)+"px "+nCursorPosX+"px)");}}};function initLoading(){jPreload=$('<img src="'+jLink.attr("href")+'" style="position:absolute;left:-9999px">').load(function(){jPreview.css("background","url("+jLink.attr("href")+") no-repeat");nPreviewWidth=jPreview.width();nPreviewHeight=jPreview.height();nImgWidth=jPreload.width();nImgHeight=jPreload.height();nWidthRatio=nImgWidth/nThumbWidth;nHeightRatio=nImgHeight/nThumbHeight;jPreload.remove();jPreview.removeClass(oSettings.loadingClass);if(bUseCursor){nCursorWidth=nPreviewWidth/nWidthRatio;nCursorHeight=nPreviewHeight/nHeightRatio;jCursor=$('<span></span>').appendTo(jLink.css("position","relative")).css({position:"absolute",top:0,left:0,display:"none"});if(oSettings.previewCursor=="simple"){jCursor.css({width:nCursorWidth,height:nCursorHeight});}else if(oSettings.previewCursor=="mask"){jCursor.css({width:nThumbWidth,height:nThumbHeight,background:"url("+jThumb.attr("src")+") no-repeat"});}
if(hover){jCursor.show();}}
bIsLoaded=true;}).appendTo("body");};});};})(jQuery);	

//Fonctions d'ajouts au panier et selection de taille :
( function($){
	$(function(){
	var form  = document.forms['ficheVetement'],
	$bouton_ajouter = $(".article-panier-bouton:first"),
	$alerte = $("#choisirTaille"),
	lestailles =  $("select[name=couleur]").attr("id"),
	tailles= lestailles.split("-"),
	cssDispo={'cursor':'pointer','color': '#000', 'border': '1px solid #000'},
	cssNonDispo ={'cursor': 'default','color': '#bbb','border': '1px solid #ccc'},
	cssSelected ={'color': '#f63', 'border': '2px solid #f63'},
	dispos=["U"],
	div = $("<div />").css({position:"absolute",zIndex:500 }). hide().appendTo($(document.body)),
	calque = $("<div />").css({background: 'url(aa/calque.png)',position:'absolute', left: 0,top: 0,zIndex:400,display:'none'})
	.appendTo($(document.body));
//***********************************************************************************************	
	function activerBouton(actif,anime){
		if(actif){
			$bouton_ajouter
			.animate({"opacity":"1"},  anime||0 );	
		}else{
			$bouton_ajouter
			.animate({"opacity":"0.5"},  anime||0 )
			.bind("mouseover", alerter)
			.bind("mouseout", function(){ $alerte.fadeOut("slow");});
		}
	}
//Centrer une div:
	$.fn.centrer = function(){
		return this.css('top', $(window).height()/2- this.height()/2).css('left', $(window).width()/2- this.width()/2); 
	}

//ccsCasesTailles permet d'assigner le ccs et l'attribut titre aux tailles:
	function ccsCasesTailles(){
		return $("#fiche-texte .taille a").each(function(){	
				if($.inArray($(this).text(),dispos) < 0) { 
					$(this).css(cssNonDispo).attr("title","Taille non disponible"); 
				}else{
					$(this).css(cssDispo).attr("title","Disponible"); 
					
					
					
				}
		});
	}
//Choix de la taille:
	function choisir(e){
		ccsCasesTailles(); // remet Ã  zÃ©ro les css.
		activerBouton(false,500);
		$(form.taille).val('') ;
		var choix = $(this).text();
		if($.inArray(choix,dispos) < 0) { 
			$("#indic").animate({"paddingLeft": 5  + "px"},500) ;
			$("#choix").html((langage==="en/")?"<strong>The size is not available</strong>" : "<strong>La taille n'est pas disponible</strong>");	
			return false;
		}
		var indexChoix = $.inArray( choix ,['S','M','L','XL'] ) ;
		if(choix=="U") { indexChoix = 0 ; choix="unique" }
		var deplacement =86 + indexChoix*22 ;
		$(this).css(cssSelected);
		$("#indic").animate({"paddingLeft" : deplacement +"px"},700,function(){activerBouton(true,500);}) ;			
		$("#choix").html((langage==="en/")?"You have choosen <strong>size "+ choix+"</strong> " : "Vous avez choisi <strong>la taille " + choix +"</strong>" );
		
		$(form.taille).val(choix);
		return false;
	}

function alerter(){
	var taille =  $(form.taille).val() ;
	if(taille == "") $alerte.fadeIn("fast");
	return (taille != "") ; 
}

$bouton_ajouter.click(function(){ if(alerter()) form.submit(); });	


function taillesDisponibles(lestailles, index){
	activerBouton(false,1000);
	$("#indic").animate({"paddingLeft": "5px"},500) ;
	
	if( /[SML]/.test(lestailles) ){
		dispos = $.map(tailles[index||0].split("_"), function(e){ return  e.charAt(0) ;});
		$("#choix").fadeOut(300, function(){ $(this).html((langage==="en/")?"no size selected" : "pas de taille sÃ©lectionnÃ©e").fadeIn(500); });
		
		

		
		$(form.taille).val('') ;	
	}else{
		//si unique: tailles=["", "", ""]
		tailles= $.map(tailles, function(e){return "U";}),	
		dispos = ["U"];	
		
		$("#indic").animate({"paddingLeft" : "86px"},700,function(){
			activerBouton(true,1000);
			$("#choix").html("<strong>Taille unique</strong>" );
			$(form.taille).val("U");
			$("#fiche-texte span.taille a").css(cssSelected);
		}) ;	
	}
	ccsCasesTailles();
	return dispos;
}

function annuleCalque(){ div.fadeOut(400,function(){ calque.fadeOut(300);}) ; }

//***********************************************************************************************		
	taillesDisponibles(lestailles) ; 



// Changement de couleur onselect :	
	$("select[name=couleur]").change(function(){
		dispos = taillesDisponibles(lestailles,$(this).attr("selectedIndex"))
	}) ;
	
	$("#fiche-texte .taille a").click(choisir);	
	


//Guide des tailles.
	$(".info-pop a").click(function(){		
			div.load((langage==="en/")?"tailles_sd_en.html" : "tailles_sd.html", function(){ 
				//$("#wrap").css("opacity", "0.2");
				calque.height($(document).height()). width($(document).width()) . show() ;
				div.centrer();
				$("#sdclose").click(annuleCalque);
			}).fadeIn("slow");
	});
	

 $(".miniature img").mouseover(
 	function(e){
 		var im = $(this).attr('alt') ; 
		document.main.src='http://www.derhy.com/shopping/Ibig/'+ im ;
		$(".jqzoom").attr("href","http://www.renderhy.com/1200/"+ im );
	}



);
//preloader l'image du  zoom: 
	//$("<img />").attr("src", $(".jqzoom").attr("href") ).load(function(){});

	
$("a.hoverzoom").hoverzoom({
				customPreviewElt: '<div class="preview"></div>',
				previewCursor: "simple"
			});
//	$(".jqzoom").jqzoom({ zoomWidth: 569,zoomHeight: 577, xOffset: 17, yOffset: -5, position: "right",title :false });

// anciennes fonctions :
	function modalDialog(msg, top){
		calque.height($(document).height()). width($(document).width()). show() ;
		var p = div.html(msg).fadeIn().centrer() ;
		$(window).resize(function(){if(p){p.centrer(p);}});
		return p;
	}


})
})(jQuery);
/* ***************************************************************************/
   function divaffiche(){
      document.getElementById("fiche-texte").style.display = "inline";
      document.getElementById("fiche-texte-form").style.display = "none";
      document.getElementById("fiche-texte-avis").style.display = "none";
      document.getElementById("fiche-texte-avis2").style.display = "none";
      document.getElementById("fiche-texte-merci").style.display = "none";
    }
    function divcache(){
      document.getElementById("fiche-texte").style.display = "none";
      document.getElementById("fiche-texte-avis").style.display = "inline";
            document.getElementById("fiche-texte-form").style.display = "none";
      document.getElementById("fiche-texte-avis2").style.display = "none";
      document.getElementById("fiche-texte-merci").style.display = "none";

    }
     function divmontreform(){
      document.getElementById("fiche-texte-form").style.display = "inline";
      document.getElementById("fiche-texte-avis").style.display = "none";
      document.getElementById("fiche-texte-avis2").style.display = "inline";
      document.getElementById("fiche-texte-merci").style.display = "none";
    }

    function putstar(){
    	if (document.getElementById('note').value==1){
			document.getElementById('Image261').src="aa/etoile-over.png";
			document.getElementById('Image26').src="aa/etoile.png";
			document.getElementById('Image262').src="aa/etoile.png";
			document.getElementById('Image263').src="aa/etoile.png";
    	}
    	else if (document.getElementById('note').value==2){
			document.getElementById('Image26').src="aa/etoile-over.png";
			document.getElementById('Image261').src="aa/etoile.png";
			document.getElementById('Image262').src="aa/etoile.png";
			document.getElementById('Image263').src="aa/etoile.png";
		}else
			if (document.getElementById('note').value==3){
				document.getElementById('Image262').src="aa/etoile-over.png";
				document.getElementById('Image26').src="aa/etoile.png";
				document.getElementById('Image261').src="aa/etoile.png";
				document.getElementById('Image263').src="aa/etoile.png";
			}else
				if (document.getElementById('note').value==4){
					document.getElementById('Image263').src="aa/etoile-over.png";
					document.getElementById('Image26').src="aa/etoile.png";
					document.getElementById('Image262').src="aa/etoile.png";
					document.getElementById('Image261').src="aa/etoile.png";
				}
	}

  function verif_form(){

	if(document.formavis.prenom_avis.value == ""){
		alert("Merci de saisir votre prénom"); return false;
	}

	if(document.formavis.email_avis.value == ""){
		alert("Merci de saisir votre email"); return false;
	}

	if(document.formavis.titre_avis.value == ""){
		alert("Merci de saisir un titre"); return false;
	}

	if(document.formavis.commentaire_avis.value == ""){
		alert("Merci de saisir votre commentaire"); return false;
	}
	document.formavis.submit();
  }
  
