<!--
/*
   InternSource JavaScript page:
   This page handles the frontpage
      link tabs functions.
   
   Author: Manuel Navarro
   Company: The Community College Foundation
   Date:   05/02/07
*/

// Setup some global variables
var infoTabExt = "_info";                 // Extention used to define info window for each tab
                                          // EX: tab_student info window would be tab_student_info
var infoWinClass = "link_info";           // Default classname for information windows

var infoLinksParentID = "bottom_half";    // Parent id name to info Link tabs
var infoDefaultName = "tab_default_info"; // Default Info Window Name

var current_infoTab = false;              // Current infoTab Object
var infoDefaultObj;                       // Variable to address default info window Object

var infoTabClassExt     = "on";           // Link tab extention to default classname (hover)
// Bullet image for list items
var tabBulletImage      = "http:\/\/framework.communitycollege.org\/images\/iSource\/red_bullet_point.gif";

// Sets a timer to call the hideAllTabInfo function
var setHideAllTimer =
   function()
   {
      if(!current_infoTab) return false;

      //overMenu = false;
      setTimeout("hideAllTabInfo()", 10);
   };

// Function to hide all tab information and show default info
function hideAllTabInfo()
{
   //if(overMenu) { return false; }

   if(current_infoTab != false)
   {
      current_infoTab.showInfo(false);
      current_infoTab = false;
   }
}

// Simple function sets the srcDiv object's display property to "block" or "none"
function displayDiv(srcDiv, show)
{
   // Show is default to true so the div will be displayed
   var show = (show == null) ? true : show;
   srcDiv.style.display = (show) ? "block" : "none";
}

// Prepares each tab link for a mouseover event
function prepareTabLinks()
{
   var curClassName, pNode, aNode, i;
   var tabLinks = getObjByName("bullet_links");
   
   if(!tabLinks) return false; // No element found

   tabLinks = tabLinks.getElementsByTagName("LI"); // Find child nodes with LI tag
   if(tabLinks.length < 1) return false;  // No nodes found

   // Set default info object window address
   infoDefaultObj = getObjByName(infoDefaultName);

   for(i = 0; i < tabLinks.length; i++)
   {
      // Find the link node element
      aNode = getFirstElementByTagName(tabLinks[i], "a");
      
      if(!aNode) continue  // Skip if we cannot find a link node

      // If the tab element contains a 'display' attribute and it is set to
      //    static then do not create a dynamic window to load
      //    the contents of the link into.
      var displayStatic = (tabLinks[i].getAttribute) ? tabLinks[i].getAttribute("display") : "";
      displayStatic = (displayStatic) ? displayStatic : "";

      if(displayStatic.toLowerCase() != "static")
      {
         // First try to find the id of the info window from the aNodes.
         //   Try by name first, then try by id, if that fails, try the tabLinks
         //   object and if that fails then skip this object.

         var objInfoWin = (aNode.name) ? aNode.name : (aNode.id) ? aNode.id : tabLinks[i].id;
         if(!objInfoWin) continue;  // Skip if we cannot find an id
         objInfoWin = objInfoWin + infoTabExt;
         
         tabLinks[i].title = aNode.innerHTML // Set the title for this object

         if(infoDefaultObj.parentNode)
            // Create new window objects
            createInfoWin(objInfoWin, tabLinks[i].title, infoDefaultObj.parentNode);

         // Set individual infoWindow objects to each link node
         // Set the actual object, not the object name.
         tabLinks[i].infoWin = getObjByName(objInfoWin); // Set window object

         // Save information
         tabLinks[i].oldClass = tabLinks[i].className;
         aNode.oldClass = aNode.className;
         tabLinks[i].aNode = aNode;                      // Set link Node object
         
         // Show that the HREF is not loaded
         tabLinks[i].loadhref = false;

         // Set mouse over event
         tabLinks[i].showInfo = displayTabInfo;
         tabLinks[i].onmouseover =
            function(){
               this.showInfo(true);
            };
      }
      else
         tabLinks[i].onmouseover = hideAllTabInfo;

      // Insert DOM image into the link node
      insertBulletImage(aNode, tabBulletImage);
   }
}

// Create display context window
// strID defines the window object ID
// strTitle is the title that the window will have
// objIn is where this new window will be inserted (leave blank to insert into body)
function createInfoWin(strID, strTitle, objIn)
{
   // Check default objIn
   var objIn = (objIn == null) ? document.body : objIn;

   var objWin = document.createElement("div");
   objWin.setAttribute("id", strID);
   objWin.className = infoWinClass;
   objWin.style.display = "none"; // Hide window for now

      // Create Title Element
      var objTitle = document.createElement("h5");
      objTitle.innerHTML = strTitle;
      objWin.appendChild(objTitle); // Attach the title to the new info window

      // Create first child (where information will be placed)
      var objPad = document.createElement("div");
      objPad.className = "child";                     // Sets the class
      objPad.setAttribute("id", strID + "_child");    // Sets the ID
      objWin.appendChild(objPad);

   // Attach the new information window to the defined object
   objIn.appendChild(objWin);
}

// Inserts an image of your choice into the link node.
function insertBulletImage(aNode, strImage)
{
   // The first thing we do is set the title for the parent object
   //    of this link node. We do this first because after we
   //    append the image to the link, the innerHTML value will
   //    include the image text.
   aNode.parentNode.setAttribute("title", aNode.innerHTML);
   var objImg = document.createElement("img");
   objImg.src = strImage;
   objImg.setAttribute("alt", aNode.innerHTML);
   aNode.insertBefore(objImg, aNode.firstChild);
}

// Function to show a link nodes information in another layer
function displayTabInfo(show)
{
   // Default show status is true
   var show = (show == null) ? true : show;

   // If this tab's information is already visible, do not show it again.
   if(current_infoTab && (current_infoTab == this && show)) return false;

   // If we are showing another tab's information while
   //    there is a current tab showing, then hide that tab's info first.
   if(current_infoTab && (current_infoTab != this && show))
   { current_infoTab.showInfo(false); }

   // Show this tab's information window if hide is set to false (default)
   if(show)
   {
      // This is the current tab being displayed
      current_infoTab = this;

      // Do not load the url again if it is already loaded
      if(!this.loadhref)
         this.loadhref = loadHREF(this.aNode.href, this.infoWin.id + "_child",
                  "Loading " + this.title + "...", "<!--extract_start-->", "<!--extract_end-->");

      // Set the mouseover classes for this tab and it's link node
      this.className = (this.oldClass != "") ? this.oldClass + infoTabClassExt : infoTabClassExt;
      if(this.aNode)
         this.aNode.className = (this.aNode.oldClass != "") ? this.aNode.oldClass + infoTabClassExt : infoTabClassExt;

      displayDiv(this.infoWin, true);
      // Hide default display window
      displayDiv(infoDefaultObj, false);
   }
   else
   {
      // The current tab is null so set it to false
      current_infoTab = false;

      // Set the mouseout classes for this tab and it's link node
      this.className = this.oldClass;
      if(this.aNode)
         this.aNode.className = this.aNode.oldClass;

      displayDiv(this.infoWin, false);
      displayDiv(infoDefaultObj, true);
   }
}

// WINDOW ONLOAD FUNCTIONS!!
addEvent(window, "load", prepareTabLinks, false);
// -->
