ccms.widgets.Tabs=function(root_element){var self=this;var links=ccms.arrayOf(root_element.getElementsByTagName('a'));var current='';self.getElement=function(){return root_element;};self.toggleTab=function(id){var c=current;if(current!=''){hide(current);current='';}
if(c!=id){current=id;show(current);}
updateLinks();ccms.dom.refresh();};self.showTab=function(id){if(current!=''&&current!=id){hide(current);}
current=id;show(current);updateLinks();ccms.dom.refresh();};self.ensureVisible=function(id){var block;if($('li_'+id)){self.showTab(id);}
else if((block=$(id))&&(block=block.parentNode)){while(block!=document.body){if(block.hasAttribute('id')){if($('li_'+block.getAttribute('id'))){self.showTab(block.getAttribute('id'));break;}}
block=block.parentNode;}}};function updateLinks(){links.foreach(function(a){if(a.href.substring(a.href.length-(current.length+1))=='#'+current)
ccms.dom.addClass(a.parentNode,'current');else
ccms.dom.removeClass(a.parentNode,'current');});}
function getUrlFragment(url){return url.replace(/^.*#(.+)/,'$1');}
function onTabClick(e){var id=getUrlFragment(this.href);if(ccms.dom.hasClass(root_element,'toggle'))
self.toggleTab(id);else
self.showTab(id);return ccms.event.killEvent(e);}
function hide(id){function _(id){ccms.dom.setStyle($(id),'display','none');}
if(ccms.browser.isIE)ccms.async.after(1,_.partial(id));else _(id);}
function show(id){function _(id){ccms.dom.setStyle($(id),'display','');ccms.events.fire('ccms.widgets.Tabs.show',id,self);}
if(ccms.browser.isIE)ccms.async.after(1,_.partial(id));else _(id);}
function init(){var id;var current='';for(var i=0;i<links.length;++i){ccms.event.attach(links[i],'click',onTabClick);id=getUrlFragment(links[i].href);if(ccms.dom.hasClass(links[i].parentNode,'current')){current=id;}
else{hide(id);}}
if(current!='')self.showTab(current);if(fragment=window.location.href.match(/#(.*)$/)){self.ensureVisible(fragment[1]);}
if(ccms.browser.isSafari){ccms.dom.hide(root_element.parentNode);window.setTimeout(function(){ccms.dom.show(root_element.parentNode);},1);}}
init();};ccms.widgets.Tabs.instances=[];ccms.widgets.Tabs.ensureVisible=function(id){ccms.widgets.Tabs.instances.foreach(function(tabs){tabs.ensureVisible(id);});var xy=ccms.dom.getXY(id);window.scrollTo(0,xy[1]);};ccms.widgets.Tabs.install=function(root){if(typeof root=='undefined'){if(window.opera)root=document.body;else root=document;}
var elts=ccms.dom.getElementsByClassName('tabs','ul',root);for(var i=0;i<elts.length;++i){if(elts[i].id!='ccmsHtmlTabs'&&!ccms.dom.hasClass(elts[i],'nojs')){ccms.widgets.Tabs.instances.push(new ccms.widgets.Tabs(elts[i]));}}};ccms.events.add('ccms.widgets.Tabs.show');ccms.event.onAvailable('ccmsHtmlTabs',function(){ccms.widgets.add(new ccms.widgets.Tabs(this));});ccms.widgets.addInstaller('tabs',ccms.widgets.Tabs.install);ccms.widgets.Tabs._cf='';ccms.widgets.Tabs.monitorFragment=function(){var f=document.location.href.replace(/^.*#(.+)/,'$1');if(ccms.widgets.Tabs._cf!==f){ccms.widgets.Tabs.ensureVisible(f);}
ccms.widgets.Tabs._cf=f;ccms.async.after(100,ccms.widgets.Tabs.monitorFragment);};ccms.widgets.Tabs.monitorFragment();