﻿/*Created by Scott to popup legal information*/
function toggleMeterPopup() {
    $('#meter_popup,#meter_cover').toggle();
}

/*============================================================================
  Gavin Brock's CSS/JavaScript Animated Odometer
  Version 1.0 - April 7th 2008
============================================================================
  Copyright (C) 2008 Gavin Brock

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
============================================================================*/
function Meter(parentDiv, opts) {
    if (!parentDiv) { throw "ERROR: Meter object must be past a document element."; }
    this.digits = 6;
    this.hundredths = 0;
    this.digitHeight = 24;
    this.digitPadding = 0;
	this.digitWidth = 18;
    this.bustedness = 0;
    this.activeDigits = 6;
    this.systemName = "MJP";
    this.value = -1;
	this.dollarWidth = this.digitWidth;
	this.digitHeightWithPadding = this.digitHeight * 1.20;
    var key;
    for (key in opts) { this[key] = opts[key]; }

    this.puncWidth = this.digitWidth / 2
    this.puncWidth2 = this.dollarWidth / 2
    var style = {
        digits: 	"position:absolute; left: 0; height:" + (this.digitHeightWithPadding) + "px; width:" + (this.digitWidth - (2 * this.digitPadding)) + "px; " +
					//"padding-bottom:" + this.digitPadding + "px;" +
					"text-align:center; ", 
        columns:	"position:relative; float:left; overflow:hidden;" +
					"height:" + (this.digitHeight) + "px; width:" + this.digitWidth + "px;",
        punc: 		"position:absolute; left: 0; height:" + this.digitHeight + "px; width:" + (this.puncWidth - (2 * this.digitPadding)) + "px; " +
                    "padding-bottom:" + this.digitPadding + "px; " +
					"text-align:center; ",
		punc2:		"text-align:center; position:absolute; left: 0; height:" + this.digitHeight + "px; width:6px; " +
                    "padding-bottom:" + this.digitPadding + "px; ",
        puncColumn2: "position:relative; float:left; overflow:hidden;" +
					"height:" + this.digitHeight + "px; width:" + this.puncWidth + "px;",
        puncColumn: "text-align:center; left:-1px; position:relative; float:left; overflow:hidden;" +
					"height:" + this.digitHeight + "px; width:6px;",
		puncColumn3: "position:relative; float:left; overflow:hidden; padding-right: 2px;" +
					 "height:" + this.digitHeight + "px; width:" + this.puncWidth2 + "px;",
		paddings:	"position:absolute; width:100%; left:0px;"
    };

	//Add padding to the top and bottom
	var paddings = [
		"top:20%; height: 32%;" + style.paddings,
		"bottom:0%; height: 8%;" + style.paddings
	];
    

    this.setDigitValue = function (digit, val, frac) {
        var di = digitInfo[digit];
        var px = Math.floor(this.digitHeightWithPadding * frac);
        px = px + di.offset;
        if (val != di.last_val) {
            var tmp = di.digitA;
            di.digitA = di.digitB;
            di.digitB = tmp;
            di.digitA.innerHTML = val;
            di.digitB.innerHTML = (1 + Number(val)) % 10;
            di.last_val = val;
            if (di.digitA.style.display == "none" && val != 0) {
                di.digitA.style.display = "inherit";
                di.digitB.style.display = "inherit";
                var commaToHide = document.getElementById("meter_comma" + this.systemName + "a" + 1);
                commaToHide.style.display = "inherit";
                commaToHide = document.getElementById("meter_comma" + this.systemName + "b" + 1);
                commaToHide.style.display = "inherit";
            }
        }
        if (px != di.last_px) {
            di.digitA.style.top = (0 - px) + "px";
            di.digitB.style.top = (0 - px + this.digitHeightWithPadding) + "px";
            di.last_px = px;
        }
    };


    this.set = function (inVal) {
        if (inVal < 0) throw "ERROR: Meter value cannot be negative.";
        this.value = inVal;
        if (this.hundredths) inVal = inVal * 100;
        var numb = Math.floor(inVal);
        var frac = inVal - numb;
        numb = String(numb);
        for (var i = 0; i < this.digits; i++) {
            var num = numb.substring(numb.length - i - 1, numb.length - i) || 0;
            if (num <= 9) this.setDigitValue(this.digits - i - 1, num, frac);
            if (num != 9) frac = 0;
        }
    };

    this.get = function () {
        return (this.value);
    };

    var meterDiv = document.createElement("div");
    var divStyle = "float: right;";
    /*meterDiv.setAttribute("class", "meter_actual");*/
    meterDiv.style.cssText = divStyle;
    parentDiv.insertBefore(meterDiv, parentDiv.firstChild);

    var digitInfo = new Array();
    var decimalLocation = this.digits - 3 /*3 because next loop is 0 based*/
	var val = 0; /* Used to determine where the comma goes */
    for (var i = 0; i < this.digits; i++) {
		if (i == 0) {
            /*Place the $ sign prior to any numbers*/
			var digitDivA = document.createElement("div");
            digitDivA.innerHTML = "$";
            digitDivA.style.cssText = style.punc;
			
			var ie7FixDiv = document.createElement("div"); /*Fix for ie7 having to do with floats*/
			ie7FixDiv.appendChild(digitDivA);

            var digitColDiv = document.createElement("div");
            digitColDiv.style.cssText = style.puncColumn3;

            digitColDiv.appendChild(ie7FixDiv);

            meterDiv.appendChild(digitColDiv);
        }
        var digitDivA = document.createElement("div");
        digitDivA.setAttribute("id", "meter_digit_" + i + "a");
        digitDivA.style.cssText = style.digits;

        var digitDivB = document.createElement("div");
        digitDivB.setAttribute("id", "meter_digit_" + i + "b");
        digitDivB.style.cssText = style.digits;

        var digitColDiv = document.createElement("div");
        digitColDiv.style.cssText = style.columns;

        digitColDiv.appendChild(digitDivB);
        digitColDiv.appendChild(digitDivA);

		//for (var j in paddings) {
        //    var hdiv = document.createElement("div");
        //    hdiv.innerHTML="<p></p>"; // For Dumb IE
        //    hdiv.style.cssText = paddings[j];
        //    digitColDiv.appendChild(hdiv);
        //}
        
        meterDiv.appendChild(digitColDiv);
        var offset = Math.floor(Math.random() * this.bustedness);
        digitInfo.push({ digitA: digitDivA, digitB: digitDivB, last_val: -1, last_px: -1, offset: offset });
        if (i == decimalLocation) {
            /*Force a decimal point into value*/
            var digitDivA = document.createElement("div");
            digitDivA.setAttribute("id", "meter_decimala");
            digitDivA.innerHTML = ".";
            digitDivA.style.cssText = style.punc2;

            var digitColDiv = document.createElement("div");
            digitColDiv.style.cssText = style.puncColumn;

            digitColDiv.appendChild(digitDivA);

            meterDiv.appendChild(digitColDiv);
        }
		val = (this.digits - i)
		if ((val % 3) == 0 && this.digits - i != 3) {
            /*Force a comma into value in the appropriate places*/
            var digitDivA = document.createElement("div");
            digitDivA.setAttribute("id", "meter_comma" + this.systemName + "a" + i);
            digitDivA.innerHTML = ",";
            digitDivA.style.cssText = style.punc;

            var digitColDiv = document.createElement("div");
            digitColDiv.style.cssText = style.puncColumn2;

            digitColDiv.appendChild(digitDivA);

            meterDiv.appendChild(digitColDiv);
        }
    };

    if (this.digits != this.activeDigits) {
        if (this.digits > this.activeDigits) {
            var hideDigits = this.digits - this.activeDigits /*Number of digits to hide instead of showing a 0*/
            for (var i = 0; i < hideDigits; i++) {
                digitInfo[i].digitA.style.display = "none";
                digitInfo[i].digitB.style.display = "none";
                if (i == 1) {
                    /*hide the comma */
                    var commaToHide = document.getElementById("meter_comma" + this.systemName + "a" + i);
                    commaToHide.style.display = "none";
                    var commaToHide = document.getElementById("meter_comma" + this.systemName + "b" + i);
                    commaToHide.style.display = "none";
                }
            }
        }
    }

    if (this.value >= 0) this.set(this.value);
}

function BiggestJackpotMeter(parentDiv, opts) {
    if (!parentDiv) { throw "ERROR: Meter object must be past a document element."; }
    this.digits = 6;
    this.hundredths = 0;
    this.digitHeight = 55;
    this.digitPadding = 0;
	this.digitWidth = 40;
    this.bustedness = 0;
    this.activeDigits = 6;
    this.systemName = "MJP";
    this.value = -1;
	var digitHeightWithPadding = this.digitHeight * 1.20;
    var key;
    for (key in opts) { this[key] = opts[key]; }

    this.puncWidth = this.digitWidth / 2
    this.puncWidth2 = this.digitWidth / 2
    var style = {
        digits: 	"position:absolute; left: 0;", 
        columns:	"position:relative; float:left; overflow:hidden;" +
					"height:" + this.digitHeight + "px; width:" + this.digitWidth + "px;",
        punc: 		"position:absolute; left: 0; height:" + this.digitHeight + "px; width:" + (this.puncWidth - (2 * this.digitPadding)) + "px; " +
                    "padding-bottom:" + this.digitPadding + "px; " +
					"text-align:center; ",
        puncColumn: "position:relative; float:left; " +
					"height:" + (this.digitHeight + 11) + "px; width:" + this.puncWidth + "px;",
        puncColumn2: "position:relative; float:left; overflow:hidden;" +
					 "height:" + this.digitHeight + "px; width:" + this.puncWidth2 + "px;",
		puncColumn3: "position:relative; float:left; overflow:hidden; padding-right: 2px;" +
					 "height:" + this.digitHeight + "px; width:" + this.puncWidth2 + "px;"
    };

    var highlights = [
        "top:20%;   height:32%;" + style.highlight,
        "top:27.5%; height:16%;" + style.highlight,
        "top:32.5%; height:6%;" + style.highlight,
        "right:0%;  width:6%;" + style.sidelowlight,
        "left:0%;   width:4%;" + style.sidehighlight,
        "top:0%;    height:14%;" + style.lowlight,
        "bottom:0%; height:25%;" + style.lowlight,
        "bottom:0%; height:8%;" + style.lowlight
    ];

    this.setDigitValue = function (digit, val, frac) {
        var di = digitInfo[digit];
        var px = Math.floor(digitHeightWithPadding * frac);
        px = px + di.offset;
        if (val != di.last_val) {
            var tmp = di.digitA;
            di.digitA = di.digitB;
            di.digitB = tmp;
            di.digitA.innerHTML = val;
            di.digitB.innerHTML = (1 + Number(val)) % 10;
            di.last_val = val;
            if (di.digitA.style.display == "none" && val != 0) {
                di.digitA.style.display = "inherit";
                di.digitB.style.display = "inherit";
                var commaToHide = document.getElementById("meter_comma" + this.systemName + "a" + 1);
                commaToHide.style.display = "inherit";
                commaToHide = document.getElementById("meter_comma" + this.systemName + "b" + 1);
                commaToHide.style.display = "inherit";
            }
        }
        if (px != di.last_px) {
            di.digitA.style.top = (0 - px) + "px";
            di.digitB.style.top = (0 - px + digitHeightWithPadding) + "px";
            di.last_px = px;
        }
    };


    this.set = function (inVal) {
        if (inVal < 0) throw "ERROR: Meter value cannot be negative.";
        this.value = inVal;
        if (this.hundredths) inVal = inVal * 100;
        var numb = Math.floor(inVal);
        var frac = inVal - numb;
        numb = String(numb);
        for (var i = 0; i < this.digits; i++) {
            var num = numb.substring(numb.length - i - 1, numb.length - i) || 0;
            if (num <= 9) this.setDigitValue(this.digits - i - 1, num, frac);
            if (num != 9) frac = 0;
        }
    };

    this.get = function () {
        return (this.value);
    };

    var meterDiv = document.createElement("div");
    var divStyle = "float: right;";
    /*meterDiv.setAttribute("class", "meter_actual");*/
    meterDiv.style.cssText = divStyle;
    parentDiv.insertBefore(meterDiv, parentDiv.firstChild);

    var digitInfo = new Array();
    var decimalLocation = this.digits - 3 /*3 because next loop is 0 based*/
	var val = 0; /* Used to determine where the comma goes */
    for (var i = 0; i < this.digits; i++) {
		
        var digitDivA = document.createElement("div");
        digitDivA.setAttribute("id", "meter_digit_" + i + "a");
		/*digitDivA.setAttribute("class", "topmeter_mid_number_inner_top");*/
		digitDivA.className = "topmeter_mid_number_inner_top";
        /*digitDivA.style.cssText = style.digits;*/

        var digitDivB = document.createElement("div");
        digitDivB.setAttribute("id", "meter_digit_" + i + "b");
		/*digitDivB.setAttribute("class", "topmeter_mid_number_inner_bot");*/
		digitDivB.className = "topmeter_mid_number_inner_top";
        /*digitDivB.style.cssText = style.digits;*/

        var digitColDiv = document.createElement("div");
		/*digitColDiv.setAttribute("class", "topmeter_mid_number_outer");*/
		digitColDiv.className = "topmeter_mid_number_outer";
        /*digitColDiv.style.cssText = style.columns;*/

        digitColDiv.appendChild(digitDivB);
        digitColDiv.appendChild(digitDivA);

        
        meterDiv.appendChild(digitColDiv);
        var offset = Math.floor(Math.random() * this.bustedness);
        digitInfo.push({ digitA: digitDivA, digitB: digitDivB, last_val: -1, last_px: -1, offset: offset });
        if (i == decimalLocation) {
            /*Force a decimal point into value*/
            var digitDivA = document.createElement("div");
            digitDivA.setAttribute("id", "meter_decimala");
			/*digitDivA.setAttribute("class", "topmeter_mid_seperators_inner");*/
			digitDivA.className = "topmeter_mid_seperators_inner";
			digitDivA.innerHTML = ".";
            /*digitDivA.style.cssText = style.punc;*/

            var digitColDiv = document.createElement("div");
			/*digitColDiv.setAttribute("class", "topmeter_mid_seperators");*/
			digitColDiv.className = "topmeter_mid_seperators";
            /*digitColDiv.style.cssText = style.puncColumn;*/

            digitColDiv.appendChild(digitDivA);

            meterDiv.appendChild(digitColDiv);
        }
		val = (this.digits - i)
		if ((val % 3) == 0 && this.digits - i != 3) {
            /*Force a comma into value in the appropriate places*/
            var digitDivA = document.createElement("div");
			/*digitDivA.setAttribute("class", "topmeter_mid_seperators_inner");*/
			digitDivA.className = "topmeter_mid_seperators_inner";
            digitDivA.setAttribute("id", "meter_comma" + this.systemName + "a" + i);
			
            digitDivA.innerHTML = ",";
            /*digitDivA.style.cssText = style.punc;*/

            var digitColDiv = document.createElement("div");
			/*digitColDiv.setAttribute("class", "topmeter_mid_seperators");*/
			digitColDiv.className = "topmeter_mid_seperators";
            /*digitColDiv.style.cssText = style.puncColumn;*/

            digitColDiv.appendChild(digitDivA);

            meterDiv.appendChild(digitColDiv);
        }
    };

    if (this.digits != this.activeDigits) {
        if (this.digits > this.activeDigits) {
            var hideDigits = this.digits - this.activeDigits /*Number of digits to hide instead of showing a 0*/
            for (var i = 0; i < hideDigits; i++) {
                digitInfo[i].digitA.style.display = "none";
                digitInfo[i].digitB.style.display = "none";
                if (i == 1) {
                    /*hide the comma */
                    var commaToHide = document.getElementById("meter_comma" + this.systemName + "a" + i);
                    commaToHide.style.display = "none";
                    var commaToHide = document.getElementById("meter_comma" + this.systemName + "b" + i);
                    commaToHide.style.display = "none";
                }
            }
        }
    }

    if (this.value >= 0) this.set(this.value);
}
