var Carousel = function() {

	var carousel; // Carousel element;
	var step = 220; // Carousel element width in pixels
	var speed = 5.5; // Animation in seconds

	var fetch = function()
	{
		carousel = jQuery("#carousel");
		if (!carousel.length) return false;

		jQuery("li", carousel).each(function(){
			jQuery(this).css({cursor: 'pointer'});

			jQuery(this).click(function(){
				href = jQuery("a.footer-link", this).attr("href");
				window.location = href;
			});
		});

		run();
	};

	var run = function()
	{
		setInterval(animate, speed * 1000);
	};

	var animate = function()
	{
		jQuery("li", carousel).eq(0).fadeOut(speed * 70);

		carousel.animate({
			left: "-"+step
		}, speed * 50, "linear", correction);
	};

	var correction = function()
	{
		childs = jQuery("li", carousel);

		// IE7 throws error when cloning all events..
		first = childs.eq(0).clone();

		childs.eq(0).remove();
		jQuery(first).css({opacity: 100, display: '', cursor: 'pointer'});

		// Readd events for now, should be done be clone (see clone)
		first.click(function(){
			href = jQuery("a.footer-link", this).attr("href");
			window.location = href;
		});

		carousel.append(first);
		carousel.css({left: 0});
	};

	return {
		init : function() {
			fetch();
		}
	}
}();

jQuery(document).ready(function() {
	Carousel.init();
});