var newsactualid=1;
var newstimerhandle;
var maxnews=10;
var pct=0;

function changepalday(day) {
	var daynames = new Array();
	daynames[1] = Array("Lu", "Luned&igrave;");
	daynames[2] = Array("Ma", "Marted&igrave;");
	daynames[3] = Array("Me", "Mercoled&igrave;");
	daynames[4] = Array("Gi", "Gioved&igrave;");
	daynames[5] = Array("Ve", "Venerd&igrave;");
	daynames[6] = Array("Sa", "Sabato");
	daynames[0] = Array("Do", "Domenica");
	for(i=0; i<7; i++) {
		$("#tab_palinsesto_day_" + i).removeClass("tab_palinsesto_selected_day");
		$("#tab_palinsesto_day_" + i).html('<a href="javascript:void(0);" onclick="changepalday(' + i + ');" title="' + daynames[i][1] + '">' + daynames[i][0] + '</a> ');
	}
	$("#tab_palinsesto_day_" + day).addClass("tab_palinsesto_selected_day");
	$("#tab_palinsesto_day_" + day + " a").remove();
	$("#tab_palinsesto_day_" + day).html(daynames[day][0]);
	$("#tab_palinsesto_day").fadeOut("fast", function() {
		$("#tab_palinsesto_loader").height($("#tab_palinsesto_day").height());
		$("#tab_palinsesto_loader").fadeIn("fast", function() {
			$.get("ajax/palinsesto.php", { nocache: new Date().getTime(), day: day }, function(data) {
				$("#tab_palinsesto_day").html(data);
				$("#tab_palinsesto_loader").fadeOut("fast", function() {
					$("#tab_palinsesto_day").fadeIn("fast");
					$("#tab_palinsesto_loader").height('auto');
				});
			});
		});
	});
}

var oldsongname = "";
var oldsmslist = "";

function showsonginfo() {	
	$.get("/ajax/songinfo.php", { nocache: new Date().getTime() }, function(data) {
		if(data != oldsongname) {
			$("#songtitle").html(data);	
		}
		if(oldsongname != "" && oldsongname != data && $("#tab_lastsongs")) {
			$("#tab_lastsongs_tablecont").fadeOut("fast", function() {
				$("#tab_lastsongs_loader").height($("#tab_lastsongs_tablecont").height());
				$("#tab_lastsongs_loader").fadeIn("fast", function() {
					$.get("ajax/lastsongs.php", { nocache: new Date().getTime() }, function(dati) {
						$("#tab_lastsongs_tablecont").html(dati);		
						$("#tab_lastsongs_loader").fadeOut("fast", function() {
							$("#tab_lastsongs_tablecont").fadeIn("fast");
							$("#tab_palinsesto_loader").height('auto');
						});
					});												 
				});
			});
		}
		oldsongname = data;
	});
	setTimeout("showsonginfo()", 10000);
}

function showsmslist() {	
	$.get("/ajax/sms.php", { nocache: new Date().getTime() }, function(data) {
		if(data != oldsmslist) {
			$("#sms_scroller").html(data);	
		}
		oldsongname = data;
	});
	setTimeout("showsmslist()", 30000);
}

function showsonginfo_popup() {	
	$.get("ajax/songinfo.php", { nocache: new Date().getTime() }, function(data) {
		if(data != oldsongname) {
			s_data = data.split(" - ");
			$("#s_artist").html(s_data[0]);
			if(s_data[1] == undefined) s_data[1] = "";
			$("#s_title").html(s_data[1]);
			$("#s_image").css("background-image", "url('onair_image.php?nocache="+new Date().getTime()+"')");
			
			$.get("ajax/songinfo.php", { next: true, nocache: new Date().getTime() }, function(data) {
				$("#nextsong").html(data);
			});
		}
		oldsongname = data;
	});
	setTimeout("showsonginfo_popup()", 10000);
}

function showhomenews(direction) {
	if(direction == 1) {
		newsactualid++;
		if(newsactualid > maxnews) {
			newsactualid = 1;
		}
	} else {
		newsactualid--;
		if(newsactualid < 1) {
			newsactualid = maxnews;
		}
	}
	$("#news").height($("#news_content").height());
	$("#news_nav_pagecount").html(newsactualid + " di " + maxnews);
	$("#news_content").hide("slow", function() {
		$.get("ajax/homenews.php", { nocache: new Date().getTime(), id: newsactualid }, function(newscontent) {
			$("#news_content").html(newscontent);
			$("#news_content").show("slow", function() {
				$("#news").height($("#news_content").height());
				clearInterval(newstimerhandle);
				pct=0;
				newstimer();
			});
		});
	});														   
}

function newsarchive() {
	location.href="news_archive.php";
}

function newstimer() {
	clearInterval(newstimerhandle);
	newstimerhandle=setInterval("newstimer_update()",100);
}

function newstimer_update() {
$("#news_nav_progressbar").reportprogress(++pct);
	if(pct==100){
		clearInterval(newstimerhandle);
		showhomenews(1);
		pct=0;
	}
}

function newstimer_freeze(yes) {
	if(yes == 1) {
		clearInterval(newstimerhandle);
	} else {
		newstimer();
	}
}

function initializenews(numnews) {
	maxnews = numnews;
	$("#news_nav_pagecount").html("1 di " + numnews);
	newstimer();
}

function openpanel(panelname, newsid) {
	if(newsid==undefined) newsid=0;
	var oldheight = $("#homerubriche_content").height();
	$("#homerubriche_content").fadeOut("fast", function() {
		$("#homerubriche_panel").show();
		$("#homerubriche_panel").height(oldheight);
		$("#homerubriche_panel_loader").html('<div style="height:' + oldheight + 'px; background: url(\'images/common/ajax-loader.gif\') center no-repeat;"></div>');
		$.get("ajax/homepanel.php", { id: newsid, fromhome: 'true', type: panelname, nocache: new Date().getTime() }, function(panelcontent) {																					
			$("#homerubriche_panel_content").html(panelcontent);
			$("#homerubriche_panel_loader").html('');
			$("#homerubriche_panel_content").fadeIn("fast", function() {
				$("#homerubriche_panel").height('auto');
			});
		});
	});	
}

function changepanelpage(panelname, offset, newsid) {
	if(newsid==undefined) newsid=0;
	if(offset==undefined) offset=0;
	var oldheight = $("#homerubriche_panel").height();
	$("#homerubriche_panel").fadeOut("fast", function() {
		$("#homerubriche_panel_content").hide();								
		$("#homerubriche_panel").show();
		$("#homerubriche_panel").height(oldheight);
		$("#homerubriche_panel_loader").html('<div style="height:' + oldheight + 'px; background: url(\'images/common/ajax-loader.gif\') center no-repeat;"></div>');
		$.get("ajax/homepanel.php", { id: newsid, o: offset, fromhome: 'false', type: panelname, nocache: new Date().getTime() }, function(panelcontent) {																					
			$("#homerubriche_panel_content").html(panelcontent);
			$("#homerubriche_panel_loader").html('');
			$("#homerubriche_panel_content").fadeIn("fast", function() {
				$("#homerubriche_panel").height('auto');												   
			});
		});
	});	
}

function closepanel() {
	$("#homerubriche_panel_content").fadeOut("fast", function() {
		$("#homerubriche_panel_content").html('');
		$("#homerubriche_content").fadeIn("fast");
	});	
}

(function($) {	
	//Main Method
	$.fn.reportprogress = function(val,maxVal) {			
		var max=100;
		if(maxVal)
			max=maxVal;
		return this.each(
			function(){		
				var div=$(this);
				var width=Math.round(val/max*100);
				$("#news_nav_progressbar").css("width",width+"%");	
			}
		);
	};
})(jQuery);

/*
 * jScroller 0.3 - Scroller Script
 *
 * Copyright (c) 2007 Markus Bordihn (http://markusbordihn.de)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * $Date: 2007-11-15 13:00:00 +0100 (Thu, 15 Nov 2007) $
 * $Rev: 0.3 $
 */
	var jscroller_interval = 0;
	var jscroller_refreshtime =  50;  // Refresh Time in ms
	var jscroller_direction = "left"; // down,right,left,up
	var jscroller_speed =     3;    // Set the Scroller Speed
	var jscroller_scroller =        "#sms_scroller";
	var jscroller_cont =   "#sms_scroller_container";

function startsmsticker() {
   
   if (jscroller_scroller && jscroller_cont) {
		$(jscroller_scroller).css({position: 'absolute', left: 250, top: 0});
		$(jscroller_cont).css('overflow','hidden');
		  jscroller_startScroll();
   }
   
}

function jscroller_startScroll() {
	if(!jscroller_interval) {
		jscroller_interval = window.setInterval(jscroller_doScroll, jscroller_refreshtime);
	}
}

function jscroller_stopScroll() {
	if(jscroller_interval) {
		window.clearInterval(jscroller_interval);
		jscroller_interval = 0;
	}
}

function jscroller_getElem(Elem) {
return (typeof Elem == "string" && document.getElementById)? document.getElementById(Elem) : Elem;
}

function jscroller_doScroll() {
if (scroller_dom = jscroller_getElem($(jscroller_scroller).attr("id"))) {
 var
  p_top= Number((/[0-9-,.]+/.exec($(jscroller_scroller).css('top'))||0)),
  p_left=Number((/[0-9-,.]+/.exec($(jscroller_scroller).css('left'))||0)),
  min_height=$(jscroller_cont).height(),
  min_width=$(jscroller_cont).width(),
  speed=jscroller_speed,
  p_height=scroller_dom.offsetHeight,
  p_width=scroller_dom.offsetWidth,
  direction=jscroller_direction,
  jscroller=jscroller_scroller;

 switch(direction) {
   case 'up':
	if (p_top <= -1*p_height) {p_top=min_height;}
	$(jscroller).css('top',p_top-speed+'px');
   break;
   case 'right':
	if (p_left >= min_width) {p_left=-1*p_width;}
	$(jscroller).css('left',p_left+speed+'px');
   break;
   case 'left':
	if (p_left <= -1*p_width) {p_left=min_width;}
	$(jscroller).css('left',p_left-speed+'px');
   break;
   case 'down':
	if (p_top >= min_height) {p_top=-1*p_height;}
	$(jscroller).css('top',p_top+speed+'px');
   break;
 }
}
}

function webtv() {
var newWindow = window.open("http://www.radiomondoweb.it/webtv.php", "webTV", "scrollbars=no,resizable=no,width=960,height=490");
}

function popup_player() {
alert("Funzione disabilitata. Per maggiori informazioni info@radiomondoweb.it");
//var newWindow = window.open("http://www.radiomondoweb.it/popup_player.php", "RMWLiveStreaming","scrollbars=no,resizable=no,width=343,height=280");
}
