/*****
 * Copyright Giagi.it web solutions di Gianluigi Copia
 */
 
 
 function parti() {
	$("#loading").fadeOut("fast");
	$("#all").fadeIn("fast");
	
}
 
 
 
 
    $.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 selmenu;
function somenu(menu)
{


if(selmenu==menu){
$("#so_"+menu).animate({ left: 0, top: +40}, 500);
$("#so_"+menu).fadeOut(500);
selmenu=0;

return false
}else{
$("#so_"+selmenu).fadeOut(500);

$("#so_"+menu).animate({ left: 0, top: +31}, 500);
$("#so_"+menu).fadeIn(500);
selmenu = menu;
 } 
  
}

function nosomenu(menu)
{
		
      $(".so_menu").fadeOut(1000);
      return false;
  
}


var images = new Array();
var imagesG = new Array();

var lx = new Array();
var tx = new Array();
var totalefoto= 6;
				
				
				images[0] = '/foto/home_0.jpg';
				imagesG[0] = '/foto/home_0G.jpg';
				lx[0] ="0";
				tx[0] = "0";
				
				images[1] = '/foto/home_1.jpg';
				imagesG[1] = '/foto/home_1G.jpg';
				lx[1] ="0";
				tx[1] = "0";
				
				images[2] = '/foto/home_2.jpg';
				imagesG[2] = '/foto/home_2G.jpg';
				lx[2] ="0";
				tx[2] = "0";
				
				images[3] = '/foto/home_3.jpg';
				imagesG[3] = '/foto/home_3G.jpg';
				lx[3] ="0";
				tx[3] = "0";
				
				images[4] = '/foto/home_4.jpg';
				imagesG[4] = '/foto/home_4G.jpg';
				lx[4] ="0";
				tx[4] = "0";
				images[5] = '/foto/home_5.jpg';
				imagesG[5] = '/foto/home_5G.jpg';
				lx[5] ="0";
				tx[5] = "0";
				



i=-2;
 function runIt() {
  i=i+1;
   if(i==totalefoto){i=0;}

 // alert($("#testo_"+i).height());
   
    $("#immagine").attr("src",images[i]);
	$("#url_immagine").attr("href",imagesG[i]);
	if(i!=0){$("#bk_testo").show();$("#bk_testo").fadeTo("slow", 0.66);}else{$("#bk_testo").hide();}
    $("#foto").fadeIn(1000);
	$("#testo_"+i).fadeIn(1000);
	$("#immagine").animate({"left": "+="+lx[i]+"px", "top": "+="+tx[i]+"px"}, 11000, function(){$("#testo_"+i).fadeOut(1000);$("#foto").fadeOut(1000, function(){$("#immagine").animate({"left": "-="+lx[i]+"px", "top": "-="+tx[i]+"px"}, "fast", runIt);})});


}
runIt();




var totale_offerte = 0;
var totale_news = 0;
var totale_reviews = 0;

function conta(){
 totale_offerte = $("#offerte_home li").length;
 totale_news = $("#news li").length;
 totale_reviews = $("#reviews li").length;

offerte_home();
runIt();
news();
trip();
}


function conta2(){
 totale_offerte = $("#offerte li").length;
 totale_news = $("#news li").length;
 
offerte();
news();
}


function conta_cc(){
 totale_offerte = $("#offerte li").length;
 totale_news = $("#news li").length;

offerte();
runIt_cc();
news();
}



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

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


var o=totale_offerte;
function offerte(){
	  o=o+1;
   		if(o==totale_offerte){o=0;}
		$("#off_"+o).fadeIn(1000);
		$("#off_"+o).wait(2000);
		$("#off_"+o).fadeOut(1000, offerte);
   		
  }




var e=totale_news;
function news(){
	  e=e+1;
   		if(e==totale_news){e=0;}
		$("#news_"+e).fadeIn(1000);
		$("#news_"+e).wait(2000);
		$("#news_"+e).fadeOut(1000, news);
   		
  } 
  
  
  
  
	
var t=totale_reviews;
function trip(){
	  t=t+1;
   		if(t==totale_reviews){t=0;}
		$("#trip_"+t).fadeIn(1000);
		$("#trip_"+t).wait(5000);
		$("#trip_"+t).fadeOut(1000, trip);
   		
  }
  
  var bud =0;
  function budget(msg)
  {
	  if(bud ==0)
	  {
		  $("#budget").animate({"width": "595px"}, 1000,function(){ $("#budget5").fadeIn( "fast",function(){$("#budget3").fadeIn( "fast",function(){$("#budget4").fadeIn("fast");});;});});
		  $("#budget").css("background","url(\"img/budget2a.gif\")", function(){});
		 
	  		bud =1;
	  
	  }
	  else
	  {
		  
		  $("#budget4").fadeOut( "fast",function(){$("#budget3").fadeOut( "fast",function(){$("#budget5").fadeOut("fast", function(){$("#budget").animate({"width": "230px"}, 1000,function(){$("#budget").css("background","url(\"img/budget.jpg\")");});});});;});
		  
	  	bud =0;
		  
		  
	  }
	  
	  
}


  
 
 
 
 function privacy(lingua)
 {
 $.ajax({
   type: "POST",
   url: "privacy_form.php",
   data: "name="+lingua,
   success: function(msg){
     $("#container").append("<div id=\"privacy_form\"><a href=\"javascript:void(0)\" onclick=\"chiudi_privacy()\">close</a><div>"+msg+"</div></div>");
   }
 });
 
 }
 function chiudi_privacy()
 {$("#privacy_form").remove();
}
 
