// ------------------------------------------
//
//		Powerslider_wm.js library. v0.4
//		Written in 2003 by 
//		The Lightsmith. 
//
//
//		Edited in 2003 and 2004 by Jac-Y-Do
//		www.Jac-Y-Do.com
//		038 - 4539855
//		06 - 23588167
//		www.Jac-Y-Do.com
//
//
// ------------------------------------------
//
// Functions work with Internet Explorer 4 and up.
// with windowsmediaplayer 9 and less.
// Netscape NOT supported.
//
// please define a variable movie_url in your page!
// looking something like this:
// movie_url="mms:nlsmal.asf";
//
// -------------------------------------------
//         	And now....!
// 
// 			the important bit...
// 			please do not touch
// 			under penalty of pain
// 
// -------------------------------------------

// included functions:
// function writeWM(width,height,url)
// function WM_Stop()
// function WM_Play()
// function WM_setFileName(url) // doesn't work right now!, so please give url only once
// function WM_PlayFrom(seconds)
// function WM_GetCurrentPos()

// -------------------------------------------
// What are we browsing on?
// -------------------------------------------
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var versionCode = parseFloat(navigator.appVersion);
var mac = (navigator.userAgent.indexOf("Mac")!=-1);
var activeX = (InternetExplorer == 1 && versionCode >= 4.0) ? true : false; 



// ------------------------------------------
// Detect the plug-in for WindowsMedia Player (if >7.1 dan volg 9 series protocol)
// ------------------------------------------

series9      = 0     // All we need to know, is if the 9 series is installed

pluginFound      = false     // Determines if the latest version of the plugin is installed
activeXFound     = false     // Determines if the latest version of the ActiveX is installed

// If this Microsoft Internet Explorer 4.5 for Macintosh, plugins detection is impossible
plgIe4Mac = false
if (navigator.appVersion.indexOf("PPC")!=-1 && navigator.userAgent.indexOf("MSIE 4")!=-1) {plgIe4Mac = true}

// Check if it's an IE Windows Browser
plgIeWin = false
if ( (navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1) ) {plgIeWin = true}

// Check if Windows Media Player 7.1 is installed
function getWmp() {

	// If IE4 Mac, plugins can't be detected
	if(plgIe4Mac) {return false}

	// Check for the WMP plugin - Can check only if it's installed
	// Note that only WMP 7.1 takes in account Mozilla Browsers such as N6.1
	plugInFound = getPlugIn("Windows","Media","Player","Plug-in")

	// Check if WMP 7 ActiveX is installed
	// Note that CLSID of WMP 9 is : CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6
	if (plgIeWin) {activeXFound = getIEComponent("6BF52A52-394A-11d3-B153-00C04F79FAA6")} else {activeXFound=false}
	if (plugInFound || activeXFound) {return true} else {return false}	
}

// Parse plugins collection with strings to find
// User has to pass strings to be found in plugin name and description
// Ex. "Shockwave","Flash","5"
function getPlugIn() {

	// search for the right plugin among all those have been installed
	allFound = false
    plugInsCollection = navigator.plugins
	
	for (i=0;i<plugInsCollection.length;i++) {

		// Get plugin description
        plugInDescription = " " + plugInsCollection[i].description
		plugInName = " " + plugInsCollection[i].name

		for (j=0;j<arguments.length;j++) {
		
			if (plugInDescription.indexOf(" " + arguments[j])!=-1 || plugInName.indexOf(" " + arguments[j])!=-1) {
				allFound = true
			} else {
				allFound = false
				break
			}
		}
		
		// Send back the search result
		if (allFound) {return true}
    }

	// Send back the search result
	return false
}

// Use the Client Capabilities behavior to check IE component installation
function getIEComponent(activeXClsId,minVersion) {
	if (plgIeWin) {return document.body.isComponentInstalled("{" + activeXClsId + "}","componentId",minVersion)} else {return false}
}

function DetectPlugs()
{
	// Add Client Capabilities behavior to the document body - Must be done at load time
	if (plgIeWin) {
		document.body.addBehavior("#default#clientCaps")
	}
	if (getWmp()) {
		series9=1;
	} else {
		series9=0;
	}
}



// -------------------------------------------
// warn for version lower than 4.0 (no visual basic or liveconnect)
// -------------------------------------------
if(versionCode<4 && InternetExplorer)
{
  window.alert('Deze pagina werkt misschien niet correct op uw browser!\n\nProbeert u het nog eens met een nieuwere versie. (versie 4 of hoger)');
}

// -------------------------------------------
// wm_functions start here!
// -------------------------------------------
//
function WM_Stop()
{
	var videoplayer = InternetExplorer ? mediaplayer : document.mediaplayer;
	if(videoplayer==null)
	{
		videoplayer = InternetExplorer ? document.all['mediaplayer'] : document.getElementById('mediaplayer');
	}
	if(series9)
	{
		if (videoplayer.controls.isAvailable('Stop'))
			videoplayer.controls.stop();
	}else
	{
		videoplayer.Stop();
	}
}

// -------------------------------------------
function WM_Play()
{
	var videoplayer = InternetExplorer ? mediaplayer : document.mediaplayer;
	if(videoplayer==null)
	{
		videoplayer = InternetExplorer ? document.all['mediaplayer'] : document.getElementById('mediaplayer');
	}
	if(series9)
	{
		if (videoplayer.controls.isAvailable('Play'))
			videoplayer.controls.play();
	}else
	{
		videoplayer.Play();
	}
}
// -------------------------------------------
function WM_Pause()
{
	var videoplayer = InternetExplorer ? mediaplayer : document.mediaplayer;
	if(videoplayer==null)
	{
		videoplayer = InternetExplorer ? document.all['mediaplayer'] : document.getElementById('mediaplayer');
	}
	if(series9)
	{
		if (videoplayer.controls.isAvailable('Pause'))
			videoplayer.controls.pause();
	}else
	{
		videoplayer.Pause();
	}
}
// -------------------------------------------
function WM_setFileName(url)
{
	var videoplayer = InternetExplorer ? mediaplayer : document.mediaplayer;
	if(videoplayer==null)
	{
		videoplayer = InternetExplorer ? document.all['mediaplayer'] : document.getElementById('mediaplayer');
	}
	//WM_Stop();
	if(series9)
	{
		//videoplayer.URL(url); // this might not be full proof... Why? Do I need to check the ability to change?
		// we can skip this part mostly, because we NEVER use this!
	}else
	{
		if (activeX)
			videoplayer.fileName = url;
		else
			videoplayer.SetFileName(url);
	}
	WM_Play();
}
// -------------------------------------------
function WM_PlayFrom(seconds)
{
	var videoplayer = InternetExplorer ? mediaplayer : document.mediaplayer;
	if(videoplayer==null)
	{
		videoplayer = InternetExplorer ? document.all['mediaplayer'] : document.getElementById('mediaplayer');
	}
	//WM_Stop();
	if(series9)
	{
		videoplayer.settings.currentPosition=seconds;
	}else
	{
		if (activeX)
		{
			videoplayer.CurrentPosition=seconds;
		}else
		{
			videoplayer.SetCurrentPosition(seconds);
		}
	}
	WM_Play();
}
// -------------------------------------------
function WM_GetCurrentPos()
{
	var time='initializing';  // initial value...
	var videoplayer = InternetExplorer ? mediaplayer : document.mediaplayer;
	if(videoplayer==null)
	{
		videoplayer = InternetExplorer ? document.all['mediaplayer'] : document.getElementById('mediaplayer');
	}
	if(series9)
	{
		time=videoplayer.controls.currentPosition;
		// this used to go to -1 in connecting to the stream, now it starts at 1??
		// this is a fix, that might get the powerslider dragging 1 second behind.
		// it will work, but if this turns out to be the case, this might need work!
		if(videoplayer.playState!=3) // playing
		{
			time=-1;	
		}
	}else
	{
		if (activeX)
		{
			time=videoplayer.CurrentPosition;
		}else
		{
			time=videoplayer.GetCurrentPosition();
		}
	}		
	return time;
}
// -------------------------------------------
function writeWM(width,height,url)
{
// this is always the first function to be called, and there usually is something on the page allready!
	DetectPlugs();
	if(series9)
	{   
		document.write('<object id="mediaplayer"');
		document.write(' width="'+width+'" height="'+height+'"');
		document.write(' classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"');
		document.write(' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading MicrosoftØ WindowsØ Media Player components..."');
		document.write(' type="application/x-oleobject">');
		document.write(' <param name="URL" value="'+url+'">');                
		document.write(' <param name="WindowlessVideo" value="1">');
		document.write(' <param name="stretchToFit" value="true">');
		document.write(' <param name="uiMode" value="none">');
		document.write(' <param name="AutoStart" value="1">');
		document.write('</object>');
	}else
	{	 
		document.write('<object id="mediaplayer"');
		document.write(' width="'+width+'" height="'+height+'"');
		document.write(' classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"');
		document.write(' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading MicrosoftØ WindowsØ Media Player components..."');
		document.write(' type="application/x-oleobject">');
	    document.write(' <param name="FileName" value="'+url+'">');                
	    document.write(' <param name="ShowStatusbar" value="0">');
	    document.write(' <param name="ShowControls" value="0">');
	    document.write(' <param name="AutoStart" value="1">');
	    document.write(' <embed'); 
		document.write('  name="mediaplayer"'); 
		document.write('  type="application/x-mplayer2"'); 
		document.write('  pluginspage="http://www.microsoft.com/windows/windowsmedia/players.asp"'); 
		document.write('  src="'+url+'"');
		document.write('  width="'+width+'" height="'+height+'"'); 
		document.write('  showstatusbar="0"');
		document.write('  showcontrols="0"');
		document.write('  autostart="1">');
	    document.write(' </embed>'); 
	    document.write('</object>');
	}
}




