// Get the HTTP Object
function getHTTPObject(){
	if (window.ActiveXObject) 
		return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest) 
		return new XMLHttpRequest();
	else {
		alert("Your browser does not support AJAX.");
		return null;
	}
}

// Implement business logic
function getPlaylist(blockId){

	httpObject1 = getHTTPObject();

	if (httpObject1 != null) {
		httpObject1.open("GET", "/resources/podcasts/playlist_new.php?blockId="+blockId);
		httpObject1.send(null);
		httpObject1.onreadystatechange = setOutputPlaylist;
	}
}

// Change the value of the outputText field
function setOutputPlaylist(){
	if(httpObject1.readyState == 4){
		if (document.getElementById('podcastPlayList')){
			document.getElementById('podcastPlayList').innerHTML = httpObject1.responseText;
		}
	}
}

function getMovie(id,autostart){

	// check to see if this page has the movie holder element. If not then we will not need to get the movie.
	if (document.getElementById('movieHolder')){
		
		httpObject2 = getHTTPObject();

		if (httpObject2 != null) {
			httpObject2.open("GET", "/podcasts/getMovie.php?id="+id+"&autostart="+autostart, true);
			httpObject2.send(null);
			httpObject2.onreadystatechange = loadMovie;
		}
		
		getMovieInfo(id);			
		
	}

}

function getMovieInfo(id){

	httpObject3 = getHTTPObject();

	if (httpObject3 != null) {
		httpObject3.open("GET", "/podcasts/getMovie.php?id="+id+"&info=1", true);
		httpObject3.send(null);
		httpObject3.onreadystatechange = loadMovieInfo;
	}
}

function loadMovie(){
	
	if(httpObject2.readyState == 4){
		info = httpObject2.responseText;
		
		
		
		src = info.substr(0,info.lastIndexOf(', '));
		
		html = "";
		html = html + "<OBJECT id='lppodcastplayer' height='220' width='225' name='lppodcastplayer' CLASSID='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' type='application/x-oleobject'>";
		html = html + "<PARAM NAME='URL' VALUE='"+src+"'>";
		html = html + "<PARAM NAME='SendPlayStateChangeEvents' VALUE='True'>";
		html = html + "<PARAM NAME='AutoSize' VALUE='True'>";
		html = html + "<PARAM NAME='StretchToFit' VALUE='True'>";
		html = html + "<PARAM NAME='AutoStart' VALUE='True'>";
		html = html + "<PARAM name='uiMode' value='Full'>";
		html = html + "<PARAM name='PlayCount' value='1'>";
		html = html + "<PARAM name='Mute' value='True'>";
		html = html + "<PARAM name='Volume' value='100'>";
		html = html + "<embed type='application/x-mplayer2' src='"+src+"' id='id' name='name' showstatusbar='1' showcontrols='1' showdisplay='0' StretchToFit='1' AutoSize='1' autostart='1'  width='220' height='225' volume='100' Mute='1' ShowAudioControls='1' >";
		html = html + "</OBJECT>";
		
		if (document.getElementById('movieHolder')){
			document.getElementById('movieHolder').innerHTML = html;
		}
		
	}
}

function loadMovieInfo(){
	
	if(httpObject3.readyState == 4){
		if (document.getElementById('movieInfo')){
			document.getElementById('movieInfo').innerHTML = httpObject3.responseText;
		}
	}
}

function getPlaylistThumbs(index,dir){

	if (document.getElementById('podcastPlayListThumbs')){
		httpObjectPlayListThumbs = getHTTPObject();

		if (httpObjectPlayListThumbs != null) {
			httpObjectPlayListThumbs.open("GET", "/resources/podcasts/playlistthumbs.php?index="+index+"&dir="+dir);
			httpObjectPlayListThumbs.send(null);
			httpObjectPlayListThumbs.onreadystatechange = setOutputPlaylistThumbs;
		}
	}
	
}

function setOutputPlaylistThumbs(){
	if(httpObjectPlayListThumbs.readyState == 4){
		if (document.getElementById('podcastPlayListThumbs')){
			document.getElementById('podcastPlayListThumbs').innerHTML = httpObjectPlayListThumbs.responseText;
		}
	}
}

function getPlaylistThumbsTwoCol(index,dir){

	if (document.getElementById('podcastPlayListThumbsTwoCol')){
		httpObjectPlayListThumbsTwoCol = getHTTPObject();

		if (httpObjectPlayListThumbsTwoCol != null) {
			httpObjectPlayListThumbsTwoCol.open("GET", "/resources/podcasts/playlistthumbsTwoCol.php?index="+index+"&dir="+dir);
			httpObjectPlayListThumbsTwoCol.send(null);
			httpObjectPlayListThumbsTwoCol.onreadystatechange = setOutputPlaylistThumbsTwoCol;
		}
		
	}
	
}

function setOutputPlaylistThumbsTwoCol(){
	if(httpObjectPlayListThumbsTwoCol.readyState == 4){
		if (document.getElementById('podcastPlayListThumbsTwoCol')){
			document.getElementById('podcastPlayListThumbsTwoCol').innerHTML = httpObjectPlayListThumbsTwoCol.responseText;
		}
	}
}

function getPlaylistThumbsThreeCol(index,dir){
	if (document.getElementById('podcastPlayListThumbsThreeCol')){
		httpObjectPlayListThumbsThreeCol = getHTTPObject();

		if (httpObjectPlayListThumbsThreeCol != null) {
			httpObjectPlayListThumbsThreeCol.open("GET", "/resources/podcasts/playlistthumbsThreeCol.php?index="+index+"&dir="+dir);
			httpObjectPlayListThumbsThreeCol.send(null);
			httpObjectPlayListThumbsThreeCol.onreadystatechange = setOutputPlaylistThumbsThreeCol;
		}
	}
}

function setOutputPlaylistThumbsThreeCol(){
	if(httpObjectPlayListThumbsThreeCol.readyState == 4){
		if (document.getElementById('podcastPlayListThumbsThreeCol')){
			document.getElementById('podcastPlayListThumbsThreeCol').innerHTML = httpObjectPlayListThumbsThreeCol.responseText;
		}
	}
}
