$('#bouncing-arrow').attr('_loaded', false);
$('#bouncing-arrow').load(function() {
    $(this).attr('_loaded', true);
});

function animate(steps)
{
    if (steps.length == 0)
        return;

    target = steps.shift();
    $('#bouncing-arrow').animate({marginLeft: target}, 300, null, function() { animate(steps) }); 
}

function
update_arrow(id)
{
    if (!window.location.hash && id == null)
        return;
    var arrow = get_id('bouncing-arrow');
    if (id != null)
        var anchor = id;
    else
        var anchor = window.location.hash.substring(1);
    var e = get_id(anchor);
    if (e) {
        e.insertBefore(arrow, e.firstChild);
        arrow.style.display = "";
        var steps = [-80, -42, -80, -42, -80, -42];
        if ($(arrow).attr('_loaded') == false)
            $(arrow).load(function() { animate(steps) });
        else
            animate(steps);
    }
}

$(document).ready(function() {
    update_arrow(null);
});
