var YCharts = 
{
    latestDates: [],
    chartSelectSaveURL: '',
    defaultChartType: 'real',
    charts: Object(),
    chartOptions: Object(),
    chartData: Object(),
    chartCompData: Object(),
    standardOptions: {
        xaxis: {
            mode: "time", 
            ticks: null, 
            tickSize: null, 
            tickFormatter: null},
        yaxis: {
            mode: null, 
            transform: null,
            inverseTransform: null,
            ticks: null, 
            tickSize: null, 
            tickFormatter: null},
        y2axis: {
            mode: null, 
            transform: null,
            inverseTransform: null,
            ticks: null, 
            tickSize: null, 
            tickFormatter: null},
        legend: {show: false, position: "nw"},  
        grid: {
            borderWidth: 1, 
            backgroundColor: "#fff", 
            hoverable: true, 
            clickable: false},
        colors: ["#0000ff", "#09b809", "#ff0000", "#ff00ff", "#ff9933"],
        series: {
            lines: { show: true, lineWidth: 2},
            points: {show: true, radius: 0},
            shadowSize: 3
        }
    },
    
    addChart: function(chartID, options) {
        YCharts.chartOptions[chartID] = options;
        YCharts.chartData[chartID] = new Array();
        YCharts.chartCompData[chartID] = new Array();
        
        if(typeof(YCharts.chartOptions[chartID].format) == 'undefined') {
            YCharts.chartOptions[chartID].format = 'none';
        }
        if(typeof(YCharts.chartOptions[chartID].daysBack) == 'undefined') {
            YCharts.chartOptions[chartID].daysBack = 0;
        }
        if(typeof(YCharts.chartOptions[chartID].clickURL) != 'undefined') {
            YCharts.chartOptions[chartID].clickURLIndexed = 
                YCharts.chartOptions[chartID].clickURL + '#indexed';
        }
        if(!YCharts.chartOptions[chartID].dateFormat || 
            !(YCharts.chartOptions[chartID].dateFormat in {'normalizedQuarter':'', 'month':''})) {
            YCharts.chartOptions[chartID].dateFormat = 'normalizedQuarter';
        }
        if(typeof(YCharts.chartOptions[chartID].maxTicks) == 'undefined') {
            YCharts.chartOptions[chartID].maxTicks = 5;
        }
        if(typeof(YCharts.chartOptions[chartID].lineWidth) == 'undefined') {
            YCharts.chartOptions[chartID].lineWidth = 2;
        }
        if(typeof(YCharts.chartOptions[chartID].pointRadius) == 'undefined') {
            YCharts.chartOptions[chartID].pointRadius = 0;
        }
        if(typeof(YCharts.chartOptions[chartID].shadowSize) == 'undefined') {
            YCharts.chartOptions[chartID].shadowSize = 3;
        }
    },
    
    deleteChart: function(chartID) {
        if(!(chartID in YCharts.charts)) {
            return;
        }
        
        YCharts.clearChart(chartID);
        
        delete YCharts.charts[chartID];
        delete YCharts.chartOptions[chartID];
        delete YCharts.chartData[chartID];
        delete YCharts.chartCompData[chartID];
    },
    
    clearChart: function(chartID) {
        $('#'+chartID).html('');
        $('#'+chartID).unbind("plothover");
        YCharts.chartOptions[chartID].format = 'none';
    },
    
    addChartOption: function(chartID, optionName, optionVal) {
        YCharts.chartOptions[chartID][optionName] = optionVal;
    },
    
    addData: function(chartID, data) {
        YCharts.chartData[chartID].push(data);
    },

    deleteData: function(chartID, data) {
        YCharts.chartData[chartID] = new Array();
    },

    addCompData: function(chartID, data) {
        YCharts.chartCompData[chartID].push(data);
    },

    deleteCompData: function(chartID) {
        YCharts.chartCompData[chartID] = new Array();
    },

    getDataSet : function(chartID) {
        return YCharts.chartData[chartID];
    },

    getCompDataSet : function(chartID) {;
        return YCharts.chartCompData[chartID];
    },
    
    getTotalDataSet : function(chartID) {
        var totalDataSet = new Array();
        var dataSet = YCharts.getDataSet(chartID);
        var compDataSet = YCharts.getCompDataSet(chartID);
        totalDataSet = $.merge(totalDataSet, dataSet);
        totalDataSet = $.merge(totalDataSet, compDataSet);
        return totalDataSet;
    },

    toggleAllReal: function() {
        YCharts.defaultChartType = 'real';
        for(id in YCharts.chartData) {
            if(YCharts.chartOptions[id].format != 'none') {
                YCharts.chartReal(id);
            }
        }
    },

    toggleAllIndexed: function() {
        YCharts.defaultChartType = 'indexed';
        for(id in YCharts.chartData) {
            if(YCharts.chartOptions[id].format != 'none') {
                YCharts.chartIndexed(id);
            }
        }
    },

    chart: function(chartID) {
        type = YCharts.chartOptions[chartID].format;
        if(type == 'none') {
            if(YCharts.defaultChartType == 'real') {
                YCharts.chartReal(chartID);
            }
            else if (YCharts.defaultChartType == 'indexed') {
                YCharts.chartIndexed(chartID);
            }
        }
        else {
            if(type == 'real') {
                YCharts.chartReal(chartID);
            }
            else if (type == 'indexed') {
                YCharts.chartIndexed(chartID); 
            }
        }
    },
    
    chartReal: function(chartID) {
        YCharts.clearChart(chartID);
        YCharts.chartOptions[chartID].format = 'real';
        var daysBack = YCharts.chartOptions[chartID].daysBack;
        var dataSet = YCharts.getDataSet(chartID);
        var compDataSet = YCharts.getCompDataSet(chartID);
        var totalDataSet = YCharts.getTotalDataSet(chartID);
        
        if(dataSet.length == 0) {
            return;
        }
        
        var options = $.extend(true, {}, YCharts.standardOptions);
        if(totalDataSet.length > 1) {
            options.legend.show = true;
        }

        
        if(YCharts.chartOptions[chartID].clickURL) {
            options.grid.clickable = true;
        }
        options.series.lines.lineWidth = YCharts.chartOptions[chartID].lineWidth;
        if(YCharts.chartOptions[chartID].pointRadius == 0) {
            options.series.points.show = false;
        }
        options.series.points.radius = YCharts.chartOptions[chartID].pointRadius;
        options.series.shadowSize = YCharts.chartOptions[chartID].shadowSize;

        // If daysBack is defined filter out all data that doesn't fall in the range
        if(daysBack > 0) {
            startTime = YCharts.timeInPast(daysBack);
            for(i in dataSet) {
                data = dataSet[i];
                var processedData = Array();
                for(j in data.rawData) {
                    if(data.rawData[j][0] >= startTime) {
                        processedData.push([data.rawData[j][0], data.rawData[j][1]]);
                    }
                }
                dataSet[i].processedData = processedData;
            }
            for(i in compDataSet) {
                data = compDataSet[i];
                var processedData = Array();
                for(j in data.rawData) {
                    if(data.rawData[j][0] >= startTime) {
                        processedData.push([data.rawData[j][0], data.rawData[j][1]]);
                    }
                }
                compDataSet[i].processedData = processedData;
            }
        }
        else {
            for(i in dataSet) {
                dataSet[i].processedData = $.extend(true, [], dataSet[i].rawData);
            }
            for(i in compDataSet) {
                compDataSet[i].processedData = $.extend(true, [], compDataSet[i].rawData);
            }
        }

        // Make the ticks for the x-axis
        var uniqueTimeValues = Object();
        for(i in totalDataSet) {
            for(j in totalDataSet[i].processedData) {
                uniqueTimeValues[totalDataSet[i].processedData[j][0]] = 1;
            }
        }

        var uniqueTimeSequence = Array();
        for(i in uniqueTimeValues) {
            uniqueTimeSequence.push(parseInt(i));
        }
        uniqueTimeSequence.sort(function(a,b){return a - b});

        maxTicks = YCharts.chartOptions[chartID].maxTicks;
        if(uniqueTimeSequence.length <= maxTicks) {
            tickStart = 1;
            tickInterval = 1;
        }
        else {
            tickInterval = Math.ceil(uniqueTimeSequence.length / maxTicks);
            tickStart = tickInterval;
        }

        var ticks = Array()
        var numItems = tickStart;
        var dateFormatter = YCharts.getTickFormatter(YCharts.chartOptions[chartID].dateFormat);
        for(i in uniqueTimeSequence) {
            if(numItems == tickInterval) {
                numItems = 1;
                ticks.push([uniqueTimeSequence[i], 
                    dateFormatter(uniqueTimeSequence[i])]);
            }
            else {
                numItems += 1;
            }
        }
        options.xaxis.ticks = ticks;
                
        // We assume that data type of the first data sequence,
        // is the same as ALL the others
        var data = dataSet[0];
        var tickFormatter = YCharts.getTickFormatter(data.type);
        options.yaxis.tickFormatter = tickFormatter;
        if(compDataSet.length > 0) {
            var data = compDataSet[0];
            var tickFormatter = YCharts.getTickFormatter(data.type);
            options.y2axis.tickFormatter = tickFormatter;
        }

        var series = Array()
        for(i in dataSet) {
            var data = dataSet[i];
            series.push({label: data.label, data: data.processedData});
        }
        for(i in compDataSet) {
            var data = compDataSet[i];
            series.push({label: data.label, data: data.processedData, yaxis: 2});
        }
        $('.dataTooltip').remove();
        YCharts.charts[chartID] = $.plot($('#'+chartID), series, options);
        $('#'+chartID).bind("plothover", YCharts.showDataTooltipHandler);
        if(YCharts.chartOptions[chartID].clickURL) {
            $('#'+chartID).click(function() {
                window.location = YCharts.chartOptions[chartID].clickURL;
            });
        }
        $('#'+chartID).bind("mouseout", function() {
            $('.dataTooltip').remove();
            if(typeof(YCharts.charts[chartID]) != 'undefined') {
                YCharts.charts[chartID].unhighlight();
            }
        });
    },
    
    chartIndexed: function(chartID) {
        YCharts.clearChart(chartID);
        YCharts.chartOptions[chartID].format = 'indexed';
        var daysBack = YCharts.chartOptions[chartID].daysBack;
        var dataSet = YCharts.getTotalDataSet(chartID);
        if(dataSet.length == 0) {
            return;
        }

        var options = $.extend(true, {}, YCharts.standardOptions);
        if(dataSet.length > 1) {
            options.legend.show = true;
        }
        if(YCharts.chartOptions[chartID].clickURL) {
            options.grid.clickable = true;
        }
        options.series.lines.lineWidth = YCharts.chartOptions[chartID].lineWidth;
        if(YCharts.chartOptions[chartID].pointRadius == 0) {
            options.series.points.show = false;
        }
        options.series.points.radius = YCharts.chartOptions[chartID].pointRadius;
        options.series.shadowSize = YCharts.chartOptions[chartID].shadowSize;
        
        // If daysBack is defined filter out all data that doesn't fall in the range
        if(daysBack > 0) {
            startTime = YCharts.timeInPast(daysBack);
            for(i in dataSet) {
                data = dataSet[i];
                var processedData = Array();
                for(j in data.rawData) {
                    if(data.rawData[j][0] >= startTime) {
                        processedData.push([data.rawData[j][0], data.rawData[j][1]]);
                    }
                }
                dataSet[i].processedData = processedData;
            }            
        }
        else {
            for(i in dataSet) {
                dataSet[i].processedData = $.extend(true, [], dataSet[i].rawData);
            }
        }

        //To properly index the data, we must find the first data point for which ALL
        //data series are non-null AND non-0
        var indexStartPoint = null;
        var startPointFound = false;
        for(i in dataSet[0].processedData) {
            indexStartPoint = dataSet[0].processedData[i][0];
            startPointFound = true;
            for(j in dataSet) {
                if(dataSet[j].processedData.length == 0) {
                    startPointFound = false;
                }
                for(k in dataSet[j].processedData) {
                    if(dataSet[j].processedData[k][0] < indexStartPoint) {
                        continue;
                    }
                    else if(dataSet[j].processedData[k][0] > indexStartPoint) {
                        startPointFound = false;
                        break;
                    }
                    else if(dataSet[j].processedData[k][0] == indexStartPoint 
                        && !dataSet[j].processedData[k][1]) {
                        startPointFound = false;
                        break;
                    }
                    else {
                        break;
                    }
                }
                if(!startPointFound) {
                    break;
                }
            }
            if(startPointFound) {
                break;
            }
        }
        if(!startPointFound) {
            return;
        }

        //Based on our indexStartPoint, save the indexer for each data series
        var indexer = Array();
        for(i in dataSet) {
            data = dataSet[i];
            for(j in data.processedData) {
                if(data.processedData[j][0] == indexStartPoint) {
                    indexer[i] = data.processedData[j][1];
                    break;
                }
            }
        }

        //Now create indexed data, starting at indexStartPoint and using indexer
        for(i in dataSet) {
            data = dataSet[i];
            var indexedData = Array();
            for(j in data.processedData) {
                if(data.processedData[j][0] < indexStartPoint) {
                    continue;
                }
                var x = data.processedData[j][0];
                var y = data.processedData[j][1];
                var yIndexer = indexer[i];
                var yIndexed = null;
                if(y != null) {
                    yIndexed = ((y / yIndexer) - 1) * 100;
                    if(y < 0 || yIndexer < 0) {
                        if(y > yIndexer) {
                            yIndexed = Math.abs(yIndexed);
                        }
                        else {
                            yIndexed = -1 * Math.abs(yIndexed);
                        }
                    }
                }
                indexedData.push([x, yIndexed]);
            }
            dataSet[i].indexedData = indexedData;
        }

        // Make the ticks for the x-axis
        var uniqueTimeValues = Object();
        for(i in dataSet) {
            for(j in dataSet[i].processedData) {
                uniqueTimeValues[dataSet[i].processedData[j][0]] = 1;
            }
        }

        var uniqueTimeSequence = Array();
        for(i in uniqueTimeValues) {
            uniqueTimeSequence.push(parseInt(i));
        }
        uniqueTimeSequence.sort(function(a,b){return a - b});

        maxTicks = YCharts.chartOptions[chartID].maxTicks;
        if(uniqueTimeSequence.length <= maxTicks) {
            tickStart = 1;
            tickInterval = 1;
        }
        else {
            tickInterval = Math.ceil(uniqueTimeSequence.length / maxTicks);
            tickStart = tickInterval;
        }

        var ticks = Array()
        var numItems = tickStart;
        var dateFormatter = YCharts.getTickFormatter(YCharts.chartOptions[chartID].dateFormat);
        for(i in uniqueTimeSequence) {
            if(numItems == tickInterval) {
                numItems = 1;
                ticks.push([uniqueTimeSequence[i], 
                    dateFormatter(uniqueTimeSequence[i])]);
            }
            else {
                numItems += 1;
            }
        }
        options.xaxis.ticks = ticks;

        //For indexed data, the tick format is always percent
        options.yaxis.tickFormatter = YCharts.percentTickFormatter;

        var series = Array()
        for(i in dataSet) {
            var data = dataSet[i];
            series.push({label: data.label, data: data.indexedData});
        }
        $('.dataTooltip').remove();
        YCharts.charts[chartID] = $.plot($('#'+chartID), series, options);
        $('#'+chartID).bind("plothover", YCharts.showDataTooltipHandlerIndexed);
        if(YCharts.chartOptions[chartID].clickURL) {
            $('#'+chartID).click(function() {
                window.location = YCharts.chartOptions[chartID].clickURL;
            });
        }
        $('#'+chartID).bind("mouseout", function() {
            $('.dataTooltip').remove();
            if(typeof(YCharts.charts[chartID]) != 'undefined') {
                YCharts.charts[chartID].unhighlight();
            }
        });
    },
    
    supportsCanvas: function() {
        canvasCompatible = false;
        try {
            canvasCompatible = !!(document.createElement('canvas').getContext('2d')); // S60
        } catch(e) {
            canvasCompatible = !!(document.createElement('canvas').getContext); // IE
        } 
        return canvasCompatible;
    },
    
    timeInPast: function(numDays) {
        numMilliSeconds = numDays * 24 * 60 * 60 * 1000;
        today = (new Date()).getTime();
        return today - numMilliSeconds;
    },

    figureFormatter: function(val, places) {
        if(val == val.toFixed(0)) {
            //If the number is the same rounded as not rounded,
            //show the whole number (rounded) version
            places = 0;
        }
        else if(places == 0) {
            // If the number is not same rounded as not rounded,
            // and the func call says to round to 0 places, ignore
            // that and round to at least one place
            places = 1;
        }
        else if(places == undefined) {
            places = 2
        }
        
        return val.toFixed(places).toString();
    },

    milFigureFormatter: function(val, places) {
        if(val == 0) {
            unit = '';
        }
        else if(val > -1000 && val < 1000) {
            unit = 'M';
        }
        else if((val >=1000 && val < 1000000) || 
            (val <=-1000 && val > -1000000)) {
            unit = 'B';
            val /= 1000;
        }
        else if((val >=1000000 && val < 1000000000) || 
            (val <=-1000000 && val > -1000000000)) {
            unit = 'T';
            val /= 1000000;
        }
        else {
            return '';
        }

        if(val == val.toFixed(0)) {
            //If the number is the same rounded as not rounded,
            //show the whole number (rounded) version
            places = 0;
        }
        else if(places == 0) {
            // If the number is not same rounded as not rounded,
            // and the func call says to round to 0 places, ignore
            // that and round to at least one place
            places = 1;
        }
        else if(places == undefined) {
            places = 2
        }

        return val.toFixed(places) + unit;
    },

    percentFormatter: function(val, places) {
        if(val == val.toFixed(0)) {
            //If the number is the same rounded as not rounded,
            //show the whole number (rounded) version
            places = 0;
        }
        else if(places == 0) {
            // If the number is not same rounded as not rounded,
            // and the func call says to round to 0 places, ignore
            // that and round to at least one place
            places = 1;
        }
        else if(places == undefined) {
            places = 2
        }

        return val.toFixed(places) + '%';
    },

    normalizedQuarterFormatter: function(val) {
        var d = new Date(val);
        //Stupid JS month is 0 indexed so we adjust
        month = d.getUTCMonth() + 1;
        year = d.getUTCFullYear();

        if($.inArray(val, YCharts.latestDates) != -1) {
            day = d.getUTCDate();
            return month + '/' + day;
        }

        quarter = '';
        if(month == 2 || month == 3 || month == 4) {
            quarter = 'Q1';
        }
        else if(month == 5 || month == 6 || month == 7) {
            quarter = 'Q2';
        }
        else if(month == 8 || month == 9 || month == 10) {
            quarter = 'Q3';
        }
        else if(month == 11 || month == 12 || month == 1) {
            quarter = 'Q4';
            if (month == 1) {
                year -= 1;
            }
        }
        year = year.toString().substring(2);
        return quarter + '/' + year;
    },

    monthFormatter: function(val) {
        var d = new Date(val);
        //Stupid JS month is 0 indexed so we adjust
        month = d.getUTCMonth() + 1;
        year = d.getUTCFullYear();

        if($.inArray(val, YCharts.latestDates) != -1) {
            day = d.getUTCDate();
            return month + '/' + day;
        }

        var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", 
            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
        monthStr = months[month-1];

        year = year.toString().substring(2);
        return monthStr + '/' + year;
    },

    figureTickFormatter: function(val, axis) {
        return YCharts.figureFormatter(val, axis.tickDecimals);
    },

    milFigureTickFormatter: function(val, axis) {
        return YCharts.milFigureFormatter(val, axis.tickDecimals);
    },

    percentTickFormatter: function(val, axis) {
        return YCharts.percentFormatter(val, axis.tickDecimals);
    },

    normalizedQuarterTickFormatter: function(val, axis) {
        return YCharts.normalizedQuarterFormatter(val);
    },

    monthTickFormatter: function(val, axis) {
        return YCharts.monthFormatter(val);
    },
    
    getFormatter: function(format) {
        if(format == 'figure' || format == 'figure_money') {
            return YCharts.figureFormatter;
        }
        else if (format == 'mil_figure' || format == 'mil_figure_money') {
            return YCharts.milFigureFormatter;
        }
        else if (format == 'percent') {
            return YCharts.percentFormatter;
        }
        else if (format == 'normalizedQuarter') {
            return YCharts.normalizedQuarterFormatter;
        }
        else if (format == 'month') {
            return YCharts.monthFormatter;
        }
        else {
            return YCharts.figureFormatter;
        }
    },

    getTickFormatter: function(format) {
        if(format == 'figure' || format == 'figure_money') {
            return YCharts.figureTickFormatter;
        }
        else if (format == 'mil_figure' || format == 'mil_figure_money') {
            return YCharts.milFigureTickFormatter;
        }
        else if (format == 'percent') {
            return YCharts.percentTickFormatter;
        }
        else if (format == 'normalizedQuarter') {
            return YCharts.normalizedQuarterTickFormatter;
        }
        else if (format == 'month') {
            return YCharts.monthTickFormatter;
        }
        
        else {
            return YCharts.figureTickFormatter;
        }
    },
    
    showDataTooltip: function(chartID, tooltipID, x, y, contents) {
        var tClass = chartID + '_Tooltip';

        $('.dataTooltip').remove();

        var tip = $('<div id="' + tooltipID + '" class="dataTooltip ' +
            tClass + '">' + contents + '</div>').appendTo("body");

        var tipHeight = tip.outerHeight();
        var tipWidth = tip.outerWidth();

        var tipTop = y - (tipHeight + 8);
        var tipLeft = x - (tipWidth / 2);
        var tipRight = tipLeft + tipWidth;

        var plotOffset = YCharts.charts[chartID].offset();
        var plotLeft = plotOffset.left;
        var plotRight = plotLeft + YCharts.charts[chartID].width();
        
        if(tipLeft < plotLeft) {
            tipLeft = plotLeft;
        }
        else if(tipRight > plotRight) {
            tipLeft = plotRight - tipWidth;
        }
        
        tip.css( {
            top: tipTop,
            left: tipLeft,
            position: 'absolute',
            display: 'none'
        });
        tip.show();
    },

    showDataTooltipHandler: function(event, pos, item) {
        var chartID = $(this).attr('id');
        if(item) {
            var tID = chartID + '_' + item.seriesIndex + '_' + item.dataIndex + '_Tooltip';
            var text = '';

            if($('#'+tID).length > 0) {
                return;
            }

            YCharts.charts[chartID].unhighlight();
            var x = item.datapoint[0];
            var xFormatter = YCharts.getFormatter(YCharts.chartOptions[chartID].dateFormat);
            var fmtX = xFormatter(x);
            text += '<div style="margin-bottom: 2px;">'+fmtX+'</div>';
            
            var dataSet = YCharts.getTotalDataSet(chartID);
            for(i in dataSet) {
                for(j in dataSet[i].processedData) {
                    if(dataSet[i].processedData[j][0] == x) {
                        var y = dataSet[i].processedData[j][1];
                        if(y === null) {
                            continue;
                        }
                        YCharts.charts[chartID].highlight(parseInt(i), parseInt(j));
                        var yFormatter = YCharts.getFormatter(dataSet[i].type);
                        var fmtY = yFormatter(y);
                        var colorY = YCharts.standardOptions.colors[i];
                        text += '<div style="color:'+colorY+'">' 
                            + fmtY + '</div>';
                    }
                }
            }
            YCharts.showDataTooltip(chartID, tID, item.pageX, item.pageY, text);
        }
        else {
            YCharts.charts[chartID].unhighlight();
            $('.dataTooltip').remove();
        }
    },
    
    showDataTooltipHandlerIndexed: function(event, pos, item) {
        var chartID = $(this).attr('id');
        if(item) {
            var tID = chartID + '_' + item.seriesIndex + '_' + item.dataIndex + '_Tooltip';
            var text = '';

            if($('#'+tID).length > 0) {
                return;
            }

            YCharts.charts[chartID].unhighlight();
            var x = item.datapoint[0];
            var xFormatter = YCharts.getFormatter(YCharts.chartOptions[chartID].dateFormat);
            var fmtX = xFormatter(x);
            text += fmtX;
            
            var dataSet = YCharts.getTotalDataSet(chartID);
            for(i in dataSet) {
                for(j in dataSet[i].indexedData) {
                    if(dataSet[i].indexedData[j][0] == x) {
                        var y = dataSet[i].indexedData[j][1];
                        if(y === null) {
                            continue;
                        }
                        YCharts.charts[chartID].highlight(parseInt(i), parseInt(j));
                        var fmtY = YCharts.percentFormatter(y);
                        var colorY = YCharts.standardOptions.colors[i];
                        text += '<br/><strong style="color:'+colorY+'">' 
                            + fmtY + '</strong>';
                    }
                }
            }
            YCharts.showDataTooltip(chartID, tID, item.pageX, item.pageY, text);
        }
        else {
            YCharts.charts[chartID].unhighlight();
            $('.dataTooltip').remove();
        }
    }
}
