1 include(bbq.BBQ);
  2 include(bbq.util.Log);
  3 include(bbq.web.Browser);
  4 include(bbq.web.DOMUtil);
  5 include(bbq.language.Language);
  6 
  7 bbq.page.Page = new Class.create(/** @lends bbq.page.Page.prototype */ {
  8 	_modalLayer: null,
  9 	_modalLayerContents: null,
 10 	_fatalError: null,
 11 	_options: null,
 12 	
 13 	/**
 14 	 * Base class for creating per-page classes.
 15 	 *
 16 	 * @param {Object} args
 17 	 * @constructs
 18 	 */
 19 	initialize: function(args) {
 20 		//Log.info("Page constructor");
 21 		currentPage = this;
 22 		this._options = args ? args : {};
 23 
 24 		DOMUtil.checkDOM();
 25 	},
 26 
 27 	/**
 28 	 * Greys out the page and shows the passed element in the middle.  The passed element should
 29 	 * extend bbq.gui.GUIWidget
 30 	 * 
 31 	 * @param	 bbq.gui.GUIWidget} guiWidget
 32 	 */
 33 	addModalLayer: function(guiWidget) {
 34 		try {
 35 			if(!this._modalLayer) {
 36 				this._modalLayer = DOMUtil.createElement("div", {className: "modalLayer", style: {display: "none"}});
 37 				document.body.appendChild(this._modalLayer);
 38 			}
 39 
 40 			this._modalLayerContents = guiWidget;
 41 			this._modalLayerContents.setStyle("display", "none");
 42 			this._modalLayerContents.appendTo(document.body);
 43 
 44 			if(Browser.Mozilla && Browser.version < 3) { // stop scroll bars from showing through modal layer
 45 				$$(".ScrollableHolder").each(function(element){
 46 					element.style.overflow = "hidden";
 47 				});
 48 
 49 				$$(".FloatingWindow .ScrollableHolder").each(function(element){
 50 					element.style.overflow = "auto";
 51 				});
 52 			}
 53 
 54 			Effect.Appear(this._modalLayer, {
 55 				duration: 0.25,
 56 				to: 0.8
 57 			});
 58 			
 59 			Effect.Appear(this._modalLayerContents.getRootNode(), {
 60 				duration: 0.25,
 61 				to: 1
 62 			});
 63 
 64 			if(this._modalLayerContents.appear && this._modalLayerContents.disappear) {
 65 				// bbq.gui.FloatingWindow
 66 				this._modalLayerContents.appear();
 67 				this._modalLayerContents.registerOneTimeListener("onDisppear", this.clearModalLayer.bind(this));
 68 			}
 69 
 70 			return guiWidget;
 71 		} catch(e) {
 72 			Log.error("Error adding modal layer", e);
 73 		}
 74 	},
 75 
 76 	/**
 77 	 * Fades out the layers added by bbq.page.Page#addModalLayer
 78 	 *
 79 	 * @see bbq.page.Page#addModalLayer
 80 	 */
 81 	clearModalLayer: function() {
 82 		if(this._fatalError) {
 83 			return;
 84 		}
 85 		
 86 		if(this._modalLayer) {
 87 			Effect.Fade(this._modalLayer, {
 88 				duration: 0.25
 89 			});
 90 		}
 91 
 92 		if(this._modalLayerContents) {
 93 			Effect.Fade(this._modalLayerContents.getRootNode(), {
 94 				duration: 0.25
 95 			});
 96 		}
 97 
 98 		if(Browser.Mozilla && Browser.version < 3) {// re-enable scroll bars
 99 			$$(".ScrollableHolder").each(function(element){
100 				element.style.overflow = "auto";
101 			});
102 		}
103 
104 		setTimeout(this._removeModalLayer.bind(this), 600);
105 	},
106 
107 	/**
108 	 * Removes the layers added by com.proxim.page.Page.addModalLayer from the document tree
109 	 */
110 	_removeModalLayer: function() {
111 		if(this._fatalError) {
112 			return;
113 		}
114 
115 		if(!this._modalLayer || this._modalLayer.parentNode != document.body) {
116 			return;
117 		}
118 
119 		if(!this._modalLayerContents || !this._modalLayerContents.rootNode || this._modalLayerContents.rootNode.parentNode != document.body) {
120 			return;
121 		}
122 
123 		try {
124 			document.body.removeChild(this._modalLayer);
125 			document.body.removeChild(this._modalLayerContents.rootNode);
126 		} catch(e) {
127 			Log.warn("Exception thrown while removing modal layer - " + e);
128 		}
129 
130 		this._modalLayer = null;
131 		this._modalLayerContents = null;
132 	}
133 });
134