(function($){

	$.fn.destak = function(options) {
		var defaults = { left: 'a.nav-left', right: 'a.nav-left', move: $(this).children('ul'), child: 'li', duration: 500, easing: 'easeOutQuad', delay: 7000 };
		
		var o = $.extend(defaults, options);
		
		var width 		= $(this).width();
		var childWidth	= $(o.move).children(o.child).width();
		var childs		= $(o.move).children(o.child).length;
		var pages		= Math.round(childs / Math.floor(width / childWidth));
		var page		= 1;
		
		$(o.move).width(width * childs);
		
		var auto = setInterval(function(){
			if(page < pages) {
				$(o.move).animate({left: '-=' + width}, {duration: o.duration, easing: o.easing});
				page++;
			} else {
				$(o.move).animate({left: 0}, {duration: o.duration, easing: o.easing});
				page = 1;	
			}
		}, o.delay);
		
		$(o.left).click(function(){
			if(page > 1) {
				$(o.move).animate({left: '+=' + width}, {duration: o.duration, easing: o.easing});
				page--;
			} else {
				$(o.move).animate({left: -(width * (pages-1))}, {duration: o.duration, easing: o.easing});
				page = pages;		
			}
			return false;
		});
		
		$(o.right).click(function(){
			if(page < pages) {
				$(o.move).animate({left: '-=' + width}, {duration: o.duration, easing: o.easing});
				page++;
			} else {
				$(o.move).animate({left: 0}, {duration: o.duration, easing: o.easing});
				page = 1;		
			}
			return false;
		});
	}

})(jQuery);
