/*
 * Landsbanki Tabs
 * jQuery plugin for accessible, unobtrusive tabs
 */
 
$.fn.tabs = function(options) {
    var ON_CLASS = 'sel';
    var OFF_CLASS = 'tabs-hide';
	options = options || {};
	options.activeTab = options.on || 0;
	var re = /([_\-\w]+$)/i;
	return this.each(function() {
		$(this).find('>div').not(':eq(' + options.activeTab + ')').addClass(OFF_CLASS);
		$(this).find('>ul>li:eq(' + options.activeTab + ')').addClass(ON_CLASS);
		var container = this;
        $(this).find('>ul>li>a').click(function(e) {
	       	var tabToShowHash = '#' + re.exec(this.href)[1];
        	if (!$(this.parentNode).is('.' + ON_CLASS)) {
        		var tabToShow = $(tabToShowHash);
        		if (tabToShow.size() > 0) {
        			$(container).find('>div:visible').addClass(OFF_CLASS);
					$(container).find('>ul>li').removeClass(ON_CLASS);
					$(this.parentNode).addClass(ON_CLASS);
				}
				tabToShow.removeClass(OFF_CLASS);
        	}
        	return false;
        });
	});
}
