(function(b){b.fn.smoothscroll=function(l){var a=b.extend({speed:1E3,easing:"swing",loadScroll:!1,headerElem:null,manualAdjust:0,noButton:!1,fade:!1,btnElem:null,btnIn:500,btnSpeed:500,btnEnterSpeed:null,btnLeaveSpeed:null,btnCourse:"bottom",btnEnterCourse:null,btnLeaveCourse:null,btnEasing:"swing",btnEnterEasing:null,btnLeaveEasing:null},l),f={init:function(){this.url=this.urlSprit(location.href);this.setEvent()},urlSprit:function(c){c=c.split("#");c[1]=c[1]?"#"+c[1]:"#";return{page:c[0],hash:c[1]}}, move:function(c){if(c.page==this.url.page){try{if("#"==c.hash)var d=0;else{if(0==b(c.hash).length)throw Error("Cannot find selector '"+c.hash+"' in this HTML document");d=b(c.hash).offset().top-a.manualAdjust;d-=null==a.headerElem?0:b(a.headerElem).outerHeight();d=0>d?0:d}parseInt(d)!=b(window).scrollTop()&&b("body,html").stop().animate({scrollTop:d},a.speed,a.easing)}catch(e){window.console.error(e)}return!1}return this},setEvent:function(){b(document).on("click.smoothScroll","a, area",function(){if(0== f.move(f.urlSprit(b(this).prop("href"))))return!1});b(window).on("load.smoothScroll",function(){a.loadScroll&&"#"!=f.url.hash&&(b("body,html").stop().scrollTop(0),f.move(f.url))})}},k={elem:b(a.btnElem),activePos:{bottom:50,right:50,opacity:1},init:function(){0!=this.elem.length&&1!=a.noButton&&(b.isNumeric(parseInt(this.elem.css("bottom")))&&(this.activePos.bottom=parseInt(this.elem.css("bottom"))),b.isNumeric(parseInt(this.elem.css("right")))&&(this.activePos.right=parseInt(this.elem.css("right"))), b.isNumeric(parseInt(this.elem.css("opacity")))&&(this.activePos.opacity=parseInt(this.elem.css("opacity"))),null==a.btnLeaveSpeed&&(a.btnLeaveSpeed=a.btnSpeed),null==a.btnEnterSpeed&&(a.btnEnterSpeed=a.btnSpeed),null==a.btnLeaveCourse&&(a.btnLeaveCourse=a.btnCourse),null==a.btnEnterCourse&&(a.btnEnterCourse=a.btnCourse),null==a.btnLeaveEasing&&(a.btnLeaveEasing=a.btnEasing),null==a.btnEnterEasing&&(a.btnEnterEasing=a.btnEasing),this.setPosition(),this.showflag=!1,this.elem.css(this.enterPos),this.checkScroll(), this.setEvent())},setPosition:function(){this.enterPos=this.setValue(a.btnEnterCourse,a.btnEnterEasing,b(window));this.leavePos=this.setValue(a.btnLeaveCourse,a.btnLeaveEasing,b(window))},setValue:function(c,d,e){var g={bottom:this.activePos.bottom,right:this.activePos.right},h=1;if(-1!==d.search(/Elastic/)||-1!==d.search(/Bounce/))h=1.3;switch(c){case "fixed":case "0":break;case "top":case "8":g.bottom=Math.floor(e.height()*h)+this.elem.outerHeight();break;case "right":case "6":g.right=-(Math.floor(e.height()* (h-1))+this.elem.outerWidth());break;case "left":case "4":g.right=Math.floor(e.height()*h)+this.elem.outerWidth();break;default:g.bottom=-(Math.floor(e.height()*(h-1))+this.elem.outerHeight())}a.fade&&(g.opacity=0);return g},checkScroll:function(){b(window).scrollTop()>a.btnIn?0==this.showflag&&(this.showflag=!0,this.elem.css(this.enterPos),this.elem.stop().animate(this.activePos,a.btnEnterSpeed,a.btnEnterEasing)):1==this.showflag&&(this.showflag=!1,this.elem.stop().animate(this.leavePos,a.btnLeaveSpeed, a.btnLeaveEasing))},setEvent:function(){b(window).on("scroll.smoothScroll",function(){k.checkScroll()});b(window).on("resize.smoothScroll",function(){k.setPosition()})}};b(function(){k.init();f.init()})}})(jQuery);