function lookup(search_input) {
       if(search_input.length < 2) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else {
		$.post("ajax_update.php?type=autocomplete_search", {search_input: ""+search_input+""}, function(data){
			if(data.length > 0) {
				$('#suggestions').show("slow");
				$('#autoSuggestionsList').html(data);
				$('#suggestions').corner("bottom");
			}
		});
	}
} // lookup

function fill(thisValue) {
	$('#search_input').val(thisValue);
	setTimeout("$('#suggestions').hide();", 200);
}
function Set_Cookie( name, value, expires, path, domain, secure )
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if ( expires )
    {
    expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}


function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

	function lookup(search_input) {

        if(search_input.length < 2) {

			// Hide the suggestion box.

			$('#suggestions').hide();

		} else {

			$.post("ajax_update.php?type=autocomplete_search", {search_input: ""+search_input+""}, function(data){

				if(data.length > 0) {

					$('#suggestions').show("slow");

					$('#autoSuggestionsList').html(data);

					$('#suggestions').corner("bottom");

				}

			});

		}

	} // lookup



	function fill(thisValue) {

		$('#search_input').val(thisValue);

		setTimeout("$('#suggestions').hide();", 200);

	}



    $(document).ready(function(){

   $('#pane2').jScrollPane({showArrows:true});



   $('#example2').hoverAccordion({

      activateitem: '1',

      speed: 'fast'

   });



   $("#container-tabs > ul").tabs();



   $('div.module-gris').corner("7px");



	$('#top_page').click(function(){

		$.scrollTo( '#logo', 800, { easing:'swing', queue:true} );

	});



	$("button.ok, button.go").live("click", function(){

		var thisform = $(this).parents("form");



		thisform.find(".message").remove();



		if ( thisform.find(".LV_invalid_field").length > 0 ) {

			thisform.find(".buttons").prepend("<p class='msg_erreur'>Le formulaire n'est pas complétement rempli</p>");

		}

	});

	// Gestion de l'affichage des attributs de différentes couleurs
	$(".masque-color").live("click", function(){

			var $this = $(this);
			var prod = $this.attr('prod');
			var option = $this.attr('option');
			var attributes_id = $this.attr('attributes_id');

			// Modification image principale
			$.ajax({
    			type: "POST",
				url: "ajax_update.php?type=modif_big_image",
                data: "prod="+prod+"&option="+option+"&attributes_id="+attributes_id,
    			success: function( result )
                {

                  	$('#big_image_int').html( result );
                  	//re-attach thickbox
					//tb_init('a.thickbox');
    			}

    		});

	        // Modification du sélecteur de couleur
	        $('#list-color li span').each(function(){
	        	if( $(this).hasClass('masque-current-color') ){
	        		$(this).removeClass('masque-current-color');
	        		$(this).addClass('masque-color');
	        	}

	        	if( $(this).attr('attributes_id') == attributes_id) {
	        		$(this).removeClass('masque-color');
	        		$(this).addClass('masque-current-color');
				}
			});

	        // Mise à jour de la liste des vignettes
			$.ajax({
				type: "POST",
				url: "ajax_update.php?type=modif_vignettes",
	            data: "prod="+prod+"&option="+option+"&attributes_id="+attributes_id,
				success: function( result )
				{
	              	$('#others_images').html( result );
	              	//re-attach thickbox
					//tb_init('a.thickbox');
	
					// on relance le javascript pour les nouvelles vignettes affichées
				    $(".vignette").each(function (i)
					{
				        vignette_id = $(this).attr('id');
				        $(this).mouseover(function ()
				        {
				            $(".vignette").removeClass("current_img");
				            $(this).addClass("current_img");
				            vignette_rel = $(this).attr('rel');
				            rep_vignette_rel = $(this).attr('rep_rel');
				            alt = $(this).attr('alt');
	
				            $.ajax({
				                type: "POST",
								url: "ajax_update.php?type=change_image&application=product",
				                data: {"vignette_rel" : vignette_rel, "rep_vignette_rel" : rep_vignette_rel, "alt" : alt},
				                success: function ( result )
								{
				                	$("#big_image_int").html( result );
				                	//re-attach thickbox
				                	tb_init('a.thickbox');
				                }
				            });
				        });
				    });
				}
	
			});

	        // Modification du bloc prix
			$.ajax({
    			type: "POST",
				url: "ajax_update.php?type=modif_prix",
                data: "prod="+prod+"&option="+option+"&attributes_id="+attributes_id,
    			success: function( result )
                {

                  	$('#add_product').html( result );
                  	
                  	tb_init('a.thickbox');
    			}

    		});
	        		
	        // Modification du bloc fiche imprimable
	        $('#print-product').attr( 'href', 'http://www.relaxe-inn.com/product_printable.php?products_id='+prod+'&attrib='+attributes_id );
	        		
	        $(".vignette").each(function (i){

        vignette_id = $(this).attr('id');

        $(this).mouseover(function (){
            $(".vignette").removeClass("current_img");
            $(this).addClass("current_img");
            vignette_rel = $(this).attr('rel');
            rep_vignette_rel = $(this).attr('rep_rel');
            alt = $(this).attr('alt');

			// MAJ de l'image principale lorsqu'on survole une vignette
            $.ajax({
                type: "POST",
                url: "ajax_update.php?type=change_image&application=product",
                data: {"vignette_rel" : vignette_rel, "rep_vignette_rel" : rep_vignette_rel, "alt" : alt},
                success: function ( result ){
                	$("#big_image_int").html( result );
                	
                	tb_init('a.thickbox');
           		 }
            });
        });
    });


	});

	// BOF 68-PANIER_ROLLOVER
	$(".active_rollover_panier").live("mouseover", function(){
		$.ajax({
			type: "POST",
			url: "ajax_update.php?type=active_rollover_panier",
			success: function( result ) {
			$(".rollover_panier").show();
			$('#active_rollover_panier_bloc').html( result );
			//re-attach thickbox
			
			tb_init('a.thickbox');
			}
		});
	});

	$(".rollover_panier_close").live("click", function(){
		$(".rollover_panier").hide();
	});
    // EOF 68-PANIER_ROLLOVER
    
	// BOF 24-PATCH_NEW_CART_ET_BONS_DE_REDUCTION
	$(".choice_shipping").live("click", function()
	{
		shipping_id = $(this).val();
		select_pays = $(this).attr('select_pays');
		select_postecode = $(this).attr('select_postecode');
		if ( shipping_id == '24' )
		{
			$.ajax({

	        			type: "POST",

	        			url: "ajax_update.php?type=choice_shipping_modif",

	        			data: "shipping_id="+shipping_id+"&select_pays="+select_pays+"&select_postecode="+select_postecode,

	        			success: function( result )

	                    {

	                      $('#mondial_relay_bloc').html( result );

	        			}

	        		});
		}
		else
		{
			$('#mondial_relay_bloc').html( '' );
		}

	});
	// EOF 24-PATCH_NEW_CART_ET_BONS_DE_REDUCTION



$(".toggleValue").focus(function(){

						if ( $(this).val() == $(this).attr("rel") ) {

							$(this).animate({ "textIndent": "-5000px" },

							1500,

                            "",

                            function () {

								$(this).val("");

								//$(this).animate( { "textIndent": 0 }, 1500 );

								$(this).css("textIndent", 0);

							});

						}

					});



					$(".toggleValue").blur( function(){

						if ( $(this).val() == "" || $(this).val() == $(this).attr("rel") ) {

							$(this).css("textIndent", "-5000px");

							$(this).val( $(this).attr("rel") );



							$(this).animate( { "textIndent": 0 }, 1500 );

						}

					});



	$("#connection-bloc-in").click(function(event) {

        event.preventDefault();

        $("#account_menu").slideToggle();

    });



    $('#search_input').focus(function(){if($(this).val() == 'vous recherchez?') {$(this).val('');}});

                  $('#search_input').blur(function(){if($(this).val() == '') {$(this).val('vous recherchez?');}});



	$(".expand_body").hide();

          //toggle the componenet with class msg_body

          //$(".expand_head").removeClass('expand_head');

          $(".expand_head").click(function()

          {

            $(".expand_body").hide();

            $(".expand_head").removeClass('expand_head_selected');

            $(this).toggleClass('expand_head_selected');

            $(this).next(".expand_body").slideToggle(1000);

          });



	$('.count_faq').live( 'click', function() {

		var id_faq = $(this).attr('rel');

        // requete ajax

		$.post (

			"ajax_update.php?action=counter_faq",

			'id_faq='+id_faq

		);

	});



	$('#create_email').live( 'keyup', function() {

		var create_email = $(this).val();

        $.ajax({

        			type: "POST",

        			url: "ajax_update.php?type=verif_email_create_customer",

        			data: "create_email="+create_email,

        			success: function( result )

                    {

                      $('#create_email').after( result );

        			}

        		});

	});



	$('#create_email').live( 'mouseout', function() {

		var create_email = $(this).val();

		$('#email_verif').html( '' );

        $.ajax({

        			type: "POST",

        			url: "ajax_update.php?type=verif_mx",

        			data: "create_email="+create_email,

        			success: function( result )

                    {

                      $('#email_verif').html( result );

        			}

        		});

	});



	$('#field_input').live( 'click', function() {

		var news_field = $('#news_field').val();

    		var optin_partenaire_value = 0;

    		if ( $('#optin_partenaire').is(':checked') )

    		{

                optin_partenaire_value = 1;

            }

            $.ajax({

            			type: "POST",

            			url: "ajax_update.php?type=inscription_newsletter",

            			data: "email="+news_field+"&optin_partenaire="+optin_partenaire_value,

            			success: function( result )

                        {

                          $('#fieldset_inscription_newsletter_message').html( result );

                          $('#news_field').val(' ');

            			}

            		});



	});

	$('#tb_remove_cookie').live( 'click', function() {
        Set_Cookie( 'popup_newsletter', '1', '100', '/', '', '' );
        tb_remove();
	});

	$('#email_news_popup_input').live( 'click', function() {
		var news_field = $('#email_news_popup').val();
    		$.ajax({
            			type: "POST",
            			url: "ajax_update.php?type=inscription_newsletter2",
            			data: "email="+news_field,
            			success: function( result )
                        {
                          $('#email_news_popup_message').html( result );
                          if ( result == '<p><strong>Votre demande a bien été prise en compte</p>' )
                          {
                                $('#email_news_popup').val(' ');
                                sleep(5000);
                                Set_Cookie( 'popup_newsletter', '1', '100', '/', '', '' );
                                tb_remove();
                          }


            			}
            		});

	});

	$('.affiche_contact_description').live( 'change', function() {

		var contacts_id = $(this).val();

        // requete ajax

        $.ajax({

        			type: "POST",

        			url: "ajax_update.php?type=affiche_contact_description",

        			data: "contacts_id="+contacts_id,

        			success: function( result )

                    {

                      $('#formrow_select_contact').after( result );

        			}

        		});

	});



          $('#bloc-0').addClass("bloc-paiement-selected");

                $(".radio").click(function() {

                   $('.bloc-paiement').removeClass("bloc-paiement-selected");

	               $(this).parents('.bloc-paiement').each(function(){



                        $(this).addClass("bloc-paiement-selected");

                    });





	            });





    $(".vignette").each(function (i){

        vignette_id = $(this).attr('id');

        $(this).mouseover(function (){
            $(".vignette").removeClass("current_img");
            $(this).addClass("current_img");
            vignette_rel = $(this).attr('rel');
            rep_vignette_rel = $(this).attr('rep_rel');
            alt = $(this).attr('alt');

			// MAJ de l'image principale lorsqu'on survole une vignette
            $.ajax({
                type: "POST",
                url: "ajax_update.php?type=change_image&application=product",
                data: {"vignette_rel" : vignette_rel, "rep_vignette_rel" : rep_vignette_rel, "alt" : alt},
                success: function ( result ){
					$("#big_image_int").html( result );

					//re-attach thickbox
					tb_init('a.thickbox');
           		 }
            });
        });
    });



$(".produit_normal .image_produit").hover(function(){

		masque_id = $(this).attr('rel');

        $('#masque_'+masque_id).show();


    }
    ,
      function () {
        masque_id = $(this).attr('rel');

        $('#masque_'+masque_id).hide();
      }

    );

});

// Fonction displaySliderAdword pour la page d'accueil
function displaySliderAd(num){
	$('.slider-ad').each(function(){
		// On cache l'item actuellement affiché
		if ( $(this).is(':visible') ) {
			$(this).fadeOut('slow', function(){
				// On affche le nouvelle élément désiré
				$('#ad_'+num).fadeIn('slow');
			});
		}
		// Mise à jour de la barre de navigation
		$('#nav-btn a').removeClass("actif");
		$('#nav-btn a').addClass("inactif");
		$('#nav-btn #nav_'+num).removeClass("inactif");
		$('#nav-btn #nav_'+num).addClass("actif");
	});
}


// Fonction slider automatique page d'accueil
var autoSlider_k=3; //all
var autoSlider_i=1; //one

autoSlider_tt=setInterval("autoSlider(1)",5000);
function autoSlider(n){
    clearInterval(autoSlider_tt);
    autoSlider_tt=setInterval("autoSlider(1)",5000);
    autoSlider_i+=n;

    if (autoSlider_i>autoSlider_k){autoSlider_i=1;}

    if (autoSlider_i==0){autoSlider_i=autoSlider_k;}

    displaySliderAd(autoSlider_i);
}


// Fonction RollText pour box de droite "Sur le Blog"
var rollText_k=3; //all
var rollText_i=1; //one

$(document).ready(function(){
	if ( $('#right-box-sur-le-blog').length > 0 ) {
		rollText_tt=setInterval("rollText(1)",5000);
	}
	
	$('#info_zoom a').live('click', function(){
		
		$('#big_image_int a').click();
		
		return false;
	});
});

function rollText(a){

    clearInterval(rollText_tt);
    rollText_tt=setInterval("rollText(1)",5000);
    rollText_i+=a;

    if (rollText_i>rollText_k){rollText_i=1;}

    if (rollText_i==0){rollText_i=rollText_k;}

 for (var j=1; j<=rollText_k; j++){
 document.getElementById("actuBlog_"+j).style.display="none";
 }
 document.getElementById("actuBlog_"+rollText_i).style.display="block";

}

// Fonction displayOnglet pour la fiche produit

// Initialisation du premier onglet
$(document).ready(function(){
	$('#info-content1').show();
});

function displayOnglet(num){
	$('.content').each(function(){
		// On cache l'item actuellement affiché
		if ( $(this).is(':visible') ) {
			$(this).fadeOut('normal', function(){
				// On affche le nouvelle élément désiré
				$('#info-content'+num).fadeIn('normal');
			});
		}
		// Mise à jour des onglet
		$('#tab-infos ul li').each(function(){
			$(this).removeClass("current");
		});
		$('#onglet'+num).addClass("current");
	});
}

// Affichage de la zone de saisie de code de réduction sur le panier
$(document).ready(function(){
	$('#code-promo').click(function(){
		$('#saisie-reduc').slideDown('slow');
	});
});
