$(document).ready( function(){ 
     
	 $("#cart").bind("mouseenter", function(){
	      $('#cart_over').show();								   
          
	  });
		
	 $("#cart").bind("mouseleave", function(){
      
		$('#cart_over').hide();
      });
	 
	 
				
		$('.promozioni ul').innerfade({
			speed: 2000,
			timeout: 7000,
			type: 'sequence',
			containerheight: '42px'
		});
	
					
}); 

	 
	 function set_values_search() {
			$('#categories_id').remove(); 
			$('#macrocategories_id').remove();
			$('#search_in_description').remove();
			$('#inc_subcat').remove();			
	 }
	 
	var keyword;

	function memorizza(obj) {
		if (obj.value != "" || obj.value != "undefined")
			keyword = obj.value;
	}

	jQuery(document).ready(function() {

		function formatItem(row) {
			return row[0];
		}
		
		function formatResult(row) {
			
			return row[0];
		}

		$("#searchName").autocomplete("searchName.php", {
			minChars: 0,
			width: 310,
			max: 20,
			matchContains: true,
			autoFill: false,
			scroll: false,
			selectFirst: false,
			formatItem: formatItem,
			formatResult: formatResult
		});
		
		$('#searchName').result(function(event, data, formatted) {
			location.href = "product_info.php?products_id=" + data[1] + "&valore_search=" + keyword;
		});


	});	 

	jQuery(document).ready(function($) 
	{
	  $('a[rel*=facebox]').facebox({
		loading_image : 'images/facebox/loading.gif',
		close_image   : 'images/facebox/closelabel.gif'
	  }) 
	});

	$(function() 
	{
		$('.tooltip').tooltip({ 
			track: true, 
			delay: 0, 
			showURL: false, 
			fixPNG: true,
			extraClass: "pretty",
			fade: 250 	
		}); 
	});

	function alterNate(elm){
		if (!elm.base) elm.base = elm.value
		if (elm.value == elm.base) elm.value = "";
		else if (elm.value == "") elm.value = elm.base;
	}

	function clearBox(elm){
		if (elm.value=="Username" || elm.value=="Password" || elm.value=="... cerca" ) elm.value = "";
	}
	
function loadcat(cid) {
	var element = "#cat-" + cid;
	if ($(element).children('img').attr('src') == 'img/1uparrow.png') {
		$(element).children('span').slideUp('slow');
		$(element).children('img').attr('src','img/1rightarrow.png');
	}
	else {
		
		$(element).children('img').attr('src','img/ajax-loader.gif');
		$.ajax({
		   url: "alemenu_cat.php?cid=" + cid,
		   success: function(msg){
			 $(element).children('span').html(msg);
			 $(element).children('img').attr('src','img/1uparrow.png');
			 $(element).children('span').slideDown('slow');
		   }
		 });
	}
}

//PRENOTAZIONI

jQuery(document).ready(function() {
	timer = setInterval("ricaricaPrezzo()",3000);
});
function ricaricaPrezzo() {
	//Raggruppo tutti gli span della pagina
	spans = document.getElementsByTagName("span");
	//Li ciclo
	for (i=0; i < spans.length; i++) {
		//Considero solo quelli con la classe prezzoPrenotazione
		if (spans.item(i).className == "prezzoPrenotazione") {
			//Prendo l'id del prodotto dall'attributo rel
			pid = spans.item(i).getAttribute("rel");
			//Faccio una chiamata ajax alla pagina ricaricaPrezzo, che mi calcola il prezzo in tempo reale
			chiamaAjax(spans.item(i),pid);
		}
	}	

}

function chiamaAjax(span,pid) {
			$.ajax({
			   type: "GET",
			   url: "ricaricaPrezzo.php?id=" + pid,
			   success: function(msg) {
				 span.innerHTML = "€ " + msg;
				 
			   }
			});
}

//AFFINA RICERCA

function affinaRicerca() {
	$('#form').submit();
}
