$(function(){

	// jQuery PNG fix
	$(document).pngFix();

	// Remove the anchor actions.  Will be replaced with new functions.
	$('a').click(function(e) {
		//e.preventDefault();
	})

	// Enable parallax effect on download link
	$('#download_resume').jparallax({xparallax: true}, {xorigin: 0.8, xtravel: 0.4, ytravel: 0.2});

	// Insert navigation divs. Inserted via jQuery since they are not part of the content.   
	$('div.project_gallery').append('<div class="nav_arrows scroll_left"></div><div class="nav_arrows scroll_right"></div>');

	// Auto-size the initial height and opacity of the navigation boxes
	$('div.scroll_left, div.scroll_right').each(function (i) {
		var p_height = $(this).parent().height();
		$(this).height(p_height);
		$(this).css('opacity', 0);
	})


	// Fade in/out for project navigation, when user rolls over arrows
	$('div.scroll_left, div.scroll_right')
		.mouseover(function(){
			$(this).stop().animate({opacity: 0.7}, 500);
		})
		.mouseout(function(){
			$(this).stop().animate({opacity: 0}, 1200);
		})
	
	// Fade in/out for project navigation, when user rolls over project, show arrows
	$('div.project_gallery ul')
		.mouseover(function(){
			$(this).parent().find('div.scroll_left, div.scroll_right').stop().animate({opacity: 0.4}, 500);
		})
		.mouseout(function(){
			$(this).parent().find('div.scroll_left, div.scroll_right').stop().animate({opacity: 0}, 500);
		})

	// Navigation functions
	$('div.scroll_left, div.scroll_right').click(function(){
		var $project = $(this).siblings().filter('ul');
		var moveby   = $project.children().filter('li').width();
		var ypos     = $project.css('left');
		var maxpos   = Math.abs(($project.children().length - 1) * moveby) * -1;
	
		ypos = Number(ypos.substring(0,ypos.indexOf('px')));
				
		if ($(this).hasClass('scroll_left')) {
			ypos += moveby;
		} else if ($(this).hasClass('scroll_right')) {
			ypos -= moveby;
		} else {
			// Do nothing to ypos
		}
		
		if (ypos % moveby == 0 && 0 >= ypos && ypos >= maxpos) {
			$project.animate({left: ypos}, 1000)  
		}
	})	
	

	/* SerialScroll non-working
	$('li.project').serialScroll({
		target: 'div.project_gallery',
		items:'li',
		prev:'div.scroll_left',
		next:'div.scroll_right',
		duration:1200,
		stop:true,
		lock:true,
		cycle:true
	});*/																						
})
