


$(document).ready(function(){

	/*this.delay = (function(){
  		var timer = 0;
  		return function(callback, ms){
    		clearTimeout (timer);
    		timer = setTimeout(callback, ms);
  		};
	})*/
	


	$("#sfld").click(function(){
		if( $(this).val() == "Recherche" ){
			$(this).val("");
		}
	})
	
	$('#siteSearchSubmit').ajaxStart(function() {
  		$(this).css('background', 'url(/img/spinner.gif) no-repeat -1px 2px');
	});
	$('#siteSearchSubmit').ajaxStop(function() {
  		$(this).css('background', 'url(/img/search-bg.png) no-repeat -1px -1px');
	});

	$('#sfld').keyup(function(){ 
		
		var keyword = $(this).val()
		if( keyword.length < 2 ){
			$('div#autoComplete').remove()
			return false;
		}
		var lan = $(this).attr('lang')
		
		//$('div#tools > form').css('background-image', 'url(/img/theme09/bg_search_on.jpg)')
		

		
			$.getJSON('/' + lan + '/product/autoComplete.html',{keyword:keyword},function(data){

				
				
				$('div#autoComplete').remove()
				$('body').append('<div id="autoComplete">&nbsp;</div>')
				
				var ct = '<table cellspacing="0" cellpadding="0"><tbody>'

				if( data.products.length ){
					ct += '<tr><th>Products</th><td><ul>';
					$.each(data.products, function(i,item){
						ct += '<li><a href="' + item.url + '"><span><img src="' + item.img + '" alt="' + item.title + '" /></span>' + item.title + '</a></li>'
		         	});
		          
					ct += '</ul></td></tr>'
				}


				if( data.applications.length ){
					ct += '<tr><th>Applications</th><td><ul>';
					$.each(data.applications, function(i,item){
						ct += '<li><a href="' + item.url + '"><span><img src="' + item.img + '" alt="' + item.title + '" /></span>' + item.title + '</a></li>'
		         	});
		          
					ct += '</ul></td></tr>'
				}
				
				
				
				ct += '</tbody></table>'
				$('div#autoComplete').html(ct);
		 
			}
		)
		
		
	})



} )

	

