// ****************************************************
// Version 0.6 StreamX Template 

// Date        Version   Description
// 2003-12-17  0.1       Dynamic agenda extended to remove separate agenda_xxx.htm files,
//                       vas and sas files merged into same folder and take URL parameters
// 2004-03-19  0.2       player.htm now uses javascript "flip" handler
//                       Tested on plenty of versions of browsers and players, see compatibility.txt
// 2004-03-23  0.3       "Test" mode now has separate default speaker, slide, titles etc and won't be affected by live event
// 2004-04-29  0.4       Agenda flips and player.htm now get most parameters from the parent frameset
//                       eStart has been removed, please use title_default.htm and title_commence.htm
// 2004-05-13  0.5       Added online Qanda
//                       Added parameters for splash page
//                       Switched back to using table rows for Agenda items
// 2004-05-19  0.6       Separate default settings for Test, Live and Archive modes


// ****************************************************
// WEBCAST PARAMETERS

var cName      = "Reed Business";
var eName      = "Key Elements of a Successful Food Safety Program";
var eDate      = "";
var eTime      = "";
var eDay       = dayName (eDate);

var strSplashMode = "archive"           // This is used if the splash page is hit with no parameters specified.
                                        // URL parameters will override this value, ie. http://streamx.com.au/jobname/index.htm?etype=archive will always show the archive links.
                                        // Possible values are "live", "archive" and "test"

var wciWidth    = "771";                // Pop-Up Dimensions
var wciHeight   = "506";                // NOTE that this specifies the height of the window WITHOUT online Qanda!

var sasPlayerWidth  = "178";            // Audio player dimensions
var sasPlayerHeight = "72";
var headFrameHeight = "136";            // Height of the head frame

var vasPlayerWidth  = "176";            // Narrowband video player dimensions
var vasPlayerHeight = "204";

var vasbPlayerWidth  = "256";           // Broadband video player dimensions
var vasbPlayerHeight = "264";



// ****************************************************
// Default Head, Title, Slides

var strDefaultHead;    // Change these in the test, live & archive sections below.
var strDefaultTitle;
var strDefaultSlide;


// **  TEST defaults  **

var strTestDefaultHead   = "heads/head_default.htm";
var strTestDefaultTitle  = "titles/title_commence.htm";
var strTestDefaultSlide  = "slides_test/sas_noqa/slide1.htm";


// **  LIVE defaults  **

var strLiveDefaultHead   = "heads/head_default.htm";
var strLiveDefaultTitle  = "titles/title_commence.htm";
var strLiveDefaultSlide  = "slides/slide_commence.htm";


// **  ARCHIVE defaults  **

var strArchiveDefaultHead   = "heads/head_default.htm";
var strArchiveDefaultTitle  = "titles/title_default.htm";
var strArchiveDefaultSlide  = "slides/slide_default.htm";



// ****************************************************
// Online Questions & Answers

var boolEnableQanda     = false;

var strQandaFrameHeight = "105";                          // Note that this height is *added to* the wciHeight for Test and Live modes!
var strQandaTestURL     = "";
var strQandaLiveURL     = "";
var strQandaURL;        // This is set in getDefaults();



// ****************************************************
// Dynamic Agenda 
// 
//    * Start by setting iNumAgendas to the correct number of agenda items, and copy/paste arrays to match the number of agendas
//
// For LIVE event:
//
//    * In the "Webcast Parameters" section at the top of this script set the default head, title and slide.
//
//    * For each agenda point set agAlias to a short & unique name (such as "qanda"), and set agDisplayText to a full text name
//      (such as "Questions and Answers", this will appear in agenda.htm)
//
//    * You do not need to set anything in agHeads, agTitles and agSlides for the live event.
//
// For ARCHIVE event:
//
//    * For each agenda point in agAlias, make sure there is a corresponding ASX file for both SAS and VAS and set the "starttime"
//      in each file.
//
//    * For each agenda point set agSlides, agTitles and agHeads to the path to the HTML files that should appear when a user 
//      clicks on the corresponding agenda link.


var iNumAgendas   = 5;
var agAlias       = new Array(iNumAgendas);
var agDisplayText = new Array(iNumAgendas);
var agHeads       = new Array(iNumAgendas);
var agTitles      = new Array(iNumAgendas);
var agSlides      = new Array(iNumAgendas);


agAlias[0]       = constStrDefaultAgenda;       // Name of the agenda points, ie. intro, preso, qanda etc.
agDisplayText[0] = constStrDefaultAgenda;       // This is the name of each agenda point as it appears in the page, ie. "Questions and Answers"
agHeads[0]       = "";                          // Default head
agTitles[0]      = "";                          // Default title
agSlides[0]      = "";                          // Default slide


agAlias[1]       = "intro";
agDisplayText[1] = "Introduction";
agHeads[1]       = "heads/head_jamiewade.htm"; 
agTitles[1]      = "titles/title_jamiewade.htm"; 
agSlides[1]      = "slides/slide1.htm"; 


agAlias[2]       = "david";
agDisplayText[2] = "Rentokil Pest Control";
agHeads[2]       = "heads/head_davidpeterson.htm";
agTitles[2]      = "titles/title_davidpeterson.htm";
agSlides[2]      = "slides/dp/slide1.htm";


agAlias[3]       = "helmut";
agDisplayText[3] = "Food/Cryogenics, BOC Limited";
agHeads[3]       = "heads/head_helmutdresselhaus.htm";
agTitles[3]      = "titles/title_helmutdresselhaus.htm";
agSlides[3]      = "slides/hd/slide1.htm";


agAlias[4]       = "phil";
agDisplayText[4] = "3M Australia Pty Ltd";
agHeads[4]       = "heads/head_philcurry.htm"; 
agTitles[4]      = "titles/title_philcurry.htm"; 
agSlides[4]      = "slides/pc/slide1.htm"; 


agAlias[5]       = "les";
agDisplayText[5] = "Albany Door Systems";
agHeads[5]       = "heads/head_lesdavies.htm";
agTitles[5]      = "titles/title_lesdavies.htm";
agSlides[5]      = "slides/ld/slide1.htm";


function writeAgenda (strCurrentAgenda) {
	var i;      // Counter variable
	
	if (eType != "test") {                                               // Agenda Heading - do not write in Test mode
		document.write ('<tr><td title="Agenda"><img src="../images/agenda.gif" alt="" border="0"></td></tr>');

		for (i=1; i <= iNumAgendas; i++) {                                   // Agenda Body
			switch (eType) {
				
				case "archive":
					if (agAlias[i] == strCurrentAgenda) {
						
						// Archive, Current agenda point. Write agenda item without link.
						document.write ('<tr><td valign="top" class="agMenuHit" title="'+agDisplayText[i]+'">'+agDisplayText[i]+'</td></tr>');
					}
					else {
						
						// Archive, Non-current agenda point. Write agenda item and include link.
						document.write ('<tr><td valign="top" class="agMenu" onMouseOver="this.className=\'agMenuOver\'" style="cursor: hand" ');
						document.write ('onMouseOut="this.className=\'agMenu\'" ');
						document.write ('onClick ="window.parent.location.href=\'index.htm?media=' + strMedia + '&etype=' + eType + '&agenda=' + agAlias[i] + '\'" ');
						document.write ('title="'+agDisplayText[i]+'">'+agDisplayText[i]+'</td></tr>');
					}
				break;

				case "live":
					if (agAlias[i] == strCurrentAgenda) {
						
						// Live, Current agenda point. Write highlighted agenda item with no link.
						document.write ('<tr><td valign="top" class="agMenuHit" title="'+agDisplayText[i]+'">'+agDisplayText[i]+'</td></tr>');
					}
					else {
						
						// Live, Non-current agenda point. Write agenda item with normal formatting and no link.
						document.write ('<tr><td class="agMenu" valign="top" style="cursor: auto" title="'+agDisplayText[i]+'">'+agDisplayText[i]+'</td></tr>');
					}
				break;
			}
		}		
	}
}



// ****************************************************
// NOTE - This section is only used if the webcast interface is hit with no parameters, which should never happen.
// Parameters to the webcast interface always come from the links in links_live.htm, links_test.htm etc.
// Parameters specified in the link will override these values.

var constStrDefaultEType     = "archive";                 // Default to archive if etype is unspecified.
var constStrDefaultMedia     = "vas";                     // Pages default to "sas" if media type is not specified.
var constStrDefaultAgenda    = "DEFAULT";
var constIntDefaultAgendaNum = 0;

var strMedia     = constStrDefaultMedia;      // Current media type.
var eType        = constStrDefaultEType;      // Current event type. Usually set by a parameter in the URL ie. ?etype=[test|live|archive]
var strAgenda    = constStrDefaultAgenda;     // Current agenda point, e.g. "intro"  This must match up to an agAlias[] value for everything to link together.
var intAgenda    = constIntDefaultAgendaNum;  // Index of current agenda point.
var playerWidth  = vasPlayerWidth;
var playerHeight = vasPlayerHeight;



// *************************************************************
// Functions below this point shouldn't need modification
//


function readURLParameters() {

	// Run this function at the top of each page/frame.
	strMedia  = readFromURL("media", constStrDefaultMedia);       // Retrieve media type from URL (sas or vas)
	eType     = readFromURL("etype", constStrDefaultEType);       // Retrieve etype from URL
	strAgenda = readFromURL("agenda", constStrDefaultAgenda);     // Retrieve agenda name from URL
	intAgenda = findAgendaNum (strAgenda);                        // Get index of this agenda
}


function getParentParameters () {
	
	// Allows subframes such as Agenda and Player to pull parameters down from the index page
	strMedia  = parent.parent.parent.strMedia;
	eType     = parent.parent.parent.eType;
	strAgenda = parent.parent.parent.strAgenda;
	intAgenda = parent.parent.parent.intAgenda;
}


function getWCIHeight () {
	if (boolEnableQanda == true && eType != "archive") {          // Adjust webcast interface height if QANDA is in use
			wciHeight = (parseInt(wciHeight) + parseInt(strQandaFrameHeight)) + '';
	}	
}


function getDefaults() {

	if (strAgenda == constStrDefaultAgenda) {
		
		// No agenda specified. Select default slide, head, title based on eType.
		if (eType == "test") {
			
			strDefaultHead  = strTestDefaultHead;
			strDefaultTitle = strTestDefaultTitle;
			strDefaultSlide = strTestDefaultSlide;
			strQandaURL     = strQandaTestURL;
		}
		else if (eType == "live") {
			
			strDefaultHead  = strLiveDefaultHead;
			strDefaultTitle = strLiveDefaultTitle;
			strDefaultSlide = strLiveDefaultSlide;
			strQandaURL     = strQandaLiveURL;			
		}
		else if (eType == "archive") {
			
			strDefaultHead  = strArchiveDefaultHead;
			strDefaultTitle = strArchiveDefaultTitle;
			strDefaultSlide = strArchiveDefaultSlide;
			strQandaURL     = "";			
		}
	}
	else {

		// Using a specific agenda. Grab slide, head, title settings from dynamic agenda.
		strDefaultHead  = agHeads[intAgenda];
		strDefaultTitle = agTitles[intAgenda];
		strDefaultSlide = agSlides[intAgenda];
		strQandaURL     = strQandaLiveURL;		
	}

	
	if (strMedia == "sas") {                                      // Player size
		playerWidth = sasPlayerWidth;
		playerHeight = sasPlayerHeight;
	}
	else if (strMedia == "vas") {
		playerWidth = vasPlayerWidth;
		playerHeight = vasPlayerHeight;
	}
	else if (strMedia == "vasb") {
		playerWidth = vasbPlayerWidth;
		playerHeight = vasbPlayerHeight;
	}
	else if (strMedia == "vasb1") {
		playerWidth = vasbPlayerWidth;
		playerHeight = vasbPlayerHeight;
	}
	else if (strMedia == "vasb2") {
		playerWidth = vasbPlayerWidth;
		playerHeight = vasbPlayerHeight;
	}		
}


function readFromURL (strParamName, strDefaultValue) {
	
	// Reads the value of the URL parameter specified by strParamName. If not found, returns strDefaultValue.
	if (location.search.indexOf("?") == -1) return strDefaultValue;
	var arrParams = location.search.split("?")[1].split("&");
	if (arrParams) {
		for (i=0; i < arrParams.length; i++) {
			var param = arrParams[i].split("=");
			if (param[0].toLowerCase() == strParamName.toLowerCase()) {
				return param[1];
			}
		}
	}
	return strDefaultValue;
}


function writePageTitle() {
	
	// Just writes a Title tag
	document.write ('<title>' + cName + ' - ' + eName + '</title>');
}


function dayName (strDate) {
	
	// dayName function - returns string
	// Takes a date in string format and returns a string with the name of the weekday.
	myDays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
	myDate = new Date(strDate);
	return (myDays[myDate.getDay()]);
}


function STX_openBrWindow (theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0

	// Centred Pop Up window New Script
	if(window.screen)if(isCenter)if(isCenter=="true") {
		var myLeft = (screen.width-myWidth)/2;
		var myTop = (screen.height-myHeight)/2;
		var myTop = myTop - 20;
		var myLeft = myLeft -15;
		features+=(features!='')?',':'';
		features+=',left='+myLeft+',top='+myTop;
	}
	window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}


function findAgendaNum (strAgendaAlias) {
		
	// Looks up the Agenda Alias by name and returns the index of the corresponding entry in agAlias[]
	var iAgCounter
	
	for(iAgCounter = 1; iAgCounter <= iNumAgendas; iAgCounter++) {
		if (agAlias[iAgCounter] == strAgendaAlias) {
			return iAgCounter;
		}
	}
	return 0;
}
