$(document).ready(function (){
    var ocupado = 0;
    //Cuando se pasa por encima del icono
    $('.ev a,.ev_hoy a').hover(
        function (){
            var pos_item = $('#agenda').position();
            /*alert("POS TOP: " + pos_item.top);
            alert("POS LEFT: " + pos_item.left);*/

            var parametros = new Array();
            link = $(this).attr('href');
            parametros = link.split('?', link.length);

            $.ajax({
                type: "POST",
                url:  "agenda_evento.php",
                data: parametros[1],
                beforeSend: function(objeto){
                    $('#divLoad').html("<img src='images/interfaz/load.gif' alt='Cargando...'/>");
                },
                success: function(datos){
                    $('#divLoad').html("");
                    $(".tooltip").html("");
                    $(".tooltip").html(datos);
                }
            });

            if (ocupado == 0){
                ocupado = 1;
                $('.tooltip').css({
                    //Aparece (ya que estaba en display none)
                    top: -80,
                    left: 164,
                    display: 'block',
                    opacity: 0
                }).animate({
                    opacity: 1
                }, 'normal',
                function (){
                    ocupado = 0;
                });
            }
        },
        //Cuando sale de la zona del icono
        function (){
            if (ocupado == 0){
                ocupado = 1;
                $('.tooltip').css({
                    opacity: 1
                }).animate({
                    opacity: 0
                }, 'slow',
                function(){
                    $('.tooltip').css({
                        display: 'none'
                    });
                    ocupado = 0;
                });
            }else {
                $('.tooltip').css({
                    display: 'none'
                });
                ocupado = 0;
            }
        });

});

