$.fn.carousel = function(options){
	
	var defaults = {
		height: null,
		width: null,
		autoplay: true,
		duration : 5000,
		fade : 300,
		next : null,
		previous : null
	};
	var self = this;
	var options = $.extend(defaults, options);		
	
	self.children('li').hide();
	self.children('li').first().show();

	if(options.width)
		self.css('width',options.width);
	if(options.height)
		self.css('height',options.height);
		
	self.css('overflow-y', 'hidden');
	self.css('overflow-x', 'hidden');
	self.children('li').first().addClass('first');
	self.children('li').last().addClass('last');

	play = function()
	{
		self.everyTime(options.duration, function() {
			animation('next');
		});
	}
	
	var animation = function(target) {
	    var item = null;
	    self.stopTime();

	    if (target == "previous") {	
		if (self.children('li:visible').hasClass('first'))
		    item = self.children('li.last');
		else
		    item = self.children('li:visible').prev();
	    }
	    else if (target == "next") {
		if(self.children('li:visible').hasClass('last'))
		    item = self.children('li.first');
		else
		    item = self.children('li:visible').next();
	    }

	    self.children('li:visible').fadeOut(options.fade, function() {
		item.fadeIn(options.fade, function() {
		    if (options.autoplay)
			play();
		});
	    });	
	};

	if(options.autoplay){
		play();
	}
	
	if(options.next)
	{
		$('#'+options.next).click(function(){	
			animation('next');	
		});		
	}
	
	if(options.previous)
	{
		$('#'+options.previous).click(function(){
			animation('previous');
		});				
	}
	

}


