/**
 * Enhanced List
 * N. Smith 2008!
 * Accepts the class you wish to modify, its parent container, and an element type.
 * If no element type is specified, all elements (*) will be used.
 **/ 
function enhancedList(elemClass, container, elemType)
{
  if(!elemType)
    elemType = "*";
  // If the container does not exist, or has no children, we should stop now.
  if(!document.getElementById(container)) return false;
  var childElems = document.getElementById(container).getElementsByTagName(elemType);
  if(!childElems) return false;
  
  // Generate Regular Expression to find class
  if(elemClass == "")
    var reg = /.*/;
  else
    var reg = new RegExp("^(\\s*\\w*\\s+)*" + elemClass + "(\\s+\\w*\\s*)*$", "g");
  
  var isOdd = true;
  for(var i = 0; i < childElems.length; i++)
  {
    var currentClass = childElems[i].className;
    if(currentClass.match(reg)){
      if(isOdd){
        childElems[i].className += " odd";
        }
      else{
        childElems[i].className += " even";
        }
      isOdd = !isOdd;
    }
  }
}

function listInit()
{
  enhancedList("entry", "entries", "div");
}

/* Start things at DOM Ready State.
 * Taken from exmaple code at http://www.hunlock.com
 */
startStack=function() { };  // A stack of functions to run onload/domready

registerOnLoad = function(func) {
   var orgOnLoad = startStack;
   startStack = function () {
      orgOnLoad();
      func();
      return;
   }
}

var ranOnload=false; // Flag to determine if we've ran the starting stack already.

if (document.addEventListener) {
  // Mozilla actually has a DOM READY event.
   document.addEventListener("DOMContentLoaded", function(){if (!ranOnload) {ranOnload=true; startStack();}}, false);
}  else if (document.all && !window.opera) {
  // This is the IE style which exploits a property of the (standards defined) defer attribute
  document.write("<scr" + "ipt id='DOMReady' defer=true " + "src=//:><\/scr" + "ipt>");  
  document.getElementById("DOMReady").onreadystatechange=function(){
    if (this.readyState=="complete"&&(!ranOnload)){
      ranOnload=true;
      startStack();
    }
  }
}

var orgOnLoad=window.onload;
window.onload=function() {
   if (typeof(orgOnLoad)=='function') {
      orgOnLoad();
   }
   if (!ranOnload) {
     ranOnload=true;
     startStack();
   }
}

registerOnLoad(listInit);