/*!
jQuery Waypoints - v1.1
Copyright (c) 2011 Caleb Troughton
Dual licensed under the MIT license and GPL license.
https://github.com/imakewebthings/jquery-waypoints/blob/master/MIT-license.txt
https://github.com/imakewebthings/jquery-waypoints/blob/master/GPL-license.txt
*/
/*
Waypoints is a small jQuery plugin that makes it easy to execute a function
whenever you scroll to an element.

GitHub Repository: https://github.com/imakewebthings/jquery-waypoints
Documentation and Examples: http://imakewebthings.github.com/jquery-waypoints

Changelog:
	v1.1.
		- Moved the continuous option out of global settings and into the options
		  object for individual waypoints.
		- Added the context option, which allows for using waypoints within any
		  scrollable element, not just the window.
	v1.0.2
		- Moved scroll and resize handler bindings out of load.  Should play nicer
		  with async loaders like Head JS and LABjs.
		- Fixed a 1px off error when using certain % offsets.
		- Added unit tests.
	v1.0.1
		- Added $.waypoints('viewportHeight').
		- Fixed iOS bug (using the new viewportHeight method).
		- Added offset function alias: 'bottom-in-view'.
	v1.0
		- Initial release.
	
Support:
	- jQuery versions 1.4+
	- IE6+, FF3+, Chrome 6+, Safari 4+, Opera 11
	- Other versions and browsers may work, these are just the ones I've looked at.
*/
(function(a,b,c,d,e){"$:nomunge";var f=a(d),g="waypoint.reached",h=function(a,c){a.element.trigger(g,c),a.options.triggerOnce&&a.element[b]("destroy")},i=function(a,b){var c=b.waypoints.length-1;while(c>=0&&b.waypoints[c].element[0]!==a[0])c-=1;return c},j=[],k=function(b){a.extend(this,{element:a(b),oldScroll:-99999,waypoints:[],didScroll:!1,didResize:!1,doScroll:a.proxy(function(){var b=this.element.scrollTop(),d=b>this.oldScroll,e=this,f=a.grep(this.waypoints,function(a,c){return d?a.offset>e.oldScroll&&a.offset<=b:a.offset<=e.oldScroll&&a.offset>b}),g=f.length;(!this.oldScroll||!b)&&a[c]("refresh"),this.oldScroll=b;if(!g)return;d||f.reverse(),a.each(f,function(a,b){(b.options.continuous||a===g-1)&&h(b,[d?"down":"up"])})},this)}),a(b).scroll(a.proxy(function(){this.didScroll||(this.didScroll=!0,d.setTimeout(a.proxy(function(){this.doScroll(),this.didScroll=!1},this),a[c].settings.scrollThrottle))},this)).resize(a.proxy(function(){this.didResize||(this.didResize=!0,d.setTimeout(a.proxy(function(){a[c]("refresh"),this.didResize=!1},this),a[c].settings.resizeThrottle))},this)),f.load(a.proxy(function(){this.doScroll()},this))},l=function(b){var c=null;return a.each(j,function(a,d){if(d.element[0]===b)return c=d,!1}),c},m={init:function(d,e){return this.each(function(){var f=a.fn[b].defaults.context,h,m=a(this);e&&e.context&&(f=e.context),a.isWindow(f)||(f=m.closest(f)[0]),h=l(f),h||(h=new k(f),j.push(h));var n=i(m,h),o=n<0?a.fn[b].defaults:h.waypoints[n].options,p=a.extend({},o,e);p.offset=p.offset==="bottom-in-view"?function(){var b=a.isWindow(f)?a[c]("viewportHeight"):a(f).height();return b-a(this).outerHeight()}:p.offset,n<0?h.waypoints.push({element:m,offset:m.offset().top,options:p}):h.waypoints[n].options=p,d&&m.bind(g,d)}),a[c]("refresh"),this},remove:function(){return this.each(function(b,c){var d=a(c);a.each(j,function(a,b){var c=i(d,b);c>=0&&b.waypoints.splice(c,1)})})},destroy:function(){return this.unbind(g)[b]("remove")}},n={refresh:function(){a.each(j,function(b,d){var e=a.isWindow(d.element[0]),f=e?0:d.element.offset().top,g=e?a[c]("viewportHeight"):d.element.height(),i=e?0:d.element.scrollTop();a.each(d.waypoints,function(a,b){var c=b.options.offset,e=b.offset;if(typeof b.options.offset=="function")c=b.options.offset.apply(b.element);else if(typeof b.options.offset=="string"){var j=parseFloat(b.options.offset);c=b.options.offset.indexOf("%")?Math.ceil(g*(j/100)):j}b.offset=b.element.offset().top-f+i-c,d.oldScroll>e&&d.oldScroll<=b.offset?h(b,["up"]):d.oldScroll<e&&d.oldScroll>=b.offset&&h(b,["down"])}),d.waypoints.sort(function(a,b){return a.offset-b.offset})})},viewportHeight:function(){return d.innerHeight?d.innerHeight:f.height()},aggregate:function(){var b=a();return a.each(j,function(c,d){a.each(d.waypoints,function(a,c){b=b.add(c.element)})}),b}};a.fn[b]=function(c){if(m[c])return m[c].apply(this,Array.prototype.slice.call(arguments,1));if(typeof c=="function"||!c)return m.init.apply(this,arguments);if(typeof c=="object")return m.init.apply(this,[null,c]);a.error("Method "+c+" does not exist on jQuery "+b)},a.fn[b].defaults={continuous:!0,offset:0,triggerOnce:!1,context:d},a[c]=function(a){return n[a]?n[a].apply(this):n.aggregate()},a[c].settings={resizeThrottle:200,scrollThrottle:100},f.load(function(){a[c]("refresh")})})(jQuery,"waypoint","waypoints",this),function(){var a=function(a,b){return function(){return a.apply(b,arguments)}};if(typeof Bobcat=="undefined"||Bobcat===null)Bobcat={};Bobcat.SlideManager=function(){function b(){this.SlideManager=a(this.SlideManager,this),this.SlideManager=a(this.SlideManager,this),this.SlideManager=a(this.SlideManager,this),this.SlideManager=a(this.SlideManager,this),this.SlideManager=a(this.SlideManager,this),this.SlideManager=a(this.SlideManager,this),this.SlideManager=a(this.SlideManager,this),this.SlideManager=a(this.SlideManager,this),this.SlideManager=a(this.SlideManager,this)}return b.minHeight=640,b.scrolling=!1,b.scrolled=!1,b.presentMode=!1,b.current=ko.observable(),b.init=function(){return this.selectSlide($(".slides .slide").first()),b.registerSlideWaypoint($(".slides .slide")),$(window).resize(a(function(){return this.resizeSlides()},this)),this.resizeSlides(),this.applySubthemes(),$(document).bind("keydown",a(function(a){var b,c,d;if((b=Bobcat.ComponentManager)!=null?!b.captureKeyboardInput():!void 0)switch(a.keyCode){case 32:case 40:a.preventDefault();if((c=Bobcat.ComponentManager)!=null?!c.current():!void 0)return this.nextSlide();break;case 38:a.preventDefault();if((d=Bobcat.ComponentManager)!=null?!d.current():!void 0)return this.prevSlide()}},this))},b.changeSlide=function(a){var b,c;b=$(".slides .slide.selected"),c=a>0?b.next():b.prev();if(c.length)return this.selectAndGotoSlide(c)},b.selectAndGotoSlide=function(a){return this.selectSlide(a),this.gotoSlide(a)},b.gotoSlide=function(b){if(!b.length)return;return $.scrollTo.window().queue([]).stop(),this.scrolling=!0,$(window).scrollTo(b,{easing:"easeOutQuint",duration:1200,onAfter:a(function(){return this.scrolling=!1},this)})},b.selectAndGotoSlideIndex=function(a){return this.selectAndGotoSlide($(".slides .slide").eq(a))},b.gotoSlideIndex=function(a){return this.gotoSlide($(".slides .slide").eq(a))},b.snapSlide=function(a){return this.gotoSlide($(".slides .slide.selected"))},b.selectSlide=function(a){return $(".slides .slide").removeClass("selected"),a.addClass("selected"),this.current(a)},b.nextSlide=function(){return this.changeSlide(1)},b.prevSlide=function(){return this.changeSlide(-1)},b.resizeSlides=function(){return $(".slides .slide").css("height",Math.max($(window).height(),this.minHeight)),$(".preview").css("height",$(window).height()-32-80)},b.registerSlideWaypoint=function(b){return b.waypoint(a(function(a,b){if(!this.scrolling)return b==="down"?this.selectSlide($(a.target)):this.selectSlide($(a.target).prev())},this),{offset:"50%",continuous:!1})},b.addSlide=function(){return Bobcat.TemplateManager.createTemplateDialog()},b.deleteSlide=function(a){var c,d;if(!window.confirm("Are you sure you want to delete this slide? This action cannot be undone."))return;return c=b.getPosition(a),a.get(0)===b.current().get(0)&&(c===0?b.selectSlide(a.next(".slide")):(d=a.prev(".slide"),b.selectAndGotoSlide(d))),a.slideUp("normal",function(){var a;return a=b.current(),Bobcat.EditPage.removeSlideData(c),$(this).remove(),b.gotoSlide(a),b.resizeSlides(),b.checkNoSlides()})},b.checkNoSlides=function(){if($(".slides .slide").length===0)return b.addSlide()},b.getPosition=function(a){return a.prevAll(".slide").length},b.applySubthemes=function(b){var c,d;return b==null&&(b=[1,2]),c=a(function(a,c){var e;return e="subtheme-"+b[d++%b.length],$(c).data("subtheme")&&$(c).removeClass($(c).data("subtheme")),$(c).addClass(e),$(c).data("subtheme",e)},this),d=0,$(".slides .slide").each(c),d=0,$(".preview .slide").each(c)},b}()}.call(this)
