var currentPosition = 0;
var deco = new Array('#erlebniswelt-deco', '#book-deco', '#shop-deco');
var overlayLinks = new Array('http://www.wiesoweshalbwarum-online.com',
'http://www.ravensburger.de/leser/wieso-weshalb-warum/index.html', 'http://www.ravensburger.de/shop/grosse-marken/wieso-weshalb-warum/index.html');

$(document).ready(function(){
	$('#menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	$('.deco-top').hide();
	$(deco[0]).show();
	$(deco[0]).css('display', 'inline');
	
	var totalWidth=0;
	var images = $('.slideshow li img');
	var imageWidth = images.eq(0).width();
	totalWidth = images.length * imageWidth;
	$('.slideshow').width(totalWidth);

	$('#menu ul li a').hover(function(event) {
		slide($(this), imageWidth);
	});
	$('a.blank-window').click(function(event) {
		window.open($(this).attr('href'), '_blank');
		event.preventDefault();
		return false;
	});
});

function slide(thisHandle, slideRange, callback) {
	$('li.menuItem').removeClass('act').addClass('inact');
	thisHandle.parent().removeClass('inact').addClass('act');
	var newPos = thisHandle.parent().prevAll('.menuItem').length;
	if(newPos === currentPosition) {
		return;
	}
	
	currentPosition = newPos;
	$('.slideshow').stop().animate({left:-newPos*slideRange}, 700, function() {
		$('.deco-top').hide(); 
		$(deco[newPos]).show();
		$(deco[newPos]).css('display', 'inline');
		$('.overlay-link').attr('href', overlayLinks[newPos]);
		$('.overlay-link').attr('id', 'overlay-link'+(newPos+1));
	});
}
