var pf_DocumentRoot = 'https://www.pregofinance.pl/partner/bankier/';

$(document).ready(function(){

    function renderRank(){
        
         $("#chart_area").fadeOut("slow");

         $.getJSON(pf_DocumentRoot + "ajax_handler.php?jsonp=1&action=rank_help&type=" + escape($("#rank_option").val()) + "&callback=?",
            function(data) {
                $("#rank_help").html(data.html);
            });

         $.getJSON(pf_DocumentRoot + "ajax_handler.php?jsonp=1&action=rank_date&callback=?",
            function(data) {
                $("#rank_date").html(data.html);
            });

         $("#chart_info").html("Tworzenie wykresu. Proszę czekać...");

         $.getJSON(pf_DocumentRoot + "ajax_handler.php?jsonp=1&action=rank_chart&type=" + escape($("#rank_option").val()) + "&c=" + Math.random() + "&callback=?",
            function(data) {

                if (data.html == "ERROR")
                    $("#chart_info").html("Wystąpił błąd podczas tworzenia wykresu. Spróbuj ponownie za chwilę.");
                else {
                    $("#chart_area").html(data.html);
                    $("#chart_info").html("&nbsp;");
                    $("#chart_area").fadeIn("slow");

                    $("#chart TR").mouseover(function (){
                        $(this).addClass("pf_highlite");
                    });

                    $("#chart TR").mouseout(function (){
                        $(this).removeClass("pf_highlite");
                    });

                }

            });

         return;
    }

    $("#rank_option").change(function(){
        renderRank();
    })


    renderRank();

});
