url="status.xml.php";

Array.prototype.inArray = function (value){
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] == value) {
			return true;
		}
	}
	return false;
};
Array.prototype.posArray = function (value){
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] == value) {
			return i;
		}
	}
	return false;
};

function teraz(targetCell){
var xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4){
		if (xmlHttp.status == 200){
			
			var xmlDoc=xmlHttp.responseXML;
			
			var streams=new Array();
			streams['name']=new Array();
			streams['audition']=new Array();
			streams['song']=new Array();
			streams['mount']=new Array();
			
			for(var i=0;i<xmlDoc.getElementsByTagName("streamname").length;i++){
				var streamName=xmlDoc.getElementsByTagName("streamname")[i].firstChild.nodeValue;
				if(!streams['name'].inArray(streamName)){
					var s = streams['name'].push(streamName) - 1;
					streams['song'].push(xmlDoc.getElementsByTagName("currentsong")[i].firstChild.nodeValue);
					streams['mount'][s]=new Array();
					streams['mount'][s].push(xmlDoc.getElementsByTagName("mount")[i].firstChild.nodeValue);
				}else{
					var s = streams['name'].posArray(streamName);
					streams['mount'][s].push(xmlDoc.getElementsByTagName("mount")[i].firstChild.nodeValue);
				}
			}
			
			radiobaobab(streams,targetCell);
			
		}
		}
	};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
/*
function teraz(){
	var xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4){
		if (xmlHttp.status == 200){
			var xmlDoc=xmlHttp.responseXML;
			
			var rHTML;
			var startCell=1;
			for(var i=0;i<xmlDoc.getElementsByTagName("streamname").length;i++){
				if(xmlDoc.getElementsByTagName("mount")[i].childNodes[0].nodeValue!="/radiobaobab.ogg" && xmlDoc.getElementsByTagName("mount")[i].childNodes[0].nodeValue!="/radiobaobab.mp3"){
					
					rHTML="";
					rHTML+="<table style=\"border:solid 2px #f20000; border-width:2px 0px 0px 0px; width:500px; height:100px; background-image:url('"+(startCell+1)+".gif'); background-repeat:no-repeat;\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tbody>";
					rHTML+="<tr><td colspan=\"2\" style=\"height:30px;\" id=\"cell_streamname\">"+xmlDoc.getElementsByTagName("streamname")[i].childNodes[0].nodeValue+"</td></tr>";
					rHTML+="<tr><td colspan=\"2\" style=\"height:16px;\">"+xmlDoc.getElementsByTagName("artist")[i].childNodes[0].nodeValue+"</td></tr>";
					rHTML+="<tr><td colspan=\"2\" style=\"height:16px;\">"+xmlDoc.getElementsByTagName("title")[i].childNodes[0].nodeValue+"</td></tr>";
					mount_url=streamserver+xmlDoc.getElementsByTagName("mount")[i].childNodes[0].nodeValue;
					rHTML+="<tr><td style=\"height:30px; width:350px;\"><a href=\""+mount_url+".m3u\" class=\"href_mount\">"+mount_url+"</a><td style=\"text-align:left;\"><a href=\""+mount_url+".m3u\"><img border=\"0\" src=\"play2.gif\"></a></td></tr>";
					rHTML+="</tbody></table>";
	
					document.getElementById("channelcell"+startCell).innerHTML=rHTML;
					
					startCell=startCell+1;
				}
			}

		}else{
			alert('There was a problem with the request.');
		}
		}
	};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	var t=setTimeout("teraz()",timeout);
}
*/

function radiobaobab(streams,targetCell){
var xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4){
		if (xmlHttp.status == 200){
			var xmlDoc=xmlHttp.responseXML;
			
			var p=streams['name'].posArray('Radio Baobab - Warszawa, Polska');
			streams['audition'][p] = xmlDoc.getElementsByTagName("audition")[0].childNodes[0].nodeValue;
			streams['song'][p] = xmlDoc.getElementsByTagName("currentsong")[0].childNodes[0].nodeValue;
			streams['name'][p] = "Audycje Radia Baobab";
			var rHTML="";
			
			if(targetCell=="channelcell"){
				
				rHTML="<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"width:90%;\"><tbody>";
				
				for(var i=0;i<streams['name'].length;i++){
					rHTML+="<tr><td style=\"height:110px;\"><table style=\"border:solid 2px #f20000; border-width:2px 0px 0px 0px; width:500px; height:100px; background-image:url('images/"+(i+1)+".gif'); background-repeat:no-repeat;\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tbody>";
					rHTML+="<tr><td colspan=\"2\" style=\"height:30px;\" id=\"cell_streamname\">"+streams['name'][i]+"</td></tr>";
					if(streams['audition'][i]!=undefined){
						rHTML+="<tr><td colspan=\"2\" style=\"height:15px;\">"+streams['audition'][i]+"</td></tr>";
					}else{
						rHTML+="<tr><td colspan=\"2\" style=\"height:15px;\">&nbsp;</td></tr>";
					}
					rHTML+="<tr><td colspan=\"2\" style=\"height:15px; padding-bottom:5px;\">"+streams['song'][i]+"</td></tr>";
					for(var j=0;j<streams['mount'][i].length;j++){
						var mountURL=streamserver+streams['mount'][i][j];
						rHTML+="<tr><td style=\"height:14px; width:350px;\"><a href=\""+mountURL+".m3u\" class=\"href_mount\">"+mountURL+"</a></td><td style=\"text-align:left;\"><a href=\""+mountURL+".m3u\"><img border=\"0\" src=\"images/play3.gif\"></a></td></tr>";
					}
					rHTML+="</tbody></table></td></tr>";
					
				}
				
				document.getElementById(targetCell).innerHTML=rHTML+"</tbody></table>";
			}else{
				rHTML+="<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tbody>";
				rHTML+="<tr><td colspan=\"2\" style=\"height:15px;\" id=\"cell_streamname\">"+streams['name'][0]+"</td></tr>";
				if(streams['audition'][0]!=undefined){
					rHTML+="<tr><td colspan=\"2\" style=\"height:15px;\">"+streams['audition'][0]+"</td></tr>";
				}else{
					rHTML+="<tr><td colspan=\"2\" style=\"height:5px;\">&nbsp;</td></tr>";
				}
				rHTML+="<tr><td colspan=\"2\" style=\"height:10px; padding-bottom:5px;\">"+streams['song'][0]+"</td></tr>";

				for(var j=0;j<streams['mount'][0].length;j++){
					var mountURL=streamserver+streams['mount'][0][j];
					rHTML+="<tr><td style=\"text-align:left;\"><a href=\""+mountURL+".m3u\"><img border=\"0\" src=\"images/play4.gif\"></a></td><td style=\"height:15px; width:350px; padding-left:15px;\"><a href=\""+mountURL+".m3u\" class=\"href_mount\">"+mountURL+"</a></td></tr>";
				}
				rHTML+="</tbody></table>";
				
				document.getElementById('topcell').innerHTML=rHTML;	
				
			}
		}
		}
	};
	xmlHttp.open("GET","radiobaobab.xml.php",true);
	xmlHttp.send(null);
}
teraz('channelcell');
teraz('topcell');
//var v=setInterval("teraz()",timeout);
/*
var audycja;
function status(){
var xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4){
		if (xmlHttp.status == 200){
			var xmlDoc=xmlHttp.responseXML;
			
			document.getElementById("title").innerHTML=xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
			document.getElementById("artist").innerHTML=xmlDoc.getElementsByTagName("artist")[0].childNodes[0].nodeValue;
			for(var i=0;i<xmlDoc.getElementsByTagName("streamname").length;i++){
				if(xmlDoc.getElementsByTagName("mount")[i].childNodes[0].nodeValue==defaultmount){
					audycja=xmlDoc.getElementsByTagName("artist")[i].childNodes[0].nodeValue;
				}
			}	
			var mount=xmlDoc.getElementsByTagName("mount")[0].childNodes[0].nodeValue;
			var stream_url=streamserver+mount;
			document.getElementById("mount").innerHTML="<a id=\"href_mount\" class=\"href_mount\" href=\""+stream_url+".m3u\">"+stream_url+"</a>";
			document.getElementById("listen").href=stream_url+".m3u";
			document.getElementById("listen2").href=stream_url+".m3u";
			
		}else{
			document.getElementById("indicator").src="offline.gif";
		}
		}
	};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	var c=setTimeout("status()",timeout);
}
*/
