	(function($) {
		$.extend($.fx.step,{
			backgroundPosition: function(fx) {
				if (fx.state === 0 && typeof fx.end == 'string') {
					var start = $.curCSS(fx.elem,'backgroundPosition');
					start = toArray(start);
					fx.start = [start[0],start[2]];
					var end = toArray(fx.end);
					fx.end = [end[0],end[2]];
					fx.unit = [end[1],end[3]];
				}
				var nowPosX = [];
				nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
				nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
				fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
	
			   function toArray(strg){
				   strg = strg.replace(/left|top/g,'0px');
				   strg = strg.replace(/right|bottom/g,'100%');
				   strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
				   var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
				   return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
			   }
			}
		});
	})(jQuery);

    function cambia_sfondo(inp){
        //$('#lista_ingredienti .ingrediente').each(function(){
        
            //if($("#"+$(this).attr("id")+" input").attr("checked"))$(this).css({backgroundColor: "#802518",color:"#ffffff"} );
            //else $(this).css({backgroundColor: "transparent",color:"#000000"} );            
        
        //});
        $('#lista_ingredienti .ingrediente').css({backgroundColor: "transparent",color:"#000000"} );
        
        //if($(inp+" input").attr("checked"))$(inp).css({backgroundColor: "#802518",color:"#ffffff"} );
        //else $(inp).css({backgroundColor: "transparent",color:"#000000"} );
    }


	function crea(dati){
		//$('#lista_ingredienti .ingrediente').css({backgroundColor: "transparent",color:"#000000"} );
        
        document.getElementById('lista_panini').innerHTML=dati;
	}

	function crea_ingr(dati){
	     
         $('#lista_ingredienti .ingrediente').css({backgroundColor: "transparent",color:"#000000"} );
         eval("var arr=new Array("+dati+");");
         jQuery.each(arr, function() {
              $("#ingrediente_" + this).css({backgroundColor: "#802518",color:"#ffffff"} );
            });

	       
		//document.getElementById('lista_ingredienti').innerHTML=dati;
	}

	function form_trivial(dati){
		document.getElementById('trivial_domande').innerHTML=dati;


        	var flashvars = {
        		config_file: "countdown_flip_config.xml"
        	};
        
        	var params = {
        		bgcolor: "transparent",
        		wmode:"transparent",
        		menu: "false",
        		quality: "high",
        		scale: "scale"
        	};
        
        	var attributes = {
        		id: "flashcontent",
        		name: "flashcontent"
        	};
        
        	if(dati.indexOf("flashcontent")>0)swfobject.embedSWF("20secondi.swf", "flashcontent", "75", "74", "8.0.0", false, flashvars, params, attributes);



	}

	function form_test(dati){
		document.getElementById('trivial_domande').innerHTML=dati;
	}
	

	var seconds = 10;
	function setCountDown(){
		seconds--;
		if (seconds < 0){
			$.post('trivial_elabora.php', $('input'), form_trivial, 'html');
			minutes--;
		}
		
		document.getElementById("colonna_timer").innerHTML = seconds;
		setTimeout ( "setCountDown()", 1000 );
	}


	$(document).ready(function(){

	//Navbar
	$('#navbar_top a.link')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -35px )"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:300})
		})

	$('#navbar_bottom a.link')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -35px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:300})
		})


	//Movimento pulsanti	
	$("#pulsante_giochi").show("slow", function () {
		// use callee so don't have to name the function
		$(this).next().show("slow", arguments.callee); 
	});

	//Animazione pulsanti giochi
	$(".latest_img").fadeTo("fast", 0.6); // This sets the opacity of the thumbs to fade down to 30% when the page loads
	$(".latest_img").hover(function(){
	$(this).fadeTo("fast", 1.0); // This should set the opacity to 100% on hover
	},function(){
	$(this).fadeTo("fast", 0.6); // This should set the opacity back to 30% on mouseout
	});
	

    
	//Loading
	$("#loading").bind("ajaxSend",f1).bind("ajaxComplete",f2);
	
	});

    function pag(p){
        $('#pageID').val(p);
        $.get('menu_genera_lista.php', $('input:checked'), crea, 'html');
    }


	function f1(){
    	$("#fascia_centrale").fadeTo("fast", 0.4); // This sets the opacity of the thumbs to fade down to 30% when the page loads
    	$($("#loading")).show();
    }
	function f2(){
    	$("#fascia_centrale").fadeTo("fast", 1.0); // This sets the opacity of the thumbs to fade down to 30% when the page loads
    	$($("#loading")).hide();    
    }
