$(document).ready(function() {
    // shows the slickbox on clicking the noted link
    $('a.show_hide_graph').click(function() {
        $(this).parents().children('.graphics').toggle(400)
        return false;
    });

    // Will add a link at the bottom of any element that is flash message
    $.each($('.error, .notice, .success, .warning, .alert'), function() {
        $(this).prepend('<a href="#" class="hide-link" title="close window">&nbsp;</a>');
    });

    // And this will actualy do the hiding of the parent element
    $('a.hide-link').click(function() {
        $(this).parent().hide('slow');
        return false
    });

    $("#portfolio").treeTable({
        // This options was modified by me to get an apropiate span style. In the origianl treeTable.js
        // library doesn't exists expander_margin options. WARNING if update.
        expander_margin: "0",
        clickableNodeNames: true
    });
    $("#posts_table").treeTable({
        // This options was modified by me to get an apropiate span style. In the origianl treeTable.js
        // library doesn't exists expander_margin options. WARNING if update.
        expander_margin: "0"
    });
    start_slider();

    $('#tabs').tabs();

});

function hide_bottom() {
    $(document).ready(function() {
        //This is a hack, and should be removed as soon as the l&f is fixed
        $('.accountBtm').hide();
        $('.push').hide();
    });
}


function start_slider() {
    var horizon_slider = $('#horizon_slider')
    if (horizon_slider) {
        var slider_handle = $('.ui-slider-handle', horizon_slider)
        var text_input = $('#dcf_valuation_horizon')
        text_input.hide()
        if (!text_input.val()) {
            text_input.val(3);
        }
        horizon_slider.slider({
            animate: true,
            minValue: 5,
            maxValue: horizon_slider.innerWidth,
            handle: '.handle',
            stop: function(event, ui) {
                if (ui.value < 25) {
                    $('.ui-slider-handle', horizon_slider).animate({ 'left' : slider_value_for(3) + '%' }, 500, 'linear');
                    text_input.val(3);
                } else if (ui.value >= 25 && ui.value < 75) {
                    $('.ui-slider-handle', horizon_slider).animate({ 'left' : slider_value_for(5) + '%' }, 500, 'linear');
                    text_input.val(5);
                } else if (ui.value >= 75) {
                    $('.ui-slider-handle', horizon_slider).animate({ 'left' : slider_value_for(10) + '%' }, 500, 'linear');
                    text_input.val(10);
                }
            }
        })
        $('.ui-slider-handle', horizon_slider).animate({ 'left' : slider_value_for(text_input.val()) + '%' }, 500, 'linear');


    }
}

function slider_value_for(real_value) {
    if (real_value == 3 || !real_value)
        return 10;
    else if (real_value == 5)
        return 44;
    else if (real_value == 10)
        return 87;
}