

function get_hotkey(e) {
	var key = (typeof e != 'undefined' && typeof e.which != 'undefined') ? e.which :
	(typeof e != 'undefined' && typeof e.keyCode != 'undefined') ? e.keyCode :
	(typeof window.event != 'undefined' && typeof event.keyCode != 'undefined') ? event.keyCode :
	null;
	if (!key) return true;
	key = String.fromCharCode(key);

	if ((typeof hotkey[key] != 'undefined' && (e.ctrlKey && e.altKey) || (window.event && window.event.altKey))) return hotkey[key]();
}

window.onkeypress = get_hotkey;
var hotkey = new Object();
hotkey['l'] = function() { 
    document.location = "/admin/login";
}


/* Util and IE Fixes */

Object.extend(Event, {
  _domReady : function() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;

    if (this._timer)  clearInterval(this._timer);
    
    this._readyCallbacks.each(function(f) { f() });
    this._readyCallbacks = null;
},
  onDOMReady : function(f) {
    if (!this._readyCallbacks) {
      var domReady = this._domReady.bind(this);
      
      if (document.addEventListener)
        document.addEventListener("DOMContentLoaded", domReady, false);
        
        /*@cc_on @*/
        /*@if (@_win32)
            document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
            document.getElementById("__ie_onload").onreadystatechange = function() {
                if (this.readyState == "complete") domReady(); 
            };
        /*@end @*/
        
        if (/WebKit/i.test(navigator.userAgent)) { 
          this._timer = setInterval(function() {
            if (/loaded|complete/.test(document.readyState)) domReady(); 
          }, 10);
        }
        
        Event.observe(window, 'load', domReady);
        Event._readyCallbacks =  [];
    }
    Event._readyCallbacks.push(f);
  }
});


var navTimeout = {};
var navLock = {};

Event.onDOMReady(function() {

	$$("#navigation > li").each(function(section){

		section.observe("mouseover", function(e){
			navDown(section);
		});
		
		section.observe("mouseout", function(e){
			navUp(section);
		});
		
		
	});
	
	$$("#navigation  ul").each(function(ul){
		
		ul.observe("mousemove", function(e) {
			section = ul.up("li");
			navDown(section);
	
		});
		
		ul.observe("mouseout", function(e){
		//	section = ul.up();
		
		});
		
	});
});

function hideHair(){
	$$('.hair').each(function(el){
		el.style.zIndex = "-1";
	})
}

function showHair() {
	$$('.hair').each(function(el){
		el.style.zIndex = "1000";
	})
}

function navDown(section) {
	
	if ((ul = section.getElementsBySelector("ul")).length) {
		if ($$("#navigation > li").indexOf(section) == 5)
			hideHair();
		ul = ul[0]
		ul.show();
		//Effect.BlindDown(ul, {duration:0.25,  queue: { position: 'end', scope: 'navdown'+section.id, limit: 1 }})
		section.getElementsBySelector("a")[0].addClassName("highlight")
	}
}

function navUp(section) {
	if ((ul = section.getElementsBySelector("ul")).length) {
		showHair();
		ul = ul[0]
		section.getElementsBySelector("a")[0].removeClassName("highlight")
		ul.hide();
		//Effect.BlindUp(ul, {duration:0.25,  queue: { position: 'end', scope: 'navup'+section.id, limit: 1 }})
	}
}


