/****************************************************
 *
 *  JavaScript Library: deg_commons
 *  
 *  @authors: Dean Edwards, Tino Zijdel, Dirk Engberg  
 *  @requires: -
 */    
 
var deg = {
  // Standard event handling functions to abstract browser specialeties
  // written by Dean Edwards, 2005
  // with input from Tino Zijdel - crisp@xs4all.nl
  // http://dean.edwards.name/weblog/2005/10/add-event/

  addEvent:function(element, type, handler)
  {
  	if (element.addEventListener)
  		element.addEventListener(type, handler, false);
  	else
  	{
  		if (!handler.$$guid) handler.$$guid = deg._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] = deg.handleEvent;
  		}
  	
  		handlers[handler.$$guid] = handler;
  	}
  },
  _addEvent_guid:1,
  
  /**********************************
   * removes (=detaches) the event
   **/         
  removeEvent:function(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];
  },

  /**************************
   * handles the event
   **/  
  handleEvent:function(event)
  {
  	event = event || deg.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;
  },

  fixEvent:function(event)
  {
  	event.preventDefault = deg._fixEvent_preventDefault;
  	event.stopPropagation = deg._fixEvent_stopPropagation;
  	return event;
  },
  
  _fixEvent_preventDefault:function()
  {
  	this.returnValue = false;
  },
  
  _fixEvent_stopPropagation:function()
  {
  	this.cancelBubble = true;
  },

  // DOM utilities and CSS detach/attach
  // written by D. Engberg
  
  Dom:{
    /**
     * get all direct child nodes of specific type
     */
    getChildNodesByType:function(theElement, theType) {
      var elms=theElement.childNodes;
      if (elms==null) return null;
      var theSet = new Array();
      for (var i=0; i<elms.length; i++) {
        if (elms[i].nodeName==theType) theSet.push(elms[i]);
      }
      return theSet;
    }
  },
  
  Css:{
    /**
     * add style class
     */
    addClass:function(theElement, theClass) {
      if (theElement.className==null || theElement.className=="") {
        theElement.className=theClass;
        return;
      }
      var classes = theElement.className.split(" ");
      for (cl in classes) // check if already existing
        if (classes[cl]==theClass) return;
      classes.push(theClass);
      theElement.className=classes.join(" ");
    },
    
    /**
     * remove style class
     */
    removeClass:function(theElement, theClass) {
      if (theElement.className==null || theElement.className=="") return;
      var classes = theElement.className.split(" ");
      var newClasses = new Array();
      var i=0
      for (cl in classes) {
        if (classes[cl]!=theClass)
          newClasses.push(classes[cl]);
        i++;
      }
      theElement.className=newClasses.join(" ");
    },
    
    /**
     * check if element contains style class
     */
    containsClass:function(theElement, theClass) {
      if (theElement.className==null || theElement.className=="") return false;
      var classes = theElement.className.split(" ");
      for (cl in classes) {
        if (classes[cl]==theClass) return true;
      }
      return false;
    }
  },
  
  /*
  * set footer height, strectches left grey bar.
  */
  Layout:{
    setNav:function(){
    obj = document.getElementById('leftnav');
    ul = obj.getElementsByTagName('ul');
	for (var i=0;i<ul.length;i++){				
	        ul[i].className = 'hidden';
	}		
    return 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 != deg.handleEvent)
		{
		    // fails in IE
			//addEvent(window, 'load', window.onload);
			//window.onload = deg.handleEvent;
		}
	}
}
// cross browser
window.onload = function() {
    deg.Layout.setNav();
}

