Figment.Import('Disney.WDPRO.UI.InterfaceBlocking', Figment.getJSRoot() + '_global/');
Figment.Import('Disney.WDPRO.IBC.UI.DynamicPleaseWait', Figment.getJSRoot() + '_global/');
Figment.Import( 'Figment.Cookies', Figment.getJSRoot() + '_framework/' );

Figment.Namespace('Disney.WDPRO.IBC.UI.DFMMsging');

Disney.WDPRO.IBC.UI.DFMMsging = {

    MESSAGING_LAYER_ID: "dfmMsgingLayer",
    CLOSEBUTTON_ID: "dfmMsgingLayer_close",
    lightbox: null,
    dfmMsgingLayerDiv: null,
    topScrollPositionRestore: 0,
    getTopScrollPosition: function(){
    
        var fromWindow = window.pageYOffset ? window.pageYOffset : 0;
        var fromDoc = document.documentElement ? document.documentElement.scrollTop : 0;
        var fromBody = document.body ? document.body.scrollTop : 0;
        
        var result = fromWindow ? fromWindow : 0;
        if (fromDoc && (!result || (result > fromDoc))) {
            result = fromDoc;
        return fromBody && (!result || (result > fromBody)) ? fromBody : result;
        }
    },
    RENDER_Msging: function(){
        //get messaging layer
        Disney.WDPRO.IBC.UI.DFMMsging.dfmMsgingLayerDiv = document.getElementById(Disney.WDPRO.IBC.UI.DFMMsging.MESSAGING_LAYER_ID);
        //show messaging layer
        if (Disney.WDPRO.IBC.UI.DFMMsging.dfmMsgingLayerDiv !== null) {
            Disney.WDPRO.IBC.UI.DFMMsging.lightbox.addContent(Disney.WDPRO.IBC.UI.DFMMsging.dfmMsgingLayerDiv);
            Disney.WDPRO.IBC.UI.DFMMsging.lightbox.turnOn();
            
            //confirmation layer in IE displays too far up, so save scroll bar position, move scroll bar up and restore later
            Disney.WDPRO.IBC.UI.DFMMsging.topScrollPositionRestore = Disney.WDPRO.IBC.UI.DFMMsging.getTopScrollPosition();
            
            //scroll window all the way up
            window.scroll(0, 0);
        }
    },
    EVENT_onClose: function(evt){
        
        if(Figment.Cookies.readCookie("IBCWDWDFMMsgCookie") != "false"){
            Disney.WDPRO.IBC.UI.DFMMsging.lightbox.turnOff();
        }
        
        Figment.Cookies.createCookie("IBCWDWDFMMsgCookie", "false", 0, '.disney.go.com');
                
    },
    
    main: function(evt){
    	
        //get light box
        Disney.WDPRO.IBC.UI.DFMMsging.lightbox = new Disney.WDPRO.UI.InterfaceBlocking();
             
        
        //attach events to messaging layer button
        var closeButton = Figment.DOM.getElementById(Disney.WDPRO.IBC.UI.DFMMsging.CLOSEBUTTON_ID);
        if (closeButton !== null) {
            Figment.EventHandler.addEvent(closeButton, "click", Disney.WDPRO.IBC.UI.DFMMsging.EVENT_onClose);
        }

        //cleanup
        delete button;
        delete cancelButton;
        delete confirmButton;
    	
    	if(Figment.Cookies.readCookie("IBCWDWDFMMsgCookie") == "true"){
    		Disney.WDPRO.IBC.UI.DFMMsging.RENDER_Msging();
    	}
    }
    
};

Figment.EntryPoint.add(Disney.WDPRO.IBC.UI.DFMMsging);

//Figment.EntryPoint.add({main:function() { if(Figment.Cookies.readCookie("IBCWDWDFMMsgCookie") == "true"){ Disney.WDPRO.IBC.UI.DFMMsging.RENDER_Msging(); } }});
