// JavaScript Document
(function ($) {
	$.fn.simpleDropDown = function (options) {
		var settings = {
				width: 1000,
				height: 50,
				backgroundImg: "img/bg.png"
			};
		$.extend(settings, options);
		var $this = $(this);
		var open_t;
		var close_t;
		var currentMenu;
		var _menu = new Object();
		_menu.init = function(){
			$("li ul", $this).each(function(){
				$(this).data("orig", $(this).height());
			});
		}
		_menu.handler = function(e){
			if(e.type == "mouseover" || e.type == "mouseenter"){
				_menu.openTimer($(e.currentTarget).children("ul"));
			}
			else if(e.type == "mouseout" || e.type == "mouseleave"){
				_menu.closeTimer();
			}
		}
		_menu.present = function(showMenu){
			_menu.clearTimer();
			_menu.conceal()
			showMenu.css({height: showMenu.data("orig")})
			showMenu.fadeIn();
			currentMenu = showMenu;
		}
		_menu.openTimer = function(openEl){
			if(open_t){
				open_t = window.clearInterval(open_t);
				open_t = null;
			}
			open_t = setTimeout(function(){
				_menu.present(openEl);
			},250)
		}
		_menu.conceal = function(){
			
			$("li ul", $this).fadeOut();
		}
		_menu.closeTimer = function(){
			if(open_t){
				open_t = window.clearInterval(open_t);
				open_t = null;
			}
			close_t = setTimeout(function(){
				_menu.conceal();
			},200)
		}
		_menu.clearTimer = function(){
			close_t = window.clearInterval(close_t);
			close_t = null;
		}
		_menu.createCSS = function(){
		}
		$("> li", this).hover(_menu.handler, _menu.handler);
	}
})(jQuery);
$(document).ready(function(){
	$("#nav").simpleDropDown();
	$("#subContent").height($("#mainContent").height());
});
