/* Copyright (c) 2006 Patrick Fitzgerald */
var tabContentCache = new Object();
function makeTabs(containerId, start) {
    var ON_CLASS = 'tabberactive';
    var AFTER_ON_CLASS = 'afterActive';
    var SPEED = 400;
    var id = '#' + containerId;
    var i = (typeof start == "number") ? start - 1 : 0;
    $(id + '>div:lt(' + i + ')').add(id + '>div:gt(' + i + ')').hide();
    $(id + '>ul>li:eq(' + i + ')').addClass(ON_CLASS);
    $(id + '>ul>li:eq(' + (i+1) + ')').addClass("afterActive");
	$(id + '>ul>li>span>span>a').focus(function() {this.blur();});
    $(id + '>ul>li>span>span>a').click(function() {
        if (!$(this.parentNode).is('.' + ON_CLASS)) {
            var re = /([_\-\w]+$)/i;
            var href = re.exec(this.href)[1];
            var target = $('#' + href);
            var link = this;
            function updateTabs(){
                $(id + ' li.'+ON_CLASS).removeClass(ON_CLASS);
                $(id + ' li.'+AFTER_ON_CLASS).removeClass(AFTER_ON_CLASS);
                var tab = $(link.parentNode.parentNode.parentNode);
                tab.addClass(ON_CLASS);
                tab.next().addClass(AFTER_ON_CLASS);
            }
            if (target.size() > 0) {
                $(id + '>div:visible').hide();
                target.show();
	            updateTabs();
            } else {
            	updateTabs();
            	if( tabContentCache[href] == undefined){
					try {
						refresh_vidlist(this.href,function(responseText){tabContentCache[href] = responseText});
					} catch(err) {
						alert('that container was empty');
					}
				}else{
					$('#onn_vid_list').html(tabContentCache[href]);
				}
            }
        }
        return false;
    });
};