/*
 
 js/sportsflash.js
 
 by adam borecki
 
 */

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

var sportsflash = new Object();

sportsflash.check = function() {
	$.getJSON("/json/sports-onair", function(data){
			  if(data.onair) {
			  $("div.sportsflash .largeRed").css("display", "block");
			  sportsflash.clear();
			  sportsflash.on = true;
			  sportsflash.loop();
			  $(".sportsflash a").html("Sports Broadcast<br /><i>On Air</i>");
			  }
			  else {
			  $("div.sportsflash .largeRed").css("display", "none");
			  sportsflash.clear();
			  $(".sportsflash a").html("Sports<br />Broadcasts");
			  }
			  });
	setTimeout("sportsflash.check();", 60*1000); // check for a broadcast every minute
};

sportsflash.on = false;
sportsflash.timer = null;

sportsflash.clear = function() {
	if(sportsflash.timer)
		clearTimeout(sportsflash.timer);
	sportsflash.timer = null;
	sportsflash.on = false;
};

sportsflash.loop = function() {
	if(sportsflash.on) {
		$(".sportsflash .largeRed").fadeOut().delay(600).fadeIn();
		sportsflash.timer = setTimeout("sportsflash.loop();", 5700);
	}
};
