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);
	}
	
	var obj = null;
	
	function checkHover() {//fonction de disparition
	if (obj) {
		$('#menu ul li.principal').removeClass('current');
        obj.children('ul').fadeOut('fast');	
	} //if
} //checkHover


    $(document).ready(function(){
    
    $('#menu ul li.principal').hover(function() {
		if (obj) {//si l'objet est présent, il est déroulé, donc on le fait disparaitre
			obj.find('ul').fadeOut('fast');
			$(this).removeClass('current');
			obj = null;
		} //sinon, on le fait apparaitre lorsque l'on passe la souris dessus
        $(this).addClass('current');
		$(this).find('ul').fadeIn('fast');
 
	}, function() { //on fait disparaitre si on est plus sur l'élément au bout de 0 seconde
		obj = $(this);
		$('#menu ul li.principal').removeClass('current');
		setTimeout(
			"checkHover()",
			0); // si vous souhaitez retarder la disparition, c'est ici
	});




	$('form').live('submit', function(){
		
		$('.tiptip_holder').remove();
		
		var list_type_valid = new Array("requis", "valid_email", "valid_numeric");
		
		var count_error = 0;
		var _form = $(this);  
		
		_form.find('.field').each(function(){

			var info_erreur_field = '';
			
			var _val_field = $(this).find('input, select, textarea').val();
			
			if ( $(this).hasClass('requis') )
			{
				
				if ( _val_field == '' )
				{
					info_erreur_field += '<li>champ requis</li>';
				}
			}              
			if ( $(this).hasClass('valid_email') )
			{                                        
				
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
				if(reg.test(_val_field) == false) {
					info_erreur_field += '<li>email mal formaté</li>'; 
				}
   
			}
      
      if ( $(this).hasClass('valid_numeric') )
			{                                        
				
				var reg = /^([0-9])$/;
				if(reg.test(_val_field) == false) {
					info_erreur_field += '<li>numérique uniquement</li>'; 
				}
   
			}			
			
			if ( info_erreur_field != '' )
			{                                    
				$(this).append('<div class="tiptip_holder"><div class="tiptip_content">'+info_erreur_field+'</div></div>');
			    count_error++;           
			}         
		});
		
		           
		if ( count_error > 0 )
		{
			//alert('un ou plusieurs champs erronés');
            return false;	
		}
		
		
	});

    
    $('a.email').each(function(){
			e = this.rel.replace('/','@');
			this.href = 'mailto:' + e;
			$(this).text(e);
		});

    $(".fancybox").fancybox();


    $('#mycarousel').jcarousel();


	$("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>");
		}
	});

	

$(".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 );
						}
					});

	

    $(".vignette").each(function (i)
    {
        vignette_id = $(this).attr('id');

        $(this).mouseover(function ()
        {
            $(".vignette").removeClass("current_img");
            $(this).addClass("current_img");
            rel = $(this).attr('rel');
            width_big = $(this).attr('width_big');
            alt = $(this).attr('alt');
            $.ajax({
                type: "POST",
                url: "ajax_update.php?action=change_image",
                data: {"rel" : rel, "alt" : alt, "width_big" : width_big},
                success: function ( result ) {
                    $("#big_image").html( result );
                }

            });

        });
    });

	$(".image_produit").hover(
		function(){
			masque_id = $(this).attr('rel');
	        $('#masque_'+masque_id).show();
	    },
	    function(){
			masque_id = $(this).attr('rel');
	        $('#masque_'+masque_id).hide();
	    }
	);

	// BOF 85-STICKER_PRODUITS
	$(".product-survol").hover(
		function(){
			$(this).parent(".product").children('.product-sticker').show();
	    },
	    function(){
			$(this).parent(".product").children('.product-sticker').hide();
	    }
	);
	// EOF 85-STICKER_PRODUITS


});
