function caricatempo(){
	var rnd = Math.floor(Math.random()*10000);
	$("#work").load('/live/meteo.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] +'&deg;');
   			$("#tempo #giorno"+j+" td.tmquattro").html(caldo[i]+ '&deg;');   			
   		}   		
	});	
}
function caricaticker() {
	rnd = Math.floor(Math.random()*10000)
        $("#top_box").load('/live/rss.php?V=3.18&feed=1&video='+video+'&timestamp='+rnd,function(){
		$("#top_box ul").liScroll()
		$("#top_box ul li b").append('***')
	});	
	rnd = Math.floor(Math.random()*10000)
       /* $("#bottom_box").load('/live/rss.php?V=4.18&feed=2&video='+video+'&timestamp='+rnd,function(){
		//$("#bottom_box ul").liScroll()
		//$("#bottom_box ul li b").append('***')
	});
		 $('div.specialnews marquee').marquee('pointer');*/
}
function caricaspot(){
	$.post("data/reseller.txt", function(data){
		if(data.indexOf("spotguardian",0) > 0){
                        $.post("tmp/onoff.txt", function(data){           
                        if(data == "ON\n"){  
                                $("#rivenditore img").attr('src','res/spotguardian.png');  
                                $("#rivenditore th").css('color','#fae04f');  
                        }else{  
                                $("#rivenditore img").attr('src','res/spotguardian_rosso.png');  
                                $("#rivenditore th").css('color','#fe4c54');  
                        } 
                        });
		}else{
                        $.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);
				
				if ($("#descrizioneins").length > 0){
					$("#info").html('<img alt="" src="res/rettangolo.png" />');	
					rnd = Math.floor(Math.random()*10000);
					//$("#top_inside").html($("#descrizioneins").html());
					$("#top_box").html($("#descrizioneins").html());
					$("#top_box ul").liScroll();
					//$("#top_box ul li b").append(':');
					azzera_top = true;
					
				}
				else {
					if (azzera_top) {
						$("#info").html('');
						rnd = Math.floor(Math.random()*10000);					
						//$("#top_inside").load('data/news1.html?id='+rnd,function(){});
						//$("#top_box").load('data/news1.html?id='+rnd,function(){
        					$("#top_box").load('http://video.spottler.com/live/rss.php?V=3.18&feed=1&video='+video+'&timestamp='+rnd,function(){
							$("#top_box ul").liScroll();
							$("#top_box ul li b").append(' - ');
						});
						azzera_top = false;
					}
				}
			}
	}, "json");
}

function caricaoroscopo(){
	
		$.post("fo.php", { func: "getNameAndTimeMy" },
			function(data){	
				//if(giro==0){	
				$("#oroscopo_title").fadeOut("slow",function(){
					$("#oroscopo_title").html('<img style="margin-right: 3px;" align="left" src="res/zodiac/'+data.segno+'.png" width="50">'+data.segno+'<br>'+data.data);
					$("#oroscopo_title").fadeIn("slow");
				});											
				//}
					if(data.oroscopo==null){
						$("#oroscopo_inside").html('Servizio momentaneamente non disponibile<br>database in aggiornamento');
					}else{
						startScroll('oroscopo_inside',''+data.oroscopo+'');
					}
			
		}, "json");  

  
		
	var quanto = 30000;

	giro++;
	if(giro==2)
		giro=0;
	setTimeout(caricaoroscopo,quanto);
}

function replaceHtml(el, html) {
	var oldEl = typeof el === "string" ? document.getElementById(el) : el;
	/*@cc_on // Pure innerHTML is slightly faster in IE
		oldEl.innerHTML = html;
		return oldEl;
	@*/
	var newEl = oldEl.cloneNode(false);
	newEl.innerHTML = html;
	oldEl.parentNode.replaceChild(newEl, oldEl);
	/* Since we just removed the old element from the DOM, return a reference
	to the new element, which can be used to restore variable references. */
	return newEl;
}
function caricareseller(){
	/*rnd = Math.floor(Math.random()*10000);
	$("#rivenditore").load('data/reseller.txt?id='+rnd,function(){		
	
	});*/
        rnd = Math.floor(Math.random()*10000);
        $("#rivenditore").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=0;
var azzera_top = true;
$(document).ready(function() {
	caricatempo();
	caricaticker();
	caricaspot();
	caricareseller();	
	caricaoroscopo();
 });

