function scrollPortfolioWorksRight() {
	var works = $('div.portfolio-works-list a');
	var indent = parseInt($('div.portfolio-works-list').css('text-indent').replace(/[^0-9]/));

	if ((indent - 109) > (0 - ((works.length - 2) * 109))) {
		$('div.portfolio-works-list').css('text-indent', (indent - 109) + 'px');
	} else if (works.length * 109 > $('div.portfolio-works-list').width()) {
		$('div.portfolio-works-list').css('text-indent', ((0 - (works.length * 109)) + $('div.portfolio-works-list').width()) + 'px');
	}

	return false;
}

function scrollPortfolioWorksLeft() {
	var indent = parseInt($('div.portfolio-works-list').css('text-indent').replace(/[^0-9]/));

	if ((indent + 109) > 0) {
		$('div.portfolio-works-list').css('text-indent', (0 - (indent + 109)) + 'px');
	} else {
		$('div.portfolio-works-list').css('text-indent', '0px');
	}

	return false;
}

function scrollPortfolioFoldersRight() {
	var folders = $('div.portfolio-folders-list a');
	var indent = parseInt($('div.portfolio-folders-list').css('text-indent').replace(/[^0-9]/));

	if ((indent - 221) > (0 - ((folders.length - 2) * 221))) {
		$('div.portfolio-folders-list').css('text-indent', (indent - 221) + 'px');
	} else if (folders.length * 221 > $('div.portfolio-folders-list').width()) {
		$('div.portfolio-folders-list').css('text-indent', ((0 - (folders.length * 221)) + $('div.portfolio-folders-list').width()) + 'px');
	}

	return false;
}

function scrollPortfolioFoldersLeft() {
	var indent = parseInt($('div.portfolio-folders-list').css('text-indent').replace(/[^0-9]/));

	if ((indent + 221) > 0) {
		$('div.portfolio-folders-list').css('text-indent', (0 - (indent + 221)) + 'px');
	} else {
		$('div.portfolio-folders-list').css('text-indent', '0px');
	}

	return false;
}

$(document).ready(function() {
	$('.portfolio-picture-preview').mousemove(function(e) {
		var previewPos = $('#portfolio_picture_preview_' + this.id.replace(/[^0-9]+/g, '')).offset();
		var mouseX = e.pageX - previewPos.left;
		var mouseY = e.pageY - previewPos.top;
		var marginX = parseInt($('#portfolio_picture_preview_' + this.id.replace(/[^0-9]+/g, '') + '_width').val()) - $('#portfolio_picture_preview_' + this.id.replace(/[^0-9]+/g, '')).width();
		var marginY = parseInt($('#portfolio_picture_preview_' + this.id.replace(/[^0-9]+/g, '') + '_height').val()) - $('#portfolio_picture_preview_' + this.id.replace(/[^0-9]+/g, '')).height();
		var ratioX = mouseX / $('#portfolio_picture_preview_' + this.id.replace(/[^0-9]+/g, '')).width();
		var ratioY = mouseY / $('#portfolio_picture_preview_' + this.id.replace(/[^0-9]+/g, '')).height();
		var xPos = 0;
		if (marginX > 0) {
			xPos = (0 - parseInt(marginX * ratioX));
		} else {
			xPos = (0 - parseInt(marginX / 2));
		}
		var yPos = 0;
		if (marginY > 0) {
			yPos = (0 - parseInt(marginY * ratioY));
		} else {
			yPos = (0 - parseInt(marginY / 2));
		}
		$('#portfolio_picture_preview_' + this.id.replace(/[^0-9]+/g, '')).css('background-position', xPos + 'px ' + yPos + 'px');
	});
});

function showFolder(folderId) {
	$('div.portfolio-folders-list a').removeClass('selected');
	$('#folder_' + folderId).addClass('selected');
	$('div.portfolio-works-list').fadeOut(150);
	$('#folder_' + folderId + '_works').fadeIn(150);
	$('.portfolio-content').fadeOut(150);
	$('#folder_content_' + folderId).fadeIn(150);
}

function showWork(workId) {
	$('div.portfolio-works-list a').removeClass('selected');
	$('#work_' + workId + '_link').addClass('selected');
	$('.portfolio-work').fadeOut(150);
	$('#work_' + workId).fadeIn(150);
}
