$(document).ready(function() {
	var elementAct = 0;
	var elementScroll = 3;
	var elementNum = $(".slideshow-item").length;
	function slideshowScroll(direction)
	{
		if(direction == "left")
		{
			if(elementAct > 0 && $("#slideshow-content > div").queue().length == 0)
			{
				$("#slideshow-content > div").animate({
					right: '-=307',
				}, 500, function() {
					// Animation complete.
				});

				elementAct--;
			}
		}
		else if(direction == "right")
		{
			if(elementAct < elementNum-elementScroll && $("#slideshow-content > div").queue().length == 0)
			{
				$("#slideshow-content > div").animate({
					right: '+=307',
				}, 500, function() {
					// Animation complete.
				});

				elementAct++;
			}
		}
	}
	$("#slideshow-button-left").click(function() {
		slideshowScroll("left");
	});
	$("#slideshow-button-right").click(function() {
		slideshowScroll("right");
	});

	if(scrollme > 0)
		var scroller = window.setInterval(plopp, scrollme);
	function plopp() {
		if (elementAct < (elementNum - elementScroll)) {
			slideshowScroll('right');
		}
		else {
			$("#slideshow-content > div").animate({
				right: '-='+307*(elementNum - elementScroll)+'px',
			}, 300, function() {
				// Animation complete.
				elementAct = 0;
			});
		}
	}

	$("#navigation ul").children("li").each(function(element) {
		var width = $(this).width();

		if(width > 2)
			$(this).children("ul").width(width + 4);
	});

	$("#products-articles-layout").children('div[class*="products-layout-"]').each(function(i,e){
	    var link = $(e).children(".products-layout-link").attr("href");
	    if(link != "")
	    {
	        $(e).css("cursor", "pointer");

	        $(e).click(function() {
	            window.location.href=link;
	        });
	    }
	});

});
