/*
 * WindowsMediaPlayer
 * copyright 2005 Axisto Media Ltd. All rights reserved.
 * by Andreas Rimbe, Axisto Media Ltd (andreas.rimbe@axisto.com, http://www.axisto.com/)
 *
 * v1.5 - 06-05-2005
 *
 * Creates a windows media player object
 *
 * Usage:
 *
 *	wmp = new FlashObject("divWhereCreateMP", width, height);
 *	wmp.setUrl("");
 *
 */
 
function OnDSScriptCommandEvt(bstrType, bstrParam)
{
    //alert(bstrType);
}
function mp_OnDSScriptCommandEvt(bstrType, bstrParam)
{
    //alert(bstrType);
}

WindowsMediaPlayer = function(divId, id, width, height, version)
{
	this.id = id ? id : "mp";
	this.divId = divId ? divId : "videoph1";
	this.audioOnlyImageId = 'audioonly';

	this.autoStart = true;
	this._wmp64PreRollTime = 0;
	this.currentPosition = 0;
	this.duration = 0;
	this.isSeeking = false;
	this.bufferProgress = 0;
	this.bufferingTime = 3000;
	this.bufferingTimeExtended = 15000;
	this.eventTimer = null;
	this.eventUpdateInterval = 500;
	this.isNSPlugin = false;			// NS<5 and WMP 6.4
	this.isNSApplet = false;			// NS > 6 and WMP v9+
	this.isWMP64 = false;
	this.playState = 0;
	this.useCallbacks = true;
	this.width = width ? width : 320;
	this.height = height ? height : 240;
	this.videoWidth = this.width;
	this.videoHeight = this.height;
	this.origHeight = this.height;
	this.uiMode = "";
	this.volume = 70;

	//do detection
	this.mpInfo = detectWMP();
	//alert(navigator.userAgent);
	//alert("wm info versionInfo:"+this.mpInfo.versionInfo+" type:"+this.mpInfo.type);
	if(this.mpInfo.installed)
	{
		if(requireScriptableMedia && !this.mpInfo.scriptable)
		{
		    var isNS = navigator.userAgent.indexOf("Navigator/") > -1 ? 1 : 0;
		    var yes = false;
		    if(isFF && isNS < 1)
		    {
		        
		        if(isWinXPAndNewer())
		        {
		            yes = confirm("You need to update your media player plugin to watch this webcast.\n\nWould you like to download Microsoft Windows Media Player Firefox Plugin?\n\n");
		            if(yes)
		            {
		                window.location.href = "http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx";
		            }
		        }
		        else
		        {
		            yes = confirm("You need to update your media player plugin to watch this webcast.\n\nWould you like to install the AxtiveX plugin for Firefox?\n\n");
		            if(yes)
		            {
		                window.location.href = "http://forums.mozillazine.org/viewtopic.php?t=206213";
		            }
		        }
		    }
		    else
		    {
		        this.mpInfo.installed = true;
		        this.mpInfo.scriptable = true;
		        this.mpInfo.type = "Plugin";
		    }
		}
	}
	else
	{
		//force embedding of object, let browser take care of it
		this.mpInfo.installed = true;
		this.mpInfo.scriptable = true;
		this.mpInfo.type = "Plugin";
	}
}
WindowsMediaPlayer.prototype.write = function()
{
	if(this.mpInfo.installed)
	{
		var s = this.createHtml();
		writeLayer(this.divId, null, s);
		
		if(navigator.appName == "Netscape" && !isFF) 
		{
            try
            {
                this.mp = document[this.id];
                this.mp = this.mp != null ? this.mp : $(this.id);
                document.appObs.setByProxyDSScriptCommandObserver(this.mp,true); 
            }
            catch(ex)
            {
            
            }   
        }
        else
        {
            this.mp = $(this.id);
            if(!this.mp)
            {
                this.mp = document.getElementsByName(this.id)[0];
            }
        }
		
		Event.observe(this.mp, 'scriptCommand', function(){alert("script command");}, false);
		
		if(this.useCallbacks && this.eventTimer == null)
		{
			this.eventTimer = new PeriodicalExecuter(this.checkState.bindAsEventListener(this), 0.25);
			this.eventTimer.start();
		}
	}
}
WindowsMediaPlayer.prototype.destroy = function()
{
	if(this.eventTimer != null)
	{
		this.eventTimer.stop();
	}
	this.mp = $(this.id);

	if(isIE && this.mp != null)
	{
		this.stop();
		var p = $(this.divId);
		try
		{
			p.removeChild(this.mp);
		}
		catch(e)
		{
		}
		this.mp = null;
	}
	else
	{
		this.mp = null;
	}
}
WindowsMediaPlayer.prototype.createHtml = function()
{
	var strWMP = "";
    var w = this.width;
    var h = this.height;
    
    if(this.uiMode == "invisible")
    {
        w = 1;
        h = 1;
    }
    
    if(this.mpInfo.versionInfo < 7)
    {
        if(this.mpInfo.type == "ActiveX")
	    {
	        this.isWMP64 = true;
			strWMP = '<object id="'+this.id+'" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95"';
			strWMP += ' width="'+w+'" height="'+h+'"';
			strWMP += '	STANDBY="Loading Windows Media Player components..."';
			strWMP += '	TYPE="application/x-oleobject" VIEWASTEXT>';
			strWMP += '<param name="AutoStart" value="'+this.autoStart.toString()+'">';
			strWMP += '<param name="AutoSize" value="1">';
			strWMP += '<param name="DisplaySize" value="0">';

			if(this.uiMode == "full" || this.uiMode == "audio")
			{
				strWMP += '<param name="ShowControls" value="1">';
				strWMP += '<param name="ShowStatusBar" value="1">';
			}
			else
			{
				strWMP += '<param name="ShowControls" value="0">';
				strWMP += '<param name="ShowStatusBar" value="0">';
			}
			
			if(this.currentPosition > 0)
			{
				strWMP += '<param name="CurrentPosition" value="' + this.currentPosition + '">';
			}
			strWMP += '<param name="Volume" value="-300">';
			strWMP += '</object>';
	    }
	    else
	    {
	        this.isNSPlugin = true;
	        strWMP = '<object id="'+this.id+'" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://www.microsoft.com/Windows/MediaPlayer/"';
			strWMP += ' standby="Loading Microsoft® Windows® Media Player components..."';
			strWMP += ' width="'+w+'" height="'+h+'"';
			strWMP += ' type="application/x-oleobject" align="middle">';
			
			//params
			strWMP += ' <param name="AutoStart" value="'+this.autoStart.toString()+'" />';
			strWMP += ' <param name="AutoSize" value="1" />';
			if(this.currentPosition > 0)
			{
				strWMP += ' <param name="CurrentPosition" value="'+this.currentPosition+'" />';
			}
			strWMP += ' <param name="DisplaySize" value="0" />';
			strWMP += ' <param name="FileName" value="'+this.url+'" />';
			if(this.uiMode == "full" || this.uiMode == "audio")
			{
				strWMP += ' <param name="ShowControls" value="1" />';
				strWMP += ' <param name="ShowStatusBar" value="1" />';
			}
			else
			{
				strWMP += ' <param name="ShowControls" value="0" />';
				strWMP += ' <param name="ShowStatusBar" value="0" />';
			}
			strWMP += ' <param name="Volume" value="-300">';
            
            //embed
            strWMP += ' <embed type="application/x-mplayer2" pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/"';
            strWMP += ' name="'+this.id+'"';
            strWMP += ' src="'+this.url+'"';
            strWMP += ' width="'+w+'" height="'+h+'"';
            strWMP += ' autostart="'+this.autoStart.toString()+'"';
            strWMP += ' autosize="1"';
            if(this.currentPosition > 0)
			{
				strWMP += ' currentposition="'+this.currentPosition+'"';
			}
            strWMP += ' displaysize="0"';
            if(this.uiMode == "full" || this.uiMode == "audio")
			{
				strWMP += ' showcontrols="1" showstatusbar="1"';
			}
			else
			{
				strWMP += ' showcontrols="0" showstatusbar="0"';
			}
			
            strWMP += ' volume="-300"';
            strWMP += '>';
            strWMP += '</embed>';
            
            strWMP += '</object>';
            
            //applet to receive events
            if (isNS47 && !isFF)
            {
                navigator.plugins.refresh();
                //strWMP += '<applet MAYSCRIPT Code="NPDS.npDSEvtObsProxy.class" archive="wmpns.jar" width="1" height="1" name="appObs" ></applet>';
                strWMP += '<applet code="WMPNS.WMP.class" archive="wmpns.jar" name="WMP" width="1" height="1" MAYSCRIPT></applet>';
            }
	    }
    }
    else
    {
        //WMP7+
        if(this.mpInfo.type == "ActiveX" || this.mpInfo.type == "GekkoActiveX" || this.mpInfo.type == "GekkoPlugin")
	    {
			//alert("wm info versionInfo:"+this.mpInfo.versionInfo+" type:"+this.mpInfo.type);
			if(this.mpInfo.type == "ActiveX" || this.mpInfo.type == "GekkoActiveX")
			{
			    strWMP = '<object id="'+this.id+'" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"';
			    strWMP += ' width="'+w+'" height="'+h+'">';
			}
			else if(this.mpInfo.type == "GekkoPlugin")
			{
			    strWMP = '<object id="'+this.id+'" type="application/x-ms-wmp"';
                if(this.url != null)
                {
	                strWMP += ' data="'+this.url+'"';
                }
                strWMP += ' width="'+w+'" height="'+h+'">';
			}
			
			//parameters
			strWMP += '<param name="autostart" value="'+this.autoStart.toString()+'" />';
			if(this.currentPosition > 0)
			{
				strWMP += '<param name="currentposition" value="' + this.currentPosition + '">';
			}
			//strWMP += '<param name="stretchtofit" value="true" />';
			if(this.uiMode != "audio")
			{
				strWMP += '<param name="uimode" value="'+this.uiMode+'" />';
			}
			if(this.url != null)
			{
				strWMP += '<param name="url" value="'+this.url+'" />';
			}
			strWMP += '<param name="volume" value="' + this.volume + '" />';
			strWMP += '</object>';
	    }
	    else
	    {
	        this.isNSApplet = true;
	        this.setUIMode('full');
	        this.height = h + 65;
	        h = this.height;
	        
	        var pc = $('play-controls');
	        if(pc) pc.style.display = 'none';
	        
            strWMP = '<object id="'+this.id+'" type="application/x-mplayer2" data="'+this.url+'"';
			strWMP += ' width="'+w+'" height="'+h+'">';
			
			//params
			strWMP += ' <param name="AutoStart" value="'+this.autoStart.toString()+'" />';
			strWMP += ' <param name="AutoSize" value="1" />';
			if(this.currentPosition > 0)
			{
				strWMP += ' <param name="CurrentPosition" value="'+this.currentPosition+'" />';
			}
			strWMP += ' <param name="DisplaySize" value="0" />';
			strWMP += ' <param name="FileName" value="'+this.url+'" />';
			if(this.uiMode == "full" || this.uiMode == "audio")
			{
				strWMP += ' <param name="ShowControls" value="1" />';
				strWMP += ' <param name="ShowStatusBar" value="1" />';
			}
			else
			{
				strWMP += ' <param name="ShowControls" value="0" />';
				strWMP += ' <param name="ShowStatusBar" value="0" />';
			}
			strWMP += ' <param name="Volume" value="-300">';
			strWMP += '</object>';
   	    }
    }
  
	return strWMP;
}
WindowsMediaPlayer.prototype.checkState = function()
{
	if(this.isNSApplet)
	{
	    this.eventTimer.stop();
	    return;
	}
	
	var x = this.getPlayState();
	if(x != null && (x == 6 || x != this.playState))
	{
		this.playState = x;
		
		//dynamic buffering
		var buffTime = this.getBufferingTime();
		buffTime = (typeof(buffTime) == "number")?buffTime:this.bufferingTime;
		
		var sourceProtocol = this.getSourceProtocol();
		if(sourceProtocol == "cache" && buffTime != 1000)
		{
		    this.setBufferingTime(1000);
		}
		else
		{
		    if(this.playState == 3 && buffTime != this.bufferingTimeExtended)
		    {
		        this.setBufferingTime(this.bufferingTimeExtended);
		    }
		    else if(this.playState != 3 && buffTime != this.bufferingTime)
		    {
		        this.setBufferingTime(this.bufferingTime);
		    }
		}
		
		if(this.playStateChange != null)
		{
			this.playStateChange(this.playState);
		}
	}
	
	var y = this.getPosition();
	if(y != null && y > 0)
	{
	    if(y > 0)
	    {
	        if(this.isSeeking)
	        {
	            if(Math.abs(y-this.currentPosition) < 2)
	            {
	                this.isSeeking = false;
    	            this.currentPosition = y;
	            } 
	        }
	        else if(y != this.currentPosition)
	        {
		        this.currentPosition = y;
	        }
	        
	        if(this.duration > 0)
	        {
	            if(Math.abs(this.duration-this.currentPosition) < 1)
	            {
	                //end of stream
	                if(this.playStateChange != null)
		            {
			            this.playStateChange(5);
		            }
	            }    
	        }
    	    
	        if(this.positionChange != null)
            {
                this.positionChange(this.currentPosition);
            }   
	    }
	}
}
WindowsMediaPlayer.prototype.getSourceProtocol = function()
{
    var x;
    try
	{
		if(this.isNSPlugin)
		{
 			x = this.mp.GetSourceProtocol();
		}
		else if (this.isWMP64)
		{
			x = this.mp.SourceProtocol;
		}
		else
		{
			if(this.isNSApplet)
			{
				x = this.mp.getNetwork().getSourceProtocol();
			}
			else
			{
				x = this.mp.network.sourceProtocol;
			}
		}
	}
	catch(e)
	{
	}
	
	x = x!=null?x:"http";
	return x.toLowerCase();
}
WindowsMediaPlayer.prototype.getBufferingTime = function()
{
    var x = 0;
	try
	{
		if(this.isNSPlugin)
		{
 			x = this.mp.GetBufferingTime();
		}
		else if (this.isWMP64)
		{
			x = this.mp.BufferingTime;
		}
		else
		{
			if(this.isNSApplet)
			{
				x = this.mp.getNetwork().getBufferingTime();
			}
			else
			{
				x = this.mp.network.bufferingTime;
			}
		}
	}
	catch(e)
	{
	}
	
	return x;
}
WindowsMediaPlayer.prototype.setBufferingTime = function(ms)
{
	try
	{
		if(this.isNSPlugin)
		{
 			this.mp.SetBufferingTime(ms);
		}
		else if (this.isWMP64)
		{
			this.mp.BufferingTime = ms;
		}
		else
		{
			if(this.isNSApplet)
			{
				this.mp.getNetwork().setBufferingTime(ms);
			}
			else
			{
				this.mp.network.bufferingTime = ms;
			}
		}
	}
	catch(e)
	{
	}
}
WindowsMediaPlayer.prototype.getDuration = function()
{
	var x = 0;
	try
	{
		if(this.isNSPlugin)
		{
 			x = this.mp.GetDuration()+1;
		}
		else if (this.isWMP64)
		{
			x = this.mp.Duration+1;
		}
		else
		{
			if(this.isNSApplet)
			{
				x = this.mp.getCurrentMedia().getDuration();
			}
			else
			{
				x = this.mp.currentMedia.duration;
			}
		}
	}
	catch(e)
	{
	}
	
	this.duration = x;
	return this.duration;
}
WindowsMediaPlayer.prototype.getPlayState = function()
{
	var ps = 0;
	try
	{
		if(this.isWMP64 || this.isNSPlugin)
		{
 			if(this.isNSPlugin)
 			{
	 			ps = this.mp.GetPlayState()+1;
			}
			else if (this.isWMP64)
			{
				ps = this.mp.PlayState+1;
			}
 			if(ps == 4)
 			{
 				//check buffering
	 			ps = 6;
	 			var x = this.getBufferingProgress();
	 			if(x != 0 && x <= 100 && x != this.bufferProgress)
	 			{
	 				this.bufferProgress = x;
	 			}
 			}
		}
		else
		{
			if(this.isNSApplet)
			{
			   ps = this.mp.GetPlayState();
			}
			else
			{
			    ps = this.mp.playState;
			}
			
			if(ps == 6)
			{
				this.bufferProgress = this.getBufferingProgress();
			}
		}
	}
	catch(e)
	{
	}
	return ps;
}
// CurrentPosition
WindowsMediaPlayer.prototype.getPosition = function()
{
	var pos = -1;
	try
	{
		if(this.isNSPlugin)
		{
 			pos =  this.mp.GetCurrentPosition();
		}
		else if (this.isWMP64)
		{
			pos = this.mp.CurrentPosition;
		}
		else
		{
			// If using v7+ interface set through applet's setXXX routine or
			// by setting property directly
			if(this.isNSApplet)
			{
				pos = this.mp.getControls().getCurrentPosition();
			}
			else
			{
				pos = this.mp.controls.currentPosition;
			}
		}
	}
	catch(e)
	{
	}
	return pos;
}
WindowsMediaPlayer.prototype.setPosition = function(time)
{
    //alert('setPosition: '+time);
	try
	{
		this.isSeeking = true;
		this.currentPosition = time;
		if(this.isNSPlugin)
		{
 			if(this.mp.GetPlayState() == 0 || this.mp.GetPlayState() == 1 || this.mp.GetPlayState() == 2)
 			{
				if(time-this._wmp64PreRollTime>=0)
				{
 					time -= this._wmp64PreRollTime;
 				}
 				if(this.mp.GetCurrentPosition() != time)
 				{
 					this.mp.SetCurrentPosition(time);
 				}
 			}
 			else
 			{
				this.currentPosition = time;
				return;
			}
		}
		else if (this.isWMP64)
		{
			if(this.mp.PlayState == 0 || this.mp.PlayState == 1 || this.mp.PlayState == 2)
			{
				if(time-this._wmp64PreRollTime>=0)
				{
 					time -= this._wmp64PreRollTime;
 				}
				if(this.mp.CurrentPosition != time)
				{
					this.mp.CurrentPosition = time;
				}
			}
			else
			{
				this.currentPosition = time;
			}
		}
		else
		{
			// If using v7+ interface set through applet's setXXX routine or
			// by setting property directly
			if(this.isNSApplet)
			{
				if(this.mp.getControls().isAvailable('currentPosition'))
				{
					this.mp.getControls().setCurrentPosition(time);
				}
				else
				{
					this.currentPosition = time;
				}
			}
			else
			{
				if(this.mp.controls.isAvailable('currentPosition'))
				{
					this.mp.controls.currentPosition = time;
				}
				else
				{
					this.currentPosition = time;
				}
			}
		}
	}
	catch(e)
	{
	    this.isSeeking = false;
	}
}
WindowsMediaPlayer.prototype.setZoom = function(p)
{
	var w = this.videoWidth*(p/100.0);
	w = w>0?w:1;
	var h = this.videoHeight*(p/100.0);
	h = h>0?h:1;
	
	if(this.uiMode != "invisible")
	{
	    var stretchToFit = true;
	    try
	    {
	        if(this.isNSPlugin)
	        {
		        this.mp.SetAutoSize(!stretchToFit);
	        }
	        else if (this.isWMP64)
	        {
		        this.mp.AutoSize = !stretchToFit;
	        }
	        else
	        {
		        if(this.isNSApplet)
		        {
			        this.mp.setStretchToFit(stretchToFit);
		        }
		        else
		        {
			        this.mp.stretchToFit = stretchToFit;
		        }
	        }
	    }
	    catch(ex){}
    	
    	
	    this.setSize(w, h);
	}
	
	//hide audioonly image
	var img = $(this.audioOnlyImageId);
	if(p == 0 && img != null)
	{
		img.style.display = 'none';
		//alert("hide image" + img);
	}
	else if(img != null && (this.uiMode == "audio" || this.uiMode == "invisible" || showAudioImage))
	{
		img.style.display = 'block';
		//alert("show image" + img);
	}
}
WindowsMediaPlayer.prototype.setSize = function(w, h)
{
	if(this.mp != null && w > 0 && h > 0)
	{
	    this.width = w;
	    this.height = h;
	    
	    if(this.uiMode == "audio" || this.uiMode == "full")
	    {
	        h += 70;
	    }
	    
		if(document.all && !document.getElementById)
		{
			document.all[this.id].style.pixelWidth = w;
			document.all[this.id].style.pixelHeight = h;
		}
		else
		{
			document.getElementById(this.id).style.width = w+"px";
			document.getElementById(this.id).style.height = h+"px";
		}
	}
	else
	{
		this.height = 1;
		this.width = 1;
	}
}
WindowsMediaPlayer.prototype.setUIMode = function(mode)
{
	if(this.uiMode != mode)
	{
		this.uiMode = mode;
		switch(mode)
		{
			case "audio":
			{
				if(this.isWMP64)
				{
					this.height = 70;
				}
				else
				{
					this.height = 63;
				}
				break;
			}
			case "none":
			{
				this.height = this.origHeight;
				break;
			}
			case "full":
			{
				if(this.isWMP64)
				{
					this.height = this.origHeight+70;
				}
				else
				{
					this.height = this.origHeight+65;
				}
				break;
			}
			case "invisible":
			{
				this.setZoom(0);
				break;
			}
		}
		if(this.mp != null)
		{
			this.setSize(this.width, this.height);
		}
		
		var img = $(this.audioOnlyImageId);
		if(img != null)
		{
			if((mode == "audio" || mode == "invisible" || showAudioImage) && img.src != "")
			{
				img.style.display = 'block';
				img.style.visibility = 'visible';
			}
			else
			{
				img.style.display = 'none';
				img.style.visibility = 'hidden';
			}
		}
		//audio - show image and controls
		//none - video window only
		//full - with controls
		//invisible
	}
}
WindowsMediaPlayer.prototype.setImage = function(url, alt)
{
	var img = $("audioonly-image");
	if(img != null && url != null && url != "")
	{
		//alert(url + this.uiMode);
		img.src = url;
		if(alt != null && alt != "")
		{
		    img.setAttribute('alt', "Image of " + alt);
		    img.setAttribute('title', alt);
		}
		if(this.uiMode == "audio" || this.uiMode  == "invisible")
		{
			img.style.display = 'block';
		}
	}	
}
// URL
WindowsMediaPlayer.prototype.setUrl = function(url)
{
	this.url = url;
	if(this.mp != null)
	{
		try
		{
			if(this.isNSPlugin)
			{
 				this.mp.SetFileName(url);
			}
			else if (this.isWMP64)
			{
				this.mp.FileName = url;
			}
			else
			{
				// If using v7+ interface set through applet's setXXX routine or
				// by setting property directly
				if(this.isNSApplet)
				{
					this.mp.setURL(url);
				}
				else
				{
					this.mp.URL = url;
				}
			}
		}
		catch(e)
		{
		}
	}
}
// Volume
WindowsMediaPlayer.prototype.getVolume = function()
{
	var vol = -1;
	try
	{
		if(this.isNSPlugin)
		{
 			vol = this.mp.GetVolume();
		}
		else if (this.isWMP64)
		{
			vol = this.mp.Volume;
		}
		else
		{
			// If using v7+ interface set through applet's setXXX routine or
			// by setting property directly
			if(this.isNSApplet)
			{
				vol = this.mp.getSettings().getVolume();
			}
			else
			{
				vol = this.mp.settings.volume;
			}
		}
	}
	catch(e)
	{
	}
	return vol;
}
WindowsMediaPlayer.prototype.setVolume = function(level)
{
	try
	{
		if(level > 0 && level <= 100 && level != "")
		{
			var mp64Level = (parseInt(level) > 40) ? 25*(parseInt(level))-2500 : (100*(parseInt(level))-6000);
			if(parseInt(level) == 0)
			{
				mp64Level = -10000;
			}
			if(mp64Level > 0)
			{
				mp64Level = 0;
			}
			if(this.isNSPlugin)
			{
 				this.mp.SetVolume(mp64Level);
			}
			else if (this.isWMP64)
			{
				this.mp.Volume = mp64Level;
			}
			else
			{
				// If using v7+ interface set through applet's setXXX routine or
				// by setting property directly
				if(this.isNSApplet)
				{
					this.mp.getSettings().setVolume(level);
				}
				else
				{
					this.mp.settings.volume = level;
				}
			}
		}
	}
	catch(e)
	{
	}
}
WindowsMediaPlayer.prototype.getErrorDescription = function(){
	var desc = "";
	if(this.isNSPlugin)
	{
 		desc = this.mp.GetErrorDescription();
	}
	else if (this.isWMP64)
	{
		desc = this.mp.ErrorDescription;
	}
	else
	{
		// If using v7+ interface set through applet's setXXX routine or
		// by setting property directly
		if(this.isNSApplet)
		{
			if(this.mp.getControls().isAvailable('stop'))
			{
				this.mp.getControls().stop();
			}
			if(this.mp.getControls().isAvailable('currentPosition'))
			{
				this.mp.getControls().setCurrentPosition(0);
			}
		}
		else
		{
			if(this.mp.controls.isAvailable('stop'))
			{
				this.mp.controls.stop();
			}
			if(this.mp.controls.isAvailable('currentPosition'))
			{
				this.mp.controls.currentPosition = 0;
			}
		}
	}
}
// PLAYBACK
WindowsMediaPlayer.prototype.stop = function()
{
	if(this.isNSPlugin)
	{
 		if(this.mp.GetPlayState() != 0)
		{
 				this.mp.Stop();
 				this.mp.SetCurrentPosition(0);
		}
	}
	else if (this.isWMP64)
	{
		if(this.mp.PlayState != 0)
		{
 				//alert("WMP64 Stop");
 				this.mp.Stop();
 				this.mp.CurrentPosition = 0;
		}
	}
	else
	{
		// If using v7+ interface set through applet's setXXX routine or
		// by setting property directly
		if(this.isNSApplet)
		{
			if(this.mp.getControls().isAvailable('stop'))
			{
				this.mp.getControls().stop();
			}
			if(this.mp.getControls().isAvailable('currentPosition'))
			{
				this.mp.getControls().setCurrentPosition(0);
			}
		}
		else
		{
			if(this.mp.controls.isAvailable('stop'))
			{
				this.mp.controls.stop();
			}
			if(this.mp.controls.isAvailable('currentPosition'))
			{
				this.mp.controls.currentPosition = 0;
			}
		}
	}
}
WindowsMediaPlayer.prototype.pause = function()
{
	if(this.playState == 2)
	{
		this.play();
		return;
	}
	if(this.isNSPlugin)
	{
 		if(this.mp.GetPlayState() == 2)
 		{
 			this.mp.Pause();
 		}
	}
	else if (this.isWMP64)
	{
		if(this.mp.PlayState == 2)
		{
 			this.mp.Pause();
 		}
	}
	else
	{
		// If using v7+ interface set through applet's setXXX routine or
		// by setting property directly
		if(this.isNSApplet)
		{
			if(this.mp.getControls().isAvailable('pause'))
			{
				this.mp.getControls().pause();
			}
			else
			{
				this.mp.controls.stop();
			}
		}
		else
		{
			if(this.mp.controls.isAvailable('pause'))
			{
				this.mp.controls.pause();
			}
			else
			{
				this.mp.controls.stop();
			}
		}
	}
}
WindowsMediaPlayer.prototype.play = function()
{
	try
	{
	    //fix for live streams
	    if(isLive && this.playState == 1)
	    {
	        this.setUrl(this.url);
	        return;
	    }
		if(this.playState == 3)
		{
			this.pause();
			return;
		}
		if(this.isNSPlugin)
		{
 			if(this.mp.GetPlayState() != 2)
 			{
 				this.mp.Play();
 			}
		}
		else if (this.isWMP64)
		{
			if(this.mp.PlayState != 2)
			{
 				this.mp.Play();
 			}
		}
		else
		{
			// If using v7+ interface set through applet's setXXX routine or
			// by setting property directly
			if(this.isNSApplet)
			{
				if(this.mp.getControls().isAvailable('play'))
				{
					this.mp.getControls().play();
				}
			}
			else if(this.mp.controls != null)
			{
				if(this.mp.controls.isAvailable('play'))
				{
					this.mp.controls.play();
				}
			}
		}
	}
	catch(e)
	{
	}
}
///CALLBACKS
WindowsMediaPlayer.prototype.getBufferingProgress = function() {
	var x = 0;
	if(this.isNSPlugin)
	{
 		x = this.mp.GetBufferingProgress();
	}
	else if (this.isWMP64)
	{
		x = this.mp.BufferingProgress;
	}
	else
	{
		if(this.isNSApplet)
		{
			if(this.mp.network.getBufferingProgress() >= 0)
			{
				x = this.mp.network.getBufferingProgress();
			}
			else if(this.mp.network.getDownloadProgress() >= 0)
			{
				x = this.mp.network.getDownloadProgress();
			}
		}
		else
		{
			if(this.mp.network.bufferingProgress >= 0)
			{
				x = this.mp.network.bufferingProgress;
			}
			else if(this.mp.network.downloadProgress >= 0)
			{
				x = this.mp.network.downloadProgress;
			}
		}
	}
	return x;
}
WindowsMediaPlayer.prototype.error = function()
{
	var errorMsg = this.getErrorDescription();
	//alert("Windows Media Player: " + errorMsg);
}
WindowsMediaPlayer.prototype.scriptCommand = function(type, data)
{
	//alert("WMP: ScriptCommand " + type + " " + data);
	if(this.scriptChange != null)
	{
		this.scriptChange(type, data);
	}
}

//init events
document.write('<script language="javascript" for="mp" event="ScriptCommand(Type, Param)" >player_event("scriptCommand", Type, Param);</script>');

