$(document).ready(function(){
	$('td.menu').hover(
		function(){
			var $this = $(this);
			if(!$this.hasClass('menu_selected')){
				$this.addClass('menu_hover');
			}
		}
		,
		function(){
			$(this).removeClass('menu_hover');
		}
	);

	$('td.menu a.poplink').click(function(evt){
		evt.preventDefault();
	});

	$('td.menu').click(function(){
		var thelink = $(this).find('a:first');
		if(thelink.hasClass('poplink')){
			pop_menu(thelink.attr('id'),this);
		}else{
			document.location.href = thelink.attr('href');
		}
	});

	$('div.pop_content a.poplink').click(function(evt){
		evt.preventDefault();
		var thelink = $(this);
		if(thelink.hasClass('poplink')){
			pop_sub_menu(thelink.attr('id'),thelink.parent());
		}
	});

	$('#logo_click').click(function(){
		document.location.href="index.html";
	});
	$('#logo_click_wide').click(function(){
		document.location.href="index.html";
	});


});

var popped_menu = null;
var popped_sub_menu = null;

function pop_menu(id,parent){
	var $menu = $('#menu_'+id);
	var $parent = $(parent);
	if(popped_sub_menu){
		$(popped_sub_menu).hide();
	}
	
	$(popped_menu).hide();
	if($menu[0] !== popped_menu){
		popped_menu = $menu[0];
		var pos = $parent.offset();
	
		$menu.css({'left':pos.left+'px','top':(pos.top+$parent.height())+'px'});
		$menu.show();
		if(!$menu[0]._issized){
			var $child = $('.pop_content',$menu[0]);
			$menu.height($child.outerHeight());
			$menu.width($child.outerWidth());
			$menu[0]._issized = true;
		}
	}else{
		popped_menu = null;
	}
}

function pop_sub_menu(id,parent){
	var $menu = $('#menu_'+id);
	var $parent = $(parent);
	
	$(popped_sub_menu).hide();
	if($menu[0] !== popped_sub_menu){
		popped_sub_menu = $menu[0];
		var pos = $parent.offset();
	
		$menu.css({'left':(pos.left+$parent.outerWidth())+'px','top':(pos.top)+'px'});
		$menu.show();
		if(!$menu[0]._issized){
			var $child = $('.pop_content',$menu[0]);
			$menu.height($child.outerHeight());
			$menu.width($child.outerWidth());
			$menu[0]._issized = true;
		}
	}else{
		popped_sub_menu = null;
	}
}

var menu_html = '<div id="menu_pop1" class="pop_wrap">'+
'			<div class="pop_content">'+
'			<a href="#" class="poplink" id="pop1_1">Upcoming Productions</a><br />'+
'			<a href="#" class="poplink" id="pop1_2">Ongoing Productions</a><br />'+
'			<a href="#" class="poplink" id="pop1_3">Past Productions</a><br />'+
'			</div>'+
'	</div>'+
'		<div id="menu_pop1_1" class="pop_wrap">'+
'			<div class="pop_content">'+
'					<a href="upcoming_kink-cad.html">Da Kink In My Hair - CAD</a><br />'+
'			</div>'+
'		</div>'+
'		<div id="menu_pop1_2" class="pop_wrap">'+
'			<div class="pop_content">'+
'					<a href="ongoing_ear.html">Da Streets To Da Ear</a><br />'+
'					<a href="ongoing_lyme.html">Lyme &amp; Tings</a><br />'+
'			</div>'+
'		</div>'+
'		<div id="menu_pop1_3" class="pop_wrap">'+
'			<div class="pop_content">'+
'					<a href="past_tedx.html">Tedx</a><br />'+
'					<a href="upcoming_kink-nyu.html">Da Kink In My Hair - NYU</a><br />'+
'					<a href="past_kink-theatre.html">Da Kink In My Hair - Theatre</a><br />'+
'					<a href="past_kink-tv.html">Da Kink In My Hair - Tv</a><br />'+
'					<a href="past_secrets.html">Secrets Of A Black Boy</a><br />'+
'					<a href="past_funny.html">Dat Girl Sho Is Funny</a><br />'+
'					<a href="past_mint.html">I Am Not A Dinner Mint</a><br />'+
'			</div>'+
'		</div>'+
'	<div id="menu_pop2" class="pop_wrap">'+
'		<div class="pop_content">'+
'				<a href="who_we_are.html">Who We Are</a><br />'+
'				<a href="bio.html">Biography</a><br />'+
'				<a href="speakers_spotlight.html">Speakers Spotlight</a><br />'+
'				<a href="awards.html">Awards</a><br />'+
'		</div>'+
'	</div>'+
'	<div id="menu_pop3" class="pop_wrap">'+
'		<div class="pop_content">'+
'				<a href="news_articles.html">Articles</a><br />'+
'				<a href="news_novel.html">Novel</a><br />'+
'				<a href="http://thetruthaccordingtotrey.blogspot.com/">Blog</a><br />'+
'		</div>'+
'	</div>';
