// JavaScript Document

function changePage(int_currentPage, int_nextPage){
	
	if(int_currentPage=="01"){
		$("#div_navigation").hide("slow");
		$("#screen").hide("slow");
		$("#currentstatus").hide("slow");
	}
	else if(int_currentPage=="02"){
		/*
		$("#div_navigation").hide("slow");
		$("#screen").hide("slow");
		$("#currentstatus").hide("slow");
		*/
	}
	
	window.location = "display" + int_nextPage + ".html";
}

function loadContent(int_currentPage){
		if(int_currentPage=="01"){
			$("#div_navigation").show("slow");
			$("#screen").show("slow");
			$("#currentstatus").show("slow");
		}
		else if(int_currentPage=="02"){
			$("#div_mainMenu").show("slow");
		}
	}

$(document).ready(function(){
	
	updateNavigation();
		
	$("#nav01").click(function () { 
      resetAll();
	  $("#nav01").hide();
	  $("#nav01_on").slideDown("slow");
	  changeContent('1','0');
    });
	
	$("#nav02").click(function () { 
      resetAll();
	  $("#nav02").hide();
	  $("#nav02_on").slideDown("slow");
	  changeContent('2','0'); 
    });
	
	$("#nav03").click(function () { 
      resetAll();
	  $("#nav03").hide();
	  $("#nav03_on").slideDown("slow");
	  changeContent('3','0'); 
    });
	
	$("#nav04").click(function () { 
      resetAll();
	  $("#nav04").hide();
	  $("#nav04_on").slideDown("slow");
	  changeContent('4','0'); 
    });
	
	$("#nav05").click(function () { 
      resetAll();
	  $("#nav05").hide();
	  $("#nav05_on").slideDown("slow");
	  changeContent('5','0'); 
    });
	
	
  });

  function updateNavigation(){
	var int_module = $.cookie('respect_module');
	var int_topic = $.cookie('respect_topic'); 
	
	
	$("#imgStatus" + int_module + int_topic).attr({ src: "images/equals.png", alt: "Current Position" }); 
	
	//alert("int_module: " + int_module);
	
	for(var x=1; x<6; x++){
	
		if(x<=int_module){
			$("#a"+x+"0_off").hide();
			$("#a"+x+"1_off").hide();
			$("#a"+x+"2_off").hide();
			$("#a"+x+"3_off").hide();
			$("#a"+x+"x_off").hide();
		}
		else if(x==int_module){

			$("#a"+x+"0_off").hide();
			
			for(var y=1; y<4; y++){
				if(y<(int_topic)){
					$("#a" + x + y + "_off").hide();	
				}
				else{
					$("#a" + x + y + "_on").hide();	
				}
			}
			
			if(int_topic=="x"){
				$("#a" + x + "x_off").hide();	
			}
			else{
				$("#a" + x + "x_on").hide();	
			}
			
		}
		else if(x>int_module){
			$("#a"+x+"0_on").hide();
			$("#a"+x+"1_on").hide();
			$("#a"+x+"2_on").hide();
			$("#a"+x+"3_on").hide();
			$("#a"+x+"x_on").hide();		
		}
	}
	$("#imgStatus" + int_module + int_topic).attr({ src: "images/equals.png", alt: "Current Position" });
	$("#a"+int_module + int_topic + "_off").hide();
	$("#a"+int_module + int_topic + "_on").show();
}
  
  function resetAll(){
  
	$("#nav01_on").hide();
	$("#nav02_on").hide();
	$("#nav03_on").hide();
	$("#nav04_on").hide();
	$("#nav05_on").hide();
	
	$("#nav01").show();
	$("#nav02").show();
	$("#nav03").show();
	$("#nav04").show();
	$("#nav05").show();
  }
  
  function changeContent(mod, topic){
	  
  		//alert("mod: " + mod + ", topic:" + topic);
  		var html_flash = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"399\" height=\"314\" id=\"content\" align=\"middle\">";
  			html_flash = html_flash + "<param name=\"allowScriptAccess\" value=\"always\" />";
  			if($.cookie('respect_lang')=="sesotho"){
				html_flash = html_flash + "<param name=\"movie\" value=\"swfs/sesotho/" + mod + "_" + topic + ".swf\" />";
			}
			else{
				
				html_flash = html_flash + "<param name=\"movie\" value=\"swfs/" + mod + "_" + topic + ".swf\" />";
			}
			html_flash = html_flash + "<param name=\"quality\" value=\"high\" />";
			html_flash = html_flash + "<param name=\"bgcolor\" value=\"#000000\" />";
			if($.cookie('respect_lang')=="sesotho"){
				html_flash = html_flash + "<embed src=\"swfs/sesotho/" + mod + "_" + topic + ".swf\" quality=\"high\" bgcolor=\"#000000\" width=\"399\" height=\"314\" name=\"content\" align=\"middle\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
			}
			else{
				html_flash = html_flash + "<embed src=\"swfs/" + mod + "_" + topic + ".swf\" quality=\"high\" bgcolor=\"#000000\" width=\"399\" height=\"314\" name=\"content\" align=\"middle\" allowScriptAccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
			}
		html_flash = html_flash + "</object>";
		//html_flash = html_flash + "<p><a href=\"#\" onclick=\"changeContent('" + mod + "', '" + topic + "')\"><img src=\"images/back.png\" border=\"0\" title=\"Back to start of this topic\"  /></a>"; 
		//html_flash = html_flash + " <a href=\"#\" onclick=\"pausePlayFlash()\"><img src=\"images/pause.png\" border=\"0\" title=\"Pause\" /></a></p>";
		
  		$("#screen").html(html_flash);
		  		
  }
  
  function getCurrentPostion(){
		
		var int_module = $.cookie('respect_module');
		var int_topic = $.cookie('respect_topic'); 
		
		if(int_module!=null){
		
			var str_returnHTML = "";
		
			var str_module = arr_modules[int_module-1];
			
			var arr_currentModule = new Array();
			
			if(int_module=="1"){
				arr_currentModule = arr_module_01;	
			}
			else if(int_module=="2"){
				arr_currentModule = arr_module_02;
			}
			else if(int_module=="3"){
				arr_currentModule = arr_module_03;
			}
			else if(int_module=="4"){
				arr_currentModule = arr_module_04;
			}
			else if(int_module=="5"){
				arr_currentModule = arr_module_05;
			}
			
			var str_topic = arr_currentModule[int_topic];
			
			str_topic = "Summary"; //TEMP
			
			str_returnHTML = "<span style=\"font-weight:bold;\">Your furthest position: </span>"; 
			str_returnHTML = str_returnHTML + "<a href=\"#\" onClick=\"dropDownMenu(" + int_module + ")\" class=\"aNavMod\">" + str_module + "</a> > <a href=\"#\" onClick=\"displayTopic(" + int_module + "," + int_topic + ")\" class=\"aNavTop\">" + str_topic + "</a>";
			document.write(str_returnHTML);
		}
  }
  
  function displayTopic(int_module, int_topic){
	  resetAll();
	  $("#nav0" + int_module).hide();
	  $("#nav0" + int_module + "_on").slideDown("slow");  
  	  changeContent(int_module, int_topic);	
  }
  
  function dropDownMenu(int_module){
		
	  resetAll();
	  $("#nav0"+ int_module).hide();
	  $("#nav0" + int_module + "_on").slideDown("slow");
	  changeContent('1','0');	
		
  }
  
  function startApp(){
	  
	  if($.cookie('respect_module')==null){
		  $.cookie('respect_module', '1');
		  $.cookie('respect_topic', '0'); 
	  }
	  updateNavigation();
	
	  resetAll();
	  $("#nav0" + $.cookie('respect_module')).hide();
	  $("#nav0" + $.cookie('respect_module') + "_on").slideDown("slow");
	  changeContent($.cookie('respect_module'), $.cookie('respect_topic'));
	  
		
  }
  
  function pausePlayFlash()
  {
		document.getElementById("bcPlayer").pausePlay();
  }
