

mediaObject = function(swfURL, swfWidth, swfHeight, bgColor, viewOption, autoStart){

this.swfURL= swfURL;
this.swfWidth=swfWidth;
this.swfHeight=swfHeight;
this.bgColor = bgColor;
this.init = false;
this.viewOption = viewOption;
this.autoStart = autoStart;
};



mediaObject.prototype.setPopupOptions = function(wName, popOptions, popupPath){
	this.wName=wName;
	this.popOptions=popOptions;
	this.popupPath=popupPath;
}

mediaObject.prototype.setFeeds = function(playlistsXML, releaseXML){
	this.playlistsXML=playlistsXML;
	this.releaseXML=releaseXML;
	
}

mediaObject.prototype.setLinks = function(browseURL, displayURL){
	this.browseURL=browseURL;
	this.displayURL=displayURL;
	
}


mediaObject.prototype.playMedia = function(trackName){
	if(this.viewOption == "popup"){
	// show popup	
	
		window.open(this.popupPath+"?trackName="+trackName+"&playlistName="+playlistName+"&swfURL="+this.swfURL+"&playlistsXML="+this.playlistsXML+"&releaseXML="+this.releaseXML+"&swfWidth="+this.swfWidth+"&swfHeight="+this.swfHeight+"&bgColor="+this.bgColor+"&wName="+this.wName, this.wName, this.popOptions);
		//alert(this.swfURL);
			
	} else if(this.viewOption == "hidden"){
		
		// check if new track and set button states
		
		//alert("want to play hidden "+trackName);
		
		if (trackName == this.currentUrlName) {
			
			//alert("trying to stop");
			
			this.stopPodcast();

	} else {
		this.currentUrlName = trackName;
		
		//alert("should play hidden "+trackName);

		var newdiv = document.createElement('div');
		newdiv.setAttribute('id', "hiddenPlayer");
		document.body.appendChild(newdiv);
		//
		
		var so = new SWFObject(this.swfURL, this.wName+"_swf", "0", "0", "9.0.47", this.bgColor, false);
			
			
			so.addVariable("playlistsXML", this.playlistsXML);
			so.addVariable("releaseXML", this.releaseXML);
			so.addVariable("trackName", trackName);
			//so.addVariable("playlistName", playlistName);
			so.addVariable("hidden", "true");
			so.addParam("allowScriptAccess", "always");
		//	so.useExpressInstall('http://cdn.sparkart.net/crissangel/flash/expressinstall.swf');
			so.write("hiddenPlayer");
			
			this.setPlayState();
			
			
	}
			
		
	} else {
		
		
		//if(this.init == false){
	// embed in div
			
			this.init = true;
			var so = new SWFObject(this.swfURL, this.wName+"_swf", this.swfWidth, this.swfHeight, "9.0.47", this.bgColor, true);
			so.useExpressInstall('http://cdn.sparkart.net/crissangel/flash/expressinstall.swf');
			so.addVariable("playlistsXML", this.playlistsXML);
			so.addVariable("releaseXML", this.releaseXML);
			so.addVariable("trackName", trackName);
			//so.addVariable("playlistName", playlistName);
			so.addVariable("browseURL", this.browseURL);
			so.addVariable("displayURL", this.displayURL);
			so.addVariable("autoStart", this.autoStart);
			so.addParam("allowScriptAccess", "always");
			so.addParam("wmode", "transparent");
			so.write(this.viewOption);
			
		//} else {
		//	alert("already embedded");
			// swf already up... just change song and playlist
		//	listen(trackName, playlistName);
		//}
		
		
		
	}
}


mediaObject.prototype.playURL = function(mediaURL,mediaTitle,mediaInfo){
	//alert("should play1 "+mediaURL);
	if(this.viewOption == "popup"){
		//alert(mediaURL+" : "+mediaTitle+" : "+mediaInfo);
		window.open(this.popupPath+"?mediaURL="+mediaURL+"&mediaTitle="+mediaTitle+"&mediaInfo="+mediaInfo+"&swfURL="+this.swfURL+"&swfWidth="+this.swfWidth+"&swfHeight="+this.swfHeight+"&bgColor="+this.bgColor+"&wName="+this.wName, this.wName, this.popOptions);
	} else {
	//	alert("should play "+mediaURL);
		var newdiv = document.createElement('div');
		newdiv.setAttribute('id', "hiddenPlayer");
		document.body.appendChild(newdiv);
		//
		var so = new SWFObject(this.swfURL, this.wName+"_swf", "0", "0", "9.0.47", this.bgColor, false);
		//so.useExpressInstall('expressinstall.swf');
		so.addVariable("mediaPath", mediaURL);
		so.addVariable("hidden", "true");
		so.addParam("allowScriptAccess", "always");
		so.write("hiddenPlayer");
	}
	
}



//



mediaObject.prototype.setPlayState = function(){
	
	//alert("should set states");
	
		this.resetPodcastList();

		var elementList = $$('.listen');
		for (i=0; i<elementList.length; i++) {

			if (elementList[i].toString().indexOf(this.currentUrlName) != -1) {
				elementList[i].className = "action stop";
				elementList[i].innerHTML = "Stop";
				break;
			}
		}
	}

mediaObject.prototype.resetPodcastList = function(){
	var elementList = $$('.stop');
	for (i=0; i<elementList.length; i++) {
		elementList[i].className = "action listen";
		elementList[i].innerHTML = "Listen";
	}
}
mediaObject.prototype.stopPodcast = function(){
	
	//alert("should stop");
	
	this.currentUrlName = "";
	this.resetPodcastList();
	// remove audio div
	$('hiddenPlayer').remove();
}






