$(function(){
    $('div.tooltip').hide();
    function reset()
    {
        $("#two_on").each(function(){
            i = $('#two_on').index(this);
            tip = $('#two_on').eq(i).attr('rel');
            $(this).tooltip({
                tip:'div.tooltip[title='+tip+']',
                effect:'slide',
                position: "top right"
            });
        });

        $('.diaEvento').hover(function(){
           $(this).parents('td').css('background', '#79bf42');
        }, function(){
             $(this).parents('td').css('background', 'none');
        });

        $('#highlight').parents('td').css('background', '#a7b8d6');

        $('#two_on').parents('td').css('background', '#79bf42');
    }
    $(".diaEvento").each(function(){
        i = $('.diaEvento').index(this);
        tip = $('.diaEvento').eq(i).attr('rel');
        $(this).tooltip({
            tip:'div.tooltip[title='+tip+']',
            effect:'slide',
            position: "top right"
        });
    });

    reset();
    

    $("a#next").live('click',function(){
        $ ( '.divCalendar'). load ( $(this).attr('rel'), function(){
            $('div.tooltip').hide();
            $(".diaEvento").each(function(){
                i = $('.diaEvento').index(this);
                tip = $('.diaEvento').eq(i).attr('rel');
                $(this).tooltip({
                    tip:'div.tooltip[title='+tip+']',
                    effect:'slide',
                    position: "top right"
                });
            });
            reset();
        });
    });
    $("a#prev").live('click',function(){
        $ ( '.divCalendar'). load ( $(this).attr('rel'), function(){
            $('div.tooltip').hide();
            $(".diaEvento").each(function(){
                i = $('a.diaEvento').index(this);
                tip = $('a.diaEvento').eq(i).attr('rel');
                $(this).tooltip({
                    tip:'div.tooltip[title='+tip+']',
                    effect:'slide',
                    position: "top right"
                });
            });
           reset();
        });
       
    });
});
