﻿// Navigation Wheel Script...

// Define Namespace...

if (!WillCurson) var WillCurson = {};
if (!WillCurson.NavWheel) WillCurson.NavWheel = {};

//--------------------------------------------------------------------------------

WillCurson.NavWheel = function()
{
    // Globals...

    // Animation Poller...
    this.animatePoll = null;

    // Data Array..
    this.data = [];

    // Total Animation Length In Milliseconds...
    this.ANIM_LENGTH = null;

    // Flags...
    // ----------

    // Browser Is Internet Explorer...
    this.isIE8 = false;

    // Control Has A Description Box...
    this.hasDesc = false;

    // ----------
};

//--------------------------------------------------------------------------------

WillCurson.NavWheel.prototype.init = function(data, intervalArg)
{
    // Mouse Over...

    try
    {
        // Set Data Array...
        this.data = data;

        // Start Animation...
        this.animatePoll = setInterval(intervalArg, 20);
    }
    catch (e)
    {
        alert("NavWheel.init Error: " + e.message);
    }
};

//--------------------------------------------------------------------------------

WillCurson.NavWheel.prototype.mouseOver = function(node)
{
    // Mouse Over...

    try
    {
        // Set Cursor...
        node.style.cursor = "pointer";

        // Get Nodes Data Array Index...
        var index = this.getNodeIndex(node.id);

        // Set Fading In...
        this.data[index][1] = true;

        // Set Start Opacity...
        this.data[index][2] = parseFloat(document.getElementById(this.data[index][5]).style.opacity) * 100;

        // Set Start Time...
        this.data[index][3] = new Date().getTime();

        // Set Default Text Container Values...
        //-----

        if (this.hasDesc)
        {
            // Set Fading In...
            this.data[0][1] = false;

            // Set Start Opacity...
            this.data[0][2] = parseFloat(document.getElementById(this.data[0][8]).style.opacity) * 100;

            // Set Start Time...
            this.data[0][3] = new Date().getTime();
        }

        //-----
    }
    catch (e)
    {
        alert("NavWheel.mouseOver Error: " + e.message);
    }
};

//--------------------------------------------------------------------------------

WillCurson.NavWheel.prototype.mouseOut = function(node)
{
    // Mouse Out...

    try
    {
        // Set Cursor...
        node.style.cursor = "default";

        // Get Nodes Data Array Index...
        var index = this.getNodeIndex(node.id);
        
        // Set Fading In...
        this.data[index][1] = false;

        // Set Start Opacity...
        this.data[index][2] = parseFloat(document.getElementById(this.data[index][5]).style.opacity) * 100;

        // Set Start Time...
        this.data[index][3] = new Date().getTime();

        // Set Default Text Container Values...
        //-----

        if (this.hasDesc)
        {
            // Set Fading In...
            this.data[0][1] = true;

            // Set Start Opacity...
            this.data[0][2] = parseFloat(document.getElementById(this.data[0][8]).style.opacity) * 100;

            // Set Start Time...
            this.data[0][3] = new Date().getTime();
        }

        //-----
    }
    catch (e)
    {
        alert("NavWheel.mouseOut Error: " + e.message);
    }
};

//--------------------------------------------------------------------------------

WillCurson.NavWheel.prototype.animate = function()
{
    // Mouse Out...

    try
    {
        // Cycle Through Data Array...

        var index = 0;

        /*
        
        Nav Wheel Data Array Entry...

        data[index][0] -> Mask Image Element ID...
        data[index][1] -> Fade In Boolean Flag...
        data[index][2] -> Start Opacity...
        data[index][3] -> Start Time...
        data[index][4] -> Icon Image Element ID...
        data[index][5] -> Icon Image Alt Element ID...
        data[index][6] -> Text Label Element ID...
        data[index][7] -> Text Label Alt Element ID...
        data[index][8] -> Description Text Element ID...

        */

        for (index = 0; index < this.data.length; index++)
        {
            // Get The Current Opacity...

            var nodeOpacity = 0.0;

            // Get Alt Icon Opacity Or Description Text Opacity...

            if (this.data[index][5] != null)
            {
                var nodeOpacity = parseFloat(document.getElementById(this.data[index][5]).style.opacity) * 100;
            }
            else
            {
                var nodeOpacity = parseFloat(document.getElementById(this.data[index][8]).style.opacity) * 100;
            }

            if (this.data[index][1] && (parseInt(nodeOpacity) < 100))
            {
                // (Is Fading In And Node Opacity Is Less Than 100)...
                // Fading In...

                // Calculate Frequency...
                var freq = Math.PI / (2 * this.ANIM_LENGTH);

                // Elapsed Time...
                var elapsedTime = new Date().getTime() - this.data[index][3];

                // f Value...
                var f = Math.abs(Math.sin(elapsedTime * freq));

                // Mamimum Displacement Distance...
                var disp = 100 - this.data[index][2];

                // Calculate Opacity...
                var opacity = Math.round(f * disp + parseInt(this.data[index][2]));

                if (this.data[index][5] != null)
                {
                    // Set Description Text Div Opacity...

                    document.getElementById(this.data[index][5]).style.opacity = (opacity / 100);

                    if (this.isIE8)
                    {
                        document.getElementById(this.data[index][5]).style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ")";
                    }
                }

                if (this.data[index][7] != null)
                {
                    // Set Alt Image Opacity...

                    document.getElementById(this.data[index][7]).style.opacity = (opacity / 100);

                    if (this.isIE8)
                    {
                        document.getElementById(this.data[index][7]).style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ")";
                    }
                }

                if (this.data[index][8] != null)
                {
                    // Set Alt Label Opacity...

                    document.getElementById(this.data[index][8]).style.opacity = (opacity / 100);

                    if (this.isIE8)
                    {
                        document.getElementById(this.data[index][8]).style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ")";
                    }
                }
            }
            else if (!this.data[index][1] && (parseInt(nodeOpacity) > 0))
            {
                // (Is Not Fading In And Node Opacity Is Greater Than 0)...
                // Fading Out...

                // Calculate Frequency...
                var freq = Math.PI / (2 * this.ANIM_LENGTH);

                // Elapsed Time...
                var elapsedTime = new Date().getTime() - this.data[index][3];

                // f Value...
                var f = Math.abs(Math.sin(elapsedTime * freq));

                // Mamimum Displacement Distance...
                var disp = 0 - this.data[index][2];

                // Calculate Opacity...
                var opacity = Math.round(f * disp + parseInt(this.data[index][2]));

                if (this.data[index][5] != null)
                {
                    // Set Description Text Div Opacity...

                    document.getElementById(this.data[index][5]).style.opacity = (opacity / 100);

                    if (this.isIE8)
                    {
                        document.getElementById(this.data[index][5]).style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ")";
                    }
                }

                if (this.data[index][7] != null)
                {
                    // Set Alt Image Opacity...

                    document.getElementById(this.data[index][7]).style.opacity = (opacity / 100);

                    if (this.isIE8)
                    {
                        document.getElementById(this.data[index][7]).style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ")";
                    }
                }

                if (this.data[index][8] != null)
                {
                    // Set Alt Label Opacity...

                    document.getElementById(this.data[index][8]).style.opacity = (opacity / 100);

                    if (this.isIE8)
                    {
                        document.getElementById(this.data[index][8]).style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ")";
                    }
                }
            }
        }
    }
    catch (e)
    {
        alert("NavWheel.animate Error: " + e.message);
    }
};

//--------------------------------------------------------------------------------

WillCurson.NavWheel.prototype.getNodeIndex = function(nodeID)
{
    // Find Next Node ID Array Array...

    try
    {
        var index = 0;

        // Find The Index Which Corrisponds To The Node ID...

        for (index = 0; index < this.data.length; index++)
        {
            if (this.data[index][0] == nodeID)
            {
                return index;

                break;
            }
        }

        return null;
    }
    catch (e)
    {
        alert("NavWheel.getNodeIndex Error: " + e.message);
    }
};

//--------------------------------------------------------------------------------
