//<!--
// ---------------------------------------------------------------------
// Compatible with StreamSync Encoder 1.4.15+. 2004-03-17.
// Please notice. This code is provided only as an example of how to
// layout and program a video player for use with StreamSync.
// ---------------------------------------------------------------------

var mElementID = "";
var mMimeType = "";
var mPayload = "";
var mCurrentSrc = "";

var mVideoSource = "";
var mWMversion = "";
var mWebcasttype = "";
var mMediaPath = "";

var is_wm = false;
var is_real = false;
var is_qt = false;
var biggieslideswindow = "";
var slideswindow = "";
var mmtThumbNr = "001";

var CurrentChapter;
var CurrentChapterFile;
var CurrentChapterTime;

var uAgent = navigator.userAgent.toLowerCase();

// ---------------------------------------------------------------------
// Init 
//
// This method is called from the SCRIPT.HTM page that is loaded from the
// Media Player URL script command. 
//
// URL is the SCRIPT.HTM document.location value
// ---------------------------------------------------------------------

function Init(URL)
{
	UpdateFromParameters(URL);
	UpdatePage(mElementID, mMimeType, mPayload);
}

// ---------------------------------------------------------------------
// GetParameters 
//
// This method extracts the parameters from the provided URL. 
//
// ---------------------------------------------------------------------

function GetParameters(URL)
{
	var StrArray = String(URL).split("?");
	return String(StrArray[1]);
}

// ---------------------------------------------------------------------
// UpdateFromParameters 
//
// This method retreives the parameters from the provided URL. Parameters 
// are separated by the & character. 
//
// ---------------------------------------------------------------------

function UpdateFromParameters(URL)
{
	var parameters =  GetParameters(URL);
	var StrArray = parameters.split("&");
	
	mElementID = String(StrArray[0]);
	mMimeType =  String(StrArray[1]).toLowerCase();
	mPayload =  String(StrArray[2]);	// 2004-02-17 Removed unescape
}

// ---------------------------------------------------------------------
// UpdatePage 
//
// This method updates the page depending on the provided parameters. 
//
// ElementID adresses the specific element on the page to update.
// MimeType is the elements media type.
// Payload is the actual payload.
//
// Syntax for the parameters string: ElementID&MimeType&Payload
// 
// ---------------------------------------------------------------------

function UpdatePage(ElementID, MimeType, Payload)
{
	if(ElementID == "undefined") return;
	if(MimeType == "undefined") return;
	if(Payload == "undefined") return;
	
	if(MimeType.indexOf("image/") > -1){
		SetImage(ElementID, Payload);
	}
	else if(MimeType.indexOf("text/") > -1){
		SetText(ElementID, Payload);
	}
	else if(MimeType.indexOf("outro") > -1){
		document.location = "outro.php";
	}
	else{
		//Ignore this MIME type
	}
	
}

// ---------------------------------------------------------------------
// SetImage 
//
// This method updates an image on the page. 
//
// ElementID adresses the specific element on the page to update.
// Payload is the actual payload.
//
// ---------------------------------------------------------------------

function SetImage(ElementID, Payload)
{

	if(mCurrentSrc == Payload + "/" + ElementID) return;
	mCurrentSrc = Payload + "/" + ElementID;
			slumptalet = new String(Math.round(Math.random() * 1000));
		if (slumptalet < 10) 
			{
			slumptalet = (slumptalet * 100);
			}
		else if (slumptalet < 100) 
			{
			slumptalet = (slumptalet * 10);
			}			
						
	eval("document." + ElementID + ".src = \"slides/" + Payload + "?" + slumptalet + "\"");
	if (!biggieslideswindow.closed && biggieslideswindow.location)
		{
		var mmtBigPath = new String(document.pic1.src.slice(0,-18));
		var mmtBigFile = new String(document.pic1.src.slice((mmtBigPath.length),-8));
		biggieslideswindow.location.href = mmtBigPath +'big_' + mmtBigFile + '.JPG';
		}
	
	if (!slideswindow.closed && slideswindow.location)
	{
	
	slideswindow.ResetThumb();
	slideswindow.SetCurrentThumb();
	
	if(slideswindow.document.biggie.width == 800 && slideswindow.follow == "yes")
	{
	eval(slideswindow.LargeView(slideswindow.currentslide));
	}

	}

}

function SlidePresenter(type)
{
	var activethumbUrl = "slidepresenter.php?" + type;
	slideswindow = window.open(activethumbUrl + '', 'thumbslidewindow','toolbar=yes,resizable=no,status=yes,scrollbars=yes,width=850,height=700,framespacing=0');
	slideswindow.focus();
}

function CloseOpenWindows()
{
	if (!slideswindow.closed && slideswindow.location)
		{
		slideswindow.close();
		}
}

function SetImageNext(slidecount)
{
	var mmtPath = new String(document.pic1.src.slice(0,-18));
	var mmtFile = new String(document.pic1.src.slice((mmtPath.length + 6),(mmtPath.length + 10)));
	mmtFile++ ;
		if (mmtFile > slidecount)
		   {
			mmtFile-- ;
			alert("This is the last slide");
			}

		if (mmtFile < 10)
		   {
			mmtFile = "000" + mmtFile;
			}
		else if (mmtFile < 100)
			{
			mmtFile = "00" + mmtFile;
			}
		else
			{
			mmtFile = "0" + mmtFile;
			}
		
		if (mmtFile == "0NaN")
			{
			mmtPath = "";
			mmtFile = "";
			}
		else
			{
			mmtFile = "slide_" + mmtFile + ".JPG";
			slumptalet = new String(Math.round(Math.random() * 1000));
		if (slumptalet < 10) 
			{
			slumptalet = (slumptalet * 100);
			}
		else if (slumptalet < 100) 
			{
			slumptalet = (slumptalet * 10);
			}			
			eval("document.pic1.src = \"" + mmtPath + mmtFile + "?" + slumptalet + "\"");
			}
}

function SetImagePrevious(firstslide)
{
	var mmtPath = new String(document.pic1.src.slice(0,-18));
	var mmtFile = new String(document.pic1.src.slice((mmtPath.length + 6),(mmtPath.length + 10)));
	mmtFile-- ;
	if (mmtFile < firstslide)
		   {
			mmtFile++ ;
			alert("This is the first slide");
			}

		if (mmtFile < 10)
		   {
			mmtFile = "000" + mmtFile;
			}
		else if (mmtFile < 100)
			{
			mmtFile = "00" + mmtFile;
			}
		else
			{
			mmtFile = "0" + mmtFile;
			}

		if (mmtFile == "0NaN")
			{
			mmtPath = "";
			mmtFile = "";
			}
		else
			{
			mmtFile = "slide_" + mmtFile + ".JPG";
			slumptalet = new String(Math.round(Math.random() * 1000));
		if (slumptalet < 10) 
			{
			slumptalet = (slumptalet * 100);
			}
		else if (slumptalet < 100) 
			{
			slumptalet = (slumptalet * 10);
			}			
			eval("document.pic1.src = \"" + mmtPath + mmtFile + "?" + slumptalet + "\"");
			}
}

// ---------------------------------------------------------------------
// SetText 
//
// This method updates a text field on the page. 
//
// ElementID adresses the specific element on the page to update.
// Payload is the actual payload.
//
// ---------------------------------------------------------------------

function SetText(ElementID, Payload)
{	
	// Replace %A with line break
	var re = /%0A/g;
	Payload = unescape(Payload.replace(re, "<br>"));	
	
	var nav4Layer = eval("document." + ElementID);				// Adress your text element for Navigator 4.5 here
	
	if(nav4Layer != null){
		// Use Netscape layers to update the text 
		nav4Layer.document.write("<font class=\"Style1\"><center>" + Payload + "</center></font>");
		nav4Layer.document.close();
	}
	else{
		var docElement = document.getElementById(ElementID);	// Adress your text element for other compliant browsers here
		if(docElement != null){
			// Use innerHTML to update the text (not a W3C standard, but it works for IE and NS6.2)
			if(docElement.innerHTML != Payload) docElement.innerHTML = Payload;
		}
	}
}

// ---------------------------------------------------------------------
// HandleCommandScript 
//
// The provided CommandScript describes the multimedia element to
// display in the browser.
//
// Syntax for the ScriptComand string: #ElementID#MimeType#Payload
//
// Windows + IE only!
//
// ---------------------------------------------------------------------

function HandleCommandScript(ScriptType, CommandScript) {
	
	if(ScriptType == "URL") return;
		
	// Turn off URL scripts
	if(document.MediaPlayer.InvokeURLs) document.MediaPlayer.InvokeURLs = false;
		
	// Parse the ScriptCommand string
	ParseCommandScript(CommandScript);
		
	// Update the element on the web page 
	UpdatePage(mElementID, mMimeType, mPayload);
}

// ---------------------------------------------------------------------
// ParseCommandScript 
//
// Updates the webpage according to the provided layout element object. 
//
// LayoutElement is a description of the multimedia element.
// ---------------------------------------------------------------------

function ParseCommandScript(ScriptCommand){

	var Attributes = ScriptCommand.split("#");
	if(Attributes == null) return; // No attributes found
	mElementID = String(Attributes[1]);
	mMimeType =  String(Attributes[2]).toLowerCase();
	mPayload =  String(Attributes[3]);
}

// ---------------------------------------------------------------------
// Detect from the provided VideoSource which player to use
// ---------------------------------------------------------------------

function DetectPlayerType(VideoSource)
{
	// Extract the extension from the extracted media path
	var Extension = GetExtension(VideoSource);
		
	// Extract the right type of player from the extracted extension
	if(".ram;.rpm;.rm;".indexOf(Extension) > -1){
		is_real = true;
	}
	else if(".asx;.asp;.wmv;asf;avi;".indexOf(Extension) > -1){
		is_wm = true;
	}
	else if(".mov;mpg;mpeg;".indexOf(Extension) > -1){
		is_qt = true;
	}
	else {
		is_wm = true;
	}
}

// ---------------------------------------------------------------------
// Extract extension from the provided MediaPath
// ---------------------------------------------------------------------

function GetExtension(MediaPath)
{
	var nLastDot = MediaPath.lastIndexOf(".");
	if(nLastDot != -1){
		var Extension = MediaPath.substring(nLastDot+1, MediaPath.length);
		return (Extension);
	}
}

// ---------------------------------------------------------------------
// Extract parameters from the document.location variable
// ---------------------------------------------------------------------

function ParseURL(URL)
{
	var StrArray = String(URL).split("?");
	var StrArray2 = String(StrArray[1]).split("&");
	
	mVideoSource = unescape(StrArray2[0]);
	mMediaPath = unescape(StrArray2[1]);
	mWMversion = unescape(StrArray2[2]);
	mWebcasttype = unescape(StrArray2[3]);
	
	//alert("mVideoSource = " + mVideoSource);
	//alert("mMediaPath = " + mMediaPath);
}

// ---------------------------------------------------------------------
// Returns the videosource to open by the player
// ---------------------------------------------------------------------

function GetVideoSource()
{
	return mVideoSource;
}

// ---------------------------------------------------------------------
// Invoke the player that fit the provided URL
// ---------------------------------------------------------------------

function WritePlayer(URL,videowidth,videoheight)
{
	ParseURL(URL);
	DetectPlayerType(GetVideoSource());
	
	if(is_real){
		// Write out the Real Player
		WriteRealPlayer(GetVideoSource(),videowidth,videoheight);
	}
	else if(is_wm){
		// Write out the Windows Media Player
		if (mWMversion == 7) {
		WriteWindowsMediaPlayer7(GetVideoSource(),videowidth,videoheight);
		}
		else 
		 {
		WriteWindowsMediaPlayer9(GetVideoSource(),videowidth,videoheight);
		}
	}
	else if(is_qt){
		// Write out the Quick Time Player
		WriteQuicktimePlayer(GetVideoSource(),videowidth,videoheight);
	}
}


// ---------------------------------------------------------------------
// Methods for controlling chapter index and current time
// ---------------------------------------------------------------------

function IndexRotator() {

if (mWMversion == 7) {
		var currPos = new String(Math.round(document.getElementById("MediaPlayer").currentPosition));
		var currFile = new String(document.getElementById("MediaPlayer").GetMediaInfoString(8));
		}
		else
		 {
		var currPos = new String(Math.round(document.getElementById("MediaPlayer").controls.currentPosition));
		var currFile = new String(document.getElementById("MediaPlayer").currentMedia.name);
		}

currFile = currFile + ".wmv";

if (videofile1.indexOf(currFile) != -1) {
var NxtChap = ChapterTimes1[CurrentChapter];
var PrevChap = ChapterTimes1[(CurrentChapter-1)];
CurrentChapterTime = parseInt(ChapterTimes1[CurrentChapterFile]);
}

if (videofile2.indexOf(currFile) != -1) {
var NxtChap = ChapterTimes2[CurrentChapter];
var PrevChap = ChapterTimes2[(CurrentChapter-1)];
CurrentChapterTime = parseInt(ChapterTimes2[CurrentChapterFile]);
}

if (videofile3.indexOf(currFile) != -1) {
var NxtChap = ChapterTimes3[CurrentChapter];
var PrevChap = ChapterTimes3[(CurrentChapter-1)];
CurrentChapterTime = parseInt(ChapterTimes3[CurrentChapterFile]);
}

if (videofile4.indexOf(currFile) != -1) {
var NxtChap = ChapterTimes4[CurrentChapter];
var PrevChap = ChapterTimes4[(CurrentChapter-1)];
CurrentChapterTime = parseInt(ChapterTimes4[CurrentChapterFile]);
}

if (videofile5.indexOf(currFile) != -1) {
var NxtChap = ChapterTimes5[CurrentChapter];
var PrevChap = ChapterTimes5[(CurrentChapter-1)];
CurrentChapterTime = parseInt(ChapterTimes5[CurrentChapterFile]);
}	
if ((parseInt(currPos)+CurrentChapterTime) > NxtChap)
{
CurrentChapter++;
SetChapterIndex(CurrentChapter);
setTimeout("IndexRotator()",100);
} else if ((parseInt(currPos)+CurrentChapterTime) < PrevChap)
{
CurrentChapter--;
SetChapterIndex(CurrentChapter);	
setTimeout("IndexRotator()",100);
} else {
setTimeout("IndexRotator()",3000);
}

}

function SetChapterIndex(i) {

if (i != null)
{
document.totalformen.chapterdropdown.options[i].selected = true;
} else 
{
i = unescape(mVideoSource.replace("chapter_", ""));
i = unescape(i.replace(".asx", ""));
document.totalformen.chapterdropdown.options[i].selected = true;
CurrentChapter = parseInt(i);
CurrentChapterFile = (CurrentChapter-1)
	
setTimeout("IndexRotator()",3000);
}
}


// ---------------------------------------------------------------------
// Methods for writing out embeded players
// ---------------------------------------------------------------------

function WriteWindowsMediaPlayer9(VideoSource,videowidth,videoheight) 
{
	is_wm = true;
	
	if (mWebcasttype == "audio") {
    height = 64;
	width = videowidth;
	}
	
	else if (mWebcasttype == "video") {
    height = videoheight + 64;
	width = videowidth;
	}
        
	var ObjectTag = "<OBJECT ID=\"MediaPlayer\" name=\"MediaPlayer\" WIDTH=\""+width+"\" HEIGHT=\""+height+"\" CLASSID=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\">";
	ObjectTag += "<PARAM NAME=\"AutoStart\" VALUE=\"1\">";
	ObjectTag += "<PARAM NAME=\"URL\" VALUE=\"" + VideoSource + "\">";
	ObjectTag += "<PARAM NAME=\"captioningID\" VALUE=\"captext\">";
	ObjectTag += "<PARAM NAME=\"uiMode\" VALUE=\"full\">";
	ObjectTag += "<PARAM NAME=\"InvokeURLs\" VALUE=\"1\">";
	ObjectTag += "<PARAM NAME=\"Volume\" VALUE=\"100\">";
	ObjectTag += "<EMBED Type=\"video/x-ms-asf-plugin\" pluginspage=\"http://www.microsoft.com/windows/mediaplayer/download/default.asp\" src=\"" + VideoSource + "\" name=\"MediaPlayer\" AutoStart=\"1\" uiMode=\"mini\" captioningID=\"captext\" ShowControls=\"1\" ShowStatusBar=\"1\" AutoSize=\"0\" width=\""+width+"\" height=\""+height+"\" Volume=\"100\" DefaultFrame=\"script\" ShowTracker=\"0\">";
	ObjectTag += "</OBJECT>";

	document.write(ObjectTag);
}

function WriteWindowsMediaPlayer7(VideoSource,videowidth,videoheight) 
{
	is_wm = true;
	
	if (mWebcasttype == "audio") {
    height = 69;
	width = videowidth;
	}
	
	else if (mWebcasttype == "video") {
    height = videoheight + 69;
	width = videowidth;
	}
        
	var ObjectTag = "<OBJECT ID=\"MediaPlayer\" name=\"MediaPlayer\" WIDTH=\""+width+"\" HEIGHT=\""+height+"\" CLASSID=\"CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95\" CODEBASE=\"http://www.microsoft.com/ntserver/netshow/download/en/nsmp2inf.cab#Version=5,1,51,415\" standby=\"Loading Microsoft Media Player components...\" type=\"application/x-oleobject\">";
	ObjectTag += "<PARAM NAME=\"AutoStart\" VALUE=\"1\">";
	ObjectTag += "<PARAM NAME=\"FileName\" VALUE=\"" + VideoSource + "\">";
	ObjectTag += "<PARAM NAME=\"captioningID\" VALUE=\"captext\">";
	ObjectTag += "<PARAM NAME=\"ShowControls\" VALUE=\"1\">";
	ObjectTag += "<PARAM NAME=\"ShowStatusBar\" VALUE=\"1\">";
	ObjectTag += "<PARAM NAME=\"AutoSize\" VALUE=\"0\">";
	ObjectTag += "<PARAM NAME=\"ControlType\" VALUE=\"0\">";
	ObjectTag += "<PARAM NAME=\"ShowTracker\" VALUE=\"1\">";
	ObjectTag += "<PARAM NAME=\"InvokeURLs\" VALUE=\"1\">";
	ObjectTag += "<PARAM NAME=\"Volume\" VALUE=\"0\">";
	ObjectTag += "<EMBED Type=\"video/x-ms-asf-plugin\" pluginspage=\"http://www.microsoft.com/windows/mediaplayer/download/default.asp\" src=\"" + VideoSource + "\" name=\"MediaPlayer\" ID=\"MediaPlayer\" AutoStart=\"1\" ShowStatusBar=\"1\" ShowControls=\"1\" captioningID=\"captext\" AutoSize=\"0\" width=\""+width+"\" height=\""+height+"\" DefaultFrame=\"script\" ShowTracker=\"0\">";
	ObjectTag += "</OBJECT>";

	document.write(ObjectTag);
}


function WriteRealPlayer(VideoSource,videowidth,videoheight) 
{	
	is_real = true;

	if (mWebcasttype == "audio") {
    height = 0;
	width = videowidth;
	displaytype = "PositionSlider";
	}
	
	else if (mWebcasttype == "video") {
    height = videoheight;
	width = videowidth;
	displaytype = "ImageWindow";
	}	
	
	var ObjectTag = "<OBJECT id=\"PlayerObjectEmbed\" CLASSID=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" WIDTH=\""+width+"\" HEIGHT=\""+height+"\">";
	ObjectTag +="<PARAM name=\"NOJAVA\" value=\"true\">";
	ObjectTag +="<PARAM name=\"LOGO\" value=\"false\">";
	ObjectTag +="<PARAM name=\"AUTOSTART\" value=\"true\">";
	ObjectTag +="<PARAM NAME=\"SRC\" VALUE=\"" + VideoSource + "\">";
	ObjectTag +="<PARAM name=\"CONSOLE\" value=\"MediaPlayer\">";
	ObjectTag +="<PARAM name=\"CONTROLS\" value=\"" + displaytype + "\">";
	ObjectTag +="<EMBED id=\"PlayerObjectEmbed\" type=\"audio/x-pn-realaudio-plugin\" WIDTH=\"" + width + "\" HEIGHT=\"" + height + "\" CONTROLS=\"" + displaytype + "\" SRC=\"" + VideoSource + "\" NOJAVA=\"true\" LOGO=\"false\" AUTOSTART=\"true\" CONSOLE=\"MediaPlayer\"  PLUGINSPAGE=\"http://www.real.com\">";
	ObjectTag +="</OBJECT><br>";

	ObjectTag +="<OBJECT id=\"thePlayerObjectConsole\" WIDTH=\""+width+"\" HEIGHT=\"64\" CLASSID=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\">";
	ObjectTag +="<PARAM name=\"NOJAVA\" value=\"true\">";
	ObjectTag +="<PARAM name=\"LOGO\" value=\"false\">";
	ObjectTag +="<PARAM name=\"AUTOSTART\" value=\"true\">";
	ObjectTag +="<PARAM name=\"SRC\" value=\"" + VideoSource + "\">";
	ObjectTag +="<PARAM name=\"CONSOLE\" value=\"MediaPlayer\">";
	ObjectTag +="<PARAM name=\"CONTROLS\" value=\"All\">";
	ObjectTag +="<EMBED id=\"thePlayerEmbedConsole\" type=\"audio/x-pn-realaudio-plugin\" WIDTH=\"384\" HEIGHT=\"64\" CONTROLS=\"All\" SRC=\"" + VideoSource + "\" NOJAVA=\"true\" LOGO=\"false\" AUTOSTART=\"true\" CONSOLE=\"MediaPlayer\"  PLUGINSPAGE=\"http://www.real.com\">";
	ObjectTag +="</OBJECT><br>";

	document.write(ObjectTag);
}

function WriteQuicktimePlayer(VideoSource,videowidth,videoheight)		// Must use player controls. Cannot use custom controls.
{	
	
	is_qt = true;
	
	width = videowidth;
    height = videoheight + 16;
    
	var ObjectTag = "<OBJECT id=\"MediaPlayer\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\" height=\"" + height + "\" width=\"" + width + "\" classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\">";
	ObjectTag += "<param name=\"src\" value=\"" + VideoSource + "\">";
	ObjectTag += "<param name=\"CONTROLLER\" value=\"TRUE\">";
	ObjectTag += "<param name=\"SCALE\" value=\"ASPECT\">";
	ObjectTag += "<EMBED NAME=\"MediaPlayer\" SCALE=\"ASPECT\" BORDER=\"0\" CONTROLLER=\"true\" TYPE=\"video/quicktime\" src=\""+VideoSource+"\" WIDTH=\""+width+"\" HEIGHT=\""+height+"\" AUTOPLAY=\"true\" BGCOLOR=\"#FFFFFF\" PLUGINSPAGE=\"http://www.apple.com/quicktime/download/\">";
	ObjectTag += "</OBJECT>";
	
	document.write(ObjectTag);
}	

//--> 
