var positions = [
		[20, 27, 0, 20],
		[30, 50, 33, 15],
		[40, 73, 66, 10],
		[50, 96, 100, 5]
	],
	currentPos = 0,
	parallaxSpeed = 2000;

function moveBackground (noAnimation) {
	$(".links-block").hide();

	if ($.browser.webkit)
	{
		for (var i = 1; i < 4; i++) {
			$("#background-" + i).css("background-position", positions[currentPos][i-1] + "% -45px");
		}
		$("#background").css("background-position", positions[currentPos][3] + "% 0%");
	}
	else
	{
		$("#background-1").stop().animate({ backgroundPosition : positions[currentPos][0] + "% -45px"}, parallaxSpeed);
		$("#background-2").stop().animate({ backgroundPosition : positions[currentPos][1] + "% -45px"}, parallaxSpeed);
		$("#background-3").stop().animate({ backgroundPosition : positions[currentPos][2] + "% -45px"}, parallaxSpeed);
		$("#background").stop().animate({ backgroundPosition : positions[currentPos][3] + "% 0"}, parallaxSpeed);
	}
	var linksPos = currentPos + 1;

	$(".links-"+ linksPos).show(parallaxSpeed);
}

function disableAnimation () {
	parallaxSpeed = 1;
	$("html").addClass("noanimation");
}

function enableAnimation () {
	parallaxSpeed = 2000;
	$("html").removeClass("noanimation");
}

$(document).ready ( function () {

	$("#background").css("background-position", positions[currentPos][3] + "% 0%");
	$("#background-1").css("background-position", positions[currentPos][0] + "% -45px");
	$("#background-2").css("background-position", positions[currentPos][1] + "% -45px");
	$("#background-3").css("background-position", positions[currentPos][2] + "% -45px");


	$(".navigator").click ( function () {

		if( $(this).attr("id") == "scroll-right" )
		{
			$("#scroll-left").show();
			currentPos ++;
			if (currentPos >= positions.length - 1) {
				$(this).hide();
			}
		}
		else
		{
			$("#scroll-right").show();
			currentPos --;
			if (currentPos <= 0) {
				$(this).hide();
			}
		}

		moveBackground();

	});

	disableAnimation ();
	currentPos = 2;
	moveBackground(true);
	enableAnimation ();



	if( location.hash )
	{
		$(".lightbox-navigator a[href="+location.hash+"]").addClass("active");
		lightbox ($(location.hash));
	}

	$("a[href='/#about']").click ( function (e) {
		e.preventDefault();
		$(".lightbox-navigator a[href=#about]").addClass("active");
		lightbox ($("#about"));
	});

	$("a[href='/#contact']").click ( function (e) {
		e.preventDefault();
		$(".lightbox-navigator a[href=#contact]").addClass("active");
		lightbox ($("#contact"));
	});
});

