$(document).ready(function(){
	$('#home_link').click(function(){$('#content').toggle('slow');$('#menu ul li.section-title').each(toggleNav)});
	
	$('#menu ul li.section-title').click(setNav);
	
	var nowSelected;
	
	function setNav(){
		//alert($(this)[0]);
		var ul = $(this).parent();
		//alert(ul.children('li').length);
		if(ul.height() > 21){
			h = 21;
			ul.removeClass('expanded');
		}else{
			h = (ul.children('li').length-1)*15+21;
			ul.addClass('expanded');
		}
		ul.animate({
			height: h
		  }, 500, function() {
			  //nowSelected = $(this);
			// Animation complete.
		  });

	}
	
	function toggleNav(){
		//alert($(this)[0]);
		var ul = $(this).parent();
		//alert(ul.children('li').length);
		if((ul.is('.expanded') && ul.height() > 21) || !ul.is('.expanded')){
			h = 21;
			//ul.removeClass('expanded');
		}else if(ul.is('.expanded') && ul.height() <= 21){
			h = (ul.children('li').length-1)*15+21;
			//ul.addClass('expanded');
		}
		ul.animate({
			height: h
		  }, 500, function() {
			// Animation complete.
		  });

	} 
	
	$('#menu ul').each(initNav);
	
	function initNav(){
		var ok = false;
		$(this).find('a').each(function(){if($(this).attr('href') == document.location){ok = true}});
		//document.title += $(this).find('a').href+' ';
		if(ok == false){
			//document.title += document.location;
			$(this).css('height','20px');
		}else{
			//nowSelected = $(this);
			$(this).addClass('expanded');
		}
	}
	
	//onclick="$('#s1 div').html(unescape('".html_entity_decode($embed[0]['embed'])."'));"
	
	$('#video_close').click(function(){$('#video_wrapper').hide('fast');});
	
	
	
});



function showVideo(embed_txt){ 
		//if($('#video_container').html() == '<a href="javascript:;" id="video_close">x</a>'){
			$('#video_container').html('<a onclick="$(\'#video_wrapper\').hide(\'fast\');$(\'#video_container\').html(\'\')" href="javascript:;" id="video_close">x</a>'+embed_txt);
			$('#video_container').css('visibility','hidden');
		//}
		$('#video_wrapper').animate({
			opacity: 1
		  }, 600, function() {
			//document.title = $('#video_container iframe').width();
			$('#video_container').css('visibility','visible');
			$('#video_container').css('width', $('#video_container iframe').width()+'px');
			$('#video_container').css('margin-left','-'+($('#video_container iframe').width()/2)+'px');
			$('#video_container').css('margin-top','-'+($('#video_container iframe').height()/2)+'px');
		  });

	}
