// livestream55.js - Javascript repository for MIstreamnet live page

function hov(loc,cls){
   if(loc.className)
      loc.className=cls;}

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=0,width=559,height=265,left = 401.5,top = 161.5');");
}

var refreshIntervalID = 0;
refreshIntervalID = setInterval("refresh()",30000);

function refresh() {
	ajaxAppear();
	setTimeout("makeRequest('/live55refresh.php',chan)",900);
	i=0;
	counter();
};

function button_update() {
	if (refreshIntervalID) {
		clearInterval(refreshIntervalID);
		refreshIntervalID = setInterval("refresh()",30000);
	}
	refresh();
};

function makeRequest(url, channel) {
 ajax_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 ajax_request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
		try {
		 ajax_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			 ajax_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!ajax_request) {
	 return false;
	}
 ajax_request.onreadystatechange = function() {
	if (ajax_request.readyState == 4) {
		if (ajax_request.status == 200) {
			 document.getElementById('scriptoutput').innerHTML = ajax_request.responseText;
			}
		}
 };
url = url + '?chan=' + channel;
 ajax_request.open('GET', url, true);
 ajax_request.send(null);
}


function counter() {
	t=setTimeout("counter()",1000);
	i=i+1;
	endCounter();
};
function endCounter() { 
	if (i>1) {
	ajaxFade();
	clearTimeout(t);
}; };

function ajaxAppear() {
	new Effect.Appear('ajax-loading',0.5);
};
function ajaxFade() {
		new Effect.Fade('ajax-loading',0.5);
};