/*
Site-wide JS
*/

var flash_duration = 6000;

$(function(){
	$("#SearchQ").hint();
	
	$("#meet").each(function(){
		var suffix = '_link';
		$('a[id$="' + suffix + '"]', $(this)).bind('click', function(e){
			e.preventDefault();
			if(!$(this).parent().hasClass('open')){
				$(this).parent().parent().children('li').removeClass('open');
				$(this).parent().addClass('open');
				$('.home_top').fadeOut('fast');
				$('#'+this.id.split(suffix)[0]).fadeIn();
			}
		}).hover(function(){
			$(this).parent().addClass('hover');
		},function(){
			$(this).parent().removeClass('hover');
		});
	});
	
	// do some javascript trickery with the main menu.
	$("body").filter(".parent_section, .parent_interior").each(function(){
		$("#menu a.currentPage").each(function(){
			$(this).parents("ul.sitemap").add($(this).find("+ ul")).show();
		});
	});
	
	$("body").filter(".interior").each(function(){
		$("#menu a.currentPage").each(function(){
			$(this).parents("a").parent("ul").prev("a").parent().andSelf().addClass('currentSection');
		});
	});
	
	setTimeout('hideMessages()', flash_duration);
});

function hideMessages() {
	$("div.message").filter(function(){
		return $(this).css("display") != "none"; // don't do the fade action if it's already hidden!
	})
	.animate({
		top: '-=75px'
	}, 'normal', 'swing', function(){
		$(this).remove();
	});
}