////////////////////////////////////////////////////////////////////////////////////////////////

//			PLUGIN:		ARMY KNIFE

//			VERSION:	1.5

//			AUTHOR:		ROMAN D. PACHECO

////////////////////////////////////////////////////////////////////////////////////////////////

(function(a){var b="armyKnife",c={cssProps:{active:{marginLeft:"0%"},above:{zIndex:100},below:{zIndex:10},hiddenR:{marginLeft:"100%"},hiddenL:{marginLeft:"-100%"},fadeOut:{opacity:0},fadeIn:{opacity:1}},regex:{transition:{fadeIn:new RegExp("fade(,|$|In)","i"),fadeOut:new RegExp("fade(,|$|Out)","i"),slideIn:new RegExp("slide(,|$|In)","i"),slideOut:new RegExp("slide(,|$|Out)","i"),none:new RegExp("none(,|$)","i")}}},d={button:a("<a />",{href:"#"})},e={speed:300,sections:"> *",startingSection:0,easing:"swing",transition:"none",autoResize:false,resizeSpeed:200,autoRotate:false,autoRotateDelay:5e3,generateNav:false,navType:"empty",navItemSource:function(a){return" "},navItemCode:function(a){var b=d.button.clone();b.html(a);return b},navID:false,navClass:b+"-Nav",navTrigger:"click",itemsPerNav:0,activeNavItemClass:"active",showSectionButtons:false,sectionButtonClass:b+"-Btn",sectionButtonCodeNext:d.button.clone(),sectionButtonCodePrev:d.button.clone(),sectionOnEnter:false,sectionOnExit:false,sectionBeforeEnter:false,sectionBeforeExit:false},f={init:function(d,g){return this.each(function(){var h=a(this),i=h.data(b);if(!i){var j=a.extend(true,{},e);j=d?a.extend(true,j,d):j;a.extend(true,j,{sectionList:[],navItems:[],currentSection:j.startingSection,targetSection:false});h.data(b,j);i=h.data(b);var k=h.find(i.sections);if(i.generateNav){f.generateNav.call(h,k)}a.each(k,function(b,d){if(b==i.startingSection){a(d).css(c.cssProps.active)}else{a(d).css(c.cssProps.hiddenR)}if(i.showSectionButtons){if(b>0){var e=i.sectionButtonCodePrev.clone();e.html()==""&&e.html("Prev");e.addClass(i.sectionButtonClass).bind("click",function(){f.prev.call(h);return false}).appendTo(a(d))}if(b<k.length-1){var g=i.sectionButtonCodeNext.clone();g.html()==""&&g.html("Next");g.addClass(i.sectionButtonClass).bind("click",function(){f.next.call(h);return false}).appendTo(a(d))}}i.sectionList.push(a(d))})}if(i.autoRotate){f.setAutoRotate.call(h)}if(i.autoResize){i.targetSection=i.currentSection;f.resizeView.call(h,g)}else{if(typeof g=="function"){g()}}i.beforeEnterComplete=new a.Deferred;a.when(i.beforeEnterComplete).then(function(){if(typeof i.sectionOnEnter=="function"){i.sectionOnEnter.call(i.sectionList[i.currentSection],f.getSectionCallbackObj.call(h,"onenter"))}});if(typeof i.sectionBeforeEnter=="function"){var l=f.getSectionCallbackObj.call(h,"beforeenter");i.sectionBeforeEnter.call(i.sectionList[i.currentSection],l)}if(!i.useContinue||typeof i.sectionBeforeEnter!="function"&&i.useContinue){f.resolveContinue.call(h,"beforeenter")}})},getSectionCallbackObj:function(c){var d=this,e=d.data(b);if(e){var g={sections:e.sectionList,cont:function(){f.resolveContinue.call(d,c)}};switch(c){case"beforeenter":a.extend(true,g,{current:e.targetSection,previous:e.currentSection});break;case"onenter":a.extend(true,g,{current:e.targetSection,previous:e.currentSection});break;case"beforeexit":a.extend(true,g,{current:e.currentSection,target:e.targetSection});break;case"onexit":a.extend(true,g,{current:e.currentSection,target:e.targetSection});break;default:a.extend(true,g,{current:e.currentSection,previous:e.currentSection})}return g}},resolveContinue:function(a){var c=this,d=c.data(b);if(d){switch(a){case"beforeenter":if(typeof d.beforeEnterComplete=="object"){d.beforeEnterComplete.resolve()}break;case"onenter":if(typeof d.onEnterComplete=="object"){d.onEnterComplete.resolve()}break;case"beforeexit":if(typeof d.beforeExitComplete=="object"){d.beforeExitComplete.resolve()}break;case"onexit":if(typeof d.onExitComplete=="object"){d.onExitComplete.resolve()}break}}},generateNav:function(c){var e=this,g=e.data(b);if(g){g.nav=a("<div />");var h=g.itemsPerNav,i=a("<ul />",{"class":g.navClass}),j=c;if(g.itemsPerNav==0){h=c.length}var k=0;while(j.length){var l=i.clone();c=j;a.each(c,function(b,i){if(b>=h){return false}var m=a("<li />"),n=d.button.clone(),i=c[b];switch(g.navType){case"numeric":n.html(parseFloat(b+1));break;case"text":var o=g.navItemSource(a(i))||g.navItemSource;n.html(o);break;case"custom":var o=g.navItemSource(a(i))||g.navItemSource,p=g.navItemCode(o)||g.navItemCode;n=typeof p=="object"?p:a(p);break;default:n.html(" ")}l.append(m);m.append(n);n.bind(g.navTrigger,{i:k},function(a){f["goto"].call(e,a.data.i);return false});if(b==g.startingSection){m.addClass(g.activeNavItemClass)}g.navItems.push(m);j=j.filter(function(a){return j[a]!=i});k++});g.nav.append(l)}if(g.nav.children().length==1){g.nav=a(g.nav.children()[0])}if(g.navID){if(a("#"+g.navID).length){a("#"+g.navID).replaceWith(g.nav)}else{e.after(g.nav)}g.nav.attr("id",g.navID)}else{e.after(g.nav)}}},setAutoRotate:function(){return this.each(function(){var c=a(this),d=c.data(b);if(d){clearTimeout(d.autoRotateInterval);d.autoRotateInterval=setTimeout(function(){if(typeof d.isAnimating=="undefined"||d.isAnimating.isResolved()){f.next.call(c)}else{if(!d.isAnimating.isResolved()){a.when(d.isAnimating).then(function(){f.next.call(c)})}}},d.autoRotateDelay)}})},resizeView:function(c){return this.each(function(){var d=a(this),e=d.data(b);if(e){var f=d.height(),g=e.sectionList[e.targetSection].outerHeight();if(f!=g){d.animate({height:g},e.resizeSpeed,function(){if(typeof c=="function"){c()}})}else{if(typeof c=="function"){c()}}}})},"goto":function(c){return this.each(function(){var d=a(this),e=d.data(b);if(e&&c!=e.currentSection&&(typeof e.isAnimating=="undefined"||e.isAnimating.isResolved())){e.isAnimating=new a.Deferred;if(e.autoRotate){f.setAutoRotate.call(d)}e.targetSection=c;var g=c<e.currentSection?"right":"left";if(e.autoResize){f.resizeView.call(d,function(){f.animate.call(d,g)})}else{f.animate.call(d,g)}}})},next:function(){return this.each(function(){var c=a(this),d=c.data(b);if(d&&d.sectionList[d.currentSection]&&(typeof d.isAnimating=="undefined"||d.isAnimating.isResolved())){d.isAnimating=new a.Deferred;if(d.autoRotate){f.setAutoRotate.call(c)}d.targetSection=d.sectionList[d.currentSection+1]?d.currentSection+1:0;if(d.autoResize){f.resizeView.call(c,function(){f.animate.call(c)})}else{f.animate.call(c)}}})},prev:function(){return this.each(function(){var c=a(this),d=c.data(b);if(d&&d.sectionList[d.currentSection]&&(typeof d.isAnimating=="undefined"||d.isAnimating.isResolved())){d.isAnimating=new a.Deferred;if(d.autoRotate){f.setAutoRotate.call(c)}d.targetSection=d.sectionList[d.currentSection-1]?d.currentSection-1:d.sectionList.length-1;if(d.autoResize){f.resizeView.call(c,function(){f.animate.call(c,"right")})}else{f.animate.call(c,"right")}}})},animate:function(d,e){e=!!e?e:function(){};return this.each(function(){var g=a(this),h=g.data(b);d=!!d?d:"left";if(h&&h.sectionList[h.currentSection]&&h.sectionList[h.targetSection]){h.beforeExitComplete=new a.Deferred;a.when(h.beforeExitComplete).then(function(){h.beforeEnterComplete=new a.Deferred;a.when(h.beforeEnterComplete).then(function(){h.sectionList[h.currentSection].css(c.cssProps.below);var b=c.cssProps.active;if(h.transition.match(c.regex.transition.slideOut)||h.transition.match(c.regex.transition.none)){b=d=="left"?c.cssProps.hiddenL:c.cssProps.hiddenR}var i=a.extend(true,{},b);!!h.transition.match(c.regex.transition.fadeOut)&&a.extend(true,i,c.cssProps.fadeOut);if(h.transition.match(c.regex.transition.none)){h.sectionList[h.currentSection].css(i);e()}else{h.sectionList[h.currentSection].animate(i,h.speed,h.easing,e)}if(h.transition.match(c.regex.transition.fadeIn)){h.sectionList[h.targetSection].css(c.cssProps.fadeOut)}else{h.sectionList[h.targetSection].css(c.cssProps.fadeIn)}h.sectionList[h.targetSection].css(c.cssProps.above);var j=c.cssProps.active;if(h.transition.match(c.regex.transition.slideIn)||h.transition.match(c.regex.transition.none)){j=d=="left"?c.cssProps.hiddenR:c.cssProps.hiddenL}h.sectionList[h.targetSection].css(j);var k=a.extend(true,{},c.cssProps.active);!!h.transition.match(c.regex.transition.fadeIn)&&a.extend(true,k,c.cssProps.fadeIn);if(h.transition.match(c.regex.transition.none)){h.sectionList[h.targetSection].css(k);h.isAnimating.resolve();e();h.onExitComplete=new a.Deferred;a.when(h.onExitComplete).then(function(){if(typeof h.sectionOnEnter=="function"){h.sectionOnEnter.call(h.sectionList[h.targetSection],f.getSectionCallbackObj.call(g,"onenter"))}});if(typeof h.sectionOnExit=="function"){h.sectionOnExit.call(h.sectionList[h.currentSection],f.getSectionCallbackObj.call(g,"onexit"))}if(!h.useContinue||typeof h.sectionOnExit!="function"&&h.useContinue){f.resolveContinue.call(g,"onexit")}}else{h.sectionList[h.targetSection].animate(k,h.speed,h.easing,function(){h.isAnimating.resolve();e();h.onExitComplete=new a.Deferred;a.when(h.onExitComplete).then(function(){if(typeof h.sectionOnEnter=="function"){h.sectionOnEnter.call(h.sectionList[h.targetSection],f.getSectionCallbackObj.call(g,"onenter"))}});if(typeof h.sectionOnExit=="function"){h.sectionOnExit.call(h.sectionList[h.currentSection],f.getSectionCallbackObj.call(g,"onexit"))}if(!h.useContinue||typeof h.sectionOnExit!="function"&&h.useContinue){f.resolveContinue.call(g,"onexit")}})}if(h.nav){h.nav.find("."+h.activeNavItemClass).removeClass(h.activeClass);h.navItems[h.targetSection].addClass(h.activeNavItemClass)}h.currentSection=h.targetSection});if(typeof h.sectionBeforeEnter=="function"){h.sectionBeforeEnter.call(h.sectionList[h.targetSection],f.getSectionCallbackObj.call(g,"beforeenter"))}if(!h.useContinue||typeof h.sectionBeforeEnter!="function"&&h.useContinue){f.resolveContinue.call(g,"beforeenter")}});if(typeof h.sectionBeforeExit=="function"){h.sectionBeforeExit.call(h.sectionList[h.currentSection],f.getSectionCallbackObj.call(g,"beforeexit"))}if(!h.useContinue||typeof h.sectionBeforeExit!="function"&&h.useContinue){f.resolveContinue.call(g,"beforeexit")}}})}};a.fn[b]=function(b){if(f[b]){return f[b].apply(this,Array.prototype.slice.call(arguments,1))}else if(!b||typeof b=="object"){return f.init.apply(this,arguments)}else{a.error(c.pluginName+": Invalid method passed")}}})(jQuery);

