(function($){
	$.fn.carousel = function(options) {
		var defaults = {
			next: "#next",
			prev: "#prev",
			title: "#title"
		};
		var options = $.extend(defaults, options);
		
		return this.each(function() {
			var slides = new Array;
			var cur = 0;
			var id = "#" + this.id;
			
			var i = 0;
			$(this).children("ul").children("li").each(function(index){
				var slide = new Array;
				slides[i] = $(this).html();
				i++;
			});	
			update(slides[cur]);
			$(options.next).click(function(){
				if(cur == slides.length-1){
					cur = 0;
				}
				else {
					cur++;
				}
				update(slides[cur]);
			});
			$(options.prev).click(function(){
				if(cur == 0){
					cur = slides.length-1;
				}
				else {
					cur--;
				}
				update(slides[cur]);
			});
				
			function update(img){
				$(id).html(img);
				$(options.title).children("span").html($(id).children("img").attr("alt"));
			}
		});  
	};
})(jQuery);
