/*
 * Javascript tab based menu.
 * Written by James Allen for JC Designs
 * Created 13th May 2006
 */
var intCurrentTabClick;
var intCurrentTabVisible;
var strColorOn;
var strColorOff;
var timerShow;
var timerHide;
var blnInSection = false;

// declare the tab colors
function init( intID ) {
  strColorOn = "#73C270";
  strColorOff = "#008853";
  intCurrentTabClick = intID;
  intCurrentTabVisible = intID;
  showTab( intID );
}

// when user clicks a tab, show and remember which tab we are now on
function mouseClick( intID ) {
  clearTimers();
  intCurrentTabClick = intID;
  showTab( intCurrentTabClick );
}

function mouseHoverSection() {
  blnInSection = true;
  /*if(!blnInSection) {
    blnInSection = true;
    if( timerShow==null ) {
      clearTimers();
      timerShow = setTimeout("showTab(" + intCurrentTabVisible + ")",300);
    }
  }*/
}

function mouseHoverTab( intID ) {
  clearTimers();
  timerShow = setTimeout("showTab(" + intID + ")",300);
}

// when user stops hovering, show the last clicked tab
function mouseOut() {
  if(!blnInSection) {
    clearTimers();
    timerHide = setTimeout("showTab(" + intCurrentTabClick + ")",600);  
  }
}

// when mouse cursor leaves the subsection then switch the flag
function mouseOutSection() {
  if(blnInSection) {    
    blnInSection = false;
    mouseOut();
  }
}

function clearTimers() {
  clearTimeout( timerShow );
  clearTimeout( timerHide );
  timerShow = null;
  timerHide = null;
}

// when user hovers over a tab, show the tabs contents
function showTab( intID ) {
  // leave section when mouse in in subsection
  if(!blnInSection) {
    var innerHTML;
    
    document.getElementById( "section" + intCurrentTabVisible  ).style.backgroundColor = strColorOff;
    intCurrentTabVisible = intID;
    innerHTML = document.getElementById( "subsection" + intID ).innerHTML;
    document.getElementById( "subsectionframe" ).innerHTML = innerHTML;
    document.getElementById( "section" + intCurrentTabClick ).style.backgroundColor = strColorOff;
    document.getElementById( "section" + intID ).style.backgroundColor = strColorOn;
    
    // prevents this from cycling over and over
    clearTimers();
  }
}