﻿//**********************************
//  CONSTRUCTOR
//**********************************
function NavRollover(oControl, oRootElement) {


    //************************************
    //  PROPERTIES
    //************************************
    var _oControl = oControl;
    var _oRootElement = oRootElement;
    var _oScope = this;
    
    //NAV ELEMENTS
    var _oNavRollOver = new Object();
    var _aNavAnimationOut = new Object(); 
    var _aNavAnimationIn = new Object();
   
    //CUSTOM CLASS
    var _overEvent = new Events(_oControl, _oRootElement);
    
   
    
    //************************************
    //  PROPERTIES
    //************************************
    
    
    this.addNavRollOver = function(oNavRollOver) {_oNavRollOver = oNavRollOver;};
    this.navRollOver = function() {return _oNavRollOver;};
    
    
    //ANIMATION
    this.addNavIn = function(aNavAnimationIn) {_aNavAnimationIn = aNavAnimationIn;};
    this.navIn = function() {return _aNavAnimationIn;};
    
    this.addNavOut = function(aNavAnimationOut) {_aNavAnimationOut = aNavAnimationOut;};
    this.navOut = function() {return _aNavAnimationOut;};
    
    
    //************************************
    //  GETTER / SETTERS
    //************************************
    
    //************************************
    //  PRIVATE
    //************************************
    
    //************************************
    //  SHOW NAV INITIALLY
    //************************************
    
    function initialNavView() {
        // initiateRollOverListener();
        initiateTimerEvent().StartTimer();
    }
    
    //************************************
    //  ROLLOVER EVENT LISTENER
    //************************************
    function initiateRollOverListener() {
        //PROPERTIES
        var oTarget = _oScope.navRollOver();

        //MOUSE MOVE EVENT       
        onMouseMoveEvent = function(events, arg) {
            //CALL FOR TIMER TO PLA
            initiateTimerEvent().StartTimer();
            removeEventListener();
        }
        
       //REMOVE EVENT LISTENER
       removeEventListener = function() {
            _overEvent.remove("OVER_EVENT");
       }
       
       //INITIATE LISTENER
       _overEvent.add("OVER_EVENT", oTarget, "MouseMove", onMouseMoveEvent);
    }
 
    
    //***********************************
    //  TIMER EVENT 
    //***********************************
    function initiateTimerEvent() {
        if(!window.SilverlightTimer) {
            window.SilverlightTimer = {};
        };
        
        SilverlightTimer.Scene = function() {};
        SilverlightTimer.Scene.prototype = {
        
            handleLoad: function(plugIn, userContext, rootElement) {
                this.plugIn = plugIn;
            }
        }
        
        var nCounterLimit = 5;
        var nCounter = 0;
        
        //SET INTERVAL
       this.StartTimer = function() {
         //  alert("Starting Timer");
         navAnimationIn();
            oTimer = window.setInterval(navHideEvent, 1000);
        }
        
        //CLEAR INTERVAL
        this.StopTimer = function() {
            window.clearInterval(oTimer);
        }
        
        //COUNTING;
        function navHideEvent() {
            nCounter++;
            if(nCounter > nCounterLimit) {
                StopTimer();
                navAnimationOut();
                nCounter = 0;
                initiateRollOverListener();
            } 
        }
        
        return this;
    
    }
    
    
    //************************************
    //  ANIMATION
    //***********************************

    function navAnimationIn() {
        var oTarget = _oScope.navIn();
        oTarget.Begin();
    
    }
    
    function navAnimationOut() {
         var oTarget = _oScope.navOut();
          oTarget.Begin();
    }

    //************************************
    //  PUBLIC
    //************************************
    
    
    //***********************************
    //  INITIATE EVENT
    //***********************************
    this.initiate = function() {
      // 
      initialNavView();
    }




}