//$Id: tab.js 4263 2008-01-16 08:26:36Z chenbl $
var tabdata = new Array();
var _timeout = 100;
var _tm = new Array();

function doTab(tab,loc) {
    var obj = $(tab+'_'+loc);
    window.clearTimeout(_tm[tab]);
    _tm[tab] = window.setTimeout(function(){_doTab(tab,loc)}, _timeout);
    obj.onmouseout = function(){window.clearTimeout(_tm[tab])};
}

function _doTab(tab,loc) {
    var obj = $(tab+'_'+loc);
    if (Element.hasClassName(obj, tab+'_active')) return;

    setCookie(tab+'_loc', loc, new Date(new Date().getTime() + (3600 * 24 * 30)) ); //记住一个月
    tabdata[loc] ? $(tab+'_c').innerHTML = tabdata[loc] : new Ajax.Request('/tab/'+loc+'.shtml', {method: 'get', onSuccess:function(ret){doTab_result(tab+'_c',loc,ret.responseText)}});

    var nodes = $A(document.getElementsByClassName(tab+'_active'));
    nodes.each(function(node){
        Element.removeClassName(node, tab+'_active');
        Element.addClassName(node, tab+'_unactive');
    });
    var obj = $(tab+'_'+loc);
    if (obj) {
        Element.removeClassName(obj, tab+'_unactive');
        Element.addClassName(obj, tab+'_active');
    }
}

function doTab_result(tab,loc,html) {
    tabdata[loc] = $(tab).innerHTML = html;
}
