/*
 * jQuery UI AriaTabs (12.07.10)
 * http://github.com/fnagel/jQuery-Accessible-RIA
 *
 * Copyright (c) 2009 Felix Nagel for Namics (Deustchland) GmbH
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 *
 * Depends: ui.core.js 1.8
 *   		ui.tabs.js
 */
(function($){$.fn.extend($.ui.tabs.prototype,{_create:function(){var self=this,options=this.options;if($.address){var jqAddressDefOpt={enable:true,title:{enable:true,split:" | "}};if(!$.isEmptyObject(options.jqAddress)){$.extend(true,jqAddressDefOpt,options.jqAddress)}else{options.jqAddress={}}$.extend(true,options.jqAddress,jqAddressDefOpt)}if($.address&&options.jqAddress.enable){var anchorId="#"+$.address.value().replace("/","")}self._tabify(true);this.anchors.bind(options.event+".tabs-accessibility",function(){this.focus()});self.list.attr("role","tablist");for(var x=0;x<self.anchors.length;x++){if($.address&&options.jqAddress.enable&&anchorId!="#"&&$(self.anchors[x]).attr("href")==anchorId){self.select(x)}self._ariaInit(x)}self.list.keydown(function(event){switch(event.keyCode){case $.ui.keyCode.RIGHT:self.select(options.selected+1);return false;break;case $.ui.keyCode.DOWN:self.select(options.selected+1);break;case $.ui.keyCode.UP:self.select(options.selected-1);return false;break;case $.ui.keyCode.LEFT:self.select(options.selected-1);return false;break;case $.ui.keyCode.END:self.select(self.anchors.length-1);return false;break;case $.ui.keyCode.HOME:self.select(0);return false;break}});if($.address&&this.options.jqAddress.enable){$.address.externalChange(function(event){var anchorId="#"+event.value.replace("/","");var x=0;while(x<self.anchors.length){if($(self.anchors[x]).attr("href")==anchorId){self.select(x);return }x++}})}},_original_load:$.ui.tabs.prototype.load,load:function(index){if($.address&&this.options.jqAddress.enable){if($(this.anchors[0]).attr("aria-selected")!==undefined){if(this.options.forceFirst===0&&index!==0){if($.address.value()==""){$.address.history(false)}$.address.value($(this.anchors[0]).attr("href").replace(/^#/,""));$.address.history(true);this.options.forceFirst=false}if(this.options.jqAddress.title.enable){$.address.title($.address.title().split(this.options.jqAddress.title.split)[0]+this.options.jqAddress.title.split+$(this.anchors[index]).text())}$.address.value($(this.anchors[index]).attr("href").replace(/^#/,""))}else{this.options.forceFirst=index}}for(var x=0;x<this.anchors.length;x++){this._ariaSet(x,false);if($.data(this.anchors[x],"href.tabs")){$(this.panels[x]).removeAttr("aria-live").removeAttr("aria-busy")}}if($.data(this.anchors[index],"href.tabs")){$(this.panels[index]).attr("aria-live","polite").attr("aria-busy","true")}this._original_load(index);if($.data(this.anchors[index],"href.tabs")){$(this.panels[index]).attr("aria-busy","false")}this._ariaSet(index,true)},_ariaSet:function(index,state){var tabindex=(state)?0:-1;var anchor=$(this.anchors[index]);anchor.attr("tabindex",tabindex).attr("aria-selected",state);if(state){if(!$.browser.msie){anchor.focus()}}else{anchor.closest("li").removeClass("ui-state-focus")}$(this.panels[index]).attr("aria-hidden",!state).attr("aria-expanded",state);if($.browser.msie){this.options.timeout=window.setTimeout(function(){anchor.focus()},100)}if(state){this._updateVirtualBuffer()}},_ariaInit:function(index){var self=this;var panelId=$(this.panels[index]).attr("id");$(this.anchors[index]).attr("role","tab").attr("aria-controls",panelId).attr("id",panelId+"-tab").parent().attr("role","presentation");$(this.panels[index]).attr("role","tabpanel").attr("tabindex",0).attr("aria-labelledby",panelId+"-tab");if(this.options.collapsible){$(this.anchors[index]).bind(this.options.event,function(event){self._ariaSet(index,!$(self.panels[index]).hasClass("ui-tabs-hide"))})}},_original_add:$.ui.tabs.prototype.add,add:function(url,label,index){this._original_add(url,label,index);this.element.attr("aria-live","polite").attr("aria-relevant","additions");if(index){this._ariaInit(index);this._ariaSet(index,false)}else{this._ariaInit(this.anchors.length-1);this._ariaSet(this.anchors.length-1,false)}},_original_remove:$.ui.tabs.prototype.remove,remove:function(index){this._original_remove(index);this.element.attr("aria-live","polite").attr("aria-relevant","removals")},_original_destroy:$.ui.tabs.prototype.destroy,destroy:function(){var self=this,options=this.options;self.element.removeAttr("role").removeAttr("aria-live").removeAttr("aria-relevant");self.list.removeAttr("role");for(var x=0;x<self.anchors.length;x++){$(self.anchors[x]).removeAttr("aria-selected").removeAttr("aria-controls").removeAttr("role").removeAttr("id").removeAttr("tabindex").parent().removeAttr("role");$(self.panels[x]).removeAttr("aria-hidden").removeAttr("aria-expanded").removeAttr("aria-labelledby").removeAttr("aria-live").removeAttr("aria-busy").removeAttr("aria-relevant").removeAttr("role")}$("body>form #virtualBufferForm").parent().remove();this._original_destroy()},_updateVirtualBuffer:function(){var form=$("body>form #virtualBufferForm");if(form.length){if(form.val()=="1"){form.val("0")}else{form.val("1")}if(form.hasClass("ui-accessibility-odd")){form.addClass("ui-accessibility-even").removeClass("ui-accessibility-odd")}else{form.addClass("ui-accessibility-odd").removeClass("ui-accessibility-even")}}else{$("body").append('<form><input id="virtualBufferForm" type="hidden" value="1" /></form>')}}})})(jQuery);