//---------------------------------------------------
// MediaPlayer Functions
//---------------------------------------------------

if (typeof(mediaplayer_width) == "undefined")		var mediaplayer_width=320;
if (typeof(mediaplayer_height) == "undefined")		var mediaplayer_height=309;
if (typeof(mediaplayer_file) == "undefined")		var mediaplayer_file='';
if (typeof(mediaplayer_type) == "undefined")		var mediaplayer_type='wmp';
if (typeof(mediaplayer_autostart) == "undefined")	var mediaplayer_autostart='1';

if (mediaplayer_autostart == "true") mediaplayer_autostart = 1;
if (mediaplayer_autostart == "false") mediaplayer_autostart = 0;

if(queryString('play') != 'false') mediaplayer_file = queryString('play');
if (mediaplayer_file != '') DrawMediaPlayer(mediaplayer_file,mediaplayer_type);

function DrawMediaPlayer(myfile,mytype) {
	var d=document;

	var myfileurl = "http://" + window.location.host;
	if (window.location.port != "" ) myfileurl += ":" + window.location.port;
	if (myfile.substr(0,1) != "/") myfileurl += "/";
	myfileurl += myfile;

	d.writeln("<div class='mediaplayer'>");
	var html="";
	if (mytype=="wmp") { // For Windows media player
		if (mediaplayer_width>0) {
			if (mediaplayer_width<320) {
				mediaplayer_height = mediaplayer_height*320/mediaplayer_width;
				mediaplayer_width = 320;
			}
		} else {
				mediaplayer_width = 320;
		}
		mediaplayer_height += 69; // add bottom control height
		if (navigator.appName == "Microsoft Internet Explorer") {
			html+="<object ID='wmpPlayer' WIDTH="+mediaplayer_width.toString()+" HEIGHT="+mediaplayer_height.toString()+"";
			//html+=" classid='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95'";
			html+=" classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'";
			html+=" codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112'";
			html+=" standby='Loading Microsoft Windows Media Player components...'";
			html+=" type='application/x-oleobject'>";
			//html+="<PARAM NAME='FileName' VALUE='"+myfileurl+"'>";
			html+="<PARAM NAME='URL' VALUE='"+myfileurl+"'>";
			html+="<PARAM NAME='autoStart' VALUE='"+mediaplayer_autostart+"'>";
			//html+="<PARAM NAME='ShowControls' VALUE='true'>";
			//html+="<PARAM NAME='ShowDisplay' VALUE='0'>";
			//html+="<PARAM NAME='ShowStatusBar' VALUE='true'>";
			html+="<PARAM NAME='uiMode' VALUE='full'>";
			html+="<PARAM NAME='stretchToFit' VALUE='true'>";
			html+="<PARAM NAME='windowlessVideo' VALUE='true'>";
			html+="</object>";
		} else {
			html+="<embed type='application/x-mplayer2'";
			html+=" pluginspage='http://www.microsoft.com/windows/windowsmedia/download/'";
			html+=" src='"+myfileurl+"'";
			html+=" Name='wmpPlayer'";
			html+=" autoStart='"+mediaplayer_autostart+"'";
			html+=" autoPlay='"+mediaplayer_autostart+"'";
			html+=" autosize='false'";
			html+=" ShowControls='true'";
			//html+=" ShowDisplay='0'";
			html+=" uiMode='full";
			html+=" ShowStatusBar='true'";
			html+=" stretchToFit='true'";
			html+=" windowlessVideo='true'";
			html+=" Controller='true'";
			html+=" loop='false'";
			html+=" WIDTH="+mediaplayer_width.toString()+" HEIGHT="+mediaplayer_height.toString()+"";
			html+="</embed>";
		}
	}
	if (mytype=="mov") { // For QuickTime player
		// <-- insert player code
	}
	d.writeln(html);
	d.writeln("<br><a href='"+myfile+"'>Click here to download the media</a>");
	d.writeln("</div>");

}

function DrawMediaPlayerDownload(mytype) {
	var d=document;

	if (mytype == '') {
		if (mediaplayer_file.indexOf(".wma")>0) mytype = "wmp";
		if (mediaplayer_file.indexOf(".wmv")>0) mytype = "wmp";
		if (mediaplayer_file.indexOf(".mov")>0) mytype = "mov";
	}

	d.writeln("<div class='mediaplayerdownload'>");
	var html="";
	if (mytype=="wmp") {
		html+="<table align='center' width=320 cellspacing=10 border=0><tr>";
		html+="<td>To view this video clip, you will require Windows Media Player</td>";
		html+="<td><a href='http://www.microsoft.com/windows/windowsmedia/download/' target='wmp'><img src='/img/get_wmp.gif' width=88 height=31 border=0 alt='Windows Media Player download'></a></td>";
		html+="</tr></table>";
	}
	if (mytype=="mov") {
		html+="<table align='center' width=320 cellspacing=10 border=0><tr>";
		html+="<td>To view this video clip, you will require QuickTime Player</td>";
		html+="<td><a href='http://www.quicktime.com/download/' target='mov'><img src='/img/get_mov.gif' width=88 height=31 border=0 alt='QuickTime download'></a></td>";
		html+="</tr></table>";
	}
	d.writeln(html);
	d.writeln("</div>");

}

function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
			return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }
}

function queryString(key){
	var page = new PageQuery(window.location.search);
	return unescape(page.getValue(key));
}
