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 active_link() {
	$("#mon-panier, #mon-panier_fleche").live("click", function(){

		$("#mon-panier_extend").slideDown(400);

	});



	$("#mon-panier_extend_bottom").live("click", function(){

		$("#mon-panier_extend").hide();

	});



	$("#mon-compte, #mon-compte_fleche").live("click", function(){

		$("#mon-compte_extend").slideDown(400);

	});




	$("#mon-compte_extend_bottom").live("click", function(){

		$("#mon-compte_extend").hide();

	});
}



$(document).ready(function(){
	// BOF 171-COMMENTAIRES_ET_SONDAGES
	$(".button-add-comment").live("click", function() {
		$("#add_comment").show();
		var _this = $(this);
		_this.hide();
	});


	$(".button-lire-suite").live("click", function() {
		var comment_id = $(this).attr('comment_id');
		var _this = $(this);
		$.ajax({
			type: "POST",
			url: "ajax_update.php?type=bls_comment",
			data: "comment_id="+comment_id,
			success: function( result ) {
				console.log(_this.prev('.msg'));
				_this.prev('.msg').html( result );
				_this.hide();
			}
		});
	});

	$(".star-vote").live("mouseover", function() {
		var $box = $(this).parents('div.box_stars');

		var msg = $(this).attr('msg');

		$box.find('.stars_vote_value').html( msg );
	});

	$(".star-vote").live("mouseout", function() {
		var $box = $(this).parents('div.box_stars');
        if ( $box.hasClass('move') )
        {
			var val = $box.find('.input_value').val();
			var msg = $box.find('a.star-vote[rel='+val+']').attr('msg');

			var newclass = 'current-rating rating star'+val;

			$box.find('.stars_vote_value').html( '' );
			$box.find('.stars_vote_value').html( msg );
			$box.find(".current-rating").attr('class', newclass);
		}


	});

	$(".star-vote").live("click", function() {
		var $box = $(this).parents('div.box_stars');
		if ( $box.hasClass('move') )
        {
			var rel = $(this).attr('rel');
			var newclass = 'current-rating rating star'+rel;

			$box.find(".input_value").val( rel );
			$box.find(".current-rating").attr('class', newclass);

			$box.find(".input_value").click();
        }


	});

	$("#add_comment_form .go").live("click", function() {
		var $box = $(this).parents('div.box_stars');

		var val_star_vote_result = $box.find(".star-vote-result").val();

		if ( val_star_vote_result < 1 ) {
			alert('message erreur');
			return false;
		}
	});
	// EOF 171-COMMENTAIRES_ET_SONDAGES


    $("#search_input").live("keyup", function()
	{
		search_value = $(this).val();
		length = search_value.length;

		$.ajax({
			type: "POST",
			url: "ajax_update.php?type=autocomplete_search",
			data: "search_value="+search_value,
			success: function( result )
			{
				$('#autocomplete_search').show();
				$('#autocomplete_search').html( result );
			}
		});
});


$("#submit_form_ac_search").live("click", function()
{
	$("#formulaire").submit();
});



var options2 = {
	zoomType: "reverse",
	imageOpacity: 0.2,
	title: false,
	showEffect: "show",
	hideEffect: "fadeout",
	fadeoutSpeed: "slow",
	zoomWidth: 400,
	zoomHeight: 400,
	xOffset: 10,
	yOffset: 0,
	position: "right" //and MORE OPTIONS
};

$(".jqzoom").jqzoom(options2);

$('#global').pngFix( );

$(".hint").ezpz_hint();



   //$(".info:last").css({border: '0px'});



   $('.btn_arrondi, .color_other, .color_selected').corner('round');



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

		}

	});



	$("#mon-panier, #mon-panier_fleche").live("click", function(){

		$("#mon-panier_extend").slideDown(400);

	});



	$("#mon-panier_extend_bottom").live("click", function(){

		$("#mon-panier_extend").hide();

	});



	$("#mon-compte, #mon-compte_fleche").live("click", function(){

		$("#mon-compte_extend").slideDown(400);

	});




	$("#mon-compte_extend_bottom").live("click", function(){

		$("#mon-compte_extend").hide();

	});



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

    		$.ajax({

            			type: "POST",

            			url: "ajax_update.php?type=inscription_newsletter",

            			data: "email="+news_field,

            			success: function( result )

                        {
                          $('#news_field').hide();
                          $('#input_email').hide();
						  $('#fieldset_inscription_newsletter_message').show();
                          $('#fieldset_inscription_newsletter_message').html( result );




            			}

            		});



	});



	$('.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").html( result );

                //re-attach thickbox

                tb_init('a.thickbox');



                }



            });



        });

    });









/*

$(".image_produit").hover(function(){

		masque_id = $(this).attr('rel');

        $('#masque_'+masque_id).show();

    });

    */



    $('.view_details').hide();

    $(".image_produit").hover(function(){

        masque_id = $(this).attr('rel');

        $('#masque_'+masque_id).show();

        	}, function() {

        $('#masque_'+masque_id).hide();

    });







    /*
    var options = {

	    zoomType: "reverse",

	    imageOpacity: 0.2,

	    title: false,

        showEffect: 100,

        hideEffect: "fadeout",

        fadeoutSpeed: "fast",

        zoomWidth: 400,

	    zoomHeight: 400,

        xOffset: 10,

        yOffset: 0,

        position: "right" //and MORE OPTIONS

};

	$(".jqzoom").jqzoom(options);
	*/





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

                            $.ajax({

                           type: "POST",

                           url: "ajax_update.php?type=change_image&application=product",

                           data: {"vignette_rel" : vignette_rel, "rep_vignette_rel" : rep_vignette_rel},

                           success: function ( result ) {

						$("#zoom_img").html( result );

						//re-attach thickbox

                        tb_init('a.thickbox');



					}



                         });



  });

                          });





});
