var curAlpha = 0;
var fadeTimeout = false;
var hasInitedQuotes = false;
var totalSubMenus = 2;
var stillHideSubMenu = false;
var subMenuTimeout = false;

function showSubMenuNum(nm) {
 for (i=0;i<totalSubMenus;i++) {
  if (i != nm) {
   document.getElementById('subMenu' + i).style.visibility = 'hidden';
  }
 }
 stillHideSubMenu = false;
 showSubMenu(nm);
}

function showSubMenu(nm) {
 tmpPOS = getPOS(document.getElementById('base'+nm));
 o = document.getElementById('subMenu'+nm);
 tmpH = tmpPOS[1] - o.offsetHeight;
 o.style.top = tmpH + 'px';
 o.style.left = tmpPOS[0] + 'px';
 o.style.visibility = 'visible';
}

function pauseHideSubMenu(nm) {
 clearTimeout(subMenuTimeout);
 stillHideSubMenu = true;
 subMenuTimeout = setTimeout('hideSubMenus();', 250);
}

function hideSubMenus() {
 if (stillHideSubMenu) {
  for (i=0;i<totalSubMenus;i++) {
   document.getElementById('subMenu' + i).style.visibility = 'hidden';
  }
 }
}

function getPOS(o) {
 retX = o.offsetLeft;
 retY = o.offsetTop;
 while (o.offsetParent) {
  o = o.offsetParent;
  retX += o.offsetLeft;
  retY += o.offsetTop;
 }
 return(new Array(retX, retY));
}


function initQuotes() {
 tmpPOS = getPOS(document.getElementById('headerImg'));
 for (i=0;i<totQuotes;i++) {
  o = document.getElementById('quote'+i);

  o.style['filter'] = 'alpha(opacity=0)';
  o.style['-moz-opacity'] = 0;
  o.style['-khtml-opacity'] = 0;
  o.style['opacity'] = 0;
  o.style.visibility = 'visible';

  tmpL = tmpPOS[0] + 920 - o.offsetWidth;
  tmpT = tmpPOS[1];
  o.style.left = tmpL + 'px';
  o.style.top = tmpT + 'px';

  if (!hasInitedQuotes) {
   tmpH = Math.round((130 - o.offsetHeight)/2);
   o = document.getElementById('quoteSpacer'+i);
   o.height = tmpH;
  }
 }

 hasInitedQuotes = true;
 fadeInQuote();
}

function fadeInQuote() {
 clearTimeout(fadeTimeout);
 o = document.getElementById('quote'+curQuote);
 curAlpha += 5
 o.style['filter'] = 'alpha(opacity='+curAlpha+')';
 tmpAlpha = curAlpha / 100; 
 o.style['-moz-opacity'] = tmpAlpha;
 o.style['-khtml-opacity'] = tmpAlpha;
 o.style['opacity'] = tmpAlpha;


 if (curAlpha >= 100) {
  fadeTimeout = setTimeout('fadeOutQuote();', 5000);
 } else {
  fadeTimeout = setTimeout('fadeInQuote();', 50);
 }
}

function fadeOutQuote() {
 clearTimeout(fadeTimeout);
 o = document.getElementById('quote'+curQuote);
 curAlpha -= 5;
 o.style['filter'] = 'alpha(opacity='+curAlpha+')';
 tmpAlpha = curAlpha / 100; 
 o.style['-moz-opacity'] = tmpAlpha;
 o.style['-khtml-opacity'] = tmpAlpha;
 o.style['opacity'] = tmpAlpha;

 if (curAlpha <= 0) {
  curQuote++;
  if (curQuote >= totQuotes)
   curQuote = 0;
  fadeTimeout = setTimeout('fadeInQuote();', 500);
 } else {
  fadeTimeout = setTimeout('fadeOutQuote();', 50);
 }
}
