jQuery.fn.slideshow = function(speed)
{

	var $speed = speed * 1000;

	var $this = $(this);
	var $all = $(this).children('img');
	var $first = $all.filter(':first');
	$this.append('<div class="end"></div>');
	
	$all.css({opacity: 0.0});

	$first.css({opacity: 1});
	$first.attr('rel', 'show');


	var $show = $(this).children('img[rel="show"]');

	setInterval(function()
	{
	    var current = ($show ? $all.filter('[rel="show"]') : $first);  
  
    //Get next image, if it reached the end of the slideshow, rotate it back to the first image  
    var next = ((current.next().length) ? ((current.next().hasClass('end'))? $first :current.next()) : $first);     
      
    //Set the fade in effect for the next image, show class has higher z-index  
    next.attr('rel', 'show').animate({opacity: 1.0}, 1000);  
  
    //Hide the current image  
    current.animate({opacity: 0.0}, 1000).attr('rel', '');  
      
	}, $speed);
}


