YUI.add("content-tabs",function(c){var b=c.Lang;function a(d){a.superclass.constructor.apply(this,arguments)}a.NAME="contentTabs";a.ATTRS={menu:{setter:function(e){var d;if(b.isObject(e)){d=e}else{d=c.one(e)}return d}},contentArea:{setter:function(d){var e;if(b.isObject(d)){e=d}else{e=c.one(d)}return e}},contentContainer:{value:"content-container"},_contentContainer:{setter:function(e){var d;if(b.isObject(e)){d=e}else{d=this.get("contentArea").all(e)}return d}},container:{value:"content"},io:{value:true},basePath:{value:""}};a.CONTENT_CONTAINER_TEMPLATE='<div id="{id}" class="{class}"></div>';a.MENU_TEMPLATE='<ul class="navigation-in_page"></ul>';a.MENU_ITEM_TEMPLATE='<li><a class="{selected}" href="{href}">{label}</a></li>';c.extend(a,c.Widget,{initializer:function(){if(!this.get("menu")||this.get("menu")&&this.get("menu").one("li a").get("href").indexOf("#")>0){this.set("io",false)}if(!this.get("menu")){if((!this.get("contentArea").one("*:first-child")||this.get("contentArea").one("*:first-child").get("nodeName")!="H3")||(!this.get("contentArea").one("*:first-child")||this.get("contentArea").one("*:first-child").get("nodeName")=="H3"&&!this.get("contentArea").one("*:first-child").hasClass("create-menu"))||(this.get("io")&&this.get("basePath")=="")){this.destroy()}}if(this.get("io")&&location.pathname!=this.get("basePath")+"/"&&location.pathname!=location.pathname.replace(this.get("basePath"),this.get("basePath")+"/#")){if(!c.UA.ie||c.UA.ie>7){location.href=location.pathname.replace(this.get("basePath"),this.get("basePath")+"/#")}}else{if(this.get("io")&&location.hash!=""){this.updateUrl(c.Node.create('<a href="'+location.href.replace(/#\//,"")+'" ></a>'))}}},destructor:function(){},renderUI:function(){if(!this.get("menu")){this._buildFromMarkup()}else{this.set("_contentContainer",this.get("contentContainer"));if(!this.get("menu").one("a.selected")){this.get("menu").one("a:first-child").addClass("selected")}}if(!this.get("io")){this._hideConent()}},bindUI:function(){this._bindHistoryListener();this._bindMenuListeners()},syncUI:function(){},_buildFromMarkup:function(){var j=this.get("contentArea");var h=j.all("> *");var g=h.size();var p=[];var d;var f=c.Node.create(c.substitute(a.MENU_TEMPLATE,{}));var k,l;var n=j.one("h3.selected")?false:true;var o=(this.get("_contentContainer"))?this.get("_contentContainer").get("className"):this.get("contentContainer");for(var m=0;m<g;m++){var e=h.item(m);if(e.get("nodeName")=="H3"){l="";if(n||(!n&&e.hasClass("selected"))){l="selected";n=false}var q=e.get("innerHTML").replace('<span style="visibility: hidden;">',"").replace("</span>","");k=c.Node.create(c.substitute(a.MENU_ITEM_TEMPLATE,{selected:l,href:"#"+q.replace(/ /g,"-"),label:q}));f.append(k);d=c.Node.create(c.substitute(a.CONTENT_CONTAINER_TEMPLATE,{id:q.replace(/ /g,"-"),"class":o}));p.push(d)}d.append(e)}for(m=0;m<p.length;m++){this.get("contentArea").append(p[m])}this.set("_contentContainer","."+o);this.set("menu",f);c.one("#nav-column").append(f)},_hideConent:function(){var d=this.get("menu").one("a.selected").get("href").split("#")[1];d=decodeURIComponent(d);this.get("_contentContainer").each(function(e){if(e.get("id")==d){e.removeClass("hide")}else{e.addClass("hide")}})},_bindMenuListeners:function(){c.on("click",this.menuClicked,this.get("menu").all("a"),null,this)},_bindContentListeners:function(){c.on("click",this.contentClicked,this.get("contentArea"),null,this)},_bindHistoryListener:function(){c.on("hashchange",this.urlChanged,c.config.win,this)},urlChanged:function(f){var d="";d=f.newHash;this._fetchContent(this.get("basePath")+(d?d:"/"))},menuClicked:function(d,f){if(f.get("io")){if(c.UA.ie==7||c.UA.chrome){return}d.preventDefault();f.updateUrl(d.target)}else{d.preventDefault();f.switchContent(d.target)}f._menuHighlight(d.target)},contentClicked:function(d,f){d.preventDefault();if(d.target.get("nodeName")=="A"){f.updateUrl(d.target)}},updateUrl:function(e){var g=e.get("href").split("#")[1];var f=e.get("href").substr(e.get("href").indexOf(this.get("basePath"))+this.get("basePath").length);var d=g?g:f;location.hash=d!="/"?d:"";this._fetchContent(this.get("basePath")+d);this._hashForceMenuHighlight(e)},_menuHighlight:function(d){this.get("menu").all("a").each(function(e){if(e==d){e.addClass("selected")}else{e.removeClass("selected")}})},_hashForceMenuHighlight:function(g){var j=g;var e=j.get("href").split("/");var h=e.length;for(var f=0;f<h;f++){e.pop();var d=e.join("/")+"/";this.get("menu").all("a").each(function(i){if(i.get("href")==d){i.addClass("selected");f=h}else{i.removeClass("selected")}})}},switchContent:function(d){var e=d.get("href").split("#")[1];e=decodeURIComponent(e);this.get("_contentContainer").each(function(f){if(f.get("id")==e){f.removeClass("hide")}else{f.addClass("hide")}})},showAllContent:function(d,f){f.menuClicked(d,f);f.get("_contentContainer").each(function(e){e.removeClass("hide")})},_fetchContent:function(e){var f={success:function(i,h,g){g.success.contentTabs.updateContent(h.responseText)},failure:function(i,h,g){}};var d={on:{success:f.success,failure:f.failure},context:f,headers:{"X-Transaction":"GET Example"},arguments:{success:{contentTabs:this,path_suffix:e}}};c.io(e+(e.indexOf("?")>=0?"&":"?")+"container="+this.get("container"),d)},updateContent:function(d){this.get("contentArea").set("innerHTML",d)}});c.namespace("Morris").ContentTabs=a},"3.2.0",{requires:["widget","io","substitute"]});YUI().use("content-tabs",function(b){var a=new b.Morris.ContentTabs({menu:"#navigation-in_page",contentArea:"#content"}).render()});
