var lastMenuItem;
function DropUpMenu( element ){
	var self = this;
	this.root = element;
	this.content = $("#navContent", this.root);
	this.link = $(".mainNav li:not(.noSubNav) a", this.root);
	this.blankLink = $(".mainNav li.noSubNav a", this.root);
	this.construct = function() {
		var switchSubNav = new SwitchSubNav(self.content);
		self.link.bind('mouseenter', switchSubNav.linkOver);
		self.blankLink.bind('mouseenter', switchSubNav.blankLinkOver);
		showHideContent = new ShowHideContent(self.content);
		self.link.bind('mouseenter', showHideContent.showContent);
		self.content.bind('bindingLeave', function() {
			self.root.bind('mouseleave', showHideContent.hideContent);
		});
	}
	this.construct();
}
function SwitchSubNav(content) {
	var self = this;
	this.content = content;
	this.linkOver = function() {
		this.className = $(this).parent().attr('class');
		if(typeof lastMenuItem !='undefined'){
			lastMenuItem.className=".subNavmedia";
		}
		this.className='ui-tabs-selected';
		lastMenuItem=this;
		$('ul:not(' + $(this).parent().attr('class') + ')', self.content).removeAttr('id');	
		$('ul' + $(this).parent().attr('class'), self.content).attr({ id: 'showSubNav' });		
	}
	this.blankLinkOver = function() {
		$('ul:not(.mainNav)', self.content).removeAttr('id');
	}
}
function ShowHideContent(content) {
	var self = this;
	this.content = content;
	this.showContent = function() {
		self.content.stop().animate( {top:'16px'}, 500, function() {
		self.content.trigger('bindingLeave');
		});
	}
	this.hideContent = function() {
		var timeOut = setTimeout(function() {
			self.content.stop().animate( {top:'43px'}, 900 );lastMenuItem.className=".subNavmedia";
		}, 2500);		
	}
}
$(function() { 
	var dropUpMenu = new DropUpMenu($('#navWrapper'));
	$("#tabs").tabs({ selected: null, fx: { opacity: 'toggle' } });
	var $tabs = $('#tabs').tabs();
	$('#defaultTabH3').click(function() { // bind click event to link
		$tabs.tabs('select', 0); 
		return false;
	});
	$("#rightTabs").tabs({ fx: { opacity: 'toggle' } }); 
	$("div.button").click(function() {
		var pageName = $(this).attr('id');
		window.location = pageName + ".php";
	});
	
	$("div.button").bind('mouseenter', function(){
	  $(this).addClass("overBigButton");
	});
	$("div.button").bind('mouseleave', function(){
	  $(this).removeClass("overBigButton");
	});
	
});