var tabLinks = new Array();
var contentDivs = new Array();

function init() {
    //if (isIE()) {
  //      document.getElementById('tabs').style.marginBottom="-3px";
        
  //  }
  // Grab the tab links and content divs from the page
    var tabListItems = document.getElementById('tabs').getElementsByTagName("a");
    
  for ( var i = 0; i < tabListItems.length; i++ ) {
      var id = getHash(tabListItems[i].getAttribute('href'));
      tabLinks[id] = tabListItems[i];
      contentDivs[id] = document.getElementById( id );
  }

  // Assign onclick events to the tab links, and
  // highlight the first tab
  var i = 0;

  for ( var id in tabLinks ) {
    tabLinks[id].onclick = showTab;
    tabLinks[id].onfocus = function() { this.blur() };
    if ( i == 0 ) tabLinks[id].className = 'selected';
    i++;
  }
  // Hide all content divs except the first
  var i = 0;
 
  for ( var id in contentDivs ) {
      if (i != 0) {
          contentDivs[id].className = 'tabContent hide';
          
      }
    i++;
  }
}

function showTab() {
  var selectedId = getHash( this.getAttribute('href') );

  // Highlight the selected tab, and dim all others.
  // Also show the selected content div, and hide all others.
  for (var id in contentDivs) {
        var tabImage = document.getElementById(id + 'TabImage');
        if ( id == selectedId ) {
            tabLinks[id].className = 'selected';
            tabImage.src = tabImage.src.replace('_off', '_on');
            contentDivs[id].className = 'tabContent';
        } 
        else {
            tabLinks[id].className = '';
            tabImage.src = tabImage.src.replace('_on', '_off');
            contentDivs[id].className = 'tabContent hide';
        }
  }

  // Stop the browser following the link
  return false;
}

function getFirstChildWithTagName( element, tagName ) {
  for ( var i = 0; i < element.childNodes.length; i++) {
    if ( element.childNodes[i].nodeName == tagName ) return element.childNodes[i];
  }
}

function getHash( url ) {
  var hashPos = url.lastIndexOf ( '#' );
  return url.substring( hashPos + 1 );
}
