function mainmenu(){
	$(" #Nav .bloc_menu ").css({display: "none"}); // Opera Fix
	$(" #Nav li").hover(function(){
		$(this).find('.bloc_menu:first').css({visibility: "visible",display: "none"}).show(400);
	},function(){
		$(this).find('.bloc_menu:first').css({visibility: "hidden"});
	});
}

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(){

   mainmenu();
   
   //BOF Bug jquery Internet explorer : On redonne le focus aux boutons radios 
       $(function () {
              if ($.browser.msie) {
                     $('input:radio').click(function() {
                            this.blur();
                            this.focus();
                     });
              }
       });
       //EOF Fin bug internet explorer
   
   

   $("#container-tabs > ul").tabs();

	$("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='message'>Le formulaire n'est pas complétement rempli</p>");

		}

	});

	// 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');

            $.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();
      }

    );

});