$(document).ready(function() {
	$("a.nav").click(function() {
		goToPage("#" + this.href.split("#")[1]);
		return false;
	});
	
	$(".menu-horizontal a").click(function() {
		horizontalMove("#" + this.href.split("#")[1]);
		return false;
	});
	
    $("#aboutSlider").jcarousel({
		auto: 5,
//		start: 3,
		visible: 3,
		scroll: 1,
		wrap: 'last',
		buttonPrevHTML: false,
		buttonNextHTML: false
	});

	
	var goToPage = function(id) {
		var offset = $(id+"_page").index()*959;
		$("a.nav").removeClass("selected");
		$("a.nav[href='"+id+"']").addClass("selected");
		
		if (offset < 0) return;
		$('html, body').animate({
			scrollTop: '0px'
		}, 300);
		$(".scrollerContent").animate({
			marginLeft: offset*-1,
			top: 0
		}, 700, 'easeInOutExpo', function() {
			window.location.hash = id;
		});
		$('.hidden').hide();
		$('.ajaxresponse').remove();
		$('.ajax_form').show();
		return false;
	}
	
	var horizontalMove = function(id) {
		var offset = $(id+"_subpage").index()*366;
		$(".menu-horizontal a").removeClass("selected");
		$(".menu-horizontal a[href='"+id+"']").addClass("selected");
		
		if (offset < 0) return;
		
		$('html, body').animate({
			scrollTop: '0px'
		}, 300);
		$(".horizontal-div").animate({
			top: '-' + offset + 'px'
		}, 700, 'easeInOutExpo', function() {
			window.location.hash = id;
		});
		return false;
	}

	if (window.location.hash) {
		goToPage(window.location.hash);
	} else {
		$("#sideBar a.nav").first().addClass("over");
	}
});

