var SalonTabs=new Class({
Implements: [Events,Options],
options:{
tabCaptionElement: 'h3.caption',
navigationClass: 'tabNavigation',
tabClass: 'isTabbed',
startTab: $empty,
transition: $empty
},
initialize: function(element,options){
this.tabContainer=element
this.setOptions(options)
this.tabContainer.addClass(this.options.tabClass)
this.findTabs()
var anchor=window.location.href.replace(/^[^#]+#?(.*)$/i,'$1')
if(anchor !=''){
var elTemp=$(anchor)
if(elTemp){
var myFx=new Fx.Scroll(window,{
duration: 1000,
wait: false
}).toElement(elTemp)}}
},
findTabs: function(){
var activeTab=0
var anchor=window.location.href.replace(/^[^#]+#?(.*)$/i,'$1')
if(this.options.startTab !=$empty){
activeTab=this.options.startTab}
if(this.options.startTab==$empty&&anchor !=''){
activeTab=-1}
this.navigation=new Element('ul')
this.navigation.addClass(this.options.navigationClass)
this.tabs=this.tabContainer.getChildren()
this.tabs.each(function(tab,index){
var caption=tab.getFirst(this.options.tabCaptionElement)
tab.addClass('hidden')
caption.addClass('hidden')
var li=new Element('li')
li.appendText(caption.get('text'))
if(caption&&tab.getChildren().length>1){
li.addEvent('click',this.showTab.bind(this,index))
li.addEvent('mouseover',function(){this.addClass('over');})
li.addEvent('mouseout',function(){this.removeClass('over');})
if(anchor !=''
&&(tab.getProperty('id')==anchor
|| tab.getProperty('id')=='tab'+anchor)){
activeTab=index}
}else{
li.addClass('disabled')
caption.addClass('noPrint')}
this.navigation.grab(li,'bottom')
},this)
this.tabContainer.grab(this.navigation,'top')
if(activeTab==-1){
activeTab=0}
this.showTab(activeTab)
},
showTab: function(tabIndex){
this.tabs.each(function(tab,index){
if(index==tabIndex){
var f=function(){tab.removeClass('hidden')}
f.delay(0)
}else{
var myFx=new Fx.Tween(tab,{
duration: 0
})
myFx.addEvent('complete',function(el){
el.addClass('hidden')
el.setStyle('height','auto')
})
myFx.start('height',0)}
})
this.navigation.getChildren('li').each(function(tabNavigation,index){
if(index==tabIndex){
tabNavigation.addClass('active')
}else{
tabNavigation.removeClass('active')}
})}
})
window.addEvent('domready',function(){
var rgtabs=$$('.tx-rgtabs-pi1')
rgtabs.each(function(tab){
var tabholder=tab.getChildren('div')
if(tabholder.length>0){
tabholder=tabholder[0]
if(tabholder){
tabholder.addClass('tabbedContent')
var headlines=tabholder.getChildren('h4')
headlines.each(function(headline){
headline.addClass('tabCaption')
var next=headline.getNext()
if(next){
var tabContainer=new Element('div')
tabContainer.addClass('tab')
headline.inject(tabContainer)
next.inject(tabContainer)
tabholder.grab(tabContainer,'bottom')}
})}}
})
var tabs=$$('.tabbedContent')
tabs.each(function(tab){
new SalonTabs($(tab),{
tabCaptionElement: 'h4.tabCaption',
navigationClass: 'tabNavigation',
startTab:-1
})
})
})
