﻿

//this func turns off all tooltips
function closeAllTooltips() {
    $('.cal_billing').hide();
}

function BindNextControl() {

    $('TD.eventcell').each(function(n) {
        $(this).hover(function() {
            var tooltip = getTooltip(n);
            $('.cal_billing').not(tooltip).hide();
            positionTooltip(this, tooltip, n);

            tooltip.show();//fade in does weirdness
        }, function() {
            var tooltip = getTooltip(n);
            $('.cal_billing').not(tooltip).hide();
            tooltip.hide();
        });
    });
    $('TD.imagecell IMG').each(function(n) {
        $(this).hover(
                function() {
                    var tooltip = getTooltip(n);
                    $('.cal_billing').not(tooltip).hide();
                    positionTooltip(this, tooltip, n);
                    tooltip.show(); //fade in does weirdness
                },
                function() {
                var tooltip = getTooltip(n);
                $('.cal_billing').not(tooltip).hide();
                    tooltip.hide; //(400); //.hide();
                }
                );
            });

    function getTooltip(idx) {
        return $('.cal_billing').eq(idx);
    }

    function positionTooltip(trigger, tooltip, idx) {
    
        //get dims of next container
        var container = $('.nextcontainer');

        var td = $('TD.eventcell').eq(idx)[0];

        var tdleft = td.offsetLeft;        
        
        //if we are on the first or last cell we need to adjust so that we dont overlap the navigation
        if (td.className.indexOf('firstcell') != -1) {
            tdleft += 12;
        }
        else if (td.className.indexOf('lastcell') != -1) {
            tdleft -= 40;
        }
        
        tooltip.css({ position: 'absolute', bottom: 0, left: tdleft });
    }
    
    addReflections();
}

function addReflections() {
    jQuery('img.reflect').reflect({ height: .5, opacity: .8
    });
}
