var _pageIndex = 1;
	
function scrollPortfolio(index) {
	// TODO: fix (bad int?) next/previous page bug
	index = parseInt(index);
	_pageIndex = index;
	$('#portfolio #latestWorkIndex p').removeClass('selected');
	$('#portfolio #latestWorkIndex p.index' + index).addClass('selected');

	window.location = '#' + index;

	$('#latestWork').animate({ scrollLeft: 626 * (index -1) }, 500);
}

$(function() {
	$('#portfolio #latestWorkIndex p').click(function() {
		scrollPortfolio($(this).text());
	}).each(function() {
		$(this).addClass('index' + $(this).text());
	});
	
	$('#latestWorkIndexNext').click(function() {
		if (_pageIndex < _pagesCount) {
			scrollPortfolio(_pageIndex +1);
		}
		return false;
	});
	
	$('#latestWorkIndexPrevious').click(function() {
		if (_pageIndex > 1) {
			scrollPortfolio(_pageIndex -1);
		}
		return false;
	});
	
	var currentUrl = window.location + '';
	var hashIndex = currentUrl.lastIndexOf('#');
	if (hashIndex > -1) {
		scrollPortfolio(currentUrl.substr(hashIndex +1));
	} else {
		scrollPortfolio(1);
	}
});
