$(function()
{
	$.extend($.fn.draaiDing = function(rightButton, leftButton, slideStuff, speed)
	{
		element = this;
		element.each(function()
		{
			if($(this).children(slideStuff).children().length <= 1)
			{
				$(this).children(rightButton).css('visibility', 'hidden');
				$(this).children(leftButton).css('visibility', 'hidden');
			}
		});
		
		/*
		if(element.children(slideStuff).children().length <= 1)
		{
			rightButton.hide();
			leftButton.hide();
		}
		*/
		if(element.length > 0)
		{
			if(!speed)
			{
				speed = 400;
			}
			element.children(leftButton).click(function()
			{
				var width = $(this).siblings(slideStuff).width();
				var nrOf = $(this).siblings(slideStuff).children().length - 1;
				$(this).siblings(slideStuff).children().each(function()
				{
					var left = parseFloat($(this).css('left'));
					$(this).animate({ left: left-width }, speed, null, function()
					{
						$(this).css('left', left-width);
						if(left-width <= -width)
						{
							$(this).css('left', width * nrOf);
						}
					});
				});
			});
			element.children(rightButton).click(function()
			{
				var width = $(this).siblings(slideStuff).width();
				var nrOf = $(this).siblings(slideStuff).children().length - 1;
				$(this).siblings(slideStuff).children().each(function()
				{
					var left = parseFloat($(this).css('left'));
					if(left >= width*nrOf)
					{
						$(this).css('left', -width);
						left = -width;
					}
					$(this).animate({ left: left+width }, speed, null, function()
					{
						$(this).css('left', left+width);
					});
				});
			});
		}
	});
});
