$(document).ready(function() {
	var $item;
	var m = window.location.toString().match(/#image-(\d+)$/);
	if (m)
		$item = $('#items .item'+m[0]);
	if (!$item || $item.size() == 0)
		$item = $('#items .item:first');
	var index = $('#items .item').index($item);
	var x = 0;
	for (var i = 0; i < index; i++) {
		x += parseInt(items[i].image_w)+30;
	}
	x -= $('html').width() / 2;
	x = x << 0;
	x += items[index].image_w / 2;
	x += parseInt($("#items").css("paddingLeft"));
	//console.log("yep: "+x);
	$('html').scrollLeft(x);
	//$('#items').data('x', x).css('left', x+'px');
	var y = Math.floor($(window).height()/2-$('#items').height()/2);
	$('#item-container').css('padding-top', y+'px');
	$('#scroll-left').click(function() {
		this.blur();
		if (index == 0)
			return false;
		var src = parseInt(items[index].image_w);
		var dst = parseInt(items[--index].image_w);
		var x = $('#items').data('x');
		x += Math.round(src/2+dst/2+30);
		$('#items').stop().animate({ 'left': x+'px' }, 'normal', 'easeInOutQuad');
		$('#items').data('x', x);
		return false;
	});
	$('#scroll-right').click(function() {
		this.blur();
		if (index == items.length-1)
			return false;
		var src = parseInt(items[index].image_w);
		var dst = parseInt(items[++index].image_w);
		var x = $('#items').data('x');
		x -= Math.round(src/2+dst/2+30);
		$('#items').stop().animate({ 'left': x+'px' }, 'normal', 'easeInOutQuad');
		$('#items').data('x', x);
		return false;
	});
	$(window).resize(function() {
		var y = Math.floor($(window).height()/2-$('#items').height()/2);
		$('#item-container').css('padding-top', y+'px');
	});
	$('.overview-link').hover(function() {
		var $title = $('#project-title');
		$title.data('title', $title.text()).text($(this).attr('title'));
		//$('#project .arrow').hide();
	}, function() {
		var $title = $('#project-title');
		$title.text($title.data('title'));
		//$('#project .arrow').show();
	});
});