var nnevent= {};

// menu controller
nnevent.menu = {

	// current menu item
	cm: false,

	// current reveal
	cv: false,

	// timer
	mt: null,

	// clear delay
	cd: 200,

	// mouse over a top menu
	menuover: function(mid) {
		clearTimeout(this.mt);
		this.cv = false;
		this.hidereveals()
		this.cm = mid.replace('tn-','');
		this.showpanel();
	},

	// mouse out of a top menu
	menuout: function() {
		this.startTimeout();
	},

	// mouse over reveal panel
	revealover: function(id) {
		this.cv = id;		
	},

	// mouse out of reveal panel
	revealout: function() {
		this.cv = false;
		this.startTimeout();
	},

	showpanel: function() {
		$("#tn-"+this.cm).addClass("hi");
		$("#"+this.cm).removeClass("offscreen").hide().slideDown('normal');
		//console.log($("#"+this.cm));
	},

	startTimeout: function() {
		clearTimeout(this.mt);
		this.mt = setTimeout('nnevent.menu.hidereveals()',this.cd);
	},

	// hide all menus
	hidereveals: function() {
		if(this.cv != false) {
			return;
		}
		$(".menu-reveal").addClass("offscreen");
		$("#tn-"+this.cm).removeClass("hi");
		this.cm = false;
		this.cv = false;
		
	}
}

// apply rounded button markup
nnevent.roundbutton = function(el) {
	c = ($.browser.mozilla) ? ' ff' : '';
	cls = el.attr("class")+ c;
	el.html('<span class="'+cls+'">'+el.text()+'</span>');
}

// JQuery thangs
$(function(){

	// menu handler
	$("#topnav a.tnr").hover(
		function(){nnevent.menu.menuover( $(this).attr("id") )},
		function(){nnevent.menu.menuout()}
	);

	// panel handler
	$("#topnav .menu-reveal").hover(
		function(){nnevent.menu.revealover( $(this).attr("id") )},
		function(){nnevent.menu.revealout()}
	);

	// popup close
	$("a.unblockui").live("click",function(e){
		e.preventDefault();
		$.unblockUI();
	})

	// buttons
	$(".rl").each(function(){
		nnevent.roundbutton($(this));
	})

})

