// tabs - jQuery plugin for accessible, unobtrusive tabs by Klaus Hartl
// http://stilbuero.de/tabs/
// Free beer and free speech. Enjoy!

$.tabs = function(containerId, start) {
    var ON_CLASS = 'on';
    var id = '.' + containerId;
    var i = (typeof start == "number") ? start - 1 : 0;
    $(id + '>div:lt(' + i + ')').add(id + '>div:gt(' + i + ')').hide();

	$(id + '>ul>li:nth-child(' + i + ')').addClass(ON_CLASS);
		
	$('#container .anchors a').bind('click',function(e){
		e.preventDefault();
	});
		
    $(id + '>ul>li>a').click(function(e) {
        if (!$(this.parentNode).is('.' + ON_CLASS) && Boolean($(this).length)) {
            var re = /([_\-\w]+$)/i;
			
			if(re.exec(this.href) != null){
				var target = $('#' + re.exec(this.href)[1]);
			} else {return false;}
			
            if (target.size() > 0) {
				// hide all blurbs first
				$("._blurbs > div").hide();
				
				// if we are clicking on a tab, switch to the next tab and panel
				if (target.hasClass("_tabpanel")) {
					$("._tabpanel").hide();	//hide all panels
					$(id + '>ul>li').removeClass(ON_CLASS);
                	$(this.parentNode).addClass(ON_CLASS);
				}
				
				// show the target
                target.show();
            } else {
                alert('There is no such container.');
            }
        }
        e.preventDefault();
    });
};
