/********************************
 * site-specific settings       *
 ********************************/

var showRolloverMenuEffect = Effect.BlindDown;
var showRolloverMenuEffectOptions = { duration: 0.2 };
var hideRolloverDelay = 150;
var hideRolloverMenuEffect = Effect.BlindUp;
var hideRolloverMenuEffectOptions = { duration: 0.2 };
var featureFadeDelay = 8000;
var featureRotateTimeout = null;

/********************************
 * site-specific functions      *
 ********************************/

function rotateFeatures(nextIndex) {
    clearTimeout(featureRotateTimeout);
    
    if (typeof(nextIndex) != 'undefined') {
        nextFeature(nextIndex)
    } else {
        nextFeature();
    }
    
    featureRotateTimeout = setTimeout(function () { rotateFeatures(); }, featureFadeDelay);
}

function nextFeature(nextIndex) {
    var list_items = $$('#features-list li');
    var nav_items = $$('#features-navigator li');
    
    // exit if misconfigured
    if (list_items.length != nav_items.length) return false;
    
    var currentIndex = null;
    
    // hide all selected
    for (var i = 0; i < list_items.length; i++) {
        if (list_items[i].className == 'selected') {
            if (!currentIndex) currentIndex = i;
            if (typeof(nextIndex) == 'undefined' || i != nextIndex) {
                Effect.Fade(list_items[i], { duration: 0.3 });
            }
        }
        
        list_items[i].className = '';
        nav_items[i].className = '';
    }
    
    if (currentIndex == null) {
        currentIndex = list_items.length - 1;
    }
    if (typeof(nextIndex) == 'undefined') {
        nextIndex = currentIndex + 1;
        if (nextIndex > (list_items.length-1)) nextIndex = 0;
    }
    
    list_items[nextIndex].className = 'selected';
    nav_items[nextIndex].className = 'selected';
    Effect.Appear(list_items[nextIndex], { duration: 0.4 })
}

/* Very good, very popular, unobtrusive event loader
 * that executes functions on page load.
 * - by JS guru Simon Willison.
 * http://simonwillison.net/2004/May/26/addLoadEvent/
 */

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

