function caricatempo(){
	var rnd = Math.floor(Math.random()*10000);
	$("#work").load('/live/tempo.php?demo=1&video='+video+'&timestamp='+rnd,function(){
		var cont = '';
		$("#tempo #citta").html($("#work .spots").html());
		$("#work tr.spot span").html();
		var giorni=['','',''];
		var soli=['','',''];
		var freddo=['','',''];
		var caldo = ['','',''];
		$("#work th.spot span").each(function(i) {
     		giorni[i] = $(this).html();
   		});
   		$("#work .img img").each(function(i) {
   			ciao = $(this).attr("src");
     		soli[i] = ciao;
     		/*ciao = $(this).attr("src");
     		if(ciao.indexOf('/')>0){
	     		ciao = ciao.substring(ciao.indexOf('/')+2);
	     		ciao = ciao.substring(ciao.indexOf('/')+1);
     		}
     		soli[i] = ciao;*/
   		});
   		$("#work .tmin").each(function(i) {
     		freddo[i] = $(this).html();
   		});
   		$("#work .tmax").each(function(i) {
     		caldo[i] = $(this).html();
   		});
   		cont = '<div id="citta">' + cont + '</div>';
   		for(i=0;i<3;i++){
   			j=i+1;
   			$("#tempo #giorno"+j+" span").html(giorni[i]);
   			$("#tempo #giorno"+j+" td.tmuno").html('<div class="stiaccia"><img src="' + soli[i] + '" class="soli"></div>');
   			$("#tempo #giorno"+j+" td.tmdue").html(freddo[i] +'°');
   			$("#tempo #giorno"+j+" td.tmquattro").html(caldo[i]+ '°');   			
   		}   		
	});	
}
function caricaticker(){
	rnd = Math.floor(Math.random()*10000);
	$("#newscountry").load('/live/rss.php?demo=1&feed=1&video='+video+'&timestamp='+rnd,function(){
		$("#newscountry ul").liScroll();
		$("#newscountry ul li b").append(':');
	});	 
	rnd = Math.floor(Math.random()*10000);
	$("#newslocal").load('/live/rss.php?demo=1&feed=2&video='+video+'&timestamp='+rnd,function(){
		$("#newslocal ul").liScroll();
		$("#newslocal ul li b").append(':');
	});	
}
function caricaspot(){
	/*$.post("tmp/onoff.txt", function(data){		
		if(data == "ON\n"){
			$("#rivenditore img").attr('src','res/logospottler.png');
			$("#rivenditore th").css('color','#fae04f');
		}else{
			$("#rivenditore img").attr('src','res/logospottler_rosso.png');
			$("#rivenditore th").css('color','#fe4c54');
		}
	});*/
	$.post("fe.php", { func: "getNameAndTime" },
		function(data){
			if(data.fine){
				caricatempo();
				caricaticker();
				caricaspot();
			}else if(data.durata==0){
				caricaspot();
			}else{
				$("#spot").html(data.spot);
				setTimeout(caricaspot,data.durata * 1000);
			}
	}, "json");
}
function caricatxt(){
	$.post("ft.php", { func: "getNameAndTime" },
		function(data){
			if(data.fine){
				caricatxt();
			}else if(data.durata==0){				
				caricatxt();
			}else{			
				$("#textleft").slideUp("fast",function(){
					$("#textleft .ttitle div").html(data.ttitle);
					$("#textleft .tbody div").html(data.tbody);
					$("#textleft .ttel div").html(data.ttel);
					$("#textleft").slideDown("slow");
				});
				$("#textright").slideUp("fast",function(){
					$("#textright .ttitle div").html(data.ttitle);
					$("#textright .tbody div").html(data.tbody);
					$("#textright .ttel div").html(data.ttel);
					$("#textright").slideDown("slow");
				});
				setTimeout(caricatxt,data.durata * 1000);
			}
	}, "json");      	
}
function caricaoroscopo(){
	$.post("fo.php", { func: "getNameAndTimeMy" },
		function(data){	
			$("#oroscopo #otitle div").fadeOut("slow",function(){
				$("#oroscopo #otitle div").html('<img style="margin-right: 3px;" align="left" src="res/zodiac/'+data.segno+'.png" width="60">'+data.segno+'<br>'+data.data);
				$("#oroscopo #otitle div").fadeIn("slow");
			});											
			//$("#oroscopo #otitle div").html('<img style="margin-right: 3px;" align="left" src="res/zodiac/'+data.segno+'.png" width="60">'+data.segno+'<br>'+data.data);
			$("#oroscopo #obody div").fadeOut("slow",function(){
				if(data.oroscopo==null){
					$("#oroscopo #obody div").html('Servizio momentaneamente non disponibile<br>database in aggiornamento');
				}else{
					$("#oroscopo #obody div").html(data.oroscopo);	
				}				
				$("#oroscopo #obody div").fadeIn("slow");
			});
			//$("#oroscopo #obody div").html(data.oroscopo);
			if(giro<=0){
				$("#oroscopo #otel div").html('consulenza immediata<br>899 892044 -  0541 1973009');
			}else if(giro == 1){
				$("#oroscopo #otel div").html('<span id="alice">www.astrostar.it</span>');
				//$("#oroscopo #otel div").animate({letterSpacing: "10px"}, 1500 ).animate({letterSpacing: ""}, 1500) ;
			}else if(giro == 2){
				$("#oroscopo #otel div").html('a cura di Alice Pazzi<br>www.astrostar.it');
			}
			else{ 
				$("#oroscopo #otel div").html('<span id="alice">899 892044</span>');
				//$("#oroscopo #otel div").animate({letterSpacing: "10px"}, 1500 ).animate({letterSpacing: ""}, 1500) ;
			}			
	}, "json");    
	giro++;	
	var quanto = 15000;
	if(giro==0){	
		giro=1;
		quanto = 7500;
	}else{
		if(giro==4) giro=0;
	}
	setTimeout(caricaoroscopo,quanto);      
}
function caricareseller(){
	rnd = Math.floor(Math.random()*10000);
	$("#work").load('/live/reseller.php?demo=1&video='+video+'&timestamp='+rnd,function(){
		$("#rivenditore th").html($("#work #nome").html()+'<br>'+$("#work #link").html());
		$("#rivenditore td").html($("#work #reseller").html());
	});
}
var rnd = Math.floor(Math.random()*10000);
var giro=-1;
$(document).ready(function() {
	caricatempo();
	caricaticker();
	caricareseller();
	caricaoroscopo();
	caricaspot();
	caricatxt();	
 });
