$(document).ready(function(){

smoothScroll: function (speed) {
			var pagePath = /\?/.test(location.href)? location.href.split('?')[0]:
			               /#/.test(location.href)? location.href.split('#')[0]:
			               location.href;
			this.each(function(){
				var actX, actY, tarY = 0, tarX = 0, scrollInt;
				speed = (!speed? 6: speed == "fast"? 3:	speed == "normal"? 6: speed == "slow"? 12: speed);
				var setScroll = function (tarX,tarY) {
					actX += (tarX - actX) / parseInt(speed);
					actY += (tarY - actY) / parseInt(speed);
					if(Math.abs(tarX - actX) < 1 && Math.abs(tarY - actY) < 1){
						clearInterval(scrollInt);
						scrollTo(Math.round(tarX),Math.round(tarY));
					}else {
						scrollTo( Math.round(actX), Math.round(actY));
					}
				}
				var anc = this.href.split('#')[1];
				if( /#/.test(this.href)  && this.href.match(pagePath) && $('#'+anc)[0] ){
					$(this).click(function (){
						var tarObj = $('#'+anc);
						tarX = ($(document).width() > tarObj.position().left + $(window).width())
							? tarObj.position().left
							: $(document).width() - $(window).width();
						tarY = ($(document).height() > tarObj.position().top + $(window).height())
							? tarObj.position().top
							: $(document).height() - $(window).height();
						actX = $(document).scrollLeft();
					 	actY = $(document).scrollTop();
						clearInterval(scrollInt);
						scrollInt = setInterval(function(){setScroll(tarX,tarY)}, 20);
						return false;
					});
				}
				//stop when mousewheel
				var wheel = function () {clearInterval(scrollInt);}
				if (window.addEventListener) window.addEventListener('DOMMouseScroll', wheel, false);
				window.onmousewheel = document.onmousewheel = wheel;
			});
			return this;
		},

});