(function($,window,document,undefined){var pluginNS="mPageScroll2id",pluginPfx="mPS2id",defaultSelector=".m_PageScroll2id,a[rel~='m_PageScroll2id'],.page-scroll-to-id,a[rel~='page-scroll-to-id'],._ps2id",defaults={scrollSpeed:1000,autoScrollSpeed:!0,scrollEasing:"easeInOutQuint",scrollingEasing:"easeOutQuint",pageEndSmoothScroll:!0,layout:"vertical",offset:0,highlightSelector:!1,clickedClass:pluginPfx+"-clicked",targetClass:pluginPfx+"-target",highlightClass:pluginPfx+"-highlight",forceSingleHighlight:!1,keepHighlightUntilNext:!1,highlightByNextTarget:!1,disablePluginBelow:!1,clickEvents:!0,appendHash:!1,onStart:function(){},onComplete:function(){},defaultSelector:!1,live:!0,liveSelector:!1,excludeSelectors:!1,encodeLinks:!1,inIframe:!1},selector,opt,_init,_trigger,_clicked,_target,_to,_axis,_offset,_dataOffset,_totalInstances=0,_liveTimer,_speed,specialChars=/[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/,methods={init:function(options){var options=$.extend(!0,{},defaults,options);$(document).data(pluginPfx,options);opt=$(document).data(pluginPfx);if(!this.selector){var selectorClass="__"+pluginPfx;this.each(function(){var el=$(this);if(!el.hasClass(selectorClass)){el.addClass(selectorClass)}});this.selector="."+selectorClass} if(opt.liveSelector)this.selector+=","+opt.liveSelector;selector=(!selector)?this.selector:selector+","+this.selector;if(opt.defaultSelector){if(typeof $(selector)!=="object"||$(selector).length===0){selector=defaultSelector}} if(opt.clickEvents){$(document).off("."+pluginPfx).on("click."+pluginPfx,selector,function(e){if(functions._isDisabled.call(null)){functions._removeClasses.call(null);return} var $this=$(this),href=$this.attr("href"),hrefProp=$this.prop("href").baseVal||$this.prop("href");if(opt.excludeSelectors&&$this.is(opt.excludeSelectors)){return} if(href&&href.indexOf("#/")!==-1){return} functions._reset.call(null);_dataOffset=$this.data("ps2id-offset")||0;if(functions._isValid.call(null,href,hrefProp)&&functions._findTarget.call(null,href)){e.preventDefault();_trigger="selector";_clicked=$this;functions._setClasses.call(null,!0);functions._scrollTo.call(null)}})} $(window).off("."+pluginPfx).on("scroll."+pluginPfx+" resize."+pluginPfx,function(){if(functions._isDisabled.call(null)){functions._removeClasses.call(null);return} var targets=$("._"+pluginPfx+"-t");targets.each(function(i){var t=$(this),id=t.attr("id"),h=functions._findHighlight.call(null,id);functions._setClasses.call(null,!1,t,h);if(i==targets.length-1){functions._extendClasses.call(null)}})});_init=!0;functions._setup.call(null);functions._live.call(null)},scrollTo:function(id,options){if(functions._isDisabled.call(null)){functions._removeClasses.call(null);return} if(id&&typeof id!=="undefined"){functions._isInit.call(null);var defaults={layout:opt.layout,offset:opt.offset,clicked:!1},options=$.extend(!0,{},defaults,options);functions._reset.call(null);_axis=options.layout;_offset=options.offset;id=(id.indexOf("#")!==-1)?id:"#"+id;if(functions._isValid.call(null,id)&&functions._findTarget.call(null,id)){_trigger="scrollTo";_clicked=options.clicked;if(_clicked){functions._setClasses.call(null,!0)} functions._scrollTo.call(null)}}},destroy:function(){$(window).off("."+pluginPfx);$(document).off("."+pluginPfx).removeData(pluginPfx);$("._"+pluginPfx+"-t").removeData(pluginPfx);functions._removeClasses.call(null,!0)}},functions={_isDisabled:function(){var e=window,a="inner",val=opt.disablePluginBelow instanceof Array?[opt.disablePluginBelow[0]||0,opt.disablePluginBelow[1]||0]:[opt.disablePluginBelow||0,0];if(!("innerWidth" in window)){a="client";e=document.documentElement||document.body} return e[a+"Width"]<=val[0]||e[a+"Height"]<=val[1]},_isValid:function(href,hrefProp){if(!href){return} hrefProp=(!hrefProp)?href:hrefProp;var str=(hrefProp.indexOf("#/")!==-1)?hrefProp.split("#/")[0]:hrefProp.split("#")[0],wloc=!opt.inIframe&&window.location!==window.parent.location?window.parent.location:window.location,loc=wloc.toString().split("#")[0];return href!=="#"&&href.indexOf("#")!==-1&&(str===""||decodeURIComponent(str)===decodeURIComponent(loc))},_setup:function(){var el=functions._highlightSelector(),i=1,tp=0;return $(el).each(function(){var $this=$(this),href=$this.attr("href"),hrefProp=$this.prop("href").baseVal||$this.prop("href");if(functions._isValid.call(null,href,hrefProp)){if(opt.excludeSelectors&&$this.is(opt.excludeSelectors)){return} var id=(href.indexOf("#/")!==-1)?href.split("#/")[1]:href.substring(href.indexOf('#')+1),t=specialChars.test(id)?$(document.getElementById(id)):$("#"+id);if(t.length>0){if(opt.highlightByNextTarget){if(t!==tp){if(!tp){t.data(pluginPfx,{tn:"0"})}else{tp.data(pluginPfx,{tn:t})} tp=t}} if(!t.hasClass("_"+pluginPfx+"-t")){t.addClass("_"+pluginPfx+"-t")} t.data(pluginPfx,{i:i});if(!$this.hasClass("_"+pluginPfx+"-h")){$this.addClass("_"+pluginPfx+"-h")} var h=functions._findHighlight.call(null,id);functions._setClasses.call(null,!1,t,h);_totalInstances=i;i++ if(i==$(el).length){functions._extendClasses.call(null)}}}})},_highlightSelector:function(){return(opt.highlightSelector&&opt.highlightSelector!=="")?opt.highlightSelector:selector},_findTarget:function(str){var val=(str.indexOf("#/")!==-1)?str.split("#/")[1]:str.substring(str.indexOf('#')+1),el=specialChars.test(val)?$(document.getElementById(val)):$("#"+val);if(el.length<1||el.css("position")==="fixed"){if(val==="top"){el=$("body")}else{return}} _target=el;if(!_axis){_axis=opt.layout} _offset=functions._setOffset.call(null);_to=[(el.offset().top-_offset[0]).toString(),(el.offset().left-_offset[1]).toString()];_to[0]=(_to[0]<0)?0:_to[0];_to[1]=(_to[1]<0)?0:_to[1];return _to},_setOffset:function(){if(!_offset){_offset=(opt.offset)?opt.offset:0} if(_dataOffset){_offset=_dataOffset} var val,obj,y,x;switch(typeof _offset){case "object":case "string":val=[(_offset.y)?_offset.y:_offset,(_offset.x)?_offset.x:_offset];obj=[(val[0]instanceof jQuery)?val[0]:$(val[0]),(val[1]instanceof jQuery)?val[1]:$(val[1])];if(obj[0].length>0){y=obj[0].height();if(obj[0].css("position")==="fixed"){y+=obj[0][0].offsetTop}}else if(!isNaN(parseFloat(val[0]))&&isFinite(val[0])){y=parseInt(val[0])}else{y=0} if(obj[1].length>0){x=obj[1].width();if(obj[1].css("position")==="fixed"){x+=obj[1][0].offsetLeft}}else if(!isNaN(parseFloat(val[1]))&&isFinite(val[1])){x=parseInt(val[1])}else{x=0} break;case "function":val=_offset.call(null);if(val instanceof Array){y=val[0];x=val[1]}else{y=x=val} break;default:y=x=parseInt(_offset)} return[y,x]},_findHighlight:function(id){var wLoc=!opt.inIframe&&window.location!==window.parent.location?window.parent.location:window.location,loc=wLoc.toString().split("#")[0],locPath=wLoc.pathname;if(loc.indexOf("'")!==-1)loc=loc.replace("'","\\'");if(locPath.indexOf("'")!==-1)locPath=locPath.replace("'","\\'");loc=decodeURIComponent(loc);locPath=decodeURIComponent(locPath);if(opt.encodeLinks){var locEnc=encodeURI(loc).toLowerCase(),locPathEnc=encodeURI(locPath).toLowerCase();return $("._"+pluginPfx+"-h[href='#"+id+"'],._"+pluginPfx+"-h[href='"+loc+"#"+id+"'],._"+pluginPfx+"-h[href='"+locPath+"#"+id+"'],._"+pluginPfx+"-h[href='#/"+id+"'],._"+pluginPfx+"-h[href='"+loc+"#/"+id+"'],._"+pluginPfx+"-h[href='"+locPath+"#/"+id+"'],._"+pluginPfx+"-h[href='"+locEnc+"#/"+id+"'],._"+pluginPfx+"-h[href='"+locEnc+"#"+id+"'],._"+pluginPfx+"-h[href='"+locPathEnc+"#/"+id+"'],._"+pluginPfx+"-h[href='"+locPathEnc+"#"+id+"']")}else{return $("._"+pluginPfx+"-h[href='#"+id+"'],._"+pluginPfx+"-h[href='"+loc+"#"+id+"'],._"+pluginPfx+"-h[href='"+locPath+"#"+id+"'],._"+pluginPfx+"-h[href='#/"+id+"'],._"+pluginPfx+"-h[href='"+loc+"#/"+id+"'],._"+pluginPfx+"-h[href='"+locPath+"#/"+id+"']")}},_setClasses:function(c,t,h){var cc=opt.clickedClass,tc=opt.targetClass,hc=opt.highlightClass;if(c&&cc&&cc!==""){$("."+cc).removeClass(cc);_clicked.addClass(cc)}else if(t&&tc&&tc!==""&&h&&hc&&hc!==""){if(functions._currentTarget.call(null,t)){t.addClass(tc);h.addClass(hc)}else{if(!opt.keepHighlightUntilNext||$("."+hc).length>1){t.removeClass(tc);h.removeClass(hc)}}}},_extendClasses:function(){var tc=opt.targetClass,hc=opt.highlightClass,$tc=$("."+tc),$hc=$("."+hc),ftc=tc+"-first",ltc=tc+"-last",fhc=hc+"-first",lhc=hc+"-last";$("._"+pluginPfx+"-t").removeClass(ftc+" "+ltc);$("._"+pluginPfx+"-h").removeClass(fhc+" "+lhc);if(!opt.forceSingleHighlight){$tc.slice(0,1).addClass(ftc).end().slice(-1).addClass(ltc);$hc.slice(0,1).addClass(fhc).end().slice(-1).addClass(lhc)}else{if(opt.keepHighlightUntilNext&&$tc.length>1){$tc.slice(0,1).removeClass(tc);$hc.slice(0,1).removeClass(hc)}else{$tc.slice(1).removeClass(tc);$hc.slice(1).removeClass(hc)}}},_removeClasses:function(destroy){$("."+opt.clickedClass).removeClass(opt.clickedClass);$("."+opt.targetClass).removeClass(opt.targetClass+" "+opt.targetClass+"-first "+opt.targetClass+"-last");$("."+opt.highlightClass).removeClass(opt.highlightClass+" "+opt.highlightClass+"-first "+opt.highlightClass+"-last");if(destroy){$("._"+pluginPfx+"-t").removeClass("_"+pluginPfx+"-t");$("._"+pluginPfx+"-h").removeClass("_"+pluginPfx+"-h")}},_currentTarget:function(t){if(!t.data(pluginPfx))return;var o=opt["target_"+t.data(pluginPfx).i],dataTarget=t.data("ps2id-target"),rect=dataTarget&&$(dataTarget)[0]?$(dataTarget)[0].getBoundingClientRect():t[0].getBoundingClientRect();if(typeof o!=="undefined"){var y=t.offset().top,x=t.offset().left,from=(o.from)?o.from+y:y,to=(o.to)?o.to+y:y,fromX=(o.fromX)?o.fromX+x:x,toX=(o.toX)?o.toX+x:x;return(rect.top>=to&&rect.top<=from&&rect.left>=toX&&rect.left<=fromX)}else{var wh=$(window).height(),ww=$(window).width(),th=dataTarget?$(dataTarget).height():t.height(),tw=dataTarget?$(dataTarget).width():t.width(),base=1+(th/wh),top=base,bottom=(th=wh/bottom,rect.left<=ww/left,rect.right>=ww/right];if(opt.highlightByNextTarget){var tn=t.data(pluginPfx).tn;if(tn){var rectn=tn[0].getBoundingClientRect();if(opt.layout==="vertical"){val=[rect.top<=wh/2,rectn.top>wh/2,1,1]}else if(opt.layout==="horizontal"){val=[1,1,rect.left<=ww/2,rectn.left>ww/2]}}} return(val[0]&&val[1]&&val[2]&&val[3])}},_scrollTo:function(){_speed=functions._scrollSpeed.call(null);_to=(opt.pageEndSmoothScroll)?functions._pageEndSmoothScroll.call(null):_to;var _scrollable=$("html,body"),speed=(opt.autoScrollSpeed)?functions._autoScrollSpeed.call(null):_speed,easing=(_scrollable.is(":animated"))?opt.scrollingEasing:opt.scrollEasing,_t=$(window).scrollTop(),_l=$(window).scrollLeft();switch(_axis){case "horizontal":if(_l!=_to[1]){functions._callbacks.call(null,"onStart");_scrollable.stop().animate({scrollLeft:_to[1]},speed,easing).promise().then(function(){functions._callbacks.call(null,"onComplete")})} break;case "auto":if(_t!=_to[0]||_l!=_to[1]){functions._callbacks.call(null,"onStart");if(navigator.userAgent.match(/(iPod|iPhone|iPad|Android)/)){var left;_scrollable.stop().animate({pageYOffset:_to[0],pageXOffset:_to[1]},{duration:speed,easing:easing,step:function(now,fx){if(fx.prop=='pageXOffset'){left=now}else if(fx.prop=='pageYOffset'){window.scrollTo(left,now)}}}).promise().then(function(){functions._callbacks.call(null,"onComplete")})}else{_scrollable.stop().animate({scrollTop:_to[0],scrollLeft:_to[1]},speed,easing).promise().then(function(){functions._callbacks.call(null,"onComplete")})}} break;default:if(_t!=_to[0]){functions._callbacks.call(null,"onStart");_scrollable.stop().animate({scrollTop:_to[0]},speed,easing).promise().then(function(){functions._callbacks.call(null,"onComplete")})}}},_pageEndSmoothScroll:function(){var _dh=$(document).height(),_dw=$(document).width(),_wh=$(window).height(),_ww=$(window).width();return[((_dh-_to[0])<_wh)?_dh-_wh:_to[0],((_dw-_to[1])<_ww)?_dw-_ww:_to[1]]},_scrollSpeed:function(){var speed=opt.scrollSpeed;if(_clicked&&_clicked.length){_clicked.add(_clicked.parent()).each(function(){var $this=$(this);if($this.attr("class")){var clickedClasses=$this.attr("class").split(" ");for(var index in clickedClasses){if(String(clickedClasses[index]).match(/^ps2id-speed-\d+$/)){speed=clickedClasses[index].split("ps2id-speed-")[1];break}}}})} return parseInt(speed)},_autoScrollSpeed:function(){var _t=$(window).scrollTop(),_l=$(window).scrollLeft(),_h=$(document).height(),_w=$(document).width(),val=[_speed+((_speed*(Math.floor((Math.abs(_to[0]-_t)/_h)*100)))/100),_speed+((_speed*(Math.floor((Math.abs(_to[1]-_l)/_w)*100)))/100)];return Math.max.apply(Math,val)},_callbacks:function(c){if(!opt){return} this[pluginPfx]={trigger:_trigger,clicked:_clicked,target:_target,scrollTo:{y:_to[0],x:_to[1]}};switch(c){case "onStart":if(opt.appendHash&&window.history&&window.history.pushState&&_clicked&&_clicked.length){var hval=_clicked.attr("href"),h="#"+(hval.substring(hval.indexOf('#')+1));if(h!==window.location.hash)history.pushState("","",h)} opt.onStart.call(null,this[pluginPfx]);break;case "onComplete":opt.onComplete.call(null,this[pluginPfx]);break}},_reset:function(){_axis=_offset=_dataOffset=!1},_isInit:function(){if(!_init){methods.init.apply(this)}},_live:function(){_liveTimer=setTimeout(function(){if(opt.live){if($(functions._highlightSelector()).length!==_totalInstances){functions._setup.call(null)}}else{if(_liveTimer){clearTimeout(_liveTimer)}} functions._live.call(null)},1000)},_easing:function(){$.easing.easeInQuad=$.easing.easeInQuad||function(x){return x*x};$.easing.easeOutQuad=$.easing.easeOutQuad||function(x){return 1-(1-x)*(1-x)};$.easing.easeInOutQuad=$.easing.easeInOutQuad||function(x){return x<0.5?2*x*x:1-Math.pow(-2*x+2,2)/2};$.easing.easeInCubic=$.easing.easeInCubic||function(x){return x*x*x};$.easing.easeOutCubic=$.easing.easeOutCubic||function(x){return 1-Math.pow(1-x,3)};$.easing.easeInOutCubic=$.easing.easeInOutCubic||function(x){return x<0.5?4*x*x*x:1-Math.pow(-2*x+2,3)/2};$.easing.easeInQuart=$.easing.easeInQuart||function(x){return x*x*x*x};$.easing.easeOutQuart=$.easing.easeOutQuart||function(x){return 1-Math.pow(1-x,4)};$.easing.easeInOutQuart=$.easing.easeInOutQuart||function(x){return x<0.5?8*x*x*x*x:1-Math.pow(-2*x+2,4)/2};$.easing.easeInQuint=$.easing.easeInQuint||function(x){return x*x*x*x*x};$.easing.easeOutQuint=$.easing.easeOutQuint||function(x){return 1-Math.pow(1-x,5)};$.easing.easeInOutQuint=$.easing.easeInOutQuint||function(x){return x<0.5?16*x*x*x*x*x:1-Math.pow(-2*x+2,5)/2};$.easing.easeInExpo=$.easing.easeInExpo||function(x){return x===0?0:Math.pow(2,10*x-10)};$.easing.easeOutExpo=$.easing.easeOutExpo||function(x){return x===1?1:1-Math.pow(2,-10*x)};$.easing.easeInOutExpo=$.easing.easeInOutExpo||function(x){return x===0?0:x===1?1:x<0.5?Math.pow(2,20*x-10)/2:(2-Math.pow(2,-20*x+10))/2};$.easing.easeInSine=$.easing.easeInSine||function(x){return 1-Math.cos(x*Math.PI/2)};$.easing.easeOutSine=$.easing.easeOutSine||function(x){return Math.sin(x*Math.PI/2)};$.easing.easeInOutSine=$.easing.easeInOutSine||function(x){return-(Math.cos(Math.PI*x)-1)/2};$.easing.easeInCirc=$.easing.easeInCirc||function(x){return 1-Math.sqrt(1-Math.pow(x,2))};$.easing.easeOutCirc=$.easing.easeOutCirc||function(x){return Math.sqrt(1-Math.pow(x-1,2))};$.easing.easeInOutCirc=$.easing.easeInOutCirc||function(x){return x<0.5?(1-Math.sqrt(1-Math.pow(2*x,2)))/2:(Math.sqrt(1-Math.pow(-2*x+2,2))+1)/2};$.easing.easeInElastic=$.easing.easeInElastic||function(x){return x===0?0:x===1?1:-Math.pow(2,10*x-10)*Math.sin((x*10-10.75)*((2*Math.PI)/3))};$.easing.easeOutElastic=$.easing.easeOutElastic||function(x){return x===0?0:x===1?1:Math.pow(2,-10*x)*Math.sin((x*10-0.75)*((2*Math.PI)/3))+1};$.easing.easeInOutElastic=$.easing.easeInOutElastic||function(x){return x===0?0:x===1?1:x<0.5?-(Math.pow(2,20*x-10)*Math.sin((20*x-11.125)*((2*Math.PI)/4.5)))/2:Math.pow(2,-20*x+10)*Math.sin((20*x-11.125)*((2*Math.PI)/4.5))/2+1};$.easing.easeInBack=$.easing.easeInBack||function(x){return(1.70158+1)*x*x*x-1.70158*x*x};$.easing.easeOutBack=$.easing.easeOutBack||function(x){return 1+(1.70158+1)*Math.pow(x-1,3)+1.70158*Math.pow(x-1,2)};$.easing.easeInOutBack=$.easing.easeInOutBack||function(x){return x<0.5?(Math.pow(2*x,2)*(((1.70158*1.525)+1)*2*x-(1.70158*1.525)))/2:(Math.pow(2*x-2,2)*(((1.70158*1.525)+1)*(x*2-2)+(1.70158*1.525))+2)/2};$.easing.easeInBounce=$.easing.easeInBounce||function(x){return 1-__bounceOut(1-x)};$.easing.easeOutBounce=$.easing.easeOutBounce||__bounceOut;$.easing.easeInOutBounce=$.easing.easeInOutBounce||function(x){return x<0.5?(1-__bounceOut(1-2*x))/2:(1+__bounceOut(2*x-1))/2};function __bounceOut(x){var n1=7.5625,d1=2.75;if(x<1/d1){return n1*x*x}else if(x<2/d1){return n1*(x-=(1.5/d1))*x+.75}else if(x<2.5/d1){return n1*(x-=(2.25/d1))*x+.9375}else{return n1*(x-=(2.625/d1))*x+.984375}}}} functions._easing.call();$.fn[pluginNS]=function(method){if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1))}else if(typeof method==="object"||!method){return methods.init.apply(this,arguments)}else{$.error("Method "+method+" does not exist")}};$[pluginNS]=function(method){if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1))}else if(typeof method==="object"||!method){return methods.init.apply(this,arguments)}else{$.error("Method "+method+" does not exist")}};$[pluginNS].defaults=defaults})(jQuery,window,document)