/***************************************************************************/
/*******************   WMP Detection / Embed *******************************/
/***************************************************************************/

var detectionObject = new Object();

detectionObject.WMPVer = "unknown";       // Set to WMP version string detected
detectionObject.HasWMP = false;          // True if either WMP v6.4 or v7+ found
detectionObject.HasWMP64 = false;        // True if WMP v6.4 found
detectionObject.HasWMP7 = false;         // True if WMP v7+ (8, 9) found


detectionObject.output = function (text) {
	document.write(text);
}; 

detectionObject.GetBrowser =  function() {
   var agt=navigator.userAgent.toLowerCase();
   if( ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)) )
       this.browser =  "IE";
   else if( ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
         && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
         && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)) )
        this.browser = "Netscape";
   else
        this.browser = "unknown";
}


detectionObject.AddDownloadLink =  function(MajorVer){
 if (!(MajorVer) || MajorVer=="unknown" || parseInt(MajorVer)<9)  { 
	  this.ouput('You do not have the latest Windows Media Player version. Please click the button below to get it.<BR><A HREF="http://windowsmedia.com/download" target="_new"><IMG SRC="http://www.microsoft.com/windows/windowsmedia/images/Download_88x31_static.gif" WIDTH="88" HEIGHT="31" BORDER="0" ALT="Get Windows Media Player" VSPACE="7"></A>');
  } 
}

detectionObject.AddOKMessage =  function(MajorVer){
   this.output('You have Windows Media Player version ' + MajorVer);
}

detectionObject.isNSPluginInstalled =  function(){
  if (navigator.mimeTypes && 
      navigator.mimeTypes["application/x-mplayer2"] && 
      navigator.mimeTypes["application/x-mplayer2"].enabledPlugin)
  {
    return true;
  }  else  {
    return false;
  }
}

detectionObject.writeEmbedCode =  function(){

   if(typeof displaycontrols == "undefined") displaycontrols = "full";
   if(typeof inPage == "undefined") inPage = "false";
   if(typeof netscapeControls == "undefined") netscapeControls = 1;
   if(typeof netscapeStatus == "undefined") netscapeStatus = 1;

	html = '<object id="player" \n';
	html += ' width="' + mediaWidth + '" \n';
	html += ' height="' + mediaHeight + '" \n';
	//html += ' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=7,0,0,1954" \n';
	html += ' classid="CLSID:' + classid + '" \n';
	html += ' standby="Loading Windows Media Player components..." \n';
	html += ' type="application/x-oleobject">\n';
	html += ' <par' + 'am name="URL" value="' + mediaUrl + '">\n';
  html += ' <par' + 'am name="uiMode" value="' + displaycontrols + '">\n';
  html += ' <par' + 'am name="windowlessVideo" value="' + inPage + '">\n';
	html += ' <par' + 'am name="autoStart" value="true">\n'; 
	html += ' <par' + 'am name="enableContextMenu" value="false">\n'; 
	
	html += ' <embed id="player" \n';
	html += ' name="player" \n';
	html += ' src="' + mediaUrl + '" \n';
	html += ' type="application/x-mplayer2" \n';
	html += ' width="' + mediaWidth + '" \n';
	html += ' height="' + mediaHeight + '" \n';
	html += ' ShowControls="' + netscapeControls + '" \n';
	html += ' ShowStatusBar="' + netscapeStatus + '" \n';
	html += ' AutoSize="true" \n';
	html += ' EnableContextMenu="0" \n';
	html += ' DisplaySize="0" \n';
	html += ' pluginspage="http://www.microsoft.com/windows/windowsmedia/" \n';
	html += ' AutoStart="true">\n';
	html += ' </embed>\n'; 
	
	html += '</object>';
	document.write(html);
}


detectionObject.detect =  function () {
	this.GetBrowser();
	this.isNSPluginInstalled();
		
	if(this.browser == "IE"){
		if (WMP7.URL != undefined) {
			this.WMPVer = WMP7.versionInfo; // Has 7.0+ (e.g 8.x, 9.x)
			this.HasWMP = true;
		} else if( WMP64.FileName != undefined) {
			this.WMPVer="6.4";
			this.HasWMP = true;
		} else if (WMP7.URl == undefined){
			this.WMPVer=0;
			this.HasWMP=false;
		}
	}
	
	if (detectionObject.HasWMP) {
		var fullVersion  = this.WMPVer.toString();
		var versionString = this.WMPVer.toString().split(".");
		var majorVersion = versionString[0]; // Returns Windows Media Player major version #
		var minorVersion = versionString[1]; // Returns Windows Media Player minor version #
	} else {
		var fullVersion,versionString,majorVersion,minorVersion = null
	}
 

	if (this.browser=="IE" && parseInt(majorVersion)>=9)  {
		this.hasPlugin = true;
	}  else if (this.isNSPluginInstalled()) {
		this.hasPlugin = true;
	} else {
		this.hasPlugin = false;
	}		

	if (this.hasPlugin) {
		mediaHeight += 64;
		this.writeEmbedCode();
	}
	
}

detectionObject.getDetails = function () {
	var buff= "Full Version= " + fullVersion + "\n" + 
			"Major Version= " + majorVersion + "\n" + 
			"Minor Version= " + minorVersion + "\n" + 
			"Browser : " + detectionObject.browser + "\n>" + 
			"mozillaPlug : " +detectionObject.mozillaPlug + "\n";

	return buff;
};

detectionObject.onError = function () {
	alert('No Media');
};

/***************************************************************************/

