jQuery.noConflict();
jQuery.fn.extend({
   findPos : function() {
       obj = jQuery(this).get(0);
       var curleft = obj.offsetLeft || 0;
       var curtop = obj.offsetTop || 0;
       while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
       }
       return {x:curleft,y:curtop};
   }
});

/* ligthbox */
jQuery(function(){
	jQuery('a.lightbox').lightBox({
	overlayBgColor: '#B7CB52',
	overlayOpacity: 0.95,
	imageLoading: 'scripts/lightbox/images/lightbox-blank.gif',		// (string) Path and the name of the loading icon
	imageBtnPrev: 'images/lightbox-btn-prev.png',			// (string) Path and the name of the prev button image
	imageBtnNext: 'images/lightbox-btn-suiv.png',			// (string) Path and the name of the next button image
	imageBtnClose: 'images/ligthbox-close.png',		// (string) Path and the name of the close btn
	imageBlank: 'scripts/lightbox/images/lightbox-blank.gif',			// (string) Path and the name of a blank image (one pixel)
	containerResizeSpeed: 100,
	txtImage: 'Image',
	txtOf: '/'
   });
});
/* superbox */
jQuery(function(){
	jQuery.superbox.settings = {
	boxId: "superbox", // Id attribute of the "superbox" element
	boxClasses: "", // Class of the "superbox" element
	overlayOpacity: .95, // Background opaqueness
	//boxWidth: "800", // Default width of the box
	//boxHeight: "400", // Default height of the box
	loadTxt: "Chargement...", // Loading text
	closeTxt: "Fermer", // "Close" button text
	prevTxt: "Précédent ", // "Previous" button text
	nextTxt: "Suivant" // "Next" button text
	};
	jQuery.superbox();
});
// tab
jQuery(function() {
	jQuery('#tab-container-0').tabs();
	jQuery('#tab-container-1').tabs();
	jQuery('#tab-container-2').tabs();
	jQuery('#tab-container-3').tabs();
	jQuery('#tab-container-4').tabs();
});
jQuery(document).ready(function(){
	// filtres
	setTimeout(function () { jQuery("#filtre").slideToggle('low'); }, 500);
	//jQuery(".sortable").tablesorter(); 
	// skin select
	jQuery("select.linkselect").linkselect({
			change: function(li, value, text){
				if( window.console ) console.log(value);
	  	}
		});
	// accordion
	jQuery("#myAccordion").myAccordion({
		speed: "fast", // @param : low, medium, fast
		defautContent: 0 // @param : number
	});
	// pave vente flash
	setTimeout(function () { jQuery("#vf").fadeIn('low'); }, 1000);
	// mini info
	jQuery('#mini_infos_container').fadeIn('low');
	jQuery('#mini_infos').innerfade({
		animationtype: 'fade',
		speed: 500,
		timeout: 3000,
		type: 'sequence',
		containerheight: '1em'
	});
	// zebra
	/*jQuery(".myZebra").myZebra({
		color1: '#fde8cd',
		color2: '#fff'
	});*/
	// pave diapo
	change_nouveaute(0);
	change_choixmois(0);
	change_cadeau(0);
	/* carousel */
	jQuery("div.bonne_affaire").carousel( { 
        autoSlide: true, 
        autoSlideInterval: 5000,
        delayAutoSlide: 2000,
		loop: true
	});
	/* slider */
	jQuery(".slider").easySlider({
		prevText: '<img src="images/fleche_prec.png" />',
		nextText: '<img src="images/fleche_suiv.png" />',
		orientation: 'vertical',
		speed: 400
	});
	/* alertes dispo */
	var id_alertereapro;
	jQuery(".alertereapro_declencheur").mouseenter(function(){
		id_alertereapro = jQuery(this).attr('id');
		jQuery(".alertereapro_contenu").hide();
		jQuery(this).next(".alertereapro_popup").show();
		jQuery(".alertereapro_plus").show();
		jQuery(".alertereapro_popup").mouseenter(function(){
			jQuery(this).stop();
			jQuery(this).css({ opacity: '1'});
		});
	});
	jQuery(".alertereapro_declencheur").mouseleave(function(){
		jQuery(".alertereapro_popup").animate({ opacity: 'hide'}, 50, function(){ 
			jQuery(".alertereapro_contenu").hide();
			jQuery(".alertereapro_plus").show();
		});
	});
	jQuery(".alertereapro_popup").mouseleave(function(){
		jQuery(".alertereapro_popup").animate({ opacity: 'hide'}, 50, function(){ 
		});
	});
	jQuery(".alertereapro_fermer").click(function(){
		jQuery(".alertereapro_popup").hide();
		jQuery(".alertereapro_contenu").hide();
	});
	jQuery(".alertereapro_plus").click(function(){
		jQuery(".alertereapro_contenu").show();
		jQuery(".alertereapro_plus").hide();
		jQuery("#alertereapro_email_"+id_alertereapro).focus();
	});
	jQuery(".alertereapro_titre").click(function(){
		jQuery(".alertereapro_contenu").show();
		jQuery(".alertereapro_plus").hide();
		jQuery("#alertereapro_email_"+id_alertereapro).focus();
	});
	/* infobulle */
	jQuery(".infobulle_declencheur").click(function(){
		id_infobulle = jQuery(this).attr('id');
		pos = jQuery("#"+id_infobulle).findPos();
		//alert(pos.x);
		jQuery("#infobulle_"+id_infobulle).css({ left: pos.x/2 });
		jQuery("#infobulle_"+id_infobulle).fadeIn("slow");
		jQuery(".infobulle_popup").click(function(){
			jQuery(".infobulle_popup").hide();
		});
	});
	jQuery(".infobulle_fermer").click(function(){
		jQuery(".infobulle_popup").hide();
	});
	/* recherche */
	jQuery("#recherche").mouseleave(function(){
		jQuery('#suggestions').hide();
	});
	jQuery("#recherche_plus").click(function(){
		if(jQuery("#recherche_plus").html() == "&gt;&gt; Cliquez ici pour masquer les articles ignorés"){
			window.location.reload();
		}
		jQuery(".liste_prod_elem").show();
		jQuery(".liste_prod_elem_last").show();
		jQuery("#recherche_plus").html(">> Cliquez ici pour masquer les articles ignorés");
	});
	/* liste favoris */
	jQuery(".liste_ref").change(function(){
		// recupere id element
		var id = jQuery(this).parents('tr').attr('id');
		id = id.split('_');
		id = id[1];
		// recupere reference selectionée
		var ref = jQuery(this).attr('value');
		// affiche le bouton ajouter et attribut valeur lien
		jQuery("#liste_btajouter_"+id).show();
		//jQuery("#ref_prod_"+id).show();
		jQuery("#ref_prod_"+id).attr({ disabled : false });
		jQuery("#ref_prod_"+id).attr({ checked : true });
		jQuery("#liste_btajouter_"+id).attr({ href : "?lien=favoris&action=panier&ref="+ref });
		jQuery("#ref_prod_"+id).attr({ value : ref });
		if(ref == ''){
			jQuery("#liste_btajouter_"+id).hide();
			//jQuery("#ref_prod_"+id).hide();
			jQuery("#ref_prod_"+id).attr({ checked : false });
			jQuery("#ref_prod_"+id).attr({ disabled : true });
		}
	});
	// pave compte
	jQuery(".pavecompte_nav").mouseleave(function(){
		jQuery(this).children('.pavecompte_sousnav').hide('fast');
	});
	jQuery(".pavecompte_nav").mouseenter(function(){
		jQuery(this).children('.pavecompte_sousnav').show()
	});
	// encart newsletter
	jQuery(".nl_choix").click(function(){
		jQuery('#nl_suite').hide();
		if(jQuery('#nl_newsletter').is(':checked') || jQuery('#nl_dossiers').is(':checked')){
			jQuery('#nl_suite').show();
		}
	});
	jQuery("#nl_submit").click(function(){
		if(!valide_email(jQuery("#nl_email").attr('value'))){
			//popup('popup_inscription_newsletter');
			//document.body.style.overflow = "hidden";
			return false;
		}
	});
});
/* Recherche / autocomplete */
function lookup(inputString) {
	if(inputString.length == 0) {
		jQuery('#autoSuggestionsList').hide();
		jQuery('#suggestions').hide();
	} else {
		var type = jQuery('#type').val();
		if(type == 'dossier'){
			jQuery('.SUBMITannexe_recherche').hide();
		}
		jQuery.post("ajax/test.php", {type: type, queryString: ""+inputString+""}, function(data){
			if(data.length >0) {
				//jQuery('#recherche-detail').hide();
				jQuery('#suggestions').show();
				jQuery('#autoSuggestionsList').show();
				jQuery('#autoSuggestionsList').html(data);
			}
			else{
				jQuery('#autoSuggestionsList').hide();
				jQuery('#suggestions').hide();
			}
		});
	}
}
function fill(thisValue) {
   //jQuery('#inputString').val(thisValue);
   jQuery('#suggestions').hide();
   document.location.href="http://www.brindilles.fr/"+thisValue+".htm";
}
function showDetail() {
   jQuery('#recherche-detail').show('fast');
   jQuery('#inputString').val('');
   jQuery('#suggestions').hide();
}
function stop_autocomplete(){
	jQuery('#suggestions').hide();
	jQuery('#recherche-detail').hide();
	jQuery('#inputString').val('');
}
/* quantite produit pour panier */
function change_quantite(mode, id){
	var max = parseInt(document.getElementById('quantite-max-'+id).value);
	var courant =  parseInt(document.getElementById('quantite-input-'+id).value);
	if(mode == '+' && parseInt(courant+1) <= max){
		jQuery('#quantite-input-'+id).val(parseInt(courant+1));
		jQuery('#quantite-view-'+id).html(parseInt(courant+1));
	}
	if(mode == '-' && parseInt(courant-1) >= 0){
		jQuery('#quantite-input-'+id).val(parseInt(courant-1));
		jQuery('#quantite-view-'+id).html(parseInt(courant-1));
	}
	if(mode == '' && parseInt(courant) > max){
		jQuery('#quantite-input-'+id).val(max);
		jQuery('#quantite-view-'+id).html(max);
		alert("Cette quantité n'est pas en stock");
	}
	total_commande();
}

function bund(id){
	if(document.getElementById(id).style.display='none')
	{document.getElementById(id).style.display='block';}
	else
	{document.getElementById(id).style.display='none';}
} 
function cache(id){
	document.getElementById(id).style.display='none';
}
function cache_by_class(classe){
	jQuery('.'+classe).hide();
}
function montre_by_class(classe){
	jQuery('.'+classe).show();
}
function change_nouveaute(id) {
	if(id == 4){ id = 0; }
	id++;
	cache_by_class('encart_nouveaute_elem');
	jQuery('#encart_nouveaute_elem_'+id).fadeIn('low');
	setTimeout("change_nouveaute("+id+")",6000);
}
function change_choixmois(id) {
	if(id == 4){ id = 0; }
	id++;
	cache_by_class('encart_choixmois_elem');
	jQuery('#encart_choixmois_elem_'+id).fadeIn('low');
	setTimeout("change_choixmois("+id+")",8000);
}
function change_cadeau(id) {
	if(id == 4){ id = 0; }
	id++;
	cache_by_class('encart_cadeau_elem');
	jQuery('#encart_cadeau_elem_'+id).fadeIn('low');
	setTimeout("change_cadeau("+id+")",7000);
}
/*
** Menu principal
*/
function show_menu(id){
jQuery(".stretcher").hide('medium');
jQuery("#stretcher-"+id).show('medium');
}



/*function findPos(obj) {
        var curleft = obj.offsetLeft || 0;
        var curtop = obj.offsetTop || 0;
        while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
        }
        return {x:curleft,y:curtop};
}*/