/* MIT Engineering Effects (requires jQuery, jQuery UI Accordion, and jQuery UI effects) */
/* by White Whale Web Services */

$(document).ready(function() { // on DOM load
	$.easing.def = 'easeInOutCubic'; // sets default easing equation for all animations
	
	var subnavs = $('.sub_subnavigation');
	if($('#subnavigation li').length>1||$('body').is('.homepage')) { // if there are more than one main links
		subnavs.hide();
	// Toggle subnavigation (on both homepage and interior pages)
		$('.subnavigation li:has(.sub_subnavigation) h3 a,#subnavigation li:has(.sub_subnavigation) h2 a').css('cursor','pointer').click(function(e) {
			e.preventDefault();
			var clicked_nav = $(this).parents('li').eq(0).find('.sub_subnavigation'),visible = clicked_nav.is(':visible');
			if($('.sub_subnavigation:visible').length) $('.sub_subnavigation:visible').slideUp(400,function() { if(!visible) clicked_nav.slideDown(650); }); // slide up any visible nav before sliding down this one
	 		else clicked_nav.slideDown(650); // otherwise, just slide down this one
	    });
	} else {
		var toggle = subnavs.prev().find('a');
		toggle.replaceWith(toggle.html());
		subnavs.show();  // hide them (they will be toggled in with JS interaction)		
	}
	
// Navigation rollover effect
//creates dumb navigation effect for IE users
if($.browser.msie){
	//adds a 60% opaque white fill to the span's background
	$('#navigation li a span').css({background:'#fff none', filter:'alpha(opacity=60)'});
	//adds hover functionality to the span
	$('#navigation li').hover(function() {
    		$(this).find('a span').css('filter','alpha(opacity=0)');
		},function() {
    		$(this).find('a span').css('filter','alpha(opacity=60)');
		}
	);
} else {
//this works in all browsers but IE
	$('#navigation li').hover(function() {
    		$('#navigation li#'+$('body').attr('class')+' span').stop().fadeTo(200,1); // gray out the active nav
    		$(this).find('a span').stop().fadeTo(300,0); // grab the overlay span and fade it out
		},function() {
    		$(this).find('a span').stop().fadeTo(200,1); // grab the overlay span and fade it in
    		$('#navigation li#'+$('body').attr('class')+' span').stop().fadeTo(200,0); // bring back the active nav
		}
	);
}; 

	
// Add "active" class to appropriate subnav li and parent based on body class
//	$('#nav_'+$('body').attr('id')).addClass('active').parents('ul').show();
	$('#subnavigation li[id^=activateOnClass]').each(function() {
		if($('body').hasClass(this.id.substr(16))) {
			$(this).find('a').addClass('active');
		}
	});
	$('.sub_subnavigation .active').parents('ul,div').show();

if($('body').is('#question')) {
	if(window.location.hash) $('.back_to_ask').attr('href','ask/'+window.location.hash);
	$('#subnavigation ul li').eq(4).nextAll().hide();
	$('<a href="#" style="font-size:0.9em;color:#666;display:block;text-align:right;margin-top:0.3em;">Show all related...</a>').insertAfter('#subnavigation ul').click(function() { $(this).remove(); $('#subnavigation ul li').eq(4).nextAll().slideDown(600); return false; });
}

});/*close ready function*/

