var _pageIndex = 1;
	
function scrollPortfolio(index) {
	// TODO: fix (bad int?) next/previous page bug
	index = parseInt(index);
	_pageIndex = index;
	//window.location = '#' + index;

	$('#slideshow').animate({ scrollLeft: 147 * (index -1) }, 500);
}

$(function() {	
	$('#latestWorkIndexNext').click(function() {
		if (_pageIndex < _pagesCount) {
			scrollPortfolio(_pageIndex +1);
		}else{
                        scrollPortfolio(1);
                }
	});
	
	$('#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);
	}*/
});

var t;
var timer_is_on=0;

if (!timer_is_on){
  timer_is_on=1;
  timedCount();
}

function timedCount(){
    $('#latestWorkIndexNext').click();
    t=setTimeout("timedCount()",3000);
}
