(function($){
	$.fn.extend({
		minusSlider : function(options){
			
			var defaults = {
				trigger: true,
				displayNumber: 1,
				speed: 333
			};
			
			var options = $.extend(defaults, options);
			
			return this.each(function(){
				var o = options;
				var holder = $(this);
				var slide = $('.sliderHolder ul.sliderContent', this);
				
				var piece = slide.children('li').outerWidth(),
				stage = piece*o.displayNumber,
				pause = o.pause,
				speed = o.speed,
				auto = o.auto
				totalWidth1 = 0, itemsNum1 = 0, xpos = 0, canSlide = true, onDisplay = 0, thumbs1 = [];
				
				/* add where am i if there is no */
				if(holder.children('.whereami').children('ul').children('li').length == 0)
					slide.children('li').each(function(){
						totalWidth1 += piece;
						holder.children('.whereami').children('ul').append('<li><a href="javascript:void(0)">'+itemsNum1+'</a></li>');
						itemsNum1++;
					});
				
				/* push into thumbs array*/
				holder.children('.whereami').children('ul').children('li').each(function(){
					thumbs1.push($(this));
				});	
					
				
				/* where am i item click handler*/
				holder.children('.whereami').children('ul').children('li').children('a').each(function(){
					$(this).click(function(){
							
						canSlide = false;
						onDisplay = parseInt($(this).parent().index());
						traceOnDisplay($(this).parent().index());
						slide.animate({left: (0-(piece*parseInt($(this).parent().index())))+'px'}, speed, function(){ canSlide = true; });
					});
				});
					
				/* keyboard 
					
					$(window)
					.jkey('right', function(){ slideNext(); })
					.jkey('left', function(){ slidePrev(); });
					
				*/
					
				/* mouse */
				holder.children('.nav').children('a.next').click(function(){ slideNext(); });
				holder.children('.nav').children('a.prev').click(function(){ slidePrev(); });
				
				/* Slider */
				function slideNext(){					
					xpos = slide.position().left;
					
					if(canSlide == true){ canSlide = false;
					// IE8 turn around slide.children('li').length
						if(xpos > stage-totalWidth1+slide.children('li').length)
							slide.animate({left: (xpos-piece)+'px'}, speed, function(){ canSlide = true; onDisplay++; traceOnDisplay(onDisplay); });
						else
							slide.animate({left: '0px'}, speed, function(){ canSlide = true; onDisplay=0; traceOnDisplay(onDisplay); });
					}
				}
					
				function slidePrev(){
					xpos = slide.position().left;
					
					if(xpos != 0)
					{
						if(canSlide == true){ canSlide = false;
							if(xpos < 0)
								slide.animate({left: (xpos+piece)+'px'}, speed, function(){ canSlide = true; onDisplay--; traceOnDisplay(onDisplay); });
							else
								slide.animate({left: (stage-totalWidth1)+'px'}, speed, function(){ canSlide = true; onDisplay=itemsNum1-1; traceOnDisplay(onDisplay); });
						}
					}	
				}
					
				/* trace on display item */
				function traceOnDisplay(n)
				{
					n == 0 ? holder.children('.nav').children('a.prev').fadeOut("fast") : holder.children('.nav').children('a.prev').fadeIn("fast");
					
				    	holder.children('.whereami').children('ul').children('li').each(function(){ $('a', this).attr('class', ''); });
				    	thumbs1[n].children('a').attr('class', 'selected');
				}
				traceOnDisplay(onDisplay);
				
				
				var proxied1 = jQuery.fn.nextb;
				var proxied2 = jQuery.fn.prevb;
				
				jQuery.fn.nextb = function(){
					slideNext(); 
					//return proxied.apply(this, arguments);
				};
				
				jQuery.fn.prevb = function(){
					slidePrev(); 
				};
			});
		}
	});
})(jQuery);
