Railo.adapters.Layout=function(){var layouts={};var layoutAreas={};function getIndexFromName(layout,names){var panels=layout.find("div.ui-tabs-panel");var result=[];if(!panels.length){Railo.globalErrorHandler("layout.LayoutHasNoChildren",[layout])}else{for(var i=0;i<panels.length;i++){for(var n=0;n<names.length;n++){if($(panels[i]).attr("id")==names[n]){result.push(i)}}}}return result}function selectHandler(event,ui){var area=layoutAreas[ui.panel.id];var layoutName=$(document.getElementById(ui.panel.id)).parent().attr("id");var layout=layouts[layoutName];if(area&&area.options.bind){var go=false;if(!area.loaded){go=true}else{if(area.options.refreshOnActivate==true||area.options.refreshOnActivate=="true"){go=true}}if(go){Railo.Events.dispatchEvent(area.options.bind,Railo.Bind.getBind(area.options.bind));area.loaded=true}}if(layout.options.tabsselect){var f=eval(configs.tabsselect);f(event,ui)}Railo.Events.dispatchEvent("Layout.afterTabSelect",ui)}return{getTabLayout:function(name){try{var l=layouts[name].object;return l}catch(e){Railo.globalErrorHandler("layout.LayoutNotFound",[name]);return}},initializeTabLayout:function(name,options){options.cache=true;options.select=selectHandler;if(options.tabsadd){options.add=eval(options.tabsadd)}if(options.tabsremove){options.remove=eval(options.tabsremove)}if(options.tabsenable){options.enable=eval(options.tabsenable)}if(options.tabsdisable){options.disable=eval(options.tabsdisable)}var t=$(document.getElementById(name)).tabs(options);layouts[name]={};layouts[name].options=options;layouts[name].object=t},createTab:function(layout,name,title,url,options){var layoutObj=this.getTabLayout(layout);var tabheight=layouts[layout].options.tabheight;if(options.index=="undefined"){options.index=layoutObj.tabs("length")}if(!name){name="_cf_layout_tab"+Math.ceil(Math.random()*100000000)}if(url){var rand="_cf_layout_tab"+Math.ceil(Math.random()*100000000);Railo.Bind.register(rand,{bindTo:name,bindExpr:[],url:url,errorHandler:options.onBindError,handler:"Railo.Bind.urlBindHandler",listener:"Railo.Ajax.innerHtml"},false);options.bind=rand}layoutObj.tabs("add","#"+name,title,options.index);layoutAreas[name]={};layoutAreas[name].options=options;layoutAreas[name].loaded=false;if(options.selected=="true"||options.selected==true){Railo.Layout.selectedTab(layout,name);if(options.bind){Railo.Events.dispatchEvent(options.bind,Railo.Bind.getBind(options.bind));layoutAreas[name].loaded=true}}if(options.disabled=="true"||options.disabled==true){Railo.Layout.disableTab(layout,name)}var style="overflow:"+options.overflow+";height:"+tabheight+"px;";if(typeof(options.style)!=undefined){style=style+options.style}$("#"+name).attr("style",style)},removeTab:function(layout,layoutArea){var layoutObj=this.getTabLayout(layout);if(typeof(layoutArea)!="object"){layoutArea=[layoutArea]}var ix=getIndexFromName(layoutObj,layoutArea);for(var i=0;i<ix.length;i++){layoutObj.tabs("remove",ix[i]);if(layoutAreas[layoutArea].options.bind){Railo.Events.removeEvent(layoutAreas[layoutArea].options.bind)}layoutAreas[layoutArea]=null}},removeLastTab:function(layout){var layoutObj=this.getTabLayout(layout);var ix=layoutObj.tabs("length")-1;var layoutArea=layoutObj.find("div.ui-tabs-panel")[ix].id;Railo.Layout.removeTab(layout,layoutArea)},removeIndexTab:function(layout,index){var layoutObj=this.getTabLayout(layout);var tabsDiv=layoutObj.find("div.ui-tabs-panel");Railo.Layout.removeTab(layout,$(tabsDiv[index]).attr("id"))},selectedTab:function(layout,layoutArea){var layout=this.getTabLayout(layout);layout.tabs("select",layoutArea)},disableTab:function(layout,layoutArea){var layoutObj=this.getTabLayout(layout);if(typeof(layoutArea)!="object"){layoutArea=[layoutArea]}var ix=getIndexFromName(layoutObj,layoutArea);for(var i=0;i<ix.length;i++){layoutObj.tabs("disable",ix[i])}},enableTab:function(layout,layoutArea){var layoutObj=this.getTabLayout(layout);if(typeof(layoutArea)!="object"){layoutArea=[layoutArea]}var ix=getIndexFromName(layoutObj,[layoutArea]);for(var i=0;i<ix.length;i++){layoutObj.tabs("enable",ix[i])}this.selectedTab(layout,layoutArea[layoutArea.length-1])}}};