

$(document).ready(function(){

	encours = 0;
	max = $('div.prod').length;
	prochain = 0;

	$('.groupeSelect input').bind('click',function(){
		var machin=$(this).attr('id');
		$(".selectGroup").each(function(){
			$(this).hide().find('select').attr('disabled','disabled');
		});
		$('#'+machin+'Select').show().removeClass('cacher').find('select').removeAttr('disabled');
		$('.'+machin+'Select').show().removeClass('cacher').find('select').removeAttr('disabled');
	});

  /* Remplacement titre */
  Cufon.replace('.din', { fontFamily: 'din' });

	/* Comportement Rollover avec class="rollover" */
	$("img.rollover").each(function(){
		attachRollOverEvent(this);
	});

	/* Remplacement image actif avec class="actif" */
	$("img.actif").each( function(){
		attachActif(this);
	});

	/* Fancybox Propriétés */
  $("a.fancy").fancybox({ 'overlayShow': true, 'overlayOpacity': 0.70, 'hideOnContentClick': true });
  $("a#fenetre").fancybox({ 'overlayShow': true, 'zoomSpeedOut':0, 'zoomSpeedIn':0, 'overlayOpacity': 0.70, 'hideOnContentClick': true });
  $("a.fancyVideoAccess").fancybox({ 'overlayShow': true, 'zoomSpeedOut':0, 'zoomSpeedIn':0, 'overlayOpacity': 0.70, 'hideOnContentClick': true, 'frameWidth':820, 'frameHeight':570, 'padding':0 });
  $("a.fancyVideo").fancybox({ 'overlayShow': true, 'zoomSpeedOut':0, 'zoomSpeedIn':0, 'overlayOpacity': 0.70, 'hideOnContentClick': false, 'frameWidth':900, 'frameHeight':430, 'padding':0 });

	$('ul.menu li a.titre:not(".actif")').next().hide();

	  $('ul.menu li:not(".geoloc") a.titre').bind("click",function(e) {
		  $(this).next().toggle('slow').prev().toggleClass("actif");
		  e.preventDefault();
	  });

	  $('ul li ul li.actif').parent().show();

	$('#visu2').cycle({
    fx:    'fade',
    speed:  2500,
    timeout:  6500
	});

	$('#headerDefile').cycle({
		fx:    'fade',
		 speed:  2500,
		 timeout:  6500
	});



	/* effet jquery survol produit*/

	$("#miniatures #contentMin img").mouseover(function(event) {
		var name = $("#miniatures #contentMin img").index(this);
		$("#offProd").hide();
		$('#affichage img:first').hide();
		$('#affichage img').eq(name).show();
	});

	$("#miniatures .ligne img").mouseout(function(event) {
		$('#affichage img').hide();
		$('#affichage img:first').show();
	});

	/* effet jquery survol produit hors photo*/

	$("#miniatures2 #contentMin img").mouseover(function(event) {
		var name = $("#miniatures2 #contentMin img").index(this);
		$("#offProd").hide();
		$('#affichage img:first').hide();
		$('#affichage img').eq(name).show();
	});

	$("#miniatures2 .ligne img").mouseout(function(event) {
		$('#affichage img:not(".visuP","#loupe")').hide();
		$("#offProd").show();
	});

	/* effet jquery survol accueil*/

	//$("#produit .prod").hide();
	//$("#produit :first-child").show();

  /* PNG Fix */
  $(document).pngFix();

	/* Tableau 1 sur 2 */
	$("#body table tr:even").addClass("even");
	$("#body table tr:odd").addClass("odd");

	/* Tableau Caract */
	$("#tableauCaracts table tbody tr:even").addClass("even");

  /* scroll to guide */

  $("a.goToMyContent").click(function(event){
	event.preventDefault();
  	var myContent=$(this).attr("id");
	$.scrollTo( 'h3.'+myContent, 400 );
  });


	$("#slider").easySlider();

	/* defilement accueil */

	$("a.nextBtn").click(function(event){
		event.preventDefault();
		changeProduit(1);
		clearInterval(changeProduitId);
	});

	$("a.prevBtn").click(function(event){
		event.preventDefault();
		changeProduit(-1);
		clearInterval(changeProduitId);
	});

	changeProduitId=setInterval(function(){
		changeProduit(1);
	},5000);

	$('div.vignz a').each(function(i){
		var myEq=i;
		$(this).hover(function(){
			//alert(myEq);
			$("div.bigz img").hide();
			$("div.bigz :eq("+myEq+")").show();
		});
	});

	/* comportement encart galerie contenu */
	$(".prod .vignz a:not('.actif'):has('img')").each(function(i){
		window['roll'+i] = $('.prod .vignz a:not(".actif"):has("img")').find('img').eq(i).attr('src');
		ImgRollover(this,i,window['roll'+i],"img/produits/min/1_roll.gif");
	});

	$(".prod .vignz a.actif").each(function(){
		ImgActif(this,"img/produits/min/1_roll.gif");
	});

	$('#offProd div.listeProd table tr td[colspan]').addClass('title');


	if(max==1){
		$("div.prod div.nav").hide();
	}

	$('input.rech').bind('focus',function(){
		if($(this).val()=='Rechercher sur le site')$(this).val('');
	}).bind('blur',function(){
		if($(this).val()=='')$(this).val('Rechercher sur le site');
	});

	$('#tableauCaracts table').each(function(){

		x=0;
		$(this).find('thead tr td').each(function(i){
			x=i;
		});
		if(x>0){
			x=x+1;
			l=Math.round(673/x);
			//alert('Largeur : 326/'+x+'='+l);
		}

		$(this).find("tbody tr").each(function(i){
			$(this).find('td').each(function(z){
				if(z>0){
					$(this).addClass('dataCaract');
				}
			});
		});
		$(this).find("tbody tr td.dataCaract").each(function(){
			html=$(this).html();
			html=html.replace('O','&#9679;');
			$(this).html(html);
		});
		c=1;
		while(c<=x){
			$(this).find("thead tr td").eq(c).width(l+'px');
			c=c+1;
		}
	});

	/*x=0;
	$("#tableauCaracts table thead tr td").each(function(i){
		x=i;
	});
	if(x>0){
		x=x+1;
		l=Math.round(673/x);
		//alert('Largeur : 326/'+x+'='+l);
	}*/
	// &#9679;

	/*$("#tableauCaracts table tbody tr").each(function(i){
		$(this).find('td').each(function(z){
			if(z>0){
				$(this).addClass('dataCaract');
			}
		});
	});
	$("#tableauCaracts table tbody tr td").each(function(){
		html=$(this).html();
		html=html.replace('O','&#9679;');
		$(this).html(html);
	});
	c=1;
	while(c<=x){
		$("#tableauCaracts table thead tr td").eq(c).width(l+'px');
		c=c+1;
	}*/
}); /* fin doc ready */



function changeProduit(modif){
	switch(modif){
		case -1:
			if(prochain==0)prochain=(max-1);
			else prochain=encours+modif;
			break;
		case 1:
			if(prochain==(max-1))prochain=0;
			else prochain=encours+modif;
			break;
	}
	$("#produit .prod").eq(encours).hide();
	$("#produit .prod").eq(prochain).show().removeClass('cacher');
	$("#produit .prod:eq("+prochain+") .bigz img").hide();
	$("#produit .prod:eq("+prochain+") .bigz img:eq(0)").show();
	encours=prochain;
}

/* ======== Fonctions ========================================================================== */

/* Comportement Rollover avec class="rollover" */
attachRollOverEvent = function(imageId){
	$(imageId).mouseover( function(){ $(this).attr("src", $(this).attr("src").replace('.','_roll.')) } );
	$(imageId).mouseout( function(){ $(this).attr("src", $(this).attr("src").replace('_roll','')) } );
}

/* Change image pour les "actif" */
attachActif = function(imageId){
	$(imageId).attr("src", $(imageId).attr("src").replace('.','_roll.'));
}

ImgRollover = function(imageId,i,orig,src){
	$(imageId).mouseover( function(){ $(this).find("img").attr("src", src); } );
	$(imageId).mouseout( function(){ $(this).find("img").attr("src", orig); } );
}

ImgActif = function(imageId,src){
	$(imageId).find("img").attr("src", src);
}

/* Impression des documents */
function imprimer(){
	if(window.print) window.print();
	else alert("Désolé mais votre navigateur ne supporte pas cette fonctionnalité. Pour la plupart des navigateurs, vous pouvez imprimer cette page  en allant dans le menu 'Fichier' > 'Imprimer'");
}

/* Ajouter aux favoris */

function favoris() {
if ( navigator.appName != 'Microsoft Internet Explorer' )
{ window.sidebar.addPanel("le nom du site","http://www.tonsite.com",""); }
else { window.external.AddFavorite("http://www.tonsite.com","le nom du site"); } }
