/**** MPlayer Class Definition ****/
// Constructor
function MPlayer(){
	var o = (arguments.length>-1 && typeof arguments[0]=="object") ? arguments[0] : null;
	this.inPlyr = (o!=null && o["nested"]) ? o["nested"] : false;
	this.tpl = (o!=null && o["template"]) ? o["template"] : "";
	this.name = (o!=null && o["name"]) ? o["name"] : "";
	this.width = (o!=null && o["width"]) ? o["width"] : 100;
	this.height = (o!=null && o["height"]) ? o["height"] : 100;
	this.url = "";
	this.config = null;
}
// Set the template url used in media player
MPlayer.prototype.setTemplate = function(){this.tpl = arguments[0];}
// Set the window name used for media player
MPlayer.prototype.setName = function(){this.name = arguments[0];}
// Set the height & width for media player window
MPlayer.prototype.setSize = function(){this.width = arguments[0];this.height = arguments[1];}
// Set the template url used to launch player
MPlayer.prototype.setTemplateUrl = function(){
	var o = arguments[0], q = "", d = "";
	for(var key in o){
		d = (q=="") ? "" : "&";
		q += d + key + "=" + escape(o[key]);
	}
	if(this.tpl.indexOf("?")>-1) this.url = this.tpl + "&" + q;
	else this.url = this.tpl + "?" + q;
	this.config = o;
}
// Play media clip
MPlayer.prototype.play = function(){
	var args = arguments;
	var status = MPlayer.preLaunch(args[0]);
	if(status==true){
		if(this.inPlyr){ MPlayer.sendConfigMsg(args[0]); }
		else{ this.launch(args[0]); }
	}
}
// launch the player window
MPlayer.prototype.launch = function(){
	this.setTemplateUrl( arguments[0] );
	MPlayer.openWin(this.name, this.url, this.width, this.height);
}
/**** MPlayer Static Methods ****/
// Open media player window
MPlayer.openWin = function(n,url,w,h) {
	if (w>screen.availWidth-12) w=screen.availWidth-12;
	if (h>screen.availHeight-48) h=screen.availHeight-48;
	_pw_l=(screen.availWidth-w-12)/2;
	_pw_t=(screen.availHeight-h-48)/2;
	_pw_z=window.open(url,n,'width='+w+',height='+h+',left='+_pw_l+',top='+_pw_t);
}
// Send media config settings to template
MPlayer.sendConfigMsg = function(){
	if(window.top.MPlayer.setConfig){
		window.top.MPlayer.setConfig( arguments[0] );
	}
}
// Override function in media player template
MPlayer.setConfig = function(){}
// Override function in media player template
// Used to process data before player launch
MPlayer.preLaunch = function(){ return true; }
// Get the config msg and return as object
MPlayer.getConfigMsg = function(){
	var q = document.location.search;
	if(q!=""){
		q=(q.substring(1)).split("&");
		var p={};
		for(var x=0;x<q.length;x++){
			var tmp=q[x].split("=");
			switch(typeof p[tmp[0]]){
				case "undefined": p[tmp[0]]=tmp[1]; break;
				case "string": var _tmp=p[tmp[0]]; p[tmp[0]]=[_tmp,tmp[1]]; break;
				case "object": var _tmp=p[tmp[0]].length; p[tmp[0]][_tmp]=tmp[1]; break;
			}
		}
		return p;
	}
	else return null;
}
// Get media player html code
MPlayer.getPlayer = function( name, murl, mtype , mwidth, mheight ){
	var plyr_tpl = (mtype!=null && mtype!="" && MPlayer[mtype]) ? MPlayer[mtype] : "";
	plyr_tpl = plyr_tpl.replace(/\[NAME\]/g, name);
	plyr_tpl = plyr_tpl.replace(/\[URL\]/g, murl);
	plyr_tpl = plyr_tpl.replace(/\[HEIGHT\]/g, mheight);
	plyr_tpl = plyr_tpl.replace(/\[WIDTH\]/g, mwidth);
	return plyr_tpl;
}
/**** MPlayer Constants ****/
MPlayer.w = "<object id='[NAME]' name='[NAME]' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' src='[URL]' width='[WIDTH]' height='[HEIGHT]'><param name='autoStart' value='true'>" +
	"<param name='uiMode' value='full'><param name='animationAtStart' value='0'><param name='transparentAtStart' value='true'><param name='url' value='[URL]'>" +
	"<param name='stretchToFit' value='true'><param name='showStatusBar' value='1'><param name='showTracker' value='1'><param name='showDisplay' value='false'>" +
	"<embed type='application/x-mplayer2' pluginspage='http://www.microsoft.com/Windows/MediaPlayer/' src='[URL]' name='[NAME]' id='mplayer' width='[WIDTH]' " +
	"height='[HEIGHT]' autostart='1'  animationatstart='0' transparentatstart='1' showstatusbar='1' showdisplay='0' showtracker='1' showcontrols='1' swliveconnect='0' nojava='1'></embed></object>";
MPlayer.r = "<object id='[NAME]' name='[NAME]' classid='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' width='[WIDTH]' height='[HEIGHT]'>" +
	"<param name='CONTROLS' value='imagewindow'/><param name='AUTOGOTOURL' value='false'/><param name='CENTER' value='true'/>" +
	"<param name='AUTOSTART' value='true'/><param name='CONSOLE' value='cstv'/><param name='NOLOGO' value='true'/><param name='SRC' value='[URL]'>" +
	"<embed name='[NAME]' id='[NAME]' type='audio/x-pn-realaudio-plugin' src='[URL]' height='[HEIGHT]' width='[WIDTH]' " +
	"controls='imagewindow' autogotourl='false' center='true' autostart='true' console='cstv' nologo='1' /></object>" +
	"<object id='realPlayerControl' classid='clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA' width='[WIDTH]' height='30'>" +
	"<param name='CONTROLS' value='ControlPanel'><param name='CONSOLE' value='cstv'>" +
	"<embed name='realPlayerControl' type='audio/x-pn-realaudio-plugin' height='30' " +
	"width='319' controls='controlpanel' console='cstv' autogotourl='false' src='[URL]' /></object>";