$j(function()
{
	var lists = $j('.mod_images.fade ul, .mod_images.fade_slow ul, .mod_images.fade_normal ul, .mod_images.fade_fast ul');
	
	if (lists.size() === 0)
	{
		return;
	}
	
	lists.each(function()
	{
		var
			list = $j(this),
			
			images = $j('img', list),

			completedImages = 0,
			
			size = images.size(),
			
			index = 0,
			
			image,
			
			speed = 4000;
		
		function show(index)
		{
			images.css('z-index', 100);
			
			if (image)
			{
				image.stop().css('z-index', 101);
			}
			
			image = images.eq(index);
			image.css('z-index', 102);
			list.height(image.get(0).height);
		}
		
		function handleImage()
		{
			if (++completedImages === images.length)
			{
				// Show the first.
				if (size > 0)
				{
					show(index);
				}
				
				// If there are more to be shown fade them.
				if (size > 1)
				{
					var fade = function()
					{
						var effect = function()
						{
							index = ++index % size;
							
							show(index);
							
							image.hide().fadeIn(2000, function()
							{
								fade();
							});
						};
						
						setTimeout(effect, speed);
					};
					
					fade();
				}
			}
		}
		
		images.each(function()
		{
			if (this.complete)
			{
				handleImage();
			}
			else
			{
				this.onload = this.onerror = this.onabort = handleImage;
			}
		});
	});
});