function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=688,height=596');");
}

// FUNCTION : SLIDE FADE TOGGLE
$.fn.slideFadeToggle = function(speed, easing, callback) {
	return this.animate({height: 'toggle', opacity: 'toggle'}, speed, easing, callback);};
 
// PAGE READY
$(document).ready(function () {

// Pop-up overlay window
var api = $('div.overlay').overlay({speed: '500',expose: {color: '#000000',opacity: 0.7,closeSpeed: 500}, api: 'true'});
var oldStatus = "load";

function streamOffline() {
		$('#ustream').load('includes/command.php?command=ustreamOffline&a=' + Math.round(10000*Math.random()));
}

function streamLive() {
		var t=setTimeout("$('#ustream').load('includes/command.php?command=ustreamLive&a=' + Math.round(10000*Math.random()))", 400);
}

loadStream(ustreamStatus);
function loadStream(data) {
	if (data == "live") {
		ustreamStatus="live";
	$('#live').show(0);
	} else {
		api.close();
		ustreamStatus="offline";
		$('#live').hide(0);
		streamOffline();
	}
	
	if (data != oldStatus && cookie != "1") {
		if (data != "live") {
		oldStatus="offline";
		api.close();
		streamOffline();
		} else {
			oldStatus="live";
			api.load();
			streamLive();
			}
	}
		
}
   var refreshId = setInterval(function() {$.get('includes/command.php?command=ustreamCheck&a=' + Math.round(10000*Math.random()), loadStream);}, 15000);
 
$('#live').click(function() {
			api.load();
			streamLive();
						   });
$('#close').click(function() {
		cookie="1";
		streamOffline();
		$.get('includes/command.php?command=makeCookie&a=' + Math.round(10000*Math.random()));
						   });
$('#closePop').click(function() {
		cookie="1";
		streamOffline();
		api.close();
		$.get('includes/command.php?command=makeCookie&a=' + Math.round(10000*Math.random()));
		popUp('ustreamPop.php');
						   });
$('#hideAlways').click(function() {
		cookie="1";
		streamOffline();
		api.close();
		$.get('includes/command.php?command=makeCookieAlways&a=' + Math.round(10000*Math.random()));
						   });
	// SLIDESHOW
    $('#slides').cycle({
		    fx: 'fade',
	 	    delay: 4000,
			timeout: '4000',
			speed: '1000',
			next: '#next', 
			prev: '#prev',
			pager: '#slideshow_nav'
    	}
	);
	$(".slide a").hover(
		function() {
			$(this).append("<img class='featured_overlay' src='images/featured_overlay.png' width='315' height='120' border='0'' />");
		},
		function() {
			$(".featured_overlay").remove();
		}
	);

 var nav_buttons = '#nav_buttons >' + page;
 var headerLinks = '.headerLinks >' + page;
 var middleBoxLinks = '#middleBoxLinks >' + page;
 $(nav_buttons).addClass('live');
 $(headerLinks).css({'color' : '#000'});
 $(middleBoxLinks).css({'color' : '#990033'});
});