(function($) {                                        
$.fn.karuzela_top = function(x) { x = $.extend({	delay:null, speed: 500, auto:null, easing:null, pokarz:null,  prev: null, next: null, prev1: null, next1: null }, x || {});
$(window).load(function() { ul_height = 0; li.each(function() { ul_height += $(this).height(); }); ul.css({'height' : ul_height });  }); 		

var div = $(this), ul = $("ul", div), li = $("li", ul);
var li_width = li.outerWidth();
var li_height =  li.outerHeight();		
var size_div = li_height * (x.pokarz); 	
var top_value = li_height * (-1); 
var max_li=li.size();
var max_clik=x.pokarz;
var timer; 
var numer = 1;



if(max_li<=x.pokarz) { $('#next').remove();  $('#prev').remove();  } else {

			$('li:first',ul).before($('li:last',ul));    
			ul.css({'top' : top_value });

		  $(x.next).click(function() {
			if ($(".scroll_gal ul:animated").length === 1) {} else {

					numer=numer+1; 
					if(numer>max_li) { numer=1; } else { numer=numer; };
					var top_indent = parseInt(ul.css('top')) - li_height;
					$(ul).not(':animated').animate({'top' : top_indent}, x.speed, x.easing, function () { 
					$('li:last',ul).after($('li:first',ul));  
					$(ul).css({'top' : top_value});	
					});
					};
			
			 return false;	});
			
			
			
		$(x.prev).click(function() {
		if ($(".scroll_gal ul:animated").length === 1) {} else {
		
					numer=numer-1; 
					if(numer<1) { numer=max_li; } else { numer=numer; };
					var top_indent = parseInt(ul.css('top')) + li_height;
					$(ul).not(':animated').animate({'top' : top_indent}, x.speed, x.easing, function () { 
					$('li:first',ul).before($('li:last',ul));           
					$(ul).css({'top' : top_value});
					});
					};
					
		return false;	});

};


cli_time = setInterval(function() {  $(x.next).click(); }, x.delay); 
$('.scroll').bind("mouseenter", function(){  clearInterval(cli_time); });	
$('.scroll').bind("mouseleave", function(){ cli_time = setInterval(function() {  $(x.next).click(); }, x.delay);  });	
}})(jQuery);


$(function() { $(".scroll_gal").karuzela_top({ delay:3000, speed:500, auto:1, pokarz:4, prev: "#prev", next: "#next" });});




