//
var d=document;

$.fn.equalHeight=function(){
	var maxH=0;
	this.each(function(){
		var h=$(this).height();
		if(h>maxH)
			maxH=h;
	});
	this.height(maxH);
}

function Tabs(trigger,content){
	
	if(!d.getElementById(trigger) || !d.getElementById(content))
		return false;
		
	var $trigger=$('#'+trigger);
	var $content=$('#'+content);
	
	$trigger.children().each(function(i){
		$(this).click(function(e){
			e.preventDefault();
			$trigger.children().removeClass('active');
			$(this).addClass('active');
			$content.children().hide().eq(i).show();
		});
	});
	
	$trigger.children().eq(0).click();
	//$content.children().equalHeight();
	
}

function menu(){
	
	var self=this;
	this.timer=false;
	this.tiemout=10;
	
	this.hide=function(){
		
		self.timer=setTimeout(function(){
			$('#menu div').hide();
		},self.tiemout);
		
	}
	
	this.retain=function(){
		if(self.timer)
			clearTimeout(self.timer);
	}

	$('#nav a').hover(function(){
							   
		self.retain();

		$('#menu div').hide();

		var target=this.className;
		var position=$(this).offset();
		var h=$(this).height();
		var css={
			top:position.top+h,
			left:position.left
		};

		$('#menu .'+target).css(css).show();

	},self.hide);

	$('#menu div').hover(self.retain,self.hide);

}


$(function(){

	new Tabs('tabs','tabContent');

	menu();

});
