(function(){

    aura.namespace('s100g');

    s100g.controlPanel = function(node)
    {

        this.isHiding = false;
        this.hidingTimeout = null;

        this.nodeHover = aura.byId(aura.dom.getAttribute(node, 'controlPanelHover'));
        this.nodeToggleOpen = aura.byId(aura.dom.getAttribute(node, 'controlPanelToggleOpen'));
        this.nodeToggleClose = aura.byId(aura.dom.getAttribute(node, 'controlPanelToggleClose'));
        this.nodeMenu = aura.byId(aura.dom.getAttribute(node, 'controlPanelMenu'));
        this.nodeTarget = aura.byId(aura.dom.getAttribute(node, 'controlPanelTarget'));

    }

    var cpp = s100g.controlPanel.prototype;

    cpp.start = function()
    {

        aura.log('word! started our control panel...');

        aura.style.set(this.nodeHover, 'z-index', '1000');
        aura.style.set(this.nodeHover, 'position', 'absolute');

        aura.style.hide(this.nodeHover);
        aura.style.hide(this.nodeMenu);

        aura.style.hide(this.nodeToggleOpen);
        aura.style.hide(this.nodeToggleClose);

        var _this = this;

        aura.event.on(this.nodeTarget, 'mouseover', function(e) { _this.handleNodeHoverShow(e); });

        aura.event.on(this.nodeHover, 'mouseover', function(e) { _this.handleNodeHoverShow(e); });

        aura.event.on(this.nodeHover, 'mouseout', function(e) { _this.handleNodeHoverHide(e); });

    };

    cpp.handleNodeHoverShow = function(e)
    {
        this.clearHidingTimeout();
        aura.style.show(this.nodeHover);
        aura.style.show(this.nodeToggleOpen);
        aura.event.stop(e);
    };

    cpp.handleNodeHoverHide = function(e)
    {
        this.setHidingTimeout();
        aura.event.stop(e);
    };

    cpp.setHidingTimeout = function()
    {
        var _this = this;
        this.clearHidingTimeout();
        this.hidingTimeout = setTimeout(function() {
            if ( ! _this.isHiding ) aura.log('Why not?');
            aura.style.hide(_this.nodeHover);
            aura.style.hide(_this.nodeToggleOpen);
            aura.style.hide(_this.nodeToggleClose);
        }, 200);
        this.isHiding = true;
    };
    cpp.clearHidingTimeout = function()
    {
        if ( this.isHiding )
        {
            if ( this.hidingTimeout ) clearTimeout(this.hidingTimeout);
            this.isHiding = false;
        }
    };


})();
