﻿/* Common Flot Functions */

/* Vars */

/* Options */
var options = {
    xaxis: { mode: "time", minTickSize: [5, "minute"] },
    yaxis: { labelWidth: 25, minTickSize: .1, min: 0 },
    lines: { show: true, fill: true, lineWidth: 2 },
    points: { show: false },
    selection: { color: "#444", mode: "xy" },
    grid: {
        show: true,
        backgroundColor: { colors: ["#EEE", "#AAA"] },
        borderColor: "#000",
        tickColor: "#DDD",
        aboveData: false,
        borderWidth: 2,
        hoverable: true,
        clickable: true,
        autoHighlight: true,
        mouseActiveRadius: 20
    },
    legend: {
        position: "nw",
        backgroundOpacity: 0
    }
};

var Ooptions = {
    lines: { show: true, lineWidth: 1 },
    xaxis: { ticks: [] },
    yaxis: { ticks: [], labelWidth: 25, min: 0 },
    selection: { color: "#444", mode: "x" },
    grid: {
        show: true,
        backgroundColor: { colors: ["#FFF", "#EEE"] },
        borderColor: "#000",
        borderWidth: 2
    },
    legend: { show: false }
}

/* Set Colors */
function setColors(series) {
    var i = 0;
    $.each(series, function(key, val) {
        val.color = i;
        val.lines = { show: true, fill: 0.2, lineWidth: 2 };
        ++i;
    });
}

/* Get Datetime */
function getDate(val) {
    var currentTime = new Date(val);
    var year = currentTime.getUTCFullYear();

    //if(level <             
    var month = currentTime.getUTCMonth() + 1;
    var day = currentTime.getUTCDate();

    var hours = currentTime.getUTCHours();
    var minutes = currentTime.getUTCMinutes() + "";
    var time = null;
    if (hours < 12) { time = "AM"; }
    else { time = "PM"; }
    if (hours == 0) { hours = 12; }
    if (hours > 12) { hours = hours - 12; }
    if (minutes.length == 1) { minutes = "0" + minutes; }
    return "at " + hours + ":" + minutes + " " + time + " on " + month + "/" + day + "/" + year;
}

/* Tooltip */
function showTooltip(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',
        opacity: 0.80
    }).appendTo("body").fadeIn(200);
}
