$(document).ready(function() {
	$('body').css('text-align','left');
	var scrollWidth = $.scrollbarWidth();
	wResize(scrollWidth);

	$('#maincol .series').hover(
		function(){
			$(this).find('.title a').addClass('hover');
		},
		function () {
			$(this).find('.title a').removeClass('hover');
		}
	);
	
	$('#maincol .series').click( function(event){
		event.preventDefault();
		linkLocation = $(this).find('.title a').attr('href');
		window.location = linkLocation;
	});
	
	$('#piece #image').click( function(event){
		event.preventDefault();
		linkLocation = $("#next").attr('href');
		window.location = linkLocation;
	});

	$('body').keyup(function (event) {
		var linkLocation;
		if (event.keyCode == 37) {
			if ($("#prev").attr("href")) {
			   linkLocation = $("#prev").attr("href");
			   window.location = linkLocation;
		   }
		   return false;
		} else if (event.keyCode == 39) {
			if ($("#next").attr("href")) {
			   linkLocation = $("#next").attr("href");
			   window.location = linkLocation;
			}
			return false;
		}
	});

	$(window).resize(function() {
		wResize(scrollWidth);
	});


});

function wResize(scrollWidth) {
	var marLeft = $(window).width() - $('.content').width();
	if ($(document).height() > $(window).height()) {
		marLeft += scrollWidth;
	}
	$('.content').css('margin-left',Math.ceil(marLeft / 2));
}

(function($){
	$.scrollbarWidth = function() {
		if (!$._scrollbarWidth) {
			var $body = $('body');
			var w = $body.css('overflow', 'hidden').width();
			$body.css('overflow','scroll');
			w -= $body.width();
			if (!w) w=$body.width()-$body[0].clientWidth; // IE in standards mode
			$body.css('overflow','');
			$._scrollbarWidth = w;
		}
		return $._scrollbarWidth;
	};
})(jQuery);


