$.fn.getCellaInfo2 = function(id,pos) {
    return this.each(function() {
        
        if ($("#cellainfo_"+id).size() > 0)
        {
            if (over_id == id)
            {
                $(this).html($("#cellainfo_"+id).html());
                jBubiPos(pos);
            }
        }
        else
        {
            var that = this;
            url = _url+"jelenido.php?action=getcellainfo&cellaid="+id+"&type=lista";
            $.get(url,function(data) {
                $("<div />").attr("id","cellainfo_"+id).html(data).appendTo("#info_bay");
                $(that).getCellaInfo2(id,pos);
            });
        }
    });
};

function jBubiHide(delay)
{
    jbubi_off_to = window.setTimeout(function() {
        $("#jelenido_bubi").hide();
    },delay);
}

function jBubiPos(pos)
{
    h = $("#jelenido_bubi").height();
    ntop = pos.top-h+15;
    nleft = pos.left+18;
    $("#jelenido_bubi").css({
        top: ntop,
        left: nleft
    });
}

function jBubiShow(id,pos)
{
    $("#jelenido_bubi").show();
    $("#jb_body_div").html("<div class='loading_gif'>&nbsp;</div>");
    jBubiPos(pos);
    $("#jb_body_div").getCellaInfo2(id,pos);
}

function nezetCheck()
{
    $("[id^=nezet_]").each(function() {
        var type = $(this).attr("id").split("_")[1];
        if ($(this).is(":checked"))
        {
            $("#nezetloader_"+type).html("<div class='loading_gif'>&nbsp;</div>");
            url = _url+"jelenido.php?action=setsession&show="+type;
            $.get(url,function(data) { /* alert(data); */ 
                $("#nezetloader_"+type).html("&nbsp;");
            });
            $(".kloader [id^=mini_"+type+"]").parent().show();
        }
        else
        {
            $(".kloader [id^=mini_"+type+"]").parent().hide();
        }
    });
    $("#start_flash").animate({"opacity":0},500,function() { $(this).remove() });
//    $("#start_flash").hide();
}

function showAktualis(type,id)
{
    $("#akt_report").html("<div class='loader_gif' style='height: 43px;'>&nbsp;</div>");
    url = _url+"jelenido.php?action=aktualis_info&"+type+"="+id;
    $.get(url,function(data) { 
        $("#akt_report").html(data);
        $("[class$=_imagepop]").tooltip({
            delay: 0,
            track: true,
            showURL: false, 
            bodyHandler: function() { 
                return $(this).parent().children("div").html();         
            }
        });
    });
}

var jbubi_off_to = null;
var over_id = 0;
$(function() {

    $("[class^=click_nezet]").click(function() {
        type = $(this).attr("class").split("_")[2];
        $("#nezet_"+type).attr('checked', true);

        nezetek = new Array();
        nezetek['img'] = "idokepek";
        nezetek['wind'] = "szel";
        nezetek['temp'] = "homerseklet";
        _gaq.push(['_trackEvent', 'jelenido_nezetek', 'valtas', nezetek[type]]);

        nezetCheck();
    });
    nezetCheck();

    $("#jb_body").add("#jb_bl").mouseover(function() {
        window.clearTimeout(jbubi_off_to);
    }).mouseout(function() {
        jBubiHide(1000);
    });

    $("[id^=mini_]").mouseover(function() {
        window.clearTimeout(jbubi_off_to);
        id = $(this).attr("id").split("_")[2];
        over_id = id;
        // pos = $(this).position();
        pos = $(this).findpos();
        jBubiShow(id,pos);
    }).mouseout(function() {
        jBubiHide(1000);
    });

    $("[class$=_imagepop]").tooltip({
        delay: 0,
        track: true,
        showURL: false,
        bodyHandler: function() {
            return $(this).parent().children("div").html();
        }
    });

});

