
(function($) {


	$.fn.gSlider = function(options) {
	
		var opts = $.extend({}, $.fn.gSlider.defaults, options);
		// iterate and reformat each matched element
		return this.each(function() {
			
			$this = $(this);
		
			opts.NumberOfChildren = $this.find('.shedSliderContent').children().length;
			var CurrentChild = 1;

			disable(CurrentChild);
			
			// Add click events to the 
			$("." + opts.nextButton, $this).click(function(e) {
				e.stopPropagation();
				if(CurrentChild >= opts.NumberOfChildren - 1) return false;
				CurrentChild = CurrentChild + 1;
				$this.find('.shedSliderViewer').scrollTo($this.find('.shedSliderContent div:eq('+ (CurrentChild + 1) +')'), opts.speed);
				
				disable(CurrentChild);
					
				
				return false;
			});
			
			$("." + opts.prevButton, $this).click(function(e) {
				e.stopPropagation();
				if(CurrentChild <= 1) return false;
				CurrentChild = CurrentChild - 1;
				$this.find('.shedSliderViewer').scrollTo($this.find('.shedSliderContent div:eq('+ (CurrentChild - 1) +')'), opts.speed);
				
				disable(CurrentChild);
				
				return false;
			});
			
		});
		
		function disable(CurrentChild) {
			if(CurrentChild >= opts.NumberOfChildren - 1) 
				$("." + opts.nextButton, $this).css(opts.disabledCss);
			else
				$("." + opts.nextButton, $this).css(opts.restoreCss);


			if(CurrentChild <= 1) 
				$("." + opts.prevButton, $this).css(opts.disabledCss);
			else
				$("." + opts.prevButton, $this).css(opts.restoreCss);

		}
	};
	
	

	$.fn.gSlider.defaults = {
		displayed: 3,
		speed: 300,
		disabledCss: {opacity: 0.2},
		restoreCss: {opacity: 1}
	};

})(jQuery);
