!function(a,b,c,d){"use strict";a.tab=a.fn.tab=function(c){var e,f,g=a(a.isFunction(this)?b:this),h=a.isPlainObject(c)?a.extend(!0,{},a.fn.tab.settings,c):a.extend({},a.fn.tab.settings),i=g.selector||"",j=(new Date).getTime(),k=[],l=arguments[0],m="string"==typeof l,n=[].slice.call(arguments,1);return g.each(function(){var c,o,p,q,r=h.className,s=h.metadata,t=h.selector,u=h.error,v="."+h.namespace,w="module-"+h.namespace,x=a(this),y=a(t.tabs),z={},A=!0,B=0,C=this,D=x.data(w);e={initialize:function(){e.debug("Initializing tab menu item",x),h.context&&(e.determineTabs(),e.debug("Using only tabs inside context",h.context,y)),h.auto&&(e.verbose("Setting up automatic tab retrieval from server"),h.apiSettings={url:h.path+"/{$tab}"}),a.isWindow(C)||(e.debug("Attaching tab activation events to element",x),x.on("click"+v,e.event.click)),e.instantiate()},determineTabs:function(){var b;"parent"===h.context?(x.closest("."+r.ui).size()>0?(b=x.closest("."+r.ui),e.verbose("Using closest UI element for determining parent",b)):b=x,c=b.parent(),e.verbose("Determining parent element for creating context",c)):(c=a(h.context),e.verbose("Using selector for tab context",h.context,c)),h.childrenOnly?(y=c.children(t.tabs),e.debug("Searching tab context children for tabs",c,y)):(y=c.find(t.tabs),e.debug("Searching tab context for tabs",c,y))},initializeHistory:function(){if(h.history){if(e.debug("Initializing page state"),a.address===d)return e.error(u.state),!1;if("state"==h.historyType){if(e.debug("Using HTML5 to manage state"),h.path===!1)return e.error(u.path),!1;a.address.history(!0).state(h.path)}a.address.bind("change",e.event.history.change)}},instantiate:function(){e.verbose("Storing instance of module",e),x.data(w,e)},destroy:function(){e.debug("Destroying tabs",x),x.removeData(w).off(v)},event:{click:function(b){var c=a(this).data(s.tab);c!==d?(h.history?(e.verbose("Updating page state",b),a.address.value(c)):(e.verbose("Changing tab",b),e.changeTab(c)),b.preventDefault()):e.debug("No tab specified")},history:{change:function(b){var c=b.pathNames.join("/")||e.get.initialPath(),f=h.templates.determineTitle(c)||!1;e.performance.display(),e.debug("History change event",c,b),q=b,c!==d&&e.changeTab(c),f&&a.address.title(f)}}},refresh:function(){o&&(e.debug("Refreshing tab",o),e.changeTab(o))},cache:{read:function(a){return a!==d?z[a]:!1},add:function(a,b){a=a||o,e.debug("Adding cached content for",a),z[a]=b},remove:function(a){a=a||o,e.debug("Removing cached content for",a),delete z[a]}},set:{state:function(b){a.address.value(b)}},changeTab:function(c){var d=b.history&&b.history.pushState,f=d&&h.ignoreFirstLoad&&A,g=h.auto||a.isPlainObject(h.apiSettings),i=g&&!f?e.utilities.pathToArray(c):e.get.defaultPathArray(c);c=e.utilities.arrayToPath(i),a.each(i,function(b,d){var j,k,l,m,n=i.slice(0,b+1),r=e.utilities.arrayToPath(n),s=e.is.tab(r),t=b+1==i.length,v=e.get.tabElement(r);return e.verbose("Looking for tab",d),s?(e.verbose("Tab was found",d),o=r,p=e.utilities.filterArray(i,n),t?m=!0:(k=i.slice(0,b+2),l=e.utilities.arrayToPath(k),m=!e.is.tab(l),m&&e.verbose("Tab parameters found",k)),m&&g?(f?(e.debug("Ignoring remote content on first tab load",r),A=!1,e.cache.add(c,v.html()),e.activate.all(r),a.proxy(h.onTabInit,v)(r,p,q),a.proxy(h.onTabLoad,v)(r,p,q)):(e.activate.navigation(r),e.content.fetch(r,c)),!1):(e.debug("Opened local tab",r),e.activate.all(r),e.cache.read(r)||(e.cache.add(r,!0),e.debug("First time tab loaded calling tab init"),a.proxy(h.onTabInit,v)(r,p,q)),a.proxy(h.onTabLoad,v)(r,p,q),void 0)):(j=a("#"+c+', a[name="'+c+'"]'),r=j.closest("[data-tab]").data("tab"),v=e.get.tabElement(r),j.size()>0&&r?(e.debug("No tab found, but deep anchor link present, opening parent tab"),e.activate.all(r),e.cache.read(r)||(e.cache.add(r,!0),e.debug("First time tab loaded calling tab init"),a.proxy(h.onTabInit,v)(r,p,q))):e.error(u.missingTab,x,r),!1)})},content:{fetch:function(b,c){var f,g,i=e.get.tabElement(b),j={dataType:"html",stateContext:i,onSuccess:function(d){e.cache.add(c,d),e.content.update(b,d),b==o?(e.debug("Content loaded",b),e.activate.tab(b)):e.debug("Content loaded in background",b),a.proxy(h.onTabInit,i)(b,p,q),a.proxy(h.onTabLoad,i)(b,p,q)},urlData:{tab:c}},k=i.data(s.promise)||!1,l=k&&"pending"===k.state();c=c||b,g=e.cache.read(c),h.cache&&g?(e.debug("Showing existing content",c),e.content.update(b,g),e.activate.tab(b),a.proxy(h.onTabLoad,i)(b,p,q)):l?(e.debug("Content is already loading",c),i.addClass(r.loading)):a.api!==d?(f=a.extend(!0,{headers:{"X-Remote":!0}},h.apiSettings,j),e.debug("Retrieving remote content",c,f),a.api(f)):e.error(u.api)},update:function(a,b){e.debug("Updating html for",a);var c=e.get.tabElement(a);c.html(b)}},activate:{all:function(a){e.activate.tab(a),e.activate.navigation(a)},tab:function(a){var b=e.get.tabElement(a);e.verbose("Showing tab content for",b),b.addClass(r.active).siblings(y).removeClass(r.active+" "+r.loading)},navigation:function(a){var b=e.get.navElement(a);e.verbose("Activating tab navigation for",b,a),b.addClass(r.active).siblings(g).removeClass(r.active+" "+r.loading)}},deactivate:{all:function(){e.deactivate.navigation(),e.deactivate.tabs()},navigation:function(){g.removeClass(r.active)},tabs:function(){y.removeClass(r.active+" "+r.loading)}},is:{tab:function(a){return a!==d?e.get.tabElement(a).size()>0:!1}},get:{initialPath:function(){return g.eq(0).data(s.tab)||y.eq(0).data(s.tab)},path:function(){return a.address.value()},defaultPathArray:function(a){return e.utilities.pathToArray(e.get.defaultPath(a))},defaultPath:function(a){var b=g.filter("[data-"+s.tab+'^="'+a+'/"]').eq(0),c=b.data(s.tab)||!1;if(c){if(e.debug("Found default tab",c),B0?b:c},tab:function(){return o}},utilities:{filterArray:function(b,c){return a.grep(b,function(b){return-1==a.inArray(b,c)})},last:function(b){return a.isArray(b)?b[b.length-1]:!1},pathToArray:function(a){return a===d&&(a=o),"string"==typeof a?a.split("/"):[a]},arrayToPath:function(b){return a.isArray(b)?b.join("/"):!1}},setting:function(b,c){if(e.debug("Changing setting",b,c),a.isPlainObject(b))a.extend(!0,h,b);else{if(c===d)return h[b];h[b]=c}},internal:function(b,c){if(a.isPlainObject(b))a.extend(!0,e,b);else{if(c===d)return e[b];e[b]=c}},debug:function(){h.debug&&(h.performance?e.performance.log(arguments):(e.debug=Function.prototype.bind.call(console.info,console,h.name+":"),e.debug.apply(console,arguments)))},verbose:function(){h.verbose&&h.debug&&(h.performance?e.performance.log(arguments):(e.verbose=Function.prototype.bind.call(console.info,console,h.name+":"),e.verbose.apply(console,arguments)))},error:function(){e.error=Function.prototype.bind.call(console.error,console,h.name+":"),e.error.apply(console,arguments)},performance:{log:function(a){var b,c,d;h.performance&&(b=(new Date).getTime(),d=j||b,c=b-d,j=b,k.push({Name:a[0],Arguments:[].slice.call(a,1)||"",Element:C,"Execution Time":c})),clearTimeout(e.performance.timer),e.performance.timer=setTimeout(e.performance.display,100)},display:function(){var b=h.name+":",c=0;j=!1,clearTimeout(e.performance.timer),a.each(k,function(a,b){c+=b["Execution Time"]}),b+=" "+c+"ms",i&&(b+=" '"+i+"'"),(console.group!==d||console.table!==d)&&k.length>0&&(console.groupCollapsed(b),console.table?console.table(k):a.each(k,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),k=[]}},invoke:function(b,c,g){var h,i,j,k=D;return c=c||n,g=C||g,"string"==typeof b&&k!==d&&(b=b.split(/[\. ]/),h=b.length-1,a.each(b,function(c,f){var g=c!=h?f+b[c+1].charAt(0).toUpperCase()+b[c+1].slice(1):b;if(a.isPlainObject(k[g])&&c!=h)k=k[g];else{if(k[g]!==d)return i=k[g],!1;if(!a.isPlainObject(k[f])||c==h)return k[f]!==d?(i=k[f],!1):(e.error(u.method,b),!1);k=k[f]}})),a.isFunction(i)?j=i.apply(g,c):i!==d&&(j=i),a.isArray(f)?f.push(j):f!==d?f=[f,j]:j!==d&&(f=j),i}},m?(D===d&&e.initialize(),e.invoke(l)):(D!==d&&e.destroy(),e.initialize())}),e&&!m&&e.initializeHistory(),f!==d?f:this},a.tab=function(c){a(b).tab(c)},a.fn.tab.settings={name:"Tab",namespace:"tab",debug:!1,verbose:!1,performance:!1,onTabInit:function(){},onTabLoad:function(){},templates:{determineTitle:function(){}},auto:!1,history:!1,historyType:"hash",path:!1,context:!1,childrenOnly:!1,maxDepth:25,ignoreFirstLoad:!1,alwaysRefresh:!1,cache:!0,apiSettings:!1,error:{api:"You attempted to load content without API module",method:"The method you called is not defined",missingTab:"Activated tab cannot be found for this context.",noContent:"The tab you specified is missing a content url.",path:"History enabled, but no path was specified",recursion:"Max recursive depth reached",state:"The state library has not been initialized"},metadata:{tab:"tab",loaded:"loaded",promise:"promise"},className:{loading:"loading",active:"active",ui:"ui"},selector:{tabs:".ui.tab"}}}(jQuery,window,document);