function assignEvents() {
    var tags = $("span.fund_fi, span.fund_fzgn, span.fund_fe, span.fund_ufk, span");

    for (i = 0; i < tags.length; i++) {
        $(tags[i]).each(function() {
            if($(this).hasClass('tooltip')) return;
            if ($(this).attr("KOD") != null || $(this).attr("fund_code") != null) {
                var ajaxPath;
                var id_param = '';
                if($(this).attr('_id'))
                    id_param = '?id=' + $(this).attr('_id');
                if ($(this).attr("KOD") != null){
                    //alert('kod')
                    ajaxPath = BASE + '/fund/tooltip/code/' +
                        $(this).attr('KOD') + '/prefix/' +
                        $(this).attr("class").toLowerCase().replace(/fund_/, '') + id_param +
                        ' div.tooltip-wrap';
                } else {
                    //alert('fund_code')
                    var str = $(this).attr("fund_code");
                    var code = str.replace(/^\w+_/, '');
                    var wzor = str.match(/(\w+)_.*/);
                    var prefix = RegExp.$1;
                    ajaxPath = BASE + '/fund/tooltip/code/' +
                        code + '/prefix/' + prefix + id_param + ' div.tooltip-wrap';
                }

                $(this).bt({
                    trigger: ['hoverIntent', 'click'],
                    fill: '#ffffff',
                    strokeStyle: '#ffffff',
                    textBackground: '#ffffff',
                    spikeLength: 10, 
                    spikeGirth: 10, 
                    padding: 8,
                    cornerRadius: 0,
                    width: 290,
                    positions: ['bottom', 'right'],
                    hoverIntentOpts: {
                        interval: 500,
                        timeout: 200
                    },
                    closeWhenOthersOpen: true,
                    ajaxPath: ajaxPath,
                    ajaxCache: false,
                    ajaxLoading:"<blink>Ładuję wykres...</blink>"
                }).addClass("tooltip").hoverIntent({
                    over: function() {
                        this.btOn();
                    },
                    out: function() {
                        this.btOff()
                    },
                    interval: 0,
                    timeout: 300
                });
            }
        });
    }
}

function hideSubsubMenu(id){
    $('#submenu' + id).css({display: 'none'});
}

var subsubmenu = true;

var is_over = new Object();

this.hideSubmenu = function(c) {
    if(!is_over[c] && !c.match(/no_hide/)){
        $(c).hide();
        if(!c.match(/submenu/)){
            $(".choose").each(function(){
                $(this).removeClass('active')
            })
        }
    }
}

this.submenu = function(){
    $(".submenu").each(function(){
        $(this).mouseenter(function(){
            var content = $("#sub"+$(this).attr('id'));
            var pos = findPos($(this));
            content.css({
                position: 'absolute',
                left: pos.left,
                top: (pos.top + $(this).height() + 8),
                display: 'block',
                'z-index': 9999,
                width: ($.browser.msie && $.browser.version < 7) ? $(this).width() : $(this).width()-20
            });
            if($(this).attr('id').match(/1/) || $(this).attr('id').match(/2/))
                $('#company_1').hide();
            if($(this).attr('id').match(/3/) || $(this).attr('id').match(/4/))
                $('#products_1').hide();
        });
        $(this).mouseleave(function(){
            $('#company_1').show();
            $('#products_1').show();
            setTimeout("hideSubmenu('#sub"+$(this).attr('id')+"');", 100);
        })
    })

    $(".menu_sub").each(function(){
        $(this).mouseenter(function(){
            var c = "#" + $(this).attr('id')
            is_over[c] = true;
            if(!$(this).attr('id').match(/no_hide/)){
                if($(this).attr('id').match(/1/) || $(this).attr('id').match(/2/))
                    $('#company_1').hide();
                if($(this).attr('id').match(/3/) || $(this).attr('id').match(/4/))
                    $('#products_1').hide();
            }
//            alert('.menu_sub over')
        })
        $(this).mouseleave(function(){
            var c = "#" + $(this).attr('id')
            is_over[c] = false;
            hideSubmenu(c);
            $('#company_1').show();
            $('#products_1').show();
//            alert('.menu_sub out')
        })
    })
}

this.topHover = function(){
    $("#searchTop").each(function(){
        $(this).mouseenter(function(){
            var content = $("#"+$(this).attr('id')+'Box');
            var pos = findPos($(this));
            content.css({
                position: 'absolute',
                left: pos.left - 44,
                top: (pos.top + $(this).height()) + 9,
                display: 'block',
                'z-index': 9999,
                width: $(this).attr('id') == 'loginTop' ? 180 : 144,
                height: 'auto'
            });
        });
        $(this).mouseleave(function(){
          //  alert('#'+$(this).attr('id')+'Box');
            setTimeout("hideSubmenu('#"+$(this).attr('id')+"Box');", 100);
        })
    })
    
}


var over = false;
$(document).ready(function() {
    $("#art_full").articlePager();
    assignEvents();
  //  submenu();
    topHover();
});

var htmlTableLimit = {};
var htmlTableOffset = {};
var htmlTableSortIdx = {};
var htmlTableSortDir = {};
var htmlTableDataCount = {};
var htmlTableOtherParams = {};
var ladowanie_na_gorze = false;

function sortHTMLTable(div_id, col_idx)
{
    if(col_idx ==  htmlTableSortIdx[div_id] && htmlTableSortDir[div_id] == 'ASC')
    {
        htmlTableSortDir[div_id] = 'DESC';
    }
    else
    {
        htmlTableSortIdx[div_id] = col_idx;
        htmlTableSortDir[div_id] = 'ASC';
    }
//    ladowanie_na_gorze = true;
//    reloadHTMLTable(div_id);
//    ladowanie_na_gorze = false;
    window.location = url.replace(/sort\/.*?\//,'sort/'+htmlTableSortIdx[div_id] + '/').replace(/sort_dir\/.*?\//, 'sort_dir/' + htmlTableSortDir[div_id] + '/');
}

function reloadHTMLTable(div_id)
{
    var preloader_width = 150;
    var preloader_top = 20;

    if(!ladowanie_na_gorze)
            preloader_top = $('#' + div_id).height() - 80;

    var preloader_left = ($('#' + div_id).width() - preloader_width) / 2 ;

    var params = {};
    params['limit'] =  htmlTableLimit[div_id];
    params['offset'] =  htmlTableOffset[div_id];
    params['sort'] =  htmlTableSortIdx[div_id];
    params['sort_dir'] =  htmlTableSortDir[div_id];

    if(htmlTableOtherParams[div_id])
    {
        for (var property in htmlTableOtherParams[div_id])
        params[property] = htmlTableOtherParams[div_id][property];
    }


    $('#' + div_id).append("<div style='background-color: white; border: 1px solid gray; position: absolute; z-index: 1000; width: " + preloader_width + "px; left: " +preloader_left+ "px; top: " + preloader_top +  "px; text-align: center;padding: 10px 10px 10px 10px'>wczytywanie danych....<br><img src='/images/preloader.gif'></div>");

    $.get("/fundusze/ajax/"+ htmlTableOtherParams[div_id]['action'], params,
                    function(data){
                        setTimeout(function(){$('#' + div_id).html(data);}, 100);
                    },
                    'html'
         );
}


