if(typeof Protoplasm=="undefined"){throw ("protoplasm.js not loaded, could not intitialize tabstrip")}if(window.Control==undefined){Control={}}Protoplasm.loadStylesheet("tabstrip.css","tabstrip");Control.TabStrip=Class.create({initialize:function(b,a){b=$(b);if(ts=b.retrieve("tabstrip")){ts.destroy()}b.addClassName("_pp_tabstrip");a=Object.extend({activeClass:"active",disabledClass:"disabled",onClick:Prototype.emptyFunction,disabled:false},a||{});this.element=b;this.options=a;this.tabs=[];this.panels=[];this.active=-1;this.disabled=[];this.listeners=[Event.on(window,"unload",this.destroy.bind(this))];this.createTabs(b,a);if(a.activeTab){this.switchTab(a.activeTab)}b.store("tabstrip",this)},createTabs:function(p){if(p.childElements().length==2){var f=p.childElements()[0];f.cleanWhitespace();f.addClassName("_pp_tabstrip_tabs");var k=f.childElements();var c=f.wrap("div",{"class":"_pp_tabstrip_scroller"});this.scroller=c;var j=p.childElements()[1];j.addClassName("_pp_tabstrip_panels");var g=j.childElements();var h=this.options.disabled;var n=this.options.disabledClass;if(k.length==g.length){for(var b=0;b<k.length;b++){var o=this;this.listeners.push(k[b].on("click",function(d){return function(i){if(!d.id||!this.disabled.include(d.id)){this.switchTab(d)}}.bindAsEventListener(o)}(k[b])));this.listeners.push(k[b].on("mousedown",function(d){Event.stop(d);return false}.bindAsEventListener(this)));this.listeners.push(k[b].on("selectstart",function(d){Event.stop(d);return false}.bindAsEventListener(this)));if((h&&h.include(k[b].id))||(n&&k[b].hasClassName(n))){this.disable(k[b])}}g.invoke("hide");this.tabs=k;this.panels=g;var m=this.tabs[this.tabs.length-1].getLayout();var l=m.get("left")+m.get("width");if(l>c.getLayout().get("width")){var e=new Element("div",{"class":"_pp_tabstrip_scroll"});var a=new Element("div",{"class":"_pp_tabstrip_scroll_left"});var l=new Element("div",{"class":"_pp_tabstrip_scroll_right"});this.makeScroller(a,f,c,20);this.makeScroller(l,f,c,-20);e.insert(a);e.insert(l);c.insert(e)}this.switchTabByIndex(0)}}},makeScroller:function(c,d,b,a){var e=false;c.on("mousedown",function(h){e=true;var g;setTimeout(function(){if(e){g=setInterval(function(){if(e){var i=d.getLayout();this.scrollTo(d,b,i.get("left")+a)}else{clearInterval(g)}}.bind(this),50)}}.bind(this),500);var f=d.getLayout();this.scrollTo(d,b,f.get("left")+a)}.bindAsEventListener(this));c.on("mouseup",function(f){e=false}.bindAsEventListener(this));c.on("mouseout",function(f){e=false}.bindAsEventListener(this));c.on("selectstart",function(f){Event.stop(f)}.bindAsEventListener(this))},scrollTo:function(g,a,c){var i=g.childNodes[g.childNodes.length-1];var e=i.getLayout();var b=e.get("left")+e.get("margin-box-width");var d=a.getLayout();var h=0;var f=-(b-d.get("width")+29+3);if(c<f){c=f}else{if(c>h){c=h}}g.style.left=c+"px"},scrollVisible:function(b){var g=this.scroller.firstChild;var e=b.getLayout();var d=g.getLayout();var a=this.scroller.getLayout();var c=-d.get("left");var i=c+(a.get("width")-29);var f=-c;if(e.get("left")<c){f=-(e.get("left")-6)}else{if(e.get("left")+e.get("margin-box-width")>i){var h=e.get("left")+e.get("margin-box-width");f=-c-(h-i)-9}}if(f!=-c){this.scrollTo(g,this.scroller,f)}},enable:function(a){var a=$(a);if(a){a.removeClassName(this.options.disabledClass);this.disabled=this.disabled.without(a.id)}},disable:function(a){var a=$(a);if(a){a.addClassName(this.options.disabledClass);if(!this.disabled.include(a.id)){this.disabled.push(a.id)}}},destroy:function(){this.switchTabByIndex(0);this.listeners.invoke("stop");this.element.select("._pp_tabstrip_tabs").invoke("removeClassName","_pp_tabstrip_tabs");this.element.select("._pp_tabstrip_panels").invoke("removeClassName","_pp_tabstrip_panels");this.element.removeClassName("_pp_tabstrip");this.scroller.parentNode.replaceChild(this.scroller.firstChild,this.scroller);this.element.store("tabstrip",null)},switchTab:function(b){b=$(b);for(var a=0;a<this.tabs.length;++a){if(this.tabs[a]==b){return this.switchTabByIndex(a)}}},switchTabByIndex:function(a){var b=this.tabs[a];if(this.active!=a){if(this.active>-1){this.tabs[this.active].removeClassName(this.options.activeClass);this.panels[this.active].hide()}Element.addClassName(b,this.options.activeClass);this.scrollVisible(b);this.panels[a].show();this.active=a;if(this.options.onClick){this.options.onClick(b)}}}});Protoplasm.register("tabstrip",Control.TabStrip);