addEvent(window, 'load', navHover);
function navHover(){
	var lis = document.getElementById('nav').getElementsByTagName('LI');
	var active = getElementsByClassName(document.getElementById('nav'), 'li', 'current')[0];

	for(var i=0; i<lis.length; i++){
		lis[i].onmouseover = function(){						
			var self = this;
			for(var a=0; a<lis.length; a++){			
				
				if(self == lis[a] || self == lis[a].parentNode.parentNode){				
					
					// keep the current item in view
					if(self.getElementsByTagName('UL')[0]) self.getElementsByTagName('UL')[0].style.left = '0px';
					if(lis[a].parentNode == 'ul') { 
						lis[a].parentNode.style.left = '0px';
					}
					
					// remove all other "current" classes from other lis
					for(var b=0; b<lis.length; b++){
						if(lis[b] != self && lis[b] != active) lis[b].className = '';
					}
					
				} else if(self != lis[a]) {				
					if(lis[a].getElementsByTagName('UL')[0]) lis[a].getElementsByTagName('UL')[0].style.left = '-5000px';				
				
					if(lis[a].className == 'current'){
						if(lis[a].getElementsByTagName('UL')[0]) lis[a].getElementsByTagName('UL')[0].style.left = '-5000px';
					}
				}																
			}						
		}
		
		lis[i].onmouseout = function(){			
			var self = this;
			if(this != active){
				if(self.getElementsByTagName('UL')[0]) self.getElementsByTagName('UL')[0].style.left = '-5000px';				
			} 
			if(active) {
				active.className = 'current'; 
				if(active.getElementsByTagName('UL')[0]) active.getElementsByTagName('UL')[0].style.left = '0px';
			}
			/*
			if(active.length > 0){
				if(active[0].getElementsByTagName('UL')[0]) active[0].getElementsByTagName('UL')[0].style.left = '18px';
				active[0].className = 'current';
			}
			*/
		}		
	}
}



// ALL PURPOSE FUNCTIONS
var Class = function(properties){
	var klass = function(){
		if (this.initialize && arguments[0] != 'noinit') return this.initialize.apply(this, arguments);
		else return this;
	};
	for (var property in this) klass[property] = this[property];
	klass.prototype = properties;
	return klass;
};


Class.empty = function(){};

Class.prototype = {

	extend: function(properties){
		var pr0t0typ3 = new this('noinit');

		var parentize = function(previous, current){
			if (!previous.apply || !current.apply) return false;
			return function(){
				this.parent = previous;
				return current.apply(this, arguments);
			};
		};

		for (var property in properties){
			var previous = pr0t0typ3[property];
			var current = properties[property];
			if (previous && previous != current) current = parentize(previous, current) || current;
			pr0t0typ3[property] = current;
		}
		return new Class(pr0t0typ3);
	},

	implement: function(properties){
		for (var property in properties) this.prototype[property] = properties[property];
	}

};



Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
}

Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    return __method.call(object, event || window.event);
  }
}

Object.extend = function(){
	var args = arguments;
	args = (args[1]) ? [args[0], args[1]] : [this, args[0]];
	for (var property in args[1]) args[0][property] = args[1][property];
	return args[0];
};

Object.Native = function(){
	for (var i = 0; i < arguments.length; i++) arguments[i].extend = Class.prototype.implement;
};

new Object.Native(Function, Array, String, Number, Class);

Function.extend({

	create: function(options){
		var fn = this;
		options = Object.extend({
			'bind': fn,
			'event': false,
			'arguments': null,
			'delay': false,
			'periodical': false,
			'attempt': false
		}, options || {});
		if (options.arguments != null && typeof options.arguments != 'undefined' && !(options.arguments instanceof Array))
			options.arguments = [options.arguments];
		return function(event){
			var args = options.arguments || arguments;
			if (options.event){
				event = (options.event === true) ? event || window.event : new options.event(event);
				args = [event].concat(args);
			}
			var returns = function(){
				return fn.apply(options.bind, args);
			};
			if (options.delay) return setTimeout(returns, options.delay);
			if (options.periodical) return setInterval(returns, options.periodical);
			if (options.attempt){
				try {
					var result = returns();
				} catch(err){
					result = err;
				} finally {
					return result;
				}
			} else return returns();
		};
	},

	pass: function(args, bind){
		return this.create({'arguments': args, 'bind': bind});
	},
	
	attempt: function(args, bind){
		return this.create({'arguments': args, 'bind': bind, 'attempt': true})();
	},

	bind: function(bind, args){
		return this.create({'bind': bind, 'arguments': args});
	},

	bindAsEventListener: function(bind, args){
		return this.create({'bind': bind, 'event': true, 'arguments': args});
	},

	delay: function(ms, bind, args){
		return this.create({'delay': ms, 'bind': bind, 'arguments': args})();
	},

	periodical: function(ms, bind, args){
		return this.create({'periodical': ms, 'bind': bind, 'arguments': args})();
	}

});



function externo(){
	var exts = getElementsByClassName(document, 'a', 'external');
	for(var i=0; i<exts.length; i++) {
		exts[i].onclick = function(){
			window.open(this.href);
			return false;
		}
	}
}
addEvent(window, 'load', externo);

function id() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}
/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com

*/

function getElementsByClassName(oElm, strTagName, strClassName){	
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);	
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");	
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }	
    return (arrReturnElements)
}



// ============ ADD EVENTS ================ //
function addEvent(obj, evType, fn){
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, true);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    } else {
	    return false;
    }
}