// tabs - jQuery plugin for accessible, unobtrusive tabs by Klaus Hartl
// http://stilbuero.de/tabs/
// Free beer and free speech. Enjoy!
jQuery(function($){
    $.extend({
        tabs : function(containerId, start, onclass) {
            var ON_CLASS = (typeof onclass == "string") ? onclass : 'current';
            var id = '#' + containerId; 
            if (!($(id).get())) {return;} //if we don't find an element
            var i = (typeof start == "number") ? start - 1 : 0;
            var child = i + 1;
            $(id + '>ul>li:nth-child(' + child + ')>a').addClass(ON_CLASS);
            
            var tabsobjs = $($.map($(id + '>ul>li>a').get(), function(i){return i.hash}).join(','));
            
            var div_tmp = $(id + '>ul>li:nth-child(' + child + ')>a').get(0); 
            var div_id = div_tmp ? div_tmp.hash : null; //show div with #id in href
            
            if(div_id) {
                tabsobjs.hide();
                $(div_id).show(); 
            } else {
                //$(id + '>div:lt(' + i + ')').add(id + '>div:gt(' + i + ')').hide();            
            }

            $(id + '>ul>li>a').click(function() {
                if ($(this).attr('href').charAt(0) != '#') {return true;} //go to real link
                if (!$(this).is('.' + ON_CLASS)) {
                    var target = $(this.hash);//#portion of the url
                    if (target.size() > 0) {
                        tabsobjs.hide();
                        target.show();
                        $(id + '>ul>li>a').removeClass(ON_CLASS);
                        $(this).addClass(ON_CLASS);
                    } else {
                        alert('There is no such container.');
                    }
                }
                return false;
            });
        }
    });
    $.tabs('idTabs1', null, 'selected');
});