/*
 
 js/livestreams.js
 
 by adam borecki
 
 */

$(document).ready(function(){livestreams.check();});

var livestreams = new Object();

livestreams.timer = null;
livestreams.delay = 1000*20; // sync every 20 seconds
livestreams.check = function() {
	if(livestreams.timer) {
		clearTimeout(livestreams.timer);
		livestreams.timer = null;
	}
	$.getJSON("/json/livestreams.php",function(response){livestreams.receive(response);});
};

livestreams.receive = function(response) {
	// sports
	if(response.sports) $("#livestream-sports").slideDown();
	else $("#livestream-sports").slideUp();
	// nowplaying
	if(response.showid) {
		//eid('livestream-icon').src = response.show.icon;
		var html = "<span class='block' style='padding-left:8px;'><img src='"+response.show.icon+"' alt='' /></span>";
		html += "<span class='block'><span class='info'>Current Show:</span><br /><b>"+response.show.showname+"</b> <i>"+response.show.genre+"</i><br />"+response.show.djs+"</span>";
		if(response.nowplaying.nowplayingid) {
			html += "<span class='block'><img src='"+response.nowplaying.icon+"' alt='' /></span>";
			html += "<span class='block'>";
			if(response.nowplaying.type == "music") {
				html += "<span class='info'>Current Song:</span><br />";
				html += "<b>"+response.nowplaying.track+"</b><br />";
				html += "by "+response.nowplaying.artist+".";
			}
			else {
				html += "<span class='info'>Current Topic:</span><br />";
				html += response.nowplaying.notes;
			}
			html += "</span>";
		}
		eid('livestream-content').innerHTML = html;
		$("#livestream-radio").slideDown();
	} else {
		$("#livestream-radio").slideUp();
	}
	// timer
	if(livestreams.timer) {
		clearTimeout(livestreams.timer);
		livestreams.timer = null;
	}
	livestreams.timer = setTimeout("livestreams.check()", livestreams.delay);
};
