  $.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };



 
var totale_offerte = 0;
var totale_news = 0;
var totale_sconti = 0;
var totale_foto = 0;

function conta(){
 totale_offerte = $("#pannello_offerte li").length;
 totale_news = $("#news li").length;
 
 
 
 totale_foto = $("#testo_home li").length;
 
 parti();

}

 

 function parti() {
	$("#loading").fadeOut("fast");
	$("#testo_home").fadeTo("slow", 0.66);
	
	$("#all").fadeIn();
	
	attiva();
	 
}

function attiva(){
 setTimeout("offerte_home()", 0);
 setTimeout("news_home()", 300);
 
  setTimeout("foto_home()", 600);

}












var im = "public/home_1.jpg";
var o=-1;
function offerte_home(){
	
	  o=o+1;
	 
   		if(o>=totale_offerte){o=0;}
	
		im = ""+$("#off_"+o).attr("title")+".jpg";
		$("#pannello_offerte").css("background","url("+im+")");
		 
		$("#pannello_offerte").show(500);
		$("#off_"+o).fadeIn(1000);
   		$("#off_"+o).animate({"left": "+=0px", "top": "+=0px"}, 5000, function(){$("#pannello_offerte").fadeOut(1000);$("#off_"+o).fadeOut(1000, function(){$("#off_"+o).animate({"left": "-=0px", "top": "-=0px"}, "fast", offerte_home);})});
     
  } 
	 
	 

var im2 = "public/home_1.jpg";
var n=-1;
function news_home(){
	
	  n=n+1;
	 
   		if(n>=totale_news){n=0;}
	
		im2 = "/public/"+$("#news_"+n).attr("title")+".jpg";
		$("#news_home").css("background","url("+im2+")");
		 
		$("#news_home").show(500);
		$("#news_"+n).fadeIn(1000);
   		$("#news_"+n).animate({"left": "+=0px", "top": "+=0px"}, 5000, function(){$("#news_home").fadeOut(1000);$("#news_"+n).fadeOut(1000, function(){$("#news_"+n).animate({"left": "-=0px", "top": "-=0px"}, "fast", news_home);})});
     
  } 	 
	 





function offerta(){ location.href = $("#off_"+o+" a").attr("href");}





var im3 = "public/home_1.jpg";
var f = -1;
function foto_home(){
	
	  f=f+1;
	
   		if(f>=totale_foto){f=0;}
	 
	
		im3 = "/foto/"+"foto_"+f+".jpg";
		$("#foto_home").css("background","url("+im3+") bottom no-repeat");
		 
		$("#foto_home").show(500);
		$("#testo_home").fadeIn(1000);
   		
		$("#foto_"+f).fadeIn(1000);
   		$("#foto_"+f).animate({"left": "+=0px", "top": "+=0px"}, 10000, function(){$("#foto_home").fadeOut(1000);$("#testo_home").fadeOut(1000, function(){$("#foto_"+f).fadeOut(1000);$("#foto_"+f).animate({"left": "-=0px", "top": "-=0px"}, "fast", foto_home);})});
     
  } 	 