jQuery(document).ready(function() {
    var check = 0;

    jQuery("#ib_faq").corner("3px");
    jQuery(".news_main").corner("3px");
    jQuery("#ib_be").corner("3px");
    jQuery("#ib_online").corner("3px");
    jQuery("#ib_stats").corner("3px");
    jQuery("#ib_best").corner("3px");
    jQuery("#ib_bank").corner("3px");
    jQuery("#ib_quotes").corner("3px");
    jQuery(".bot_tab_act").corner("3px top");
    jQuery("table#bot_tab_table td div.sel").corner("3px bottom");
    jQuery("#ib_deal_top_5").corner("3px bottom");
    jQuery("#ib_compare_top_manager").corner("3px bottom");

    set_time();

    if (jQuery("div#news").length) {
        get_data_news();
    }

});

var news_id = 0;
var block_id = 0;
var res;

function get_data_news() {
    jQuery.post('/ru/ajax_loader/stat_main_page/', {}, function(data) {
        res = eval("(" + data + ")");
        select_block_news(0);
    });
}

function select_block_news(bid) {
    if (news_id == get_count_news(bid)) {
        block_id += 1;
        jQuery('#news span ul li').remove();
        if (res.block_count_lines.length == block_id) {
            block_id = 0;
            news_id = 0;
        }
    }
    update_block_news(news_id);
    news_id += 1;
}

function update_block_news(nid) {
    jQuery('<li><div style="display:none;">' + res.lines[nid] + '</div></li>').appendTo('#news span ul');
    jQuery('#news span ul li:last div').fadeIn("slow");
    setTimeout("select_block_news(block_id)", 3000);
}

function get_count_news(bid) {
    c = 0;
    for (i = 0; i <= bid; i++) {
        c += parseInt(res.block_count_lines[i], 10);
    }
    return c;
}

var hours;
var mins;
var seconds;

function set_time() {

    jQuery.post('/ru/ajax_loader/world_time/', {}, function(data) {
        ndata = eval('(' + data + ')');
        hours = parseInt(ndata["hour"], 10);
        mins = parseInt(ndata["min"], 10);
        seconds = parseInt(ndata["sec"], 10);
        setTimeDisplay();
        setTimeAfter();
    });
}

function setTimeAfter() {
    timeGoing();
    setTimeDisplay();
    setTimeout("setTimeAfter()", 1000);
}

function timeGoing() {

    if ( seconds < 59 ) {
        seconds++;
    } else {
        seconds = 0;
        if ( mins < 59 ) {
            mins++;
        } else {
            mins = 0;
            if (hours < 23) {
                hours++;
            } else {
                hours = 0;
            }
        }
    }

}

function setTimeDisplay() {

    jQuery("div#world_time div#moskow div").html(add_null(hours) + ":" + add_null(mins));
    l_hours = hours - 3;
    if (hours < 3) { l_hours = 24 + l_hours }
    jQuery("div#world_time div#london div").html(add_null(l_hours) + ":" + add_null(mins));
    ny_hours = hours - 8;
    if (hours < 8) { ny_hours = 24 + ny_hours }
    jQuery("div#world_time div#new_york div").html(add_null(ny_hours) + ":" + add_null(mins));
    p_hours = hours - 2;
    if (hours < 2) { p_hours = 24 + p_hours }
    jQuery("div#world_time div#paris div").html(add_null(p_hours) + ":" + add_null(mins));
    t_hours = hours + 8;
    if (hours > 16) { t_hours = t_hours - 24 }
    jQuery("div#world_time div#tokyo div").html(add_null(t_hours) + ":" + add_null(mins));

}

function add_null(number) {
    if (number < 10) number = '0' + number;
    return number;
}

function gotoUrl(url){	document.location.href = url;}
