/*
Two new Side Navigation functions were added, and the original object oriented JavaScript (which is an odd concept indeed) is now deprecated. The original functions are left here for old pages.

*/

// Jump the Browser to the selected location on the given Select Element
function jump(selectElement)
{
 				document.location.href = selectElement[selectElement.selectedIndex].value;
}

// Remove the first <li> element from the <ul> named "sideNav"
function changeSideNavList()
{
  // get the side nav we need, as well as all of the li elements within it
  var sideNavList = document.getElementById("sideNav");
  var listElements = sideNavList.getElementsByTagName("li");
  
  if(listElements[0])
  {
    // remove the first child from the list
    sideNavList.removeChild(listElements[0]);
  }
}

// Change the <ul> element named "sideNav" to be a dropdown menu, instead of a list
function changeDropdownLinks()
{

  // get the side nav we need, as well as all of the li elements within it
  var sideNavList = document.getElementById("sideNav");
  var listElements = sideNavList.getElementsByTagName("li");
  
  // remove the side nav from the page
  sideNavList.style.display = "none";
  
  // write out the header for the new dropdown menu
  document.write("<select id='quickmenu' class='small-font' onchange='jump(this);'>");
  
  // iterate through the list elements to make the options
  for(i = 0; i < listElements.length; i++)
  {
   			// get the name of the element, and the link that the element points to
   			var menuName = listElements[i].firstChild.firstChild.nodeValue;
  			var menuLink = listElements[i].firstChild.href;
  			
  			// if this is the first item in the list, write out a little bit different option
  			
  			// for example, in the Academics dropdown, this will write out two options, both
  			// of which will link to whatever the list item was pointing to. 
  			
  			// So ... <li><a href="/academics/">Academics</a> ... will turn in to:
  			// <option value="/academics/">Academics Links</option>
  			// <option value="/academics/">Home</option>
  			
   			if(i == 0)
  			{			
  			 			document.write("<option value='"+menuLink+"'>"+menuName+" Links</option>");
  						document.write("<option value='"+menuLink+"'>Home</option>");
  			}
  			// if this isn't the first item in the list, then it will write out a simpler
  			// option to use
  			
  			// So ... <li><a href="/academics/undergrad/index.html">Undergraduate</a></li> ... will turn in to:
  			// <option value="/academics/undergrad/index.html">Undergraduate</option>
  			else
  			{
  			 			document.write("<option value='"+menuLink+"'>"+menuName+"</option>");
  			}
  }
  
  //write out the end tag
  document.write("</select>");
}

/* ----------=========================---------- */
/* Don't use anything below this line            */
/* ----------=========================---------- */

function SideNav() {
   this.items = new Array();
   this.titleItem = new SideNavItem('','');
   this.add = sideNavAdd;
   this.addTitle = sideNavAddTitle;
   this.displayLink = sideNavDisplayLink;
   this.displayDropdown = sideNavDisplayDropdown;
   this.jump = sideNavJump;
}

function sideNavDisplayLink() {
   if (this.items.length > 0) {
      document.writeln('<ul>');
      for (var i=0;i < this.items.length;i++) {
         this.items[i].displayLink();
      }
      document.writeln('</ul>');      
   }
}

function sideNavDisplayDropdown() {
   if (this.items.length > 0) {
      document.writeln('<select id="quickmenu" class="small-font" onChange="sidenav.jump(this.options[this.selectedIndex].value)">');
   if(this.titleItem.title != "")
   {
      document.writeln('<option value="">'+this.titleItem.title+' Links</option>');
      document.writeln('<option value="'+this.titleItem.url+'">Home</option>');
   }
   else
   {
      document.writeln('<option value="">Menu</option>');
   }
      for (var i=0;i < this.items.length;i++) {
         this.items[i].displayDropdown();
      }
      document.writeln('</select>');
   }
}

function sideNavJump(url) {
   if (url != '') {
       document.location.href = url;
   }
}

function sideNavAdd(title, url) {
   this.items.push(new SideNavItem(title, url));
}

function sideNavAddTitle(title,url)
{
   this.titleItem = new SideNavItem(title,url);
}

function SideNavItem(title, url) {
   this.title = title;
   this.url = url;
   this.displayLink = sideNavItemDisplayLink;
   this.displayDropdown = sideNavItemDisplayDropdown;
}

function sideNavItemDisplayLink() {
   document.writeln('<li><a href="'+this.url+'">'+this.title+'</a></li>');
}

function sideNavItemDisplayDropdown() {
   var title = this.title;
   document.writeln('<option value="'+this.url+'">'+title+'</option>');
}