(function($){
	
	$.fn.scroller = function(options) {
		var isMethodCall = (typeof options == "string") || false;
		var args = arguments;
		if (!isMethodCall)
			var options = $.extend({}, options, {});
		
		$(this).each(function(){
			var tab = $(this).data("scroller");
			if (isMethodCall && tab) {
				if (tab[options] && typeof tab[options] == "function"){
					tab[options].apply(tab, $.makeArray(args).slice(1));
				}
				return;
			} else {
				tab = new $.scroller(this, options);
				$(this).data("scroller", tab);
			}
		});
		return this;
	};
	
	$.scroller = function(elem, options) {
		this.elem = elem;
		this.options = $.extend({}, options, $.scroller.defaults);
		this.init();
	};
	
	$.extend($.scroller, {
		defaults: {
		},
		prototype: {
			init: function() {
				var self = this;
				var content = $(".scroller_content", self.elem);
				var more = $(".scroller_more .more", self.elem);
				
				var contentH = 0;
				$(content).children().each(function(){
					contentH += $(this).outerHeight();
				});
				
				var availableH = $(content).innerHeight();
				
				if (contentH <= availableH) {
					$(more).hide();
					return;
				}
				
				var steps = [], h=0, curStep = 0;
				steps.push(h);
				while (1) {
					
					
					if (h + availableH < contentH) {
						h += availableH;
					} else {
						h = contentH - availableH;
						steps.push(h);
						break;
					}
					
					steps.push(h);
				}
				
				more.bind("click.scroller", function() {
					curStep ++;
					if (curStep >= steps.length-1) {
						curStep = 0;
					}
					
					content.stop();
					content.scrollTo(steps[curStep],{axis:'y', duration:400, easing:"swing"});
					
					this.blur();
					return false;
				});
			}
		}
	});
})(jQuery);