if (typeof EUNIT == "undefined") {
     var EUNIT = {};
 }

//name space for the flot_widget
EUNIT.flot_widget = {};

// Array of month names
EUNIT.flot_widget.months = Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

// xaxis formatter to display month names rather then 1,2,3,4 etc
EUNIT.flot_widget.monthFormatter = function(val, axis){
        
        return EUNIT.flot_widget.months[val-1];
};

// creates an actual tooltip
EUNIT.flot_widget.showTooltip = function(x, y, contents) {
    $('<div id="tooltip">' + contents + '</div>').css( {
        position: 'absolute',
        display: 'none',
        top: y + 5,
        left: x + 5,
        border: '1px solid #fdd',
        padding: '2px',
        'background-color': '#fee',
        'color': '#000',
        opacity: 0.80
    }).appendTo("body").fadeIn(200);
};

// The previous position that a tooltip has been shown
EUNIT.flot_widget.prevToolTipPoint = null;

// shows a tooltip over data points on the graph
EUNIT.flot_widget.bindToolTip = function(parent){
    $(parent).bind("plothover", function (event, pos, item) {
        $("#x").text(pos.x.toFixed(2));
        $("#y").text(pos.y.toFixed(2));

        if (item) {
            if (EUNIT.flot_widget.prevToolTipPoint != item.datapoint) {
                EUNIT.flot_widget.prevToolTipPoint = item.datapoint;
                
                $("#tooltip").remove();
                var y = item.datapoint[1].toFixed(0);
                
                EUNIT.flot_widget.showTooltip(item.pageX, item.pageY,
                    item.series.label + " " + y);
            }
        }
        else {
            $("#tooltip").remove();
            EUNIT.flot_widget.prevToolTipPoint = null;            
        }
    });
    
};
