//navscript.js

//handles showing and hiding subsections

var sectionname = new Array();

function defineglobalvariables()
{   
// define two arrays. noneorblock contains the show or hide (block or none) status for
// each of the 9 sections (numbered 0 through 8). sectionname contains the
// id's of the sections. the id's are just strings that name each section.
// the noneorblock array will be referenced by the sectionname rather than directly
// by an index. you can reference it indirectly by an index by using the sectionname
// array. this will be useful in the showorhide function which gets the id of the section
// as a string. noneorblock will have all elements initialized to none. this means you 
// don't need to have each sections display property set in the css file since javascript
// is doing this when navigationpage.html loads. same goes for the buttonstatus array.

//   alert('defining global variables in navscript.js');
   
   sectionname[0] = "algebra";
   sectionname[1] = "geometry";
   sectionname[2] = "units";
   sectionname[3] = "statistics";
   sectionname[4] = "numbertheory";
   sectionname[5] = "reading";
   sectionname[6] = "logic";
   sectionname[7] = "sequences";
   
}   

var globalwhichchange;

function changeall(whichchange)
{
   globalwhichchange = whichchange;
   changealluseglobal();
}

var numberofchangealluseglobaltries = 0;

function changealluseglobal()
{
   if (numberofchangealluseglobaltries>20) {return;}
   
   var loaded = false;
   loaded = top.allframes_loaded();
   
   if (!loaded) 
   {
      numberofchangealluseglobaltries++;
      setTimeout('changealluseglobal()',200);
      return;
   }
   numberofchangealluseglobaltries = 0;
   
   //now okay to do the function
   
   for (var index=0; index<8; index++)
   {
      document.getElementById(sectionname[index]).style.display = globalwhichchange;
   }
   
   if (globalwhichchange == "none")
   {
      document.getElementById('openbutton').style.display = "inline";
      document.getElementById('closebutton').style.display = "none";      
   }
   else
   {
      document.getElementById('openbutton').style.display = "none";
      document.getElementById('closebutton').style.display = "inline";      
   }
   
   scrollBy(0,0); //safari bug
   
}

function setarticlesbutton()
{ 
   var stylereference = document.getElementById("articles").style;
   var buttonreference = document.getElementById("articlesbutton");
   
   stylereference.display = parent.articlesnoneorblock;
   buttonreference.value = parent.articlesplusorminus;
}

function showorhide(sectionid)
{   
//this function gets called when the "+" or "-" button next to a category name (e.g., algebra)
//is clicked. it changes the noneorblock array to "block" or "none", whatever is different
//from the current setting of the css display property. the idea is to toggle whether or not
//the subsections (e.g., manipulation) are displayed. the blockstatus array keeps track of
//whether the value property of the button object says + or -. once the two associative
//array elements are set (noneorblock and buttonstatus are both associated with string ids
//corresponding to the name of each section) the display property of the div that corresponds
//to the section that got clicked as well as the button's value property can be changed.
//the page is then scrolled 1 pixel to force it to redraw because of bugs in safari that
//leave junk on the page if it isn't redrawn.
//I would like to have showorhide know where the mouse was so the screen can scroll if it is
//near the bottom of the document. but clientY is always zero even though the event is
//being sent successfully (you get "click" if you look at e.type and you get undefined
//if you misspell clientY as clienty) and safari recognized clientY but for some reason
//sets it to zero. the event object is sent as a parameter in the function call on the
//onclick event in the html that makes the button. I've commented out the lines that
//use the event (e) but kept it so that e is sent. maybe it has something to do 
//with using frames. 
    
  //alert('in showorhide');
 
    var buttonname = sectionid + "button";
    
  // alert('buttonname is ' + buttonname);
    
    var styleref = document.getElementById(sectionid).style;
    
    //alert('styleref is ' + styleref);
    
    var buttonref = document.getElementById(buttonname);

    //alert('buttonref is ' + buttonref);

    var currentsetting = buttonref.value;  //problem: it reads styleref.display as empty even tho = "none"
    
    //alert('currentsetting = ' + currentsetting);
    
    if (currentsetting == "-")
    {
        styleref.display = "none";
        parent.articlesnoneorblock = "none";
        buttonref.value = "+";
        parent.articlesplusorminus = "+"
    }
    else if (currentsetting == "+")
    {
        styleref.display = "block";
        parent.articlesnoneorblock = "block";
        buttonref.value = "-";
        parent.articlesplusorminus = "-";
    }
 
 scrollBy(0,0); //don't delete this MORON. safari has bugs!!!!!
 
}
