(function($) {

	$.fn.panel = function(options) {
		
		var defaults = {
			panels: ".panel",
			images: ".image",
			classShow: "show",
			classPrev: "prev",
			classNext: "next"
		};
		var options = $.extend(defaults, options);
		
		return this.each(function() {
			
			var _idx = 0;
			
			var $panels = $(options.panels, this);
			var $imgs = $(options.images, this);
			var $prev = $("<a/>").attr("href", "#").attr("class", options.classPrev).appendTo($imgs);
			var $next = $("<a/>").attr("href", "#").attr("class", options.classNext).appendTo($imgs);
			
			$("." + options.classPrev, this).click(function() {
				if (0 < _idx) {
					_idx--;
				} else {
					_idx = $panels.length - 1;
				}
				
				showPanels();
				
				return false;
			});
			
			$("." + options.classNext, this).click(function() {
				if (_idx < $panels.length - 1) {
					_idx++;
				} else {
					_idx = 0;
				}
				
				showPanels();
				
				return false;
			});
			
			showPanels();
			
			function showPanels() {
				$panels.removeClass(options.classShow);
				$panels.eq(_idx).addClass(options.classShow);
			}
		
		});
	
	};

})(jQuery);

