str_length = 26;
suggestion = true;
	function lookup(inputString) {
		if(inputString.length == 0 || inputString.length == 1 && suggestion) {
			$('#suggestions').hide();
		} else {
			if(inputString.length <= str_length) {suggestion = true;}
			if(str_length > 0 && suggestion) {
			$.get(fw_uri+'/'+$('html').attr('lang')+"/search/autocompletion/index."+inputString+".html", {/*variable : ""+valeur+""*/}, function(data){
				if(data.length == 0) {
					$('#suggestions').hide();
					suggestion = false;
					str_length = inputString.length;
				}
				if(data.length >1) {
					n = -1;
					suggestion = true;
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
			}	
		}
	} 
	
	function fill(thisValue) {
		$('#search').val(thisValue);
		setTimeout("$('#suggestions').hide();", 200);
	}



$(document).ready(function(){
Shadowbox.init();

//Défilement des news
	posStart = 0;
    compteur = 0;
    $('#liste_news').find('li').each(function() {
        $(this).css('top', posStart+'px');
        posStart +=  $(this).height();
        compteur++;
    });
    
    if(compteur > 1)
    {
        startDefil();
	}
    

var fw_produits_id = $('#produits_id').val();
	$('#sendfriend').live('click', function(){
		showOverlay();
		showLoading();
		$.ajax({
			type: 'POST',
			url : fw_uri+'/'+$('html').attr('lang')+'/sendfriend/',
			data : 'produits_id='+fw_produits_id,
			success : function(msg){
				$('body').append(msg);
				hideLoading();

				/** Submit sur le formulaire */
				$('#form_sendfriend').live('submit',function(){
					$('#sendfriend_ajax_box').remove();
					showLoading();
					var s = $(this).serialize();
					$.ajax({
						type: 'POST',
						url :fw_uri+'/'+$('html').attr('lang')+'/sendfriend/check/',
						data : s,
						
						success : function(msg){						
							$('body').append(msg);
							hideLoading();
							setTimeout('showOk()',4000);
						}
						
					});
					return false;
				});
			}
		});
	return false;
	});
    


    $.fn.cycle.defaults.speed   = 900;
    $.fn.cycle.defaults.timeout = 3000;

$(function() {
    // run the code in the markup!
    $('#fondu_marques pre code').each(function() {
        eval($(this).text());
    });
});



	/*$('#ul_menu_top').find('.sousmenu').parent().each(function(){
		var submenu = $(this).find('.sousmenu:eq(0)');
		var alink = $(this).find('a:eq(0)');
		$(this).click(
			function(){
				submenu.slideToggle('fast');
			},
			function(){
				submenu.fadeOut('fast');
			}
		);
	});*/
	
	$("#li_familles").click(
			
			function(){
				$(this).siblings('.sousmenu').slideToggle('fast');
				return false;
			});
			
	$("#li_contact").click(
			
			function(){
				$(this).siblings('.sousmenu').slideToggle('fast');
				return false;
			});
	
	




	$('#search').focus(function() {
		$(this).val('');
	});
	/** Auto-completion **/
	$('#search').attr('autocomplete','off');
	n = -1;
	$('#search').live('keyup', function(event) {
		if(event.keyCode == 40) {
 			if(n+1 < $("#autoSuggestionsList > ul > li").length) {
				n = n + 1;
				$("#autoSuggestionsList > ul > li").eq(n).attr('class','hover').focus();
				if(n > 0 && n < $("#autoSuggestionsList > ul > li").length) {
					$("#autoSuggestionsList > ul > li").eq(n-1).removeClass('hover');
				}
			}
		} else if(event.keyCode == 38) {
			if(n > 0) {
				n = n - 1;
				if(0 <= n <= $("#autoSuggestionsList > ul > li").length) {
					$("#autoSuggestionsList > ul > li").eq(n).attr('class','hover').focus();
				}
				if(n >= 0) {
					$("#autoSuggestionsList > ul > li").eq(n+1).removeClass('hover');
				}
			} 
		}
		else {
			if(event.keyCode != 13) {
				lookup($(this).attr('value'));
			}

		}
	});
	
	$('body').keydown(function(event) {
		if(event.keyCode == 13) {
			$('#form_search').submit(function() {
				if($('#autoSuggestionsList > ul > li.hover').length > 0){
					fill($('#autoSuggestionsList > ul > li.hover').eq(0).html());
					$('#autoSuggestionsList > ul > li.hover').removeClass('hover');
					return false;
				} else {
					return true;
				}
			});
		}
	});
	

	$('#search').blur(function() {
		fill();
	});
	$('.suggestionList > ul > li').live('click',function() {
		fill($(this).html());
	});
// fin autocompletion
});

/** Ferme le bloc ok aprËs quelques secondes et cache l'overlay **/
function showOk() {
	if($('#ok_box').length>0) {
		$('#ok_box').fadeOut('slow');
		hideOverlay();
	}
}
/** Supprime le bloc AJAX **/
$('.close_ajax_box').live('click',function(){
	$(this).parents('.ajax_box').remove();
	hideOverlay();
});

/** Fonctions d'affichage / masquage des loaders et de l'overlay **/
function showOverlay() 		{ $("#overlay").css({'display': 'block','opacity': 0.4});}
function showLoading() 		{ $('#loading').show()}
function showBasketLoading(){ $('#loading_basket').show()}
function showFiltreLoading(){ $('#filtre_loading_ajax').show()}

function hideOverlay() 		{ $("#overlay").css({'display': 'none'});}
function hideLoading() 		{ $('#loading').hide()}
function hideBasketLoading(){ $('#loading_basket').hide()}
function hideFiltreLoading(){ $('#filtre_loading_ajax').hide()}


function startDefil()
{
    $('#liste_news').find('li').each(function() {
    	var position = $(this).position();
    	var topDest = position.top - $(this).height();
    	
    	$(this).animate({ 
            top: topDest +'px'
            }, 2000);
    });
    
    window.setTimeout(function() {
        var position = $('ul#liste_news>li:last').position();
        var hauteur = $('ul#liste_news>li:last').height();
        var dest = position.top + hauteur;
        
        $('#liste_news>li:first').clone().insertAfter('#liste_news>li:last').css('top', dest+'px');
        $('#liste_news>li:first').remove();
        startDefil()
        
    },6000);	
}


