/* for histogram bar animation */
var _goal_height = new Array(12);

function init_bar(c) {
    var c_max = 0;
    for(var i=0;i<12;i++) if(parseInt(c[i]) > c_max) c_max = parseInt(c[i]);
    c_max *= 1.1;
    for(var i=0;i<12;i++) _goal_height[i] = (c_max == 0) ? 0 : Math.floor(161 * (parseInt(c[i]) / c_max));
    _update_bar();
    return false;
}

function _update_bar() {
    var ok = 0;
    for(var i=0;i<12;i++) {
        var o = $("bar"+i);
        var gh = _goal_height[i];
        o.style.height = gh + "px";
        o.style.top = (181 - gh) + "px";
    }
    return;
}

/* for histogram box transition */
var _chain_histo = new Array();
var _now_histo = 0;
var _next_histo = -1;
var _switch_timer = null;

function init_switch_histogram() {
    for(var i=1;i<=12;i++) 
        if($("histogram_"+i) != null) 
            _chain_histo.push(i);
    // show first star
    if( _chain_histo.length > 0 ) {
        show( $("histogram_"+ _chain_histo[0]) );
        $s($("more_athlete"), "href", "star.php?s="+_chain_histo[0]);
        change_histogram(0);
    }
    return;
}

function _switch_histogram() {
/*
    var opacityTween1 = new OpacityTween($("histogram_"+ _chain_histo[ _now_histo ]),Tween.bounceEaseOut, 100, 0, 2);
    var a = new Object();
    a.onMotionFinished = function(){
        var o = $("histogram_"+ _chain_histo[ _now_histo ]);
        hide( o );
        if(_next_histo >= 0)
            _now_histo = _next_histo;
        else
            _now_histo = (_now_histo + 1) % _chain_histo.length;
        _next_histo = -1; 
        o = $("histogram_"+ _chain_histo[ _now_histo ]);
        $o( o, 0);
        show( o );
        $s($("more_athlete"), "href", "star.php?s="+_chain_histo[ _now_histo ]);
        var opacityTween2 = new OpacityTween(o,Tween.bounceEaseOut, 0, 100, 2);
        var b = new Object();
        b.onMotionFinished = function() {
            setTimeout("_switch_histogram()", 1000);
        }
        opacityTween2.addListener(b);
        opacityTween2.start();
    };
    opacityTween1.addListener(a);
    opacityTween1.start();
*/
    change_histogram( (_now_histo + 1) % _chain_histo.length );

    return;
}

function change_histogram(s) {
    if(_switch_timer != null) clearTimeout(_switch_timer);
    hide( $("histogram_"+ _chain_histo[ _now_histo ]) );
    show( $("histogram_"+ _chain_histo[ s ]) );
    $s($("more_athlete"), "href", "star.php?s="+_chain_histo[ s ]);
    _now_histo = s;
    _next_histo = -1; 
    _switch_timer = setTimeout("_switch_histogram()", 5000);
    return false;
}

function show_rule() {
    if($("lightbox_rule").innerHTML.length > 0) 
        showLightbox("lightbox_rule", 500, 300);
    else {
        showLightboxLoading();
        ajax_load("rule.php", "get", "", 
            function(res) {
                $("lightbox_rule").innerHTML = res;
                showLightbox("lightbox_rule", 500, 300);
            });
    }
    return false;
}
