//--PREPARE/EXECUTE CONTENT--//
function init_page(index){
	 //var counter=0;

	 //set content page based on current index value
           top.content.location=top.page_list[top.page_index];
	   top.page_number = index+1;
	   page_num = top.page_number;
	   setDisplay(page_num);
	   //page_title = top.title_list[index];
	   if ((index==0) && (index!=(top.page_list.length)-1)){
	      setNavigation("back_disabled");}
	   if ((index>0) && (index<(top.page_list.length)-1)){
	      setNavigation("all_enabled");}
	   if ((index>0) && (index==(top.page_list.length)-1)){
	      setNavigation("next_disabled");}
	   if ((index==0) && (index==(top.page_list.length)-1)){
	      setNavigation("all_disabled");}
	   
	   if (top.debugState=="TRUE"){
	      showSB();}
	   else{
	      hideSB();}
	 }



function setNavigation(status){
	 //check value of status and set button states accordingly
	   switch(status){
	     case "back_disabled":
	          top.document.forward_button.src=top.forward_image;
		  top.forward_active="TRUE";	
		  top.document.back_button.src=top.back_inactive;
		  top.back_active="FALSE";
	   	  break;
	     case "all_enabled":
		  top.document.forward_button.src=top.forward_image;
		  top.forward_active="TRUE";
		  top.document.back_button.src=top.back_image;
		  top.back_active="TRUE";
		  break;
	     case "next_disabled":
		  top.document.forward_button.src=top.forward_inactive;
		  top.forward_active="FALSE";
		  top.document.back_button.src=top.back_image;
		  top.back_active="TRUE";
		  break;
	     case "all_disabled":
		  top.document.forward_button.src=top.forward_inactive;
		  top.forward_active="FALSE";
		  top.document.back_button.src=top.back_inactive;
		  top.back_active="FALSE";
		  break;}
	 }



function setDisplay(page_num){
	//update cell contents for title and page number
 	//top.menubar.title_cell.innerHTML="&nbsp"+"&nbsp"+page_title;
	//top.menubar.pageNum_cell.innerHTML="&nbsp"+"&nbsp"+"Page "+page_num+" of "+top.page_list.length;
	  top.pageNum_cell.innerHTML="Page "+page_num+" of " +top.page_list.length;
	}



function go_next(){
	 //no action if at the end of a lesson or on interaction page, otherwise increment index and refresh content
	   if (top.page_number==top.page_list.length){
	      }
	   else{
              top.page_index++;
	      init_page(top.page_index);
	   }
	 }



function go_back(){
	 //no action if at the beginning of a lesson, otherwise decrement index and refresh content
	   if (top.page_index==0){
	      }
	   else{	
	      top.page_index--;
	      init_page(top.page_index);
	   }
	 }



function setDebug(){
	 //toggle 'debug' button on and off
	   if (top.debugState=="FALSE"){
	      top.debugState="TRUE";
	      showSB();}
	   else{
	      top.debugState="FALSE";
	      hideSB();}
	 }



function showSB(){
	//display storyboard# in navigation frame/table cell
	top.debug_cell.innerHTML=top.page_list[top.page_index];
	}



function hideSB(){
	//display blank in navigation frame/table cell
	top.debug_cell.innerHTML="";
	}



//Rollover functions
function closeRollover(){
         document.close_button.src="../media_interface/book_close_o.gif";
	 }


function closeRollout(){
         document.close_button.src="../media_interface/book_close.gif";
	 }


function forwardRollover(){
         if (forward_active=="TRUE"){
	    document.forward_button.src=forward_over_image;
	    document.forward_button.style.cursor="hand";}
         else{
	    document.forward_button.style.cursor="default";}
         }


function forwardRollout(){
         if (forward_active=="TRUE"){
	    document.forward_button.src=forward_image;
	    document.forward_button.style.cursor="default";}
         }


function backRollover(){
         if (back_active=="TRUE"){
	    document.back_button.src=back_over_image;
 	    document.back_button.style.cursor="hand";}
         else{
	    document.back_button.style.cursor="default";}
         }


function backRollout(){
         if (back_active=="TRUE"){
	    document.back_button.src=back_image;
	    document.back_button.style.cursor="default";}
         }



//--COMMUNICATE WITH BROWSER WINDOW--//

function resizeme()
 {
    window.resizeTo(800,600);
 }



function moveme()
   {
   //moveTo(((screen.width)-800)/2,((screen.height)-600)/2);
     moveTo(15,155);
   }



function popup(page){
     windowprops = "location=no,"
     + "scrollbars=yes,menubar=no,directories=no,titlebar=yes,status=no,resizable=no,height=500, width=600";
	var new_window=window.open(page, "_blank", windowprops)
         if (new_window.opener == null)   {
            new_window.opener = self
          }
	new_window.focus();
	window.name="page";
}



function launch(lesson, title){
     windowprops = "location=no,"
     + "scrollbars=no,menubar=no,directories=no,titlebar=no,status=no,resizable=no,height=440, width=743";
	var new_window=window.open(lesson, title, windowprops)
         if (new_window.opener == null){
            new_window.opener = self
          }
	new_window.focus();
	//window.name="lesson";
}




function openWin(lesson, height, width){
   var xTop = screen.width/2 - (width/2);
   var yTop = screen.height/2 - (height/2);

   //windowprops = "location=no,"
   //+ "scrollbars=no,menubar=no,directories=no,titlebar=yes,status=yes,resizable=no, left=' + xTop + ',top=' + yTop + ', height=600, width=600";
   var new_window=window.open(lesson, "_blank", 'height='+height+',width='+width+',scrollbars=0,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,left=' + xTop + ',top=' + yTop + '');
       if (new_window.opener == null){
          new_window.opener = self
       }
   new_window.focus();
   //window.name="lesson";
}



var page;
function redirect(page){
	 top.window.opener.location=page;
	 top.self.close();
}

