$(document).ready(function() {
	/* Remove <a> from <img> so scrollable works correctly */
	$('#portfolio_nav .items img').each(function(){
		$(this).unwrap();
	});
	$('#outer_nav_prev, #outer_nav_next').each(function(){
		$(this).removeAttr('href');
	});

	/* Scroll Portfolio Image and Info */
	$("#portfolio_img, #portfolio_info").scrollable({
		size: 1,
		clickable:false,
		speed: 500,
		nextPage: '#inner_nav_next',
		prevPage: '#inner_nav_prev'		
	}).navigator({
		navi: "#portfolio_nav",
		naviItem: 'img'
	});

	/* Scroll Portfolio Nav */
	$("#portfolio_nav").scrollable({
		size: 3, 
		keyboard: false,
		speed: 500,
		nextPage: '#outer_nav_next',
		prevPage: '#outer_nav_prev'		
	}).navigator();		
			
	/* Toggle Portfolio Inner Nav */
	$('#portfolio_img').mouseenter(function(){
		$('#inner_nav_next, #inner_nav_prev').dequeue().fadeTo(500,1);
	}).mouseleave(function(){
		$('#inner_nav_next, #inner_nav_prev').dequeue().fadeTo(500,0.01);
	});	
	
	/* Toggle Portfolio Link */
	$('#portfolio_img div').mouseenter(function(){
		$(this).find('a').dequeue().fadeTo(500,1);
	}).mouseleave(function(){
		$(this).find('a').dequeue().fadeTo(500,0.01);
	});	
	
	/* Nav Highlight Onload */
	var anchor = document.location.hash.substring(1);
	if (anchor != '') { 
		$('#nav_'+anchor).css('backgroundPosition','0 -12px');
	} else {
		$('#nav_home').css('backgroundPosition','0 -12px');
	}
	
	/* Nav Highlight Events */
	$('ul li[id^="nav_"] a').not('#nav_quote a').mouseover(function(){
		$(this).closest('li').css('backgroundPosition','0 -12px');
	}).mouseout(function(){
		var anchor = (document.location.hash != '')?document.location.hash.substring(1):'home';
		if ($(this).closest('li').attr('id') != 'nav_'+anchor) {
			$(this).closest('li').css('backgroundPosition','0 24px');
		}
	}).click(function(){
		var parent = $(this).closest('li').attr('id');
		$('ul li[id^="nav_"]').not('#'+parent+', #nav_quote').css('backgroundPosition','0 24px');
	});

	/* Animate Quote Me */
	$('#nav_quote').mouseover(function(){
		$(this).animate({'top':'0'},{duration:200, queue:false});
	}).mouseout(function(){
		$(this).animate({'top':'-10px'},{duration:200, queue:false});
	});

});

