jQuery(function( $ ){
	$('#archives-pane ul li:last').addClass('lastNews');
	$('.singleFade').fadeIn(1000);
});
/* NAV EXCLUSIONS AND DIV CREATION */

$(buttonHide = function() {
	setTimeout(function(){
		var elemM = $('.menuClip:visible');
   		if (elemM[0].scrollHeight - elemM.scrollTop() == elemM.outerHeight()) {
			$('.menuDown').animate({"opacity":"0"}, 200);
		} else {
			$('.menuDown').animate({"opacity":"1"}, 200);
		}
		
		if (elemM.scrollTop() == 0) {
			$('.menuUp').animate({"opacity":"0"}, 200);
		} else {
			$('.menuUp').animate({"opacity":"1"}, 200);
		}
	}, 200);
});

jQuery(function( $ ){
	/* link disabling */
    $('#nav .page-item-1345>a, #nav .page-item-711>a, #nav .page-item-823>a, #nav .page-item-5>a, #nav .page-item-22>a, #nav .page-item-20>a, #nav .page-item-18>a, #nav .page-item-16>a, #nav .page-item-206>a, #nav .page-item-6>a').attr("href", "#");
    $('#nav .page-item-1345>a, #nav .page-item-711>a, #nav .page-item-823>a, #nav .page-item-5>a, #nav .page-item-22>a, #nav .page-item-20>a, #nav .page-item-18>a, #nav .page-item-16>a, #nav .page-item-206>a, #nav .page-item-6>a').addClass("peup");
	
	/* kill titles cause Tooltips interrupts my script! */
    $('#nav li a').removeAttr('title');
	/* kill titles for thumbs on project pages */

	/* wraps the sub-sub-nav in a div for scrolling... I can't BELIEVE this works*/
	$('#nav > li > ul > li > ul').wrap('<div class="menuClip"></div>');
	$('.menuClip').wrap('<div class="subsubnav"></div>');
	
	/* creates nav buttons */
	$('.menuClip').before('<div class="menuUp menuInactive"></div>');
	$('.menuClip').after('<div class="menuDown menuInactive"></div>');
});





/* MENU FADING */

jQuery(function( $ ){
	/* actions for top-level items */
	$('#nav > li:not(.current_page_ancestor, .current_page_item)').hoverIntent(
		function() {
			$(this).find('ul').fadeIn(200);
			$(document).find('.current_page_ancestor > ul, .current_page_item > ul, .current_page_parent > .subsubnav').fadeOut(200);
		}, function() {
			$(this).find('ul').fadeOut(200);
		}
	);

	/* action for current top-level items */
	$('#nav > li.current_page_ancestor, #nav > li.current_page_item').hoverIntent(
		function() {
			$(this).find('ul').fadeIn(200);
		}, function() {}
	);

	/* actions for 2nd-level items */
	$('#nav > li > ul > li:not(.current_page_parent, .current_page_item)').hoverIntent(
		function() {
			$(document).find('.current_page_parent > .subsubnav, .current_page_item > .subsubnav').fadeOut(200);
			$(this).find('.subsubnav').fadeIn(200, buttonHide );
		}, function() {
			$(this).find('.subsubnav').fadeOut(200);
		}
	);

	/* action for current 2nd-level items */
	$('#nav > li > ul > li.current_page_parent, #nav > li > ul > li.current_page_item').hoverIntent(
		function() {
			$(this).find('.subsubnav').fadeIn(200, buttonHide );
		}, function() {}
	);

	/* actions for leaving nav area */
	$('#navigation').hoverIntent(
		function(){}, function () {
			setTimeout(function(){
				$(document).find('.archive .page-item-4 > ul, .current_page_ancestor > ul, .current_page_item > ul, .current_page_parent > .subsubnav, .current_page_item > .subsubnav').fadeIn(200);
				$(document).find('.menuClip').stop().scrollTo( $('.current_page_item'));
				buttonHide();
			}, 600);
		}
	);
});

jQuery(function( $ ){

/* BEGIN MENU SCROLLER INITIALIZATION */

	// Resets pane
	$('.menuClip').scrollTo( 0 );

	// scrolls to active item to 
	$('body:not(.archive) .menuClip').stop().scrollTo( $('.current_page_item') );

	$('.menuDown').click(function(){
		$('.menuClip').stop().scrollTo( '+=70px', 800, {
			onAfter:function(){
				buttonHide();
			}
		});
	});
	$('.menuUp').click(function(){
		$('.menuClip').stop().scrollTo( '-=70px', 800, {
			onAfter:function(){
				buttonHide();
			}
		});
	});

/* END MENU SCROLLER INITIALIZATION */	

});

jQuery(function( $ ){

	$(inactiveContentStates = function() {
		var elemC = $('#content');
		if (elemC[0].scrollHeight - elemC.scrollTop() == elemC.outerHeight()) {
			$('#move_this_down').animate({"opacity":"0"}, 200);
		} else {
			$('#move_this_down').animate({"opacity":"1"}, 200);
		}
		
		if (elemC.scrollTop() == 0) {
			$('#move_this_up').animate({"opacity":"0"}, 200);
		} else {
			$('#move_this_up').animate({"opacity":"1"}, 200);
		}
	});




/* BEGIN CONTENT SCROLLER INITIALIZATION */

	// Resets pane to (0,0)
	$('#content').scrollTo( 0 );
	
	$('#move_this_down').click(function(){
		$('#content').stop().scrollTo( '+=270', 1000,
			{ onAfter:function(){
				inactiveContentStates();
			}
		});
	});

	$('#move_this_up').click(function(){
		$('#content').stop().scrollTo( '-=270', 1000,
			{ onAfter:function(){
				inactiveContentStates();
			}
		});
	});

/* END CONTENT SCROLLER INITIALIZATION */





/* BEGIN NEWS SCROLLER INITIALIZATION */

	// Resets pane to (0,0)
	$('#archives-pane').scrollTo( 0 );

	// Set class for first link
	$('#newsLinks > li:eq(0) a').addClass('selectedPoast');

	// handles indexing variable stuff, class changing, etc
	$('#newsLinks li').click(function(){
		var listy = $('#newsLinks li');
		var opa = listy.index(this);
		$('#archives-pane').stop().scrollTo( 'li:eq('+opa+')', 1000 );
		$(document).find('.selectedPoast').removeClass('selectedPoast');
		$(this).find('a').addClass('selectedPoast');		
	});

/* END NEWS SCROLLER INITIALIZATION */


});
