jQuery.fn.slide = function(option) {
	option = jQuery.extend({
		slideAnimate: false,
		slideSpeed: 500
	}, option);	
	
	return this.each(function(i){	

		a = $(this).find('.slider');
		b = a.find('ul');
		c = b.find('li');
		d = c.size();
		e = f= 0;
		g = true;
		
		c.each(function(){
			e = parseInt($(this).width());
			f = parseInt(f);
			f = e+f+20;
		});
		
		b.css('width',f+'px');
		$(this).append('<span class="slider-clear"></span>');

		h = a.width();
		q = b.width();	
		
		
	
	
		var o,p;
		o = '<a href="#" class="btn btn-prev" rel="0" title="Poprzedni produkt"><span>poprzedni</span></a>';
		p = '<a href="#" class="btn btn-next" rel="0" title="Następny produkt"><span>następny</span></a>';
		a.after(o+p);
		
		o = $('.btn-prev');
		p = $('.btn-next');
		
		function navigate(s){
			if(s <= 0)
				o.hide();
			else
				o.show();
				
			if(s+1 >= d-1)
				p.hide();
			else
				p.show();	
		
			o.attr('rel',s-1);
			p.attr('rel',s+1);
			
		}
		
		
		navigate(0);
			
		o.bind('click', function(event){
			event.preventDefault();		
			
			if(g){
				g = false;
				i = parseInt($(this).attr('rel'));
				
				navigate(i);
				
				i = i;
				i = c.eq(i).width()+20;
				j = a.attr('scrollLeft') - i;
				j = j<i ? 0: j;
				
				a.animate({scrollLeft: j +'px' }, option.slideSpeed,function(){
					g = true;
				});
				
				//$('#dump').prepend('prev'+j+'<br />');
			
			}		
	   }); // bind #btn-prev	
	
		p.bind('click', function(event){
			event.preventDefault();		
			
			
			if(g){
				g = false;

				i = parseInt($(this).attr('rel'));
				navigate(i);
				
				
				i = i;
				j = a.attr('scrollLeft') + c.eq(i).width()+20;
				
	
				a.animate({scrollLeft: j+'px' }, option.slideSpeed,function(){
					g = true;
				});
				
				if( j+h >= q )
					$(this).hide();
				
				
				//$('#dump').prepend('next'+j+'<br />');
			}
							
	   }); // bind #btn-next	
	

   
	}); // each
}
	
