// JavaScript Document

var streamId
//  alert to show the flash is passing the add Id properly
var htmlHTTP;
var ADhtmlHTTP;

function updateRelatedMediaAd(adId)
{ 
	//alert(adId);
	if(adId != '' && adId != 0 && !isNaN(adId)){
			//alert('id: ' + adId);
			ADhtmlHTTP=GetXmlHttpObject()
			if (ADhtmlHTTP==null)
			{
				alert ("Browser does not support HTTP Request")
				return
			} 
			 var url="/mediacenter/related_ad.php?ad="+adId
			// alert(url);
			 ADhtmlHTTP.onreadystatechange=stateChanged 
			 ADhtmlHTTP.open("GET",url,true)
			 ADhtmlHTTP.send(null)
	}
}

function stateChanged() 
{ 
	if (ADhtmlHTTP.readyState==4 || ADhtmlHTTP.readyState=="complete")
	{	
 	 	//document.getElementById("relatedAdBlock").innerHTML ='asdf';//
		try{
		document.getElementById("relatedAdBlock").innerHTML=ADhtmlHTTP.responseText;
		}catch(exception){
			
		}
		//alert(ADhtmlHTTP.responseText);
 	}
}


function updateNowPlaying(id, catID){
	//http://anga.ws.rci.local/mediacenter/nowPlaying.php?id=536&catid=2
	
	htmlHTTP=GetXmlHttpObject()
	if (htmlHTTP==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	 var url="/mediacenter/nowPlaying.php?id=" + id + "&catid="+catID;
	// alert(url);
	 htmlHTTP.onreadystatechange=stateChangedNowPlaying
	 htmlHTTP.open("GET",url,true)
	 htmlHTTP.send(null)
}

function stateChangedNowPlaying()
{
	if (htmlHTTP.readyState==4 || htmlHTTP.readyState=="complete"){
		document.getElementById("nowplaying").innerHTML=htmlHTTP.responseText;
		
	 }
}
 
 

function GetXmlHttpObject()
{ 
	var objXMLHttp=null
 	if (window.XMLHttpRequest)
  	{
  		objXMLHttp=new XMLHttpRequest()
  	}
 	else if (window.ActiveXObject)
  	{
  		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  	}
 	return objXMLHttp
}



//  sets the stream id
function set(sid) {	streamId = sid;	}
//  function used by flash to get the current stream id.
//  this id equals the current stream id then flash does nothing
function getsid() {	return streamId;}

function loadNewFlash(id, catID){
	obj = document.getElementById("flashHolder");
	goToAnchor = true;
	if(!catID){
		catID = 1;
		goToAnchor = false;
	}
	
	var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	
	outVar = "";
	
	outVar += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="393" height="328" wmode="transparent" allowFullScreen="true">';
	outVar += '<param name="movie" value="/flash/media_center.swf?vnum=0&sid=' + id + '" />';
	outVar += '<param name="allowScriptAccess" value="always" />';
	outVar += '<param name="quality" value="high" />';
	outVar += '<param NAME="wmode" VALUE="transparent" />';
	if(!isIE){
		outVar += '<object type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" data="/flash/media_center.swf?vnum=0&sid=' + id + '" width="393" height="328" wmode="transparent">';
		outVar += '</object>';
	}else{
		outVar += '<embed type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" data="/flash/media_center.swf?vnum=0&sid=' + id + '" width="393" height="328" wmode="transparent">';
		outVar += '</embed>';
	}
	outVar += '</object>';
	
	obj.innerHTML = outVar;
	
	updateNowPlaying(id, catID);//udates the now playing section through ajax
	
	if(goToAnchor){
		location.href = '#anchor_media_center';
	}
}