$.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);
            });
        }
    });
};

$.fn.getDangerInfo = function(id,pos) {
    return this.each(function() {
        if ($("#dangerinfo_"+id).size() > 0)
        {
            if (over_id == id)
            {
                $(this).html($("#dangerinfo_"+id).html());
                jBubiPos(pos);
            }
        }
        else
        {
            var that = this;
            url = _url+"jelenido.php?action=getdangerinfo&dangerid="+id;
            $.get(url,function(data) {
                $("<div />").attr("id","dangerinfo_"+id).html(data).appendTo("#info_bay");
                $(that).getDangerInfo(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 jBubiShow2(id,pos)
{
    $("#jelenido_bubi").show();
    $("#jb_body_div").html("<div class='loading_gif'>&nbsp;</div>");
    jBubiPos(pos);
    $("#jb_body_div").getDangerInfo(id,pos);
}

function nezetCheck()
{
    $("[id^=nezet_]").each(function() {
        var type = $(this).attr("id").split("_")[1];

        if ($(".kloader [id^=mini_"+type+"]").size() > 0)
        {
            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();
            }
        }
        else if ($("#danger_big").size() > 0)
        {
            if (type != "danger" && $(this).is(":checked"))
            {
                window.location = _url+"jelenido.php?nezet="+type;
            }
        }
        else
        {
            if ($(this).is(":checked"))
            {
                window.location = _url+"jelenido.php?nezet="+type;
            }
        }
    });
    $("#start_flash").animate({"opacity":0},500,function() { $(this).remove() });
}

var jbubi_off_to = null;
var over_id = 0;
$(function() {

    $("[class^=click_nezet]").click(function() {
        type = $(this).attr("class").split("_")[2];

        nezetek = new Array();
        nezetek['img'] = "idokepek";
        nezetek['wind'] = "szel";
        nezetek['temp'] = "homerseklet";
        nezetek['danger'] = "veszely";
        _gaq.push(['_trackEvent', 'jelenido_nezetek', 'valtas', nezetek[type]]);

        if (!$("#nezet_"+type).is(":checked")) $("#nezet_"+type).attr('checked', true);
        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).findpos();
        jBubiShow(id,pos);
    }).mouseout(function() {
        jBubiHide(1000);
    });

    $("[id^=dpop_]").mouseover(function() {
        window.clearTimeout(jbubi_off_to);
        d = $(this).attr("id").split("_");
        id = d[2]+"_"+d[3];
        over_id = id;
        pos = $(this).findpos();
        jBubiShow2(id,pos);
    }).mouseout(function() {
        jBubiHide(1000);
    });

});

