(function($){
	$.fn.boxScroll = function(boxheight) {
		var _this = this;
		var allHeight = this.height();
		this.css({"position":"relative","overflow":"hidden","height":boxheight});
		this.wrapInner("<div class='boxscroll' style='position:absolute;left:0;top:0;'><div class='wrap'></div></div>").append("<div class='action'><span class='top'></span><span class='bottom'></span></div>");
		var jBoxscroll = this.find(".boxscroll");
		var jBtnTop = this.find(".action .top");
		var jBtnBottom = this.find(".action .bottom");
		jBoxscroll.append(jBoxscroll.find(".wrap").clone());
		var state = "static";
		function animation(direction) {
			state = "dynamic";
			var currentTopValue = parseInt(jBoxscroll.css("top"));
			if (direction === "top") {
				if (currentTopValue === 0) {
					jBoxscroll.css("top",-allHeight);
				}
				var directionValue = parseInt(jBoxscroll.css("top")) + boxheight;
			} else {
				if (Math.abs(currentTopValue) === allHeight) {
					jBoxscroll.css("top","0");
				}
				var directionValue = parseInt(jBoxscroll.css("top")) - boxheight;
			}
			jBoxscroll.animate({
				top: directionValue
			},"slow",function() {
				state = "static";
			});
		}
		jBtnTop.click(function() {
			if (state != "static") return false;
			animation("top");
		});
		jBtnBottom.click(function() {
			if (state != "static") return false;
			animation("bottom");
		});
	}
})(jQuery);
