/*
 * Tabs 1 - New Wave Tabs
 *
 * Copyright (c) 2007 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 */

// tabs - jQuery plugin for accessible, unobtrusive tabs by Klaus Hartl
// http://stilbuero.de/tabs/
// Free beer and free speech. Enjoy!

$.tabs = function(containerId, start, ON_CLASS) {
//    var ON_CLASS = 'on';
    var id = '#' + containerId;
//    var i = (typeof start == "number") ? start - 1 : 0;
	var i = start;
    $(id + '>div:lt(' + i + ')').add(id + '>div:gt(' + i + ')').hide();
    
 /* This is a brute-force method to get the desired behaviors. */   
    $("#Region2").hide(); $("#Region1").show();
    
//    $(id + '>ul>li:nth-child(' + i + ')').addClass(ON_CLASS);
    var selected = $(id + '>ul>li:nth-child(' + i + ')');
    selected.addClass(ON_CLASS);
    $(id + '>ul>li>a').click(function() {
        if (!$(this.parentNode).is('.' + ON_CLASS)) {
            var re = /([_\-\w]+$)/i;
            var target = $('#' + re.exec(this.href)[1]);
            if (target.size() > 0) {
                $(id + '>div:visible').hide();
                target.show();
                $(id + '>ul>li').removeClass(ON_CLASS);
                $(this.parentNode).addClass(ON_CLASS);
            } else {
                alert('There is no such container.');
            }
        }
        return false;
    });
};