// Configurable values
//var ids = ['special', 'staff', 'banner'];
var ids = ['staff'];
var idTypes = [1, 1, 0];
var fadeSpeed = 50;
var pause = 10500;
var delta = 5;

// Fixed values
var opacity;
var direction;
var idCounts = [];
var idMaxCounts = [];

// Specials html doesn't really live at the top of the page - use javascript to move the code 
// into place from a placeholder div
function setSpecials() {
 var specialsHolder =  document.getElementById('specialsHolder');
 if (specialsHolder) {
  var specials = document.getElementById('special');
  if (specials) {
   specials.innerHTML = specialsHolder.innerHTML;
  }
 }
}

function startFadeElement() {
 if (!document.getElementById('staff1')) {
   return;
 }

 opacity = 99;
 direction = -1;
 for (var a = 0; a < ids.length; a++) {
  idCounts[a] = 0;
  var root = ids[a];
  var count = 0;
  var id = root + count;
  var element = document.getElementById(id);
  while (element) {
   if (idTypes[a] == 0) {
    element.style.display = "block";
   }
   idMaxCounts[a] = count;
   count++;
   id = root + count;
   element = document.getElementById(id);
  }
 }
 
 setTimeout('fadeElement()', pause);
}

function fadeElement() {
  opacity = opacity + (delta * direction);
  if (opacity < 0) {
   opacity = 0;
  } else if (opacity > 99) {
   opacity = 99;
  }

  // Set opacity for each active element
  for (var a = 0; a < ids.length; a++) {
   if (direction < 0 || idTypes[a] == 1) {
     var count = idCounts[a];
     var id = ids[a] + count;
     var element = document.getElementById(id);
     setOpacity(element, opacity);
   }
  }

  if (opacity > 0) {
   if (direction < 0 || opacity < 99) {
    setTimeout('fadeElement()', fadeSpeed);
   }

   if (direction == 1 && opacity == 99) {
    opacity = 99;
    direction = -1;
   }
  } else if (direction < 0) {
   // Increment and validate element counts
   for (var a = 0; a < ids.length; a++) {
    var count = idCounts[a];
    setDisplayType(a, 'none');
    count++;

    if (count > idMaxCounts[a]) {
     count = 0;
     if (idTypes[a] == 0) {
      resetElements(ids[a]);
     }
    }
    idCounts[a] = count;
    setDisplayType(a, 'block');
   }

   // Fade in new text
   direction = 1;
   setTimeout('fadeElement()', fadeSpeed);

   // Set next full cycle
   setTimeout('fadeElement()', pause);
  }
}

function setDisplayType(a, display) {
 if (idTypes[a] == 1) {
  var id = ids[a] + idCounts[a];
  var element = document.getElementById(id);
  if (element) {
   element.style.display = display;
   if (display == 'block') {
    setOpacity(element, 0);
   }
  }
 }

}

function resetElements(root) {
 var element = document.getElementById(root + 0);
 var i = 0;
 while (element) {
  setOpacity(element, 99);
  i++;
  element = document.getElementById(root + i);
 }
}


function setOpacity(element, opacity) {
 if (element) {
  if (element.filters) {
   element.style.filter = 'alpha(opacity=' + opacity + ')';
  } else {
   element.style.MozOpacity = opacity/101;
  }
 }
}

function initiateOnloadCalls() {
 //ACELoadMenu();
 setSpecials();
 startFadeElement(); 
 loadCoolMenus();
}


function displayFlash() {
 document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="898" height="217" ><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="/monoslideshow.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="showLogo=false&amp;showVersionInfo=false"><embed src="/monoslideshow.swf" quality="high" bgcolor="#ffffff" width="898" height="217" name="slideshow" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="showLogo=false&amp;showVersionInfo=false" /></object>');
}