(function($) {
	$.fn.slideshow = function(options) {
		// Define option defaults
		var defaults = {
			containerClass:"slides",
			slideClass:"slide",
            activeSlideCount:1
		}
        // Extend our default options with those provided.
	    var options = $.extend(defaults, options);
	    // Grab slides
		var slides = this.find('.' + options.slideClass);
		var slidesWorkingCount = (slides.length - (options.activeSlideCount - 1));
		var firstActiveSlideID = 0;

        // Calculate a single slide width
		var w = slides.eq(0).outerWidth(true);
		// Grab the container element
		var container = this.find('.' + options.containerClass);
		// Set container width to sum of slide widths, plus a little extra
		container.width((w * slides.length) + 4);
        // Necessary for slide animation
		container.css("position", "relative");		
		
		this.find(".prev").click(function(){ previousSlide(); return false; });
		this.find(".next").click(function(){ nextSlide(); return false; });

		// Functions
		function showSlide(id) {
            firstActiveSlideID = id;
            container.animate({left:(-w * id)}, 300, "linear", function(){ return true; });
		}
		function nextSlide() {
		    targetID = (firstActiveSlideID + 1) % slidesWorkingCount;
            showSlide(targetID);
		}
		function previousSlide() {
		    targetID = (firstActiveSlideID + (slidesWorkingCount - 1)) % slidesWorkingCount;
			showSlide(targetID);
		}
	};
})(jQuery);


