/* 2008-10-17 (mca) : to support college football bowls branding */

var collegeFootballBowls = function()
{
  var g = {};
  g.links = null;
  g.targetName = 'topNav';
  g.linkName = 'Navbar1_dlPackageNav';
  
  function init()
  {
    getLinks();
    modLinks();
    updateMenu();
  }
  
  // copy the navigation into the top branding area
  function updateMenu()
  {
    var elm,ul,li,i,a,s,node,old;
    
    if(g.links)
    {
      elm = document.getElementById(g.targetName);
      if(elm)
      {
        elm.innerHTML = '';
        ul = document.createElement('ul');
        for(i=0;i<g.links.length;i++)
        {
          node = g.links[i].cloneNode(true);
          li = document.createElement('li');
          li.appendChild(node);
          ul.appendChild(li);
        }
        
        // now handle myaccount link
        s = document.createElement('span');
        s.appendChild(document.createTextNode('My Account'))
        a = document.createElement('a');
        a.href = '/account/';
        a.title='My Account';
        a.appendChild(s);
        li = document.createElement('li');
        li.appendChild(a);
        ul.appendChild(li);
  
        // add to collection
        elm.appendChild(ul);

        // hide old menu now
        old = document.getElementById(g.linkName);
        if(old)
        {
          old.style.display='none';
        }
      }
    }
  }
  
  // modify the standard nav links to match this branding css
  function modLinks()
  {
    var i,s,child;
    
    if(g.links)
    {
      for(i=0;i<g.links.length;i++)
      {
        child = g.links[i].firstChild;
        s = document.createElement('span');
        s.appendChild(child);
        g.links[i].appendChild(s);
      }
    }
  }
  
  // get all the package nav links on this page
  function getLinks()
  {
    var elm;
    
    elm = document.getElementById(g.linkName);
    if(elm)
    {
      g.links = elm.getElementsByTagName('a');
      /*
      if(g.links && g.links.length!=0)
      {
        elm.style.display='none';
      }
      */
    }
  }
  
  // publish the init function
  var that = {};
  that.init = init;
  return that;
}

// run at startup
window.onload = function()
{
  f = collegeFootballBowls();
  f.init();
}