(function($) {
	$.fn.easySlider = function(options){

		var defaults = {
			prevId: 		'prevBtn',
			nextId: 		'nextBtn',
			speed: 			'slow',
			scrollBlock:	'lastGoodsScroll',
			orientation:	'',
			visibleElement: 5
		};

		var options = $.extend(defaults, options);

		return this.each(function() {
			obj = $(this);
			var s = $("li", obj).length;
			var h = obj.parent().height();
			var ts = s-1;
			var t = 0;
			var ul = $("ul",obj);
			var gorizontal = (options.orientation == 'horizontal');
			
			if (gorizontal) {
				ts = ts - options.visibleElement + 1;
			}
			
			$('#'+options.scrollBlock).html(
				'<a href="javascript:void(0)" id="'+ options.prevId +'" class="up">&nbsp;</a> <a href="javascript:void(0)" id="'+ options.nextId +'" class="down">&nbsp;</a>'
			);
			
			$("#"+options.prevId).css('background-position','0 100%');
			$("#"+options.nextId).hide();

			$("#"+options.nextId).click(function(){
				if (gorizontal) {
					shift("next");
				} else {
					animate("next");
				}
				
				if (t>=ts) $(this).css('background-position','0 100%');
				$("#"+options.prevId).css('background-position','0 0');
			});
			
			$("#"+options.prevId).click(function(){
				if (gorizontal) {
					shift("prev");
				} else {
					animate("prev");
				}
				if (t<=0) $(this).css('background-position','0 100%');
				$("#"+options.nextId).css('background-position','0 0');
			});
			function shift(dir){
				if(dir == "next"){
					t = (t>=ts) ? ts : (t+1);
					ul.find('li:eq(' + (t+options.visibleElement-1) + '):first').show();
					ul.find('li:eq(' + (t-1) + '):first').hide();
				} else {
					t = (t<=0) ? 0 : (t-1);
					ul.find('li:eq(' + (t+options.visibleElement) + '):first').hide();
					ul.find('li:eq(' + (t) + '):first').show();
				};
				
			};
			
			function animate(dir){
				if(dir == "next"){
					t = (t>=ts) ? ts : t+1;
				} else {
					t = (t<=0) ? 0 : t-1;
				};
				p = (t*h*-1);
				ul.animate(
					{ marginTop: p },
					options.speed,
					'easeInCubic'
				);
			};
			
			if(s>1) $("#"+options.nextId).fadeIn();
		});

	};

})(jQuery);
