
$(document).ready(function(){
	
	// fix png transparency
	$(document).pngFix();
	
	// smoove scroll
	$.localScroll({ hash: true });
    $.localScroll.hash({ hash: true });
						   
	// load Superfish navigation
	$("ul.nav").superfish({ animation : { opacity : "show", height : "show" } , speed : "fast" });
	
	/* --------------------------------------------
	 * main nav parent and current classes
	 * -------------------------------------------- */
	
	$("ul.nav li li ul").parent("li").addClass("parent");

	var l2Node = "node" + pageGlobals.level2NodeId;
	var nodeId = "node" + pageGlobals.nodeId;
	
	$("ul.nav a[class*='" + l2Node +"']").parent('li').addClass('current');
	$("ul.nav a[class*='" + nodeId +"']").parent('li').addClass('current');
	
	
	/* --------------------------------------------
	 * spotlight opacity
	 * -------------------------------------------- */
	
	$(".spot a").css('opacity', 0.6).hover(
		function(){ $(this).stop().fadeTo( 'normal', 1 ); },
		function(){ $(this).stop().fadeTo( 2500, 0.6 ); }
	);
	
	/* --------------------------------------------
	 * nav-local animations
	 * -------------------------------------------- */
	
	$(".nav-local ul a:not(.current)").hover(
		function(){ $(this).stop().animate( { backgroundColor: '#f2f6fb', textIndent: "5px" }, 200 ); },
		function(){	$(this).stop().animate( { backgroundColor: '#fcfcfc', textIndent: "0" }, 500 ); }
	);
	
	
	/* --------------------------------------------
	 * dostuff spotlight
	 * -------------------------------------------- */

	function show_dostuff( obj ){
		$(obj).find('ul').slideDown( 600 ); 
	}
	function hide_dostuff( obj ){
		$(obj).find('ul').slideUp( 1000, 'easeOutExpo' );
	}
	
	// $('#dostuff').css('opacity', 0.6);
	$("#dostuff ul").hide();
	$("#dostuff").attr( "tabindex", "0").hoverIntent(
		function(){ 
			$(this).stop().fadeTo( 'normal', 1 ); show_dostuff( this ); 
		},
		function(){ 
			hide_dostuff( this ); // $(this).stop().fadeTo( 2500, 0.6 ); 
		}				
	);
	$("#dostuff ul a").hover(
		function(){ $(this).stop().animate( { backgroundColor: '#f2f6fb', textIndent: "5px" }, 400 ); },
		function(){ $(this).stop().animate( { backgroundColor: '#fcfcfc', textIndent: "0" }, 300 ); }
	);
	
	$("ul.associated").hide();
	$(".nav-local h2").click( function(){ 
								$(this).siblings('h2').animate( { color: '#777777' }, 400)
									   .end().animate( { color: '#111111' }, 600)
									   .next().slideToggle().siblings('ul').slideUp();
								}
	);
	
	/* --------------------------------------------
	 * multitoggles
	 * -------------------------------------------- */
	 
	function showToggle( el ){
		$(el).parents('div.toggle').addClass('open').find('.target').slideDown();
		$(el).parents('div.toggle').animate( { backgroundColor: '#e5eef7' }, 600 );
		setToggleAll( el );
	}
	function hideToggle( el ){
		$(el).parents('div.toggle').removeClass('open').find('.target').slideUp();
		$(el).parents('div.toggle').animate( { backgroundColor: '#ffffff' }, 600 );
		setToggleAll( el );
	}
	
	function setToggleAll( el, mtoggle ){
		var mtoggle = mtoggle || $(el).parents('div.mtoggle').get(0);
		var allOpen = $(mtoggle).find('.toggle.open').length == $(mtoggle).find('.toggle').length;
		if( allOpen ){
			$(mtoggle).find('h2 a')
				.unbind('click')
				.find('span').html('hide all').end()
				.bind('click', function(e){
					$(mtoggle).find('h3 a').each( function(){ hideToggle( this ); })
					return false;
			});
		} else {
			$(mtoggle).find('h2 a')
				.unbind('click')
				.find('span').html('show all').end()
				.bind('click', function(){
					$(mtoggle).find('h3 a').each( function(){ showToggle( this ); })
					return false;
			});
		}
			
	}
	
	// set up the "show/hide all" link			
	 $(".mtoggle h2")
		.append(' <span>show all</span>')
		.wrapInner('<a href="#" class="multi-toggler"></a>');			
	
	$('div.mtoggle').each( function(){ setToggleAll( null, this) } );

	
	// initialize the individual toggles
	$(".toggle").each( function(){
		$(this).addClass('js').find('.target').hide();
		
		$(this).find('h3:first').wrapInner('<a href="#" class="toggler"></a>')
			.click( function(e){
				e.preventDefault();
				var isOpen = $(this).parents('div.toggle').hasClass('open');
				if( isOpen ){
					hideToggle( this );	
				} else {
					showToggle( this );
				}
			})
			.find('a').append('<span>read more</span>');	
	});		
}); // end document.ready()