	function init() {
		// quit if this function has already been called
		if (arguments.callee.done) return;
		
		// flag this function so we don't do the same thing twice
		arguments.callee.done = true;
		
		// kill the timer
		if (_timer) {
			clearInterval(_timer);
			_timer = null;
		}
		
    initMenus();
	};
	
	/* for Mozilla */
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", init, false);
	}
	
	/* for Internet Explorer */
	/*@cc_on @*/
	/*@if (@_win32)
		document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
		var script = document.getElementById("__ie_onload");
		script.onreadystatechange = function() {
			if (this.readyState == "complete") {
				init(); // call the onload handler
			}
		};
	/*@end @*/
	
	/* for Safari */
	if (/WebKit/i.test(navigator.userAgent)) { // sniff
		var _timer = setInterval(function() {
			if (/loaded|complete/.test(document.readyState)) {
				init(); // call the onload handler
			}
		}, 10);
	}
	
	/* for other browsers */
	window.onload = init;

// written by Dean Edwards, 2005
// with input from Tino Zijdel - crisp@xs4all.nl
// http://dean.edwards.name/weblog/2005/10/add-event/
function addEvent(element, type, handler) {
  if (!element.nodeName) {
    return;
  } else {
    if (element.addEventListener) {
        element.addEventListener(type, handler, false);
    } else {
        if (!handler.$$guid) {
            handler.$$guid = addEvent.guid++;
        }
        if (!element.events) {
            element.events = {};
        }
        var handlers = element.events[type];
        if (!handlers) {
            handlers = element.events[type] = {};
            if (element['on' + type]) handlers[0] = element['on' + type];
            element['on' + type] = handleEvent;
        }
        handlers[handler.$$guid] = handler;
    }
  }
}
addEvent.guid = 1;
function removeEvent(element, type, handler) {
    if (element.removeEventListener){
        element.removeEventListener(type, handler, false);
    } else if (element.events && element.events[type] && handler.$$guid) {
        delete element.events[type][handler.$$guid];
    }
}
function handleEvent(event) {
    event = event || fixEvent(window.event);
    var returnValue = true;
    var handlers = this.events[event.type];
    for (var i in handlers) {
        if (!Object.prototype[i]) {
            this.$$handler = handlers[i];
            if (this.$$handler(event) === false) {
                returnValue = false;
            }
        }
    }
    if (this.$$handler) {
        this.$$handler = null;
    }
    return returnValue;
}
function fixEvent(event) {
    event.preventDefault = fixEvent.preventDefault;
    event.stopPropagation = fixEvent.stopPropagation;
    return event;
}
fixEvent.preventDefault = function () {
    this.returnValue = false;
}
fixEvent.stopPropagation = function () {
    this.cancelBubble = true;
}
// This little snippet fixes the problem that the onload attribute on the body-element will overwrite
// previous attached events on the window object for the onload event
if (!window.addEventListener) {
    document.onreadystatechange = function () {
        if (window.onload && window.onload != handleEvent) {
            addEvent(window, 'load', window.onload);
            window.onload = handleEvent;
        }
    }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

function Menu(e,x,r,c) {
    if(!addEvent){alert("You must install the addEvent() function.")}
    this.e = !e.nodeName?document.getElementById(e):e;
    this.x = x; // axis
    this.r = r; // is root?
    this.c = c;
    this.l = this.e.hasChildNodes?this.e.childNodes:0;
    this.t = null;
    var element = this.e,
        closeNodes = function () {
            var n = element.getElementsByTagName("LI");
            for (i=0;i<n.length;i++) {
                n[i].className = "hide";
            }
        },
        startClock = function (){
            clearTimeout(this.t);
            this.t = setTimeout(closeNodes,1500);
        },
        resetClock = function (){
            clearTimeout(this.t);
            this.t=null;
        },
        swapStyle = function (){
          if (!document.getElementById(this.className+'SS').nodeName) {
            alert("Can't find the correct Style Sheet. Check that the classes and IDs match (minus the SS used in the style sheet only.)");
          } else {
            document.getElementById(this.className+'SS').href = this.href;
            var styleCookie = createCookie(this.className+'SS',this.href,7);
            closeNodes();
            return false;
          }
        },
        emptyFn = function (){return false;}
    if (this.r && this.r === true) {
        this.e.className = this.x;
        addEvent(this.e,"mouseover",resetClock);
        addEvent(this.e,"mouseout",startClock);
    }
    var css = document.getElementsByTagName("LINK");
    for (i=0;i<css.length;i++) {
      var styleCookie = readCookie(css[i].id);
      if (styleCookie) {
        css[i].href = styleCookie;
      }
    }
    var a = element.getElementsByTagName("A");
    for (i=0;i<a.length;i++) {
      if(a[i].className==='thgLayout'||
         a[i].className==='thgFormat'||
         a[i].className==='thgFont'||
         a[i].className==='thgText'||
         a[i].className==='thgTheme'){
        addEvent(a[i],"mousedown",swapStyle);
// Opera won't play nice and cancel the onclick event, visiting the CSS page instead
        a[i].onclick=function(){return false;};
      }
    }
    for (var i=0,j=0,child; child=this.l[i];i++,j++) {
        if (child.nodeName==="LI" && child.firstChild.nodeName==="A") {
            if (this.c === true) {
                j = new Node(child,this.r,this.c);
            } else {
                j = new Node(child);
            }
        }
        if (child.childNodes[1] && child.childNodes[1].nodeName==="UL") {
            j = new Menu(child.childNodes[1]);
        }
    }
    addEvent(document.getElementsByTagName("BODY")[0],"click",closeNodes);
}
function Node(n,r,c) {
    this.n = n;
    this.r = r;
    this.c = c;
    this.n.className = "hide";
    if (this.n.hasChildNodes() === true &&
        this.n.childNodes.length>1) {
        this.n.childNodes[0].className = "indicator";
    }
  if (this.n.nodeName === 'LI') {
    addEvent(this.n,"mouseover",this.show);
    addEvent(this.n,"mouseout",this.hide);
  }
}
Node.prototype.show = function () {
    var ulParent = this.parentNode,
        siblings = ulParent.childNodes;
    for (var i=0;i<siblings.length;i++) {
        if (siblings[i].nodeName==="LI") {
            siblings[i].className="hide";
        }
    }
    this.className = "show";
}
Node.prototype.hide = function () {//need to incorporate NEWS check
    var parent = this.parentNode,
        siblings = parent.childNodes,
        aunt,
        uncle,
        nephews;
    for (var i=0;i<siblings.length;i++) {
        if (siblings[i] != this &&
            siblings[i].hasChildNodes()===true &&
            siblings[i].childNodes.length>1) {
            aunt = siblings[i].childNodes[0];
            uncle = siblings[i].childNodes[1];
            if (uncle.hasChildNodes()===true) {
                nephews = uncle.childNodes;
                for (var j=0;j<nephews.length;j++) {
                    nephews[j].className = "hide";
                }
            }
        }
    }
}
function initMenus() {
    var styleMenu = new Menu("thgStyleMenu","horizontal",true,false);
}

//addEvent(window,"load",initMenus);
