// javascript control page
// holds all data and contains all functions to control the movie

//DEFINE THE CONSTANTS

/* define a 2d string indexed array
eg
sitePages[0] = array("id"=>0, "title"=>"Introduction", "pgRef"=>"intro.htm", "colour"=>"", "nav"=>"no")

The colour field indicates the colour scheme to be used in the page - varies with section - and the nav means when on this page should the breadcrumb nav be shown at the top of the screen. The others are obvious
*/

var sitePages	= new Array();		//holds list of ALL pages in the web site

var arr			= new Array();
arr["id"]		= 0;
arr["title"]	= "Choose different route";
arr["pgRef"]	= "journeyChoice.htm";
arr["colour"]	= "";
arr["nav"]		= "no";
sitePages[0]	= arr;

var arr			= new Array();
arr["id"]		= 1;
arr["title"]	= "Full Site Map";
arr["pgRef"]	= "map.htm";
arr["colour"]	= "";
arr["nav"]		= "no";
sitePages[1]	= arr;

var arr			= new Array();
arr["id"]		= 2;
arr["title"]	= "Journey Site Map";
arr["pgRef"]	= "map.htm";
arr["colour"]	= "";
arr["nav"]		= "no";
sitePages[2]	= arr;

var arr			= new Array();
arr["id"]		= 3;
arr["title"]	= "Browse Site Map";
arr["pgRef"]	= "map.htm";
arr["colour"]	= "";
arr["nav"]		= "no";
sitePages[3]	= arr;


var arr			= new Array();
arr["id"]		= 4;
arr["title"]	= "Before you shoot";
arr["pgRef"]	= "before_you_shoot.htm";
arr["colour"]	= "blue";
arr["nav"]		= "yes";
sitePages[4]	= arr;


var arr			= new Array();
arr["id"]		= 5;
arr["title"]	= "Know your story";
arr["pgRef"]	= "know_your_story.htm";
arr["colour"]	= "blue";
arr["nav"]		= "yes";
sitePages[5]	= arr;


var arr			= new Array();
arr["id"]		= 6;
arr["title"]	= "Decide how to tell your story";
arr["pgRef"]	= "decide_how_to_tell_your_story.htm";
arr["colour"]	= "blue";
arr["nav"]		= "yes";
sitePages[6]	= arr;


var arr			= new Array();
arr["id"]		= 7;
arr["title"]	= "Follow your programme style";
arr["pgRef"]	= "follow_your_programme_style.htm";
arr["colour"]	= "blue";
arr["nav"]		= "yes";
sitePages[7]	= arr;


var arr			= new Array();
arr["id"]		= 8;
arr["title"]	= "Choose your kit";
arr["pgRef"]	= "choose_your_kit.htm";
arr["colour"]	= "blue";
arr["nav"]		= "yes";
sitePages[8]	= arr;


var arr			= new Array();
arr["id"]		= 9;
arr["title"]	= "Plan your shoot";
arr["pgRef"]	= "plan_your_shoot.htm";
arr["colour"]	= "blue";
arr["nav"]		= "yes";
sitePages[9]	= arr;


var arr			= new Array();
arr["id"]		= 10;
arr["title"]	= "Film the perfect picture";
arr["pgRef"]	= "film_the_perfect_picture.htm";
arr["colour"]	= "red";
arr["nav"]		= "yes";
sitePages[10]	= arr;


var arr			= new Array();
arr["id"]		= 11;
arr["title"]	= "Focus your camera";
arr["pgRef"]	= "focus_your_camera.htm";
arr["colour"]	= "red";
arr["nav"]		= "yes";
sitePages[11]	= arr;


var arr			= new Array();
arr["id"]		= 12;
arr["title"]	= "Use lenses effectively";
arr["pgRef"]	= "use_lenses_effectively.htm";
arr["colour"]	= "red";
arr["nav"]		= "yes";
sitePages[12]	= arr;

var arr			= new Array();
arr["id"]		= 13;
arr["title"]	= "Frame your picture";
arr["pgRef"]	= "frame_your_picture.htm";
arr["colour"]	= "red";
arr["nav"]		= "yes";
sitePages[13]	= arr;

var arr			= new Array();
arr["id"]		= 14;
arr["title"]	= "Filming movement";
arr["pgRef"]	= "filming_movement.htm";
arr["colour"]	= "red";
arr["nav"]		= "yes";
sitePages[14]	= arr;

var arr			= new Array();
arr["id"]		= 15;
arr["title"]	= "Shoot for continuity";
arr["pgRef"]	= "shoot_for_continuity.htm";
arr["colour"]	= "red";
arr["nav"]		= "yes";
sitePages[15]	= arr;

var arr			= new Array();
arr["id"]		= 16;
arr["title"]	= "Capture what's important";
arr["pgRef"]	= "capture_whats_important.htm";
arr["colour"]	= "red";
arr["nav"]		= "yes";
sitePages[16]	= arr;

var arr			= new Array();
arr["id"]		= 17;
arr["title"]	= "Expose correctly";
arr["pgRef"]	= "expose_correctly.htm";
arr["colour"]	= "red";
arr["nav"]		= "yes";
sitePages[17]	= arr;

var arr			= new Array();
arr["id"]		= 18;
arr["title"]	= "Make the most of available light";
arr["pgRef"]	= "make_the_most_of_available_light.htm";
arr["colour"]	= "red";
arr["nav"]		= "yes";
sitePages[18]	= arr;

var arr			= new Array();
arr["id"]		= 19;
arr["title"]	= "Set white balance";
arr["pgRef"]	= "set_white_balance.htm";
arr["colour"]	= "red";
arr["nav"]		= "yes";
sitePages[19]	= arr;

var arr			= new Array();
arr["id"]		= 20;
arr["title"]	= "Record the sound you want";
arr["pgRef"]	= "record_the_sound_you_want.htm";
arr["colour"]	= "yellow";
arr["nav"]		= "yes";
sitePages[20]	= arr;

var arr			= new Array();
arr["id"]		= 21;
arr["title"]	= "Record clean sound";
arr["pgRef"]	= "record_clean_sound.htm";
arr["colour"]	= "yellow";
arr["nav"]		= "yes";
sitePages[21]	= arr;

var arr			= new Array();
arr["id"]		= 22;
arr["title"]	= "Reduce unwanted noise";
arr["pgRef"]	= "reduce_noise.htm";
arr["colour"]	= "yellow";
arr["nav"]		= "yes";
sitePages[22]	= arr;

var arr			= new Array();
arr["id"]		= 23;
arr["title"]	= "Find sound solutions";
arr["pgRef"]	= "use_the_best_mic.htm";
arr["colour"]	= "yellow";
arr["nav"]		= "yes";
sitePages[23]	= arr;

var arr			= new Array();
arr["id"]		= 24;
arr["title"]	= "Record atmos";
arr["pgRef"]	= "record_atmos.htm";
arr["colour"]	= "yellow";
arr["nav"]		= "yes";
sitePages[24]	= arr;

var arr			= new Array();
arr["id"]		= 25;
arr["title"]	= "Prepare for the edit";
arr["pgRef"]	= "prepare_for_the_edit.htm";
arr["colour"]	= "green";
arr["nav"]		= "yes";
sitePages[25]	= arr;

var arr			= new Array();
arr["id"]		= 26;
arr["title"]	= "Review what you've got";
arr["pgRef"]	= "review_what_youve_got.htm";
arr["colour"]	= "green";
arr["nav"]		= "yes";
sitePages[26]	= arr;

var arr			= new Array();
arr["id"]		= 27;
arr["title"]	= "Log and rough cut your shots";
arr["pgRef"]	= "log_your_shots.htm";
arr["colour"]	= "green";
arr["nav"]		= "yes";
sitePages[27]	= arr;


/** this should always be the last page in the array **/
var arr			= new Array();
arr["id"]		= 28;
arr["title"]	= "Practice";
arr["pgRef"]	= "complete.htm";
arr["colour"]	= "";
arr["nav"]		= "no";
sitePages[28]	= arr;



//define the journeys
var journeyArray	= new Array();
journeyArray[0]		= new Array(8,21,22,23,24,27);			//sound need improving
journeyArray[1]		= new Array(8,17,18,19);				//light look good
journeyArray[2]		= new Array(5,6,7,14,15,16,21,22);		//shots dont cut together
journeyArray[3]		= new Array(5,6,7,8,9,16,26,27);		//run out of time
journeyArray[4]		= new Array(8,11,12,17,18,19);				//cameras
journeyArray[5]		= new Array(6,9,16,15,21);				//90 second challenge



//define the jouney names
var journeyNameArray	= new Array();
journeyNameArray[0]	= "Improve your sound";
journeyNameArray[1]	= "Make the available light look good";
journeyNameArray[2]	= "Ensure your shots cut together";
journeyNameArray[3]	= "Make the best use of time";
journeyNameArray[4]	= "Understand cameras better";
journeyNameArray[5]	= "90 second challenge, pre-workshop topics";


exploreDescription	= "Explore the course from here. Click a topic to start. Click ‘Home’ to select a different route.";
fullDescription		= "Work through the whole course from here. We recommend taking breaks in between sections. Your progress will be remembered if you leave the course part way through. Click ‘Start’ to begin, or ‘Home’ to change your route.";
fullDescriptionReturn	= "Welcome back to the whole course. Your progress from last time has been saved. Click 'Continue' to carry on where you left off. Click 'Home' to select a different route.";


/** emulate inbuilt push function for old browsers **/
if (Array.prototype.push == window.undefined) {
	Array.prototype.push = function() {
	for (var i = 0; i < arguments.length; i++)
	this[this.length] = arguments[i];
	return this.length;
	}
}



// define the sections
var sectionArray	= new Array();
sectionArray[0]		= new Array(4,5,6,7,8,9);						//before you shoot
sectionArray[1]		= new Array(10,11,12,13,14,15,16,17,18,19);		//film the perfect picture
sectionArray[2]		= new Array(20,21,22,23,24);					//record the sound you want
sectionArray[3]		= new Array(25,26,27);							//prepare for the edit

//define the full path through the site (ie all pages in section order)
var fullArray	= new Array();



for (var a=0; a<sectionArray.length; ++a) {
	for (var b=0; b<sectionArray[a].length; ++b) {
		//fullArray[k] =sectionArray[a][b];
		fullArray.push( sectionArray[a][b] );
	}
}

//define the colour schemes


var yellow = new Array();

yellow["highlight"] = "#b8a209";
yellow["clight"] = "#635920";			//content light (features + tips box)
yellow["cdark"] = "#423c27";			//content dark (intro box)
yellow["blight"] = "#9b8b21";			//button light (arrow bit)
yellow["bdark"] = "#423c27";			//button dark (text bit)
yellow["txtdark"] = "#66614e";			//text dark
yellow["border"] = "#b1ac90";			//tab border
yellow["tabBackground"] = "#736A37";		//background colour of second tab option
yellow["boxCorner"] = "#8A7A18";		//colour of the little fold-up corner thingy
// 	MAP Colours	//
yellow["mapHighlightBG"] = "#A69112";		//background highlight colour for Map
yellow["mapHeadBG"] = "#7A6C1C";		//background colour of section head for map
yellow["mapSectionBG"] = "#645920";		//background colour of a section block for map
yellow["mapSectionVisitedBG"] = "#423C27";	//background colour of a visited section block for map
yellow["mapHighlightText"] = "#FFFFFF";		//text highlight colour for Map
yellow["mapHeadText"] = "#BDB68E";		//text colour of section head for map
yellow["mapSectionText"] = "#6D1CEBD";		//text colour of a section block for map
yellow["mapSectionVisitedText"] = "#686352";	//text colour of a visited section block for map



var blue = new Array();
blue["highlight"] = "#076f9f";
blue["clight"] = "#174361";
blue["cdark"] = "#1c3147";
blue["blight"] = "#1c668d";
blue["bdark"] = "#1c3147";
blue["txtdark"] = "#495a6c";
blue["border"] = "#8ba1b0";
blue["tabBackground"] = "#2F5671";
blue["boxCorner"] = "#1D577C";
// MAP Colours
blue["mapHighlightBG"] = "#0D6693";
blue["mapHeadBG"] = "#144F71";
blue["mapSectionBG"] = "#174361";
blue["mapSectionVisitedBG"] = "#1C3147";
blue["mapHighlightText"] = "#FFFFFF";
blue["mapHeadText"] = "#8AA7B8";
blue["mapSectionText"] = "#BAC7D0";
blue["mapSectionVisitedText"] = "#495A6C";

var red = new Array();
red["highlight"] = "#ad1e2d";
red["clight"] = "#5f2130";
red["cdark"] = "#3f202f";
red["blight"] = "#932c3b";
red["bdark"] = "#3f202f";
red["txtdark"] = "#654d59";
red["border"] = "#af9098";
red["tabBackground"] = "#6F3845";
red["boxCorner"] = "#782B3D";
// MAP Colours
red["mapHighlightBG"] = "#9B2131";
red["mapHeadBG"] = "#732130";
red["mapSectionBG"] = "#5F2130";
red["mapSectionVisitedBG"] = "#3F202F";
red["mapHighlightText"] = "#FFFFFF";
red["mapHeadText"] = "#B99098";
red["mapSectionText"] = "#CFBDC1";
red["mapSectionVisitedText"] = "#654D59";


var green = new Array();
green["highlight"] = "#0b7348";
green["clight"] = "#19453b";
green["cdark"] = "#1d3235";
green["blight"] = "#1f694f";
green["bdark"] = "#1d3235";
green["txtdark"] = "#4a5b5d";
green["border"] = "#8ca29d";
green["tabBackground"] = "#30584F";
green["boxCorner"] = "#145B43";
// MAP Colours
green["mapHighlightBG"] = "#116A48";
green["mapHeadBG"] = "#165140";
green["mapSectionBG"] = "#19453B";
green["mapSectionVisitedBG"] = "#1D3235";
green["mapHighlightText"] = "#FFFFFF";
green["mapHeadText"] = "#8BA8A0";
green["mapSectionText"] = "#BAC8C5";
green["mapSectionVisitedText"] = "#4A5B5D";



//define a string indexed array to hold all the colour schemes
var colourArray = new Array();
colourArray["yellow"] = yellow;
colourArray["blue"] = blue;
colourArray["red"] = red;
colourArray["green"] = green;



//DEFINE THE VARIABLES

//holds the pages to be viewed - defaults to the 'introduction' and the 'how do you wanna browse' pages
var pageArray	= new Array();

// add some general properties
var currentPageNum	= 0;				// number of current page
var contentFrame	= parent.content;	//just a shortkut to the main content frame
var browseType;							//container for the browse type (ie. journey, full course, browse, etc);
var browseTypeIndex;					//which journey the user has requested
var browseTypeArray	= new Array;		//holds the array according to the browseType and index, ie journeyArray[index] or sectionArray[index]
var	firstPageIndex	= 0;				//pageArray index for the first page in the user path through the site
var	lastPageIndex;						//pageArray index for the last page in the user path through the site. Changes as the user navigates
var currentShowNav = "no";				//current layout (fat or thin crumbtrail frame)
var journeyName;				// holds the current journey name

var lastPageNum	='';			//holds the last place; return to this 	
var lastPageArray = new Array;

function getNav(){

	//called by footer.htm when it loads/is refreshed
	lastPageIndex		= pageArray.length-1;
	var navString		= "";

	var nextLightBgColStr	= " bgcolor=\"#9c9ba1\"";
	var nextDarkBgColStr	= " bgcolor=\"#74737c\"";
	var prevLightBgColStr	= " bgcolor=\"#9c9ba1\"";
	var prevDarkBgColStr	= " bgcolor=\"#74737c\"";

	var buttonText ;
	var curPage =  contentFrame.mainContent.location.pathname;
	curPage =  curPage.substring( curPage.lastIndexOf('/', curPage.length) +1, curPage.length);

	//check for full course progress cookie
	if ( ( browseType == 'full' ) && ( curPage == 'map.htm' ) ){
		getProgressFromCookie( getCookie("fcp") );
	}

	//return  cookie memory - make sure that this only appears for the right browse type
	if (  lastPageArray['pgRef'] != window.undefined ) {
	  if ( lastPageArray["browseType"] == browseType && lastPageArray["browseTypeIndex"]  == browseTypeIndex){

		if (lastPageArray['colour']>"") {
			eval("var nextLightCol = " + lastPageArray['colour'] + "['blight'];");
			nextLightBgColStr = " bgcolor='" + nextLightCol + "'";
			eval("var nextDarkCol = " + lastPageArray['colour'] + "['bdark'];");
			nextDarkBgColStr = ' bgcolor="' + nextDarkCol + '"';
			}	
			
		if  ( ( browseType == 'full' ) && ( getCookie("fcp") != null )  && ( curPage == 'map.htm' ) ) { buttonText= 'Continue'; }  else {  buttonText =lastPageArray["title"]}
		navString += '<td class="footerCell" width="100"' + nextDarkBgColStr + '><span class="footerButton"><a href="javascript: cPage.goBack();">' + buttonText + '</a></span></td><td class="footerCell" width="30"' + nextLightBgColStr + '><a href="javascript: cPage.goBack();"><img src="images/next_'+lastPageArray["colour"]+'.gif" border="0" alt="" width="14" height="15" /></a></td>';
		return navString;	
		}
	}
	
	//back button
	if((currentPageNum > firstPageIndex) &&( currentPageNum>2 ) ){

		if (pageArray[currentPageNum-1]['colour']>"") {
			eval("var prevLightCol = " + pageArray[currentPageNum-1]['colour'] + "['blight'];");
			prevLightBgColStr = " bgcolor='" + prevLightCol + "'";
			eval("var prevDarkCol = " + pageArray[currentPageNum-1]['colour'] + "['bdark'];");
			prevDarkBgColStr = ' bgcolor="' + prevDarkCol + '"';
		}
		navString += "<td class='footerCell' width='30'" + prevLightBgColStr + "><a href='javascript:cPage.prevPage();'><img src='images/back_"+pageArray[currentPageNum-1]['colour']+".gif' border='0' alt='' width='14' height='15' /></a></td><td class='footerCell' width='100'" + prevDarkBgColStr + "><span class='footerButton'><a href='javascript:cPage.prevPage();'>" + pageArray[currentPageNum-1]['title'] + "</a></span></td>";
	}
	
	//forward button
	if(currentPageNum < lastPageIndex){

		if (pageArray[currentPageNum+1]['colour']>"") {
			eval("var nextLightCol = " + pageArray[currentPageNum+1]['colour'] + "['blight'];");
			nextLightBgColStr = " bgcolor='" + nextLightCol + "'";
			eval("var nextDarkCol = " + pageArray[currentPageNum+1]['colour'] + "['bdark'];");
			nextDarkBgColStr = ' bgcolor="' + nextDarkCol + '"';
		}
		
		buttonText = pageArray[currentPageNum+1]["title"];
		if   ( currentPageNum==1){  buttonText= 'Start'; }
		navString += '<td class="footerCell" width="100"' + nextDarkBgColStr + '><span class="footerButton"><a href="javascript:cPage.nextPage();">' + buttonText + '</a></span></td><td class="footerCell" width="30"' + nextLightBgColStr + '><a href="javascript:cPage.nextPage();"><img src="images/next_'+pageArray[currentPageNum+1]['colour']+'.gif" border="0" alt="" width="14" height="15" /></a></td>';
	}

	return navString;
}

function nextPage(){

	//called by footer.htm when the next button is clicked
	currentPageNum++;
	recordProgress( currentPageNum );
	addUniqueToCookieArray("pageHistory", pageArray[currentPageNum]['pgRef']);
	 refreshPage();
}

function prevPage(){
	//called by footer.htm when the back button is clicked
	currentPageNum--;
	recordProgress(currentPageNum  );
	refreshPage();
	
}

function refreshPage(){
	if(!checkFrameLayout()){
		checkSrc();
		// refresh the crumbtrail and footer frames
		contentFrame.crumbTrail.location.href = contentFrame.crumbTrail.location.href;
		contentFrame.footer.location.href = contentFrame.footer.location.href;
	}
}


function getArrayFromIndex(parent, id) {		//takes a 2d array and the index of the reqd subArray and returns the subArray
	var child = new Array;
	for (var i=0; i<parent[id].length; ++i) {
		child[i] = parent[id][i];
	}
	return child;
}


function findArrayIndex(parent, id) {	//searches childArrays of a 2d array for a value and returns the id of the parent array
	for (var i=0; i<parent.length; ++i) {
		var child = parent[i];
		for (var j=0; j<child.length; ++j) {
			if (child[j]==id) {
				return i;
			}
		}
	}
}


function callPage(sitePageId) {	//receives the id of the page selected
	//only used from the 'explore' and 'text' map pages, this fn resets the pageArray and loads up the page requested (or the entire section if the browseType is 'full' and the section header page has been selected)
	initPageType();		

		lastPageArray = new Array;
		pageArray.push( sitePages[3]  );				//'explore' map page
		pageArray.push(sitePages[sitePageId]);		//page selected
		
	nextPage();
	
}

function loadTextMap(){
		//load the text version map ;
		initPageType();		
		browseType="text" ;		
		pageArray.push(sitePages[3]  );				//'explore' map page
		nextPage();
}


function isOnline(){
	//check to see if this is running off line or online //
	var d = document.location;
	var s = new String(d);
	
	if ( d.protocol == 'http:' ) {
		if ( s.indexOf( 'bbc.co.uk', 0) > 0 ){	return true; }
	} 
	
	return false;
}

function  initFullJourney( index ){

		// called by map.htm
		initPageType();	// init the array;
		pageArray.push(sitePages[1]);	//add the map to page array

		if ( index== window.undefined){
			fullJourneySetup( fullArray[0] ); //setup the full journey
		} else {
			fullJourneySetupByIndex(  index ); //setup the journey for a particluar section only
		}
}


function fullJourneySetup(sitePageId  ){
		//called by callPage()  to set up the full journey inorder with the correct top nav bar
		// called by initFullJourney() 
		
		//load the entire section into the pageArray
		var sectionId = findArrayIndex(sectionArray, sitePageId);	//gets the page ids for the section that sitePageId is in
		//var pageIds = getArrayFromIndex(sectionArray, sectionId);	//gets the page ids for the section that sitePageId is in
		var nextPageIndex = pageArray.length;
		for (var i=0; i<fullArray.length; ++i) {
			var pageId = fullArray[i];
			pageArray[nextPageIndex] = sitePages[pageId];			//append the pages
			++nextPageIndex;
		}
		pageArray.push(sitePages[sitePages.length-1]);				// add complete page
		browseTypeArray = new Array();
		browseTypeArray = sectionArray[sectionId];					//add the elements for the top nav
}


function fullJourneySetupByIndex( index ){
	// called by initFullJourney()  
	//setup the journey for a particluar section only
	
	browseTypeArray = new Array();
	browseTypeArray = sectionArray[ index ];	
	//load the entire section into the pageArray
	for(var i=0; i<browseTypeArray.length; i++){
		pageArray.push(sitePages[browseTypeArray[i]]);
	}
	pageArray.push(sitePages[sitePages.length-1]);				// add complete page			 
}


function goBack(){	

	// go back to the current map index page //
	var mapType = lastPageArray["browseType"];
	var mapTypeindx = 0;
	var retURL = lastPageArray['pgRef'];

	if ( retURL != '' ){

		if( mapType != '' && mapType != window.undefined){ mapType=browseType; }
		if( browseTypeIndex != window.undefined){ mapTypeindx = browseTypeIndex; }
	
		if (mapType =='explore'){
			currentPageNum = 1;
			callPage(  lastPageArray['id']  );
		}
	
		if (mapType =='journey'){
			currentPageNum = lastPageArray['pageNum'];
			checkSrc();
			refreshPage();
		}
	
		if (mapType =='full'){
			currentPageNum = lastPageArray['pageNum'];
			initFullJourney();
			checkSrc();
			refreshPage();				
		}
		
		//reset array
		lastPageArray = new Array;

	} else { 
		top.location.reload();
	}

}



function goBackToMap(){
	// go back to the current map index page //
	var mapType = 'explore';
	var mapTypeindx = 0;
	
	if( mapType != '' && mapType != window.undefined){ mapType=browseType; }
	if( browseTypeIndex != window.undefined){ mapTypeindx = browseTypeIndex; }
	
	if (  currentPageNum +1 >= pageArray.length  ){
		//dont remember the last page
		lastPageArray = new Array();
	} else if ((mapType =='full' || mapType =='journey')  ){
		lastPageArray = new Array();
		lastPageArray = pageArray[ currentPageNum ];
		lastPageArray["pageNum"] =  currentPageNum; // add page num
		lastPageArray["browseType"] =  browseType; //add brows type
		lastPageArray["browseTypeIndex"] = browseTypeIndex;
	}
	
	currentPageNum = 0;
	setBrowseType( mapType , browseTypeIndex);
}


function openExercise(url , id ) {
	//set cookie
	addUniqueToCookieArray("featuresHistory", url);		//store the feature visited
	
	//change image as 'visted'
	dynamicVisitedIcon(id);
	
	//open pg
	if(url.split("/")[0] == "flash"){ //if its a flash file the window needs to be a little smaller
		var featureWin = window.open(url, "featureF", "toolbar=no,status=no,menubar=no,location=no,scrollbars=no,resizable=no,height=373,width=622");	
	} else {
		var featureWin = window.open(url, "feature", "toolbar=no,status=no,menubar=no,location=no,scrollbars=yes,resizable=no,height=401,width=697");	
	}

}


function dynamicVisitedIcon( id ){
	// called by openExercise //
	// changes the icon to visted state //
	var currentColour= pageArray[currentPageNum]["colour"]
	var visitedFeature = contentFrame.mainContent.document.getElementById("visited"+id);
	if ( visitedFeature && currentColour != window.undefined ) {
		visitedFeature.innerHTML = '<img src="images/viewed_' + currentColour + '.gif">';
	}
	
}	


function setBrowseType(type, index){
	//called by journeyChoice.htm when user chooses how they want to browse course
	browseType = type;	//eg "journey", "full", "explore"
	initPageType();		//reset the pageType array so previous paths through the site are erased

	var k = pageArray.length;


	if (index!=window.undefined) {
		browseTypeIndex = index;
	} 
	
	if (browseType=="journey") {		//follow a journey

		pageArray.push(sitePages[2]);	//add the map to page array
		browseTypeArray	= journeyArray[browseTypeIndex];
		journeyName = journeyNameArray[browseTypeIndex];

	}
	else if (browseType=="full") {		//follow all section in sequence
		pageArray.push(sitePages[1]);	//add the map to page array
		if ( index == null  || index == window.undefined){ index =0; }
		browseTypeArray	= sectionArray[index]; //add the first nav thingy
		journeyName = "full course";		
	}
	else {								//explore the entire list
		pageArray.push(sitePages[3]);	//add the map to page array
	}
	

	for(var i=0; i<browseTypeArray.length; i++){
		pageArray.push(sitePages[browseTypeArray[i]]);
	}
	
	//add finalPage//
	if (browseType=="journey") {	
		pageArray.push(sitePages[sitePages.length-1]);
	}
	nextPage();
}




function checkFrameLayout(){
	var showNav	= pageArray[currentPageNum]["nav"];
	if(currentShowNav != showNav){
		currentShowNav = showNav;
		if((showNav=="no") || (browseType=="explore") || (browseType=="text")  ){
			contentFrame.location.replace( "frame_intro_nonav.htm");
			
		} else {
			contentFrame.location.replace("frame_intro.htm");
		}
		return true;
	}
}

function checkSrc(){

	

	//called by blank.htm (the default page loaded into a new frameset
	var pgRef ='';
	if ( ! parseInt(currentPageNum) ){ currentPageNum = 0 };

	if ( browseType=="text" && currentPageNum > 1 ){ 
		pgRef = 'text/'+pageArray[currentPageNum]["pgRef"]; 
		//pgRef = replaceStr( pgRef, '.xml', '.htm' );
	} else { 
		pgRef = pageArray[currentPageNum]["pgRef"]; 
	}

	if(contentFrame.mainContent.location.href != pgRef) {
		contentFrame.mainContent.location.replace( pgRef );

	}
}


function replaceStr( src, inStr , outSrc ){
	var myString = new String(src);
	var rExp = eval('/'+inStr+'/gi');
	var newString = new String (inStr);
	var results = myString.replace(rExp, outSrc);
	return results;
}


function printPage(){
	var w = contentFrame.mainContent;
	if (w.focus){ w.focus(); }  
	if (w.print) { 
		w.print();  
	} else {
		var agt=navigator.userAgent.toLowerCase();
		var is_mac    = (agt.indexOf("mac")!=-1);
		var msg = "Your browser does not support automatic printing\n ";
		if ( is_mac )  { msg += "Please press APPLE(COMMAND)+P buttons"; }
		else { msg += "Please use the button on your browser"; }
		alert(msg); 
	}

}



function recordProgress( pID ){
	//record full course progress
	
	if ( browseType=="full" ){
		var cur = parseInt( pID );

		if (cur >=pageArray.length -1){
			setCookie("fcp", null);
		} else if ( cur > 1 ){
			setCookie("fcp", pID);
		}
	}

}



function getProgressFromCookie( pageID ){

			var p = parseInt(pageID);

			//get the section				
			var sectionId = findArrayIndex( sectionArray, p );
					
			//get the top nav browser id array
			if ( sectionId != null && sectionId != window.undefined){
			
				browseTypeArray = new Array;
				browseTypeArray = sectionArray[sectionId];

				lastPageArray = new Array;
				lastPageArray = sitePages[ p +2]
				lastPageArray["pageNum"] = p;
				lastPageArray["browseType"] = 'full';

				
			}
	
}


function initPageType() {
	pageArray		= new Array(); //pageArray index for the first page in the user path through the site
	browseTypeArray = new Array();	
	//browseTypeIndex = null
	pageArray[0]	= sitePages[0];	
}


function init(){
	contentFrame.location.replace("frame_intro_nonav.htm");

}




//call the following the first time the page loads
init();
initPageType();