var _now_list = "hot_comment_list";
var _now_counter = 0;
var _new_comment_list_full_height = 825;
var _hot_comment_list_full_height = 655;
var _new_comment_list_rate = -(_new_comment_list_full_height / 25);
var _hot_comment_list_rate = -(_hot_comment_list_full_height / 25);
var _new_comment_list_height = _new_comment_list_full_height;
var _hot_comment_list_height = 0;
var _now_timer = null;
var _submit_fold_timer = null;

function fold_side_bar(list) {
    var l = "new_comment_list";
    if(list == 2) l = "hot_comment_list"; 
    else if(list != 1) return false;
    if(l == _now_list) return false;
    if(_now_timer != null) return false;
    _submit_fold_timer = null;
    _expanding_list = "hot_comment_list";
    _now_counter = 0;
    if(l == "new_comment_list") { 
        _new_comment_list_rate = (_new_comment_list_full_height / 25);
        _hot_comment_list_rate = -(_hot_comment_list_full_height / 25) - 1;
        $("new_comment_list").style.height="0px"; 
        _new_comment_list_height = 0;
        _hot_comment_list_height = _hot_comment_list_full_height;
        show($("new_comment_list"));
    } else { 
        _new_comment_list_rate = -(_new_comment_list_full_height / 25);
        _hot_comment_list_rate = (_hot_comment_list_full_height / 25) + 1;
        $("hot_comment_list").style.height="0px"; 
        _new_comment_list_height = _new_comment_list_full_height;
        _hot_comment_list_height = 0;
        show($("hot_comment_list")); 
    }
    _do_fold(l);

    return false;
}

function submit_fold(list) {
    if(_submit_fold_timer != null) clearTimeout(_submit_fold_timer);
        _submit_fold_timer = setTimeout("fold_side_bar("+list+")", 500);    
    return false;
}

function cancel_fold() {
    if(_submit_fold_timer != null) clearTimeout(_submit_fold_timer);
    return false;
}

function _do_fold(l) {
    /* update per 50ms, complete in 1250s */
    /* new_comment_list 825px -> 33px per 50ms */
    /* hot_comment_list 655px -> 27px per 50ms */
    var a = _new_comment_list_height + _now_counter * _new_comment_list_rate;
    var b = _hot_comment_list_height + _now_counter * _hot_comment_list_rate;
    if(a < 0) a = 0; else if(a > _new_comment_list_full_height) a = _new_comment_list_full_height;
    if(b < 0) b = 0; else if(b > _hot_comment_list_full_height) b = _hot_comment_list_full_height;

    $("new_comment_list").style.height = a + "px";    
    $("hot_comment_list").style.height = b + "px";    
    _now_counter++;
    if(_now_counter < 35)
        _now_timer = setTimeout( "_do_fold('"+l+"')", 20);
    else {
        hide($(_now_list));
        _now_list = l;
        _now_timer = null;
    }
    return false;
}
