/**
* jQuery Dashboard Gauges v0.2.0
* http://techoctave.com/c7
*
* Copyright (c) 2010 by Tian Valdemar Davis
* 
* Free for Personal and Educational Use
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Date: Mon Sep 6 10:00:00 2010 -0500
*/
Normality = function (gaugeID) {
    //[State]
    var tick;
    var tickStop;

    //[Initialization]
    this.SetGaugeID(gaugeID);
    this.SetGaugeX(195); this.SetGaugeY(195);

    this.SetPosX(85); this.SetPosY(23); this.SetWidth(23); this.SetHeight(85);
    this.LoadCX(0); this.LoadCY(-2);

    this.CreateGauge();
    this.SetTick(0); //initialize control
};

//Inherit gauge functionality
Normality.prototype = new Gauge();

//[Properties]
Normality.prototype.SetTick = function (tick) {
    this.tick = tick;

    if (this.tickValidated())
        this.RotateNeedle(this.tick2deg());
};
Normality.prototype.SetTickStop = function (tickStop) {
    this.tickStop = tickStop * 10;
};
Normality.prototype.GetTick = function () {
    return this.tick;
};
Normality.prototype.GetTickStop = function () {
    return this.tickStop;
};


//[Methods]
//Speed to degree mappings
Normality.prototype.tick2deg = function () {
    return ((this.tick - 50) * 2.62) + (((this.tick - 50) * 1.8999) * 0.022900763);
};


Normality.prototype.Accelerate = function () {
    //Setup Timer
    jQuery(this).everyTime(10, function (i) {
        if (i < 300) {
            var v = i * 80;
            var s = easeInCirc(i, 0, v, 500);
            if (this.tickStop == 100) {
                if (s <= (this.tickStop * (1 + i * .0009999999)))  // was .0000999999
                    this.SetTick(easeInCirc(i, 0, v, 100));  // was 500
            } else {
                if (s <= (this.tickStop * (1 + i * .0001599999)))  // was .0000999999
                    this.SetTick(easeInCirc(i, 0, v, 504));  // was 500
            }

        }
    }, 0);

    /////////// CIRCULAR EASING: sqrt(1-t^2) //////////////
    // circular easing in - accelerating from zero velocity
    // t: current time, b: beginning value, c: change in position, d: duration
    easeInCirc = function (t, b, c, d) {
        return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
    };
};

//Validation
Normality.prototype.tickValidated = function () {
    return ((this.tick >= 0) && (this.tick <= 100));
};

