Event.observe( window, 'load', function() { new Tabs(); }, false ); var Tabs = Class.create( { initialize: function() { Cookie.init( { name: 'tabs' } ); this.tabs = {}; $$('div.tabs a[rel]').each( function( item ) { item.onclick = this.clickEvent.bindAsEventListener( this ); var data = item.rel.split( "_" ); var group = data[1]; var id = data[2]; if ( this.tabs[group] == undefined ) { this.tabs[group] = {}; } this.tabs[group][id] = { item : item, content : $('tab_'+group+'_'+id+'_content'), status : false }; var j = Cookie.getData( 'tabs_' + group ) || 0; if ( id == j ) { this.tabs[group][id].item.addClassName( 'active' ); this.tabs[group][id].content.show(); this.tabs[group][id].status = true; } }.bind( this ) ); }, clickEvent: function( event ) { Cookie.init( { name: 'tabs' } ); var tab = Event.element( event ); var data = tab.rel.split( "_" ); var group = data[1]; var id = data[2]; var tabs = this.tabs[group]; for ( var i in tabs ) { if ( i == id ) { tabs[i].item.addClassName( 'active' ); tabs[i].content.show(); tabs[i].status = true; Cookie.setData( 'tabs_' + group, i ); } else if ( tabs[i].status ) { tabs[i].item.removeClassName( 'active' ); tabs[i].content.hide(); tabs[i].status = false; } } return false; } } );