
(function($){$.fn.tabs=function(initial,settings){if(typeof initial=='object')settings=initial;settings=$.extend({initial:(initial&&typeof initial=='number'&&initial>0)?--initial:0,disabled:null,bookmarkable:$.ajaxHistory?true:false,fxFade:null,fxSlide:null,fxShow:null,fxHide:null,fxSpeed:'normal',fxShowSpeed:null,fxHideSpeed:null,fxAutoHeight:false,onClick:null,onHide:null,onShow:null,selectedClass:'tabs-selected',disabledClass:'tabs-disabled',hideClass:'tabs-hide',tabStruct:'div'},settings||{});$.browser.msie6=$.browser.msie&&/MSIE 6.0/.test(navigator.userAgent);var _unFocus=function(){scrollTo(0,0);};return this.each(function(){var container=this;var tabs=$('>ul:eq(0)>li>a',this);if(location.hash){tabs.each(function(i){if(this.hash==location.hash){settings.initial=i;if($.browser.msie||$.browser.opera){var toShow=$(location.hash);var toShowId=toShow.attr('id');toShow.attr('id','');setTimeout(function(){toShow.attr('id',toShowId);},500);}
_unFocus();return false;}});}
if($.browser.msie){_unFocus();}
$('>'+settings.tabStruct,this).filter(':eq('+settings.initial+')').show().end().not(':eq('+settings.initial+')').addClass(settings.hideClass);$('>ul:eq(0)>li:eq('+settings.initial+')',this).addClass(settings.selectedClass);if(settings.fxAutoHeight){var tabsContents=$('>'+settings.tabStruct,container);var _setAutoHeight=function(reset){var heights=$.map(tabsContents.get(),function(el){var h,jq=$(el);if(reset){if($.browser.msie6){el.style.removeExpression('behaviour');el.style.height='';el.minHeight=null;}
h=jq.css({'min-height':''}).height();}else{h=jq.height();}
return h;}).sort(function(a,b){return b-a;});if($.browser.msie6){tabsContents.each(function(){this.minHeight=heights[0]+'px';this.style.setExpression('behaviour','this.style.height = this.minHeight ? this.minHeight : "1px"');});}else{tabsContents.css({'min-height':heights[0]+'px'});}};_setAutoHeight();var cachedWidth=container.offsetWidth;var cachedHeight=container.offsetHeight;var watchFontSize=$('#tabs-watch-font-size').get(0)||$('<span id="tabs-watch-font-size">M</span>').css({display:'block',position:'absolute',visibility:'hidden'}).appendTo(document.body).get(0);var cachedFontSize=watchFontSize.offsetHeight;setInterval(function(){var currentWidth=container.offsetWidth;var currentHeight=container.offsetHeight;var currentFontSize=watchFontSize.offsetHeight;if(currentHeight>cachedHeight||currentWidth!=cachedWidth||currentFontSize!=cachedFontSize){_setAutoHeight((currentWidth>cachedWidth||currentFontSize<cachedFontSize));cachedWidth=currentWidth;cachedHeight=currentHeight;cachedFontSize=currentFontSize;}},50);}
var showAnim={},hideAnim={};var showSpeed,hideSpeed;if(settings.fxSlide||settings.fxFade){if(settings.fxSlide){showAnim['height']='show';hideAnim['height']='hide';}
if(settings.fxFade){showAnim['opacity']='show';hideAnim['opacity']='hide';}
showSpeed=hideSpeed=settings.fxSpeed;}else{if(settings.fxShow){showAnim=settings.fxShow;showSpeed=settings.fxShowSpeed||settings.fxSpeed;}else{showAnim['min-width']=0;showSpeed=settings.bookmarkable?50:1;}
if(settings.fxHide){hideAnim=settings.fxHide;hideSpeed=settings.fxHideSpeed||settings.fxSpeed;}else{hideAnim['min-width']=0;hideSpeed=settings.bookmarkable?50:1;}}
var onClick=settings.onClick,onHide=settings.onHide,onShow=settings.onShow;if(settings.bookmarkable){tabs.history();$.ajaxHistory.initialize(function(){tabs.eq(settings.initial).click();});}
tabs.bind('triggerTab',function(){var hash=this.hash;if($(hash).is(':hidden')&&!$(this.parentNode).is('.'+settings.disabledClass)){if($.browser.msie){$(this).click();if(settings.bookmarkable){$.ajaxHistory.update(hash);location.hash=hash.replace('#','');}}else if($.browser.safari){var tempForm=$('<form action="'+hash+'"><div><input type="submit" value="h" /></div></form>').get(0);tempForm.submit();$(this).click();if(settings.bookmarkable){$.ajaxHistory.update(hash);}}else{if(settings.bookmarkable){location.hash=hash.replace('#','');}else{$(this).click();}}}});tabs.bind('disableTab',function(){$(this.parentNode).addClass(settings.disabledClass);});if(settings.disabled&&settings.disabled.length){for(var i=0,k=settings.disabled.length;i<k;i++){tabs.eq(--settings.disabled[i]).trigger('disableTab').end();}};tabs.bind('enableTab',function(){var jq=$(this.parentNode);jq.removeClass(settings.disabledClass);if($.browser.safari){jq.fadeTo(1,1.0).css({display:'',opacity:1});setTimeout(function(){jq.css({opacity:''});},30);}});tabs.bind('click',function(){var jqLi=$(this.parentNode);if(jqLi.is('.'+settings.disabledClass)){return false;}
if(!jqLi.is('.'+settings.selectedClass)){var toShow=$(this.hash);if(toShow.size()>0){if(settings.bookmarkable&&$.browser.msie){var toShowId=this.hash.replace('#','');toShow.attr('id','');setTimeout(function(){toShow.attr('id',toShowId);},0);}
var clicked=this;var toHide=$('>'+settings.tabStruct+':visible',container);if(typeof onClick=='function'){setTimeout(function(){onClick(clicked,toShow[0],toHide[0]);},0);}
toHide.animate(hideAnim,hideSpeed,function(){$(clicked.parentNode).addClass(settings.selectedClass).siblings().removeClass(settings.selectedClass);if(typeof onHide=='function'){onHide(clicked,toShow[0],toHide[0]);}
toHide.addClass(settings.hideClass).css({display:'',overflow:'',height:''});toShow.removeClass(settings.hideClass).animate(showAnim,showSpeed,function(){toShow.css({overflow:'',height:''});if($.browser.msie){}
if(typeof onShow=='function'){onShow(clicked,toShow[0],toHide[0]);}});});}else{alert('There is no such container.');}}
var scrollX=window.pageXOffset||document.documentElement&&document.documentElement.scrollLeft||document.body.scrollLeft||0;var scrollY=window.pageYOffset||document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop||0;setTimeout(function(){window.scrollTo(scrollX,scrollY);},0);this.blur();return settings.bookmarkable;});});};var tabEvents=['triggerTab','disableTab','enableTab'];for(var i=0;i<tabEvents.length;i++){$.fn[tabEvents[i]]=(function(tabEvent){return function(tabIndex){return this.each(function(){var i=tabIndex&&tabIndex>0&&tabIndex-1||0;$('>ul:eq(0)>li>a',this).eq(i).trigger(tabEvent);});};})(tabEvents[i]);}})(jQuery);