// dropdown navigation
function Dropdown(item){
	this.onItem = false;
	this.onSubNav = false;
	this.isOpen = false;
	this.item = $(item);
	this.subnav = this.item.siblings("ul");
	this.init();
	return this;
}

Dropdown.prototype = {
	start: function(){
		var self = this;
	
		this.timer = window.setInterval(function(){
			if(!self.onItem && !self.onSubNav && self.isOpen){
				self.stop();
			}
		}, 250);
	},
	stop: function(){
		window.clearInterval(this.timer);
		this.subnav.hide();
		this.isOpen = false;
		this.item.removeClass("active");
	},
	init: function(){
		var self = this;
	
		// bind to the main item
		this.item.bind("mouseenter mouseleave", function(e){
		
			// assume no
			self.onItem = false;
		
			if(e.type === "mouseenter"){
				$(this).addClass("active");
				self.start();
				self.subnav.show();
				self.onItem = true;
				self.isOpen = true;
			}
		});
	
		// bind to subnav
		this.subnav.bind("mouseenter mouseleave", function(e){
			self.onSubNav = (e.type === "mouseenter") ? true : false;
		});
	}
}

