/**
 * Lucid Tabs
 * Easy tabs with minimal markup.
 *
 * Copyright (c) 2009 PJ Dietz
 * Version: 1.00
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * http://pjdietz.com/jquery-plugins/lucid-tabs/
 */
(function($){var TabSet,Tab,Page;TabSet=function(elem,options){var domTabs,domPage,domTab,tab,i,u;this.options=$.extend({},TabSet.defaultOptions,options);this.selected=this.options.selected;this.tabs=[];elem.data("TabSet",this);domTabs=elem.find("a[href^=#]");for(i=0,u=domTabs.length;i<u;i+=1){domTab=$(domTabs[i]);domPage=$(domTab.attr("href"));if(domPage.length===1){domPage.hide();tab=new Tab(domTab,domPage,this);this.tabs.push(tab);}}
this.tabs[this.selected].select();};TabSet.prototype={select:function(index){if(typeof index==="object"){index=this.getIndex(index);}
if(index<0||index>this.tabs.length){return false;}
if(index===this.selected){return false;}
this.tabs[index].select();this.tabs[this.selected].deselect();this.selected=index;return true;},getIndex:function(tab){var i,u;for(i=0,u=this.tabs.length;i<u;i+=1){if(this.tabs[i]===tab){return i;}}
return-1;}};TabSet.defaultOptions={selected:0,cssSelected:'selected',showPage:function(elem){elem.show();},hidePage:function(elem){elem.hide();}};Tab=function(domTab,domPage,tabSet){this.domTab=domTab;this.tabSet=tabSet;domTab.data('Tab',this);domTab.click(Tab.handleClick);this.page=new Page(domPage,this);};Tab.prototype={select:function(){var cls=this.tabSet.options.cssSelected;if(!this.domTab.hasClass(cls)){this.domTab.addClass(cls);}
this.page.show();},deselect:function(){var cls=this.tabSet.options.cssSelected;if(this.domTab.hasClass(cls)){this.domTab.removeClass(cls);}
this.page.hide();}};Tab.handleClick=function(event){var tab=$(event.target).data('Tab');tab.tabSet.select(tab);return false;};Page=function(domPage,tab){this.domPage=domPage;this.tab=tab;domPage.data('Page',this);};Page.prototype={show:function(){if(this.domPage.is(":hidden")){this.tab.tabSet.options.showPage(this.domPage);}},hide:function(){if(this.domPage.is(":visible")){this.tab.tabSet.options.hidePage(this.domPage);}}};$.fn.extend({tabs:function(options){return this.each(function(){var dummy=new TabSet($(this),options);});}});}(jQuery));
