/**
 * Description.
 * @module co2calc
 * @requires jQuery, tbelt, json
*/



(function($j, $tb) {
    /**
    * Widget is the core class for all CO2 Calculator widgets.
    * @class Widget
    * @namespace co2calc.widget 
    */
    co2calc.widget.Widget = (function() {
        /**
         * Constructor for the Widget instance. Extends the instance with the opts parameter; assigns Widget.jI; wraps the opts.totalEl and opts.averageEl in jQuery objects; adds the new instances to co2calc.widgets.
         * @for Widget
         * @constructor
         * @param opts {Object} An object whose properties are copied into the instance.
         */
		function Widget(opts) {
            var I = this;
            I.opts = opts;
            $j.extend(I, I.opts);
			I.jI=$j(I);
            //create the view manager
            I.views = new co2calc.widget.WidgetViewManager({ widget: I });

            if (I.name == null) I.name = "Widget" + new Date().getUTCMilliseconds().toString();

            I.totalEl = $j(I.totalEl);
            I.averageEl = $j(I.averageEl);

            co2calc.widgets.add(I);
        }

        Widget.prototype = {
            /**
             * This instance wrapped in a jQuery object. Assigned in the constructor. Used primarily for binding and triggering events.
             * @property jI
             * @type jQuery
             * @default null
             */
			jI:null,
			/**
			 * The name of this object's class.
			 * @property className
			 * @type String
			 * @default "Widget"
			 */
			className:"Widget",
			/**
            * The original opts parameter passed to the constructor.
            * @property opts
            * @type Object
            * @default null
            */
            opts: null,
			/**
			 * The name of this Widget instance.
			 * @property name
			 * @type String
			 * @default null
			 */
            name: null,
			/**
			 * Represents the element that Widget.total() writes the total value to.
			 * Should be a jQuery selector, HTML DOM Element, or jQuery element when passed to the constructor in the opts parameter.
			 * @property totalEl
			 * @type jQuery element
			 * @default null
			 */
            totalEl: null,
			/**
			 * Represents the element that Widget.average() writes the average value to.
			 * Should be a jQuery selector, HTML DOM Element, or jQuery element when passed to the constructor in the opts parameter.
			 * @property averageEl
			 * @type jQuery element
			 * @default null
			 */
            averageEl: null,
            /**
            * The WidgetViewManager instance for this Widget instance.
            * @property views
            * @type WidgetViewManager
            * @default null
            */
            views: null,
			/**
            * Updates the total, average, and co2calc.sessionData based on the user's input. Dispatches the Widget.update event.
            * @method update
            * @return {Widget} This widget instance.
            */
            update: function() {
				this.average(true);
				this.total(true);
				
				co2calc.sessionData(true);
				
				/**
				 * Fired when the Widget.update() method is called.
				 * @event Widget.update
				 */
				this.jI.trigger(this.className+".update");
				
				return this;
            },
			/**
			 * The calculated total of this widget. Set by the total() method.
			 * @property _total
			 * @type float
			 * @default 0.00
			 * @private
			 */
			_total:0.00,
            /**
            * Updates the widget total and/or returns the current value.
            * @method total
            * @param doUpdate {Boolean} Instructs the function to calculate the active view's total and update the _total property.
            * @return {float} Current widget's views.activeView.calculate().
            */
            total: function(doUpdate) {
				if(!doUpdate) return this._total;
				var I=this,
				total=I._total, totalHtml;
					
				if (I.views.activeView.formHandler.validate()) {
					total = I.views.activeView.calculate();					
				}

				totalHtml = I._prepNumString(total);
                I.totalEl.html(totalHtml);
				I._total=total;
				
				/**
				 * Fired when the Widget.total() method is called.
				 * @event Widget.total
				 * @param total {float} The value of Widget._total.
				 */
				I.jI.trigger(I.className+".total", total);	 
				
				return I._total;
            },
			/**
			 * The calculated average of this widget. Set by the average() method.
			 * @property _average
			 * @type float
			 * @default 0.00
			 * @private
			 */
			_average:0.00,			
            /**
            * Updates the widget average and/or returns the current value.
            * @method average
            * @param doUpdate {Boolean} Instructs the function to calculate the active view's average and update the _average property.
            * @return {float} Current widget's views.activeView.calculate(true).
            */
            average: function(doUpdate) {
				var I = this;
				if(!doUpdate) return I._average;
				
				I._average = I.views.activeView.calculate(true);											
			
				var averageHtml = I._prepNumString(I._average);					
				I.averageEl.html(averageHtml);				
				
				/**
				 * Fired when the Widget.average() method is called.
				 * @event Widget.average
				 * @param average {float} The value of Widget._average.
				 */
				I.jI.trigger(this.className+".average", I._average);	                
				
				return I._average;
            },
			/**
			 * Prepares a number string to be displayed as the total or average.
			 * @method _prepNumString
			 * @param {Number} num
			 * @return {String} Each character of the num parameter wrapped in a <span> tag.
			 * @private
			 */
			_prepNumString:function(num){
				var I = this,
				result = $tb.num.roundDecimal(num, 2)
				result = result.toString().replace(/(.*\.[0-9])$/, "$10");
				result = $tb.string.charNodes(result, "char char-");
				return result;
			},
			/**
			 * Gathers the properties of this object, primarily to be used by the JSON.stringify() method.
			 * @method toJSON
			 * @param {String} key
			 * @return {Object} An object containing the properties of this instance needed to save a user's session data.
			 */
			toJSON:function(key){
				var I = this,
				rootObj = new Object(),
				views = I.views.list(),
				view;
				//loop through this widget's views
				for(var v=0; v<views.length; v++){
					view = views[v];
					rootObj[view.name] = view.toJSON();	
								
				}
				//console.dir(rootObj)
				return rootObj;
			}
        };

        return Widget;


    })();




   



    /**
    * Represents a view state of a Widget instance.
    * @class WidgetView
    * @namespace co2calc.widget
    */
    co2calc.widget.WidgetView = (function() {
        /**
        * Constructor for the WidgetView instance. Extends the instance with the opts parameter; kicks off the WidgetView.init() function if WidgetView.autoInit is true.
        * @for WidgetView
        * @constructor
        * @param {Object} opts An object whose properties are copied into the instance.
        */
        function WidgetView(opts) {
            var I = this;
            I.opts = opts;
			opts.data = $j.extend({}, I.data, opts.data);
            $j.extend(I, I.opts);
			I.jI=$j(I);

            if (I.name == null) I.name = "WidgetView" + new Date().getUTCMilliseconds().toString();

            if(I.autoInit) I.init();
        }

        WidgetView.prototype = {
            /**
             * This instance wrapped in a jQuery object. Assigned in the constructor. Used primarily for binding and triggering events.
             * @property jI
             * @type jQuery
             * @default null
             */
			jI:null,
			/**
             * The name of this object's class.
             * @property className
             * @type String
             * @default WidgetView
             */
			className:"WidgetView",
			/**
			 * Determines whether the constructor runs the WidgetView.init() method.
			 * @property autoInit
			 * @type Boolean
			 * @default true
			 */
			autoInit:true,
			/**
			 * The original opts parameter passed to the constructor.
			 * @property opts
			 * @type Object
			 * @default null
			 */
			opts: null,
			/**
			 * The parent Widget of this WidgetView.
			 * @property widget
			 * @type Widget
			 * @default null
			 */
            widget: null,
			/**
			 * The name of this WidgetView instance.
			 * @property name
			 * @type String
			 * @default null
			 */
            name: null,
			/**
			 * Represents the element that triggers the visible state of this WidgetView;
			 * WidgetView.onTrigger() is assigned to this element's click event;
			 * Should be a jQuery selector, HTML DOM Element, or jQuery element when passed to the constructor in the opts parameter;
			 * @property trigger
			 * @type jQuery element
			 * @default null
			 */
            trigger: null,
			/**
			 * Represents the element that contains this WidgetView.
			 * Should be a jQuery selector, HTML DOM Element, or jQuery element when passed to the constructor in the opts parameter.
			 * @property container
			 * @type jQuery element
			 * @default null
			 */
            container: null,
			/**
			 * Represents the element where the total value is written to.
			 * Should be a jQuery selector, HTML DOM Element, or jQuery element when passed to the constructor in the opts parameter.
			 * @property totalEl
			 * @type jQuery element
			 * @default null
			 */
            totalEl: null,
			/**
			 * Represents the element where the average value is written to.
			 * Should be a jQuery selector, HTML DOM Element, or jQuery element when passed to the constructor in the opts parameter. 
			 * @property averageEl
			 * @type jQuery element
			 * @default null
			 */
            averageEl: null,
			/**
			 * The calculated total of this WidgetView. Assigned by WidgetView.calculate().
			 * @property total
			 * @type float
			 * @default 0.00
			 */
			total:0.00,
			/**
			 * The calculated average of this WidgetView. Assigned by WidgetView.calculate(true).
			 * @property average
			 * @type float
			 * @default 0.00
			 */
			average:0.00,
			/**
			 * Defines the static average to be displayed. If the value is >-1, calculate(true) always returns this.
			 * @property staticAverage
			 * @type float
			 * @default -1
			 */
			staticAverage:-1,
			/**
			 * The message box for this WidgetView.
			 * @property messageBox
			 * @type WidgetViewMessageBox
			 * @default null
			 */
			messageBox:null,
			/**
			 * The tbelt.form.Handler instance for this WidgetView. Generated automatically in WidgetView.init().
			 * @property formHandler
			 * @type tbelt.form.Handler
			 * @default null
			 */
            formHandler: null,
			/**
			 * Contains the WidgetViewDataItems for this WidgetView.
			 * @property data
			 * @type Object
			 * @default {}
			 */
            data: {},
			/**
			 * Initializes this WidgetView.
			 * @method init
			 * @return WidgetView This WidgetView instance.
			 */
            init: function() {
                var I = this;
                I.container = $j(I.container);

                //set the trigger action
                if (I.trigger) {
                    I.trigger = $j(I.trigger);
                    I.trigger.click(function(evt) {
                        evt.preventDefault();
                        I.widget.views.show(I.name);

                    });
                }

                //setup the form handler
                if (I.formHandler == null) I.formHandler = I._buildFormHandler(I.container);

                I.formHandler.onError = function(handler, errorMsg) {
                    //alert(errorMsg.replace(/<\/li>/ig, "\n").replace(/<li>/ig, ""));
					I.messageBox.show("<h4>We're having trouble using your input.</h4><ul>"+errorMsg+"</ul>");
                }
				
				I.formHandler.onSuccess = function(){
					I.messageBox.hide(true);
				}
				
				I.bindDataFields();
				
				//associate DataViewItems with this instance
				for(var item in I.data){
					I.data[item].view = I;
					I.data[item].name=item;
				}
			
				return I;
				
            },
            /**
            * Does nothing. This function should be overridden on all extension classes.
            * @method calculate
            * @return {Number} 0
            */
            calculate: function(isAverage) {
                var I = this;
                //customize this function for each WidgetView class extension
				if(isAverage && I.staticAverage>-1) return I.staticAverage;

                return 0;
            },
			
			/**
			 * Updates the fields property in the WidgetView.formHandler.
			 * @method updateFormHandler
			 * @return {WidgetView} The current WidgetView instance.
			 */
			updateFormHandler:function(){
				this.formHandler.fields=this._buildFormHandler(this.container).fields;
				return this;				
			},

			/**
            * Assigns the element property of the WidgetViewDataItems in WidgetView.data.
            * @method bindDataFields
            * @return {WidgetView} The current WidgetView instance.
            */			
			bindDataFields:function(){
				var I = this;
				
				for(var f=0; f<I.formHandler.fields.length; f++){
					var field = I.formHandler.fields[f];
					//map the element to its data reference
					dataRef = field.element.attr("data");
					if (dataRef && dataRef.match(/^\{\$.*/)) {
						dataRef = dataRef.replace(/^\{\$(.*)\}\s*?$/, "$1");
						if (I.data[dataRef]) {
							I.data[dataRef].element = field.element[0];
						}
					}
				}
				return I;
			},

            /**
            * Builds a tbelt.form.Handler with all of the input elements found in WidgetView.container.
            * @method _buildFormHandler
            * @param {HTMLElement} container The HTML element containing all of the fields you want included in the handler.
            * @return {tbelt.form.Handler} 
            * @private
            */
            _buildFormHandler: function(container) {
                container = $j(container);
                var I=this, fields = new Array(),
				nodeName, fieldType, handler, dataRef, element, field;
                container.find("*").each(function(i, e) {
                    nodeName = e.nodeName.toLowerCase();
					element = $j(e);
					fieldType = element.attr("type");					
                    
                    if (nodeName == "input" || nodeName == "textarea" || nodeName=="select") {
                        
						if(element.data("tbelt.form.Select") || element.data("tbelt.form.TextField") || element.data("tbelt.form.Checkbox")){
							//do not create a new input handler if one already exists
							field = element.data("tbelt.form.Select") || element.data("tbelt.form.TextField") || element.data("tbelt.form.Checkbox");
						}else{
							field = {
	                            element:element,
	                            required: (element.attr("required") == "true"),
	                            skin: "<span></span>",
	                            criteria: eval(element.attr("criteria")),
	                            errorMessage: element.attr("message")
	                        };
							
						}
						
						if(nodeName=="select")field.skin = false;
						
						fields.push(field);
						
                    }
                   
                });

				for(var f=0; f<fields.length;f++){
					field = fields[f];
					if (field.validate==null) 
					{
						nodeName = field.element[0].nodeName.toLowerCase();
						fieldType = field.element.attr("type");
						if (fieldType == "checkbox") {
							field = new $tb.form.Checkbox(field);
						} else if (fieldType == "radio") {
							field = new $tb.form.RadioButton(field);
						} else if (fieldType == "text" || nodeName == "textarea") {
							field = new $tb.form.TextField(field);
							
						} else if (nodeName == "select") {
							
							field = new $tb.form.Select(field);
						};
					}
					
				}

                handler = new $tb.form.Handler({
                    form: container,
                    fields: fields
                });
                return handler;
            },
			
			/**
			 * Tells the containing Widget.views (WidgetViewManager) to show this WidgetView.
			 * @method onTrigger
			 * @param {Object} evt
			 * @return null
			 */
            onTrigger: function(evt) {
                var I = this;
                I.widget.views.show(I.name);
                I.calculate();
            },
			
			/**
			 * Gathers the properties of this object, primarily to be used by the JSON.stringify() method.
			 * @param {String} key
			 * @return {Object} An object containing the properties of this instance needed to save a user's session data.
			 */
			toJSON:function(key){
				var I = this,
				rootObj = {
					total:I.total,
					average:I.average,
					active:(I == I.widget.views.activeView)
				},
				propName,
				prop,
				jsonProp;
				//loop through the view's data
				for(propName in I.data){
					try{
						
						prop = I.data[propName];
						rootObj[propName]=prop.toJSON();
						//console.dir(jsonProp);

					}catch(err){
						trace(I.className+".toJSON(): Could not save '"+propName+"' property.")
					}
					
				}
				//console.dir(rootObj)
				return rootObj;
			},
			
			/**
			 * Uses the data in co2calc.sessionData() for this object.
			 * @method fromJSON
			 * @param obj {Object} The object to be used to restore this object's data.
			 * @return WidgetView This WidgetView instance.
			 */
			fromJSON:function(obj){
				var I = this, 
				sessionData = JSON.parse(co2calc.sessionData()),
				field, dataRef, curItem, storItem, dispVal, storUserVal, storTypVal, curTypVal, curUserVal, nodeName, nodeType;
				
				if(obj==null && sessionData[I.widget.name] && sessionData[I.widget.name][I.name]) 
					obj = sessionData[I.widget.name][I.name];
				else return;
					
				if(obj.active) I.widget.views.show(I.name);	
				
				for(var itemName in I.data){
					I.data[itemName].fromJSON();
					//console.dir(I.data[itemName])
				}			
				
				return I;
			}


        }

        return WidgetView;


    })();
	
	

	
	/**
    * Represents a data value in WidgetView.data.
    * @class WidgetViewDataItem
    * @namespace co2calc.widget
    * 
    */
    co2calc.widget.WidgetViewDataItem = (function() {
        /**
         * Extends the instance with the opts parameter.
         * @for WidgetViewDataItem
         * @constructor
         * @param opts {Object} An object whose properties are copied into the instance.
         */
        function WidgetViewDataItem(opts) {
            var I = this;
            I.opts = opts;
            $j.extend(I, I.opts);
			
        }

        WidgetViewDataItem.prototype = {			
			/**
			 * The class name of this object.
			 */
			className:"WidgetViewDataItem",
			/**
			 * The name of this instance.
			 * @property name
			 * @type String
			 * @default null
			 */
			name:null,
			/**
			 * The original opts parameter passed to the constructor.
			 * @property opts
			 * @type Object
			 * @default null
			 */
			opts:null,		
			/**
			 * The containing WidgetView.
			 * @property view
			 * @type WidgetView
			 * @default null
			 */	
			view:null,
			/**
			 * The input/select/textarea element related to this WidgetViewDataItem. Assigned by WidgetView.bindDataFields().
			 * @property element
			 * @type jQuery element
			 * @default null 
			 */
			element:null,
			/**
			 * A function that returns the user defined value of this WidgetViewDataItem by checking WidgetViewDataItem.element. Defaults to WidgetViewDataItem.typical().
			 * @method user
			 * @return Object
			 */
			user:function(){
				var I = this, val=null;
				if(I.element){
					val = $j(I.element).val();
					if(I.element.type && I.element.type.toLowerCase()=="checkbox") val = I.element.checked;
					else if(!isNaN(parseFloat(val))) val = parseFloat(val);					
				}
				if(typeof(val)=="number"&&val==0){return 0}
				return ((val==""||val==null)) ? I.typical() : val;
			},
			
			/**
			 * A function that returns the typical value as defined by co2calc.dataSet. Should be extended by each WidgetViewDataItem instance by passing it in the opts parameter.
			 * @method typical
			 * @return null
			 */
			typical:function(){
				var I = this;
			},
			
			/**
			 * Gathers the properties of this object, primarily to be used by the JSON.stringify() method.
			 * @param {String} key
			 * @return {Object} An object containing the properties of this instance needed to save a user's session data.
			 */
			toJSON:function(key){
				var I = this, obj={
					user:$j(I.element).val(),
					typical:I.typical()		
				};
				//filter user value
				if(obj.user==null||obj.user==undefined||obj.user=="") delete obj.user;
				else if(I.element.type && I.element.type.toLowerCase()=="checkbox") obj.user = I.element.checked;
				else if(obj.user.match(/true|false/i)) obj.user = (obj.user.toLowerCase()=="true");
				else if(!isNaN(parseFloat(obj.user))) obj.user=parseFloat(obj.user);
				
				//filter typical value
				if(obj.typical==null||obj.typical==undefined) delete obj.typical;
				
				return obj;
			},
			
			/**
			 * Uses the data in co2calc.sessionData() for this object.
			 * @method fromJSON
			 * @param obj {Object} The object to be used to restore this object's data.
			 * @return WidgetViewDataItem This WidgetViewDataItem instance.
			 */
			fromJSON:function(obj){
				var I = this,
				sessionData = JSON.parse(co2calc.sessionData()),
				element = $j(I.element),
				storUserVal, storTypVal, curUserVal, curTypVal, dispVal;				
				
				/*console.dir({
					widget:I.view.widget.name,
					view:I.view.name,
					me:I.name
				})*/

				if(obj==null && sessionData[I.view.widget.name][I.view.name][I.name])
					obj = sessionData[I.view.widget.name][I.view.name][I.name];
				else return;
				
				storUserVal = obj.user;
				storTypVal = obj.typical;
				curUserVal = I.user();
				
				dispVal = storUserVal;
				
				if (element.length > 0 && element[0]!=document) {
					//trace(element[0])
					//trace(dispVal);
					if (element[0].type && element[0].type.toLowerCase() == "checkbox") {
						element.data("tbelt.form.Checkbox").checked(dispVal == true || dispVal == "true");
					} else if(dispVal && dispVal.toString().length>0)
						element.val(dispVal);
					else
						element.val("");
				}
					
				return I;
			}
		}
		
		return WidgetViewDataItem;
			
	})();
	
	
	
	/**
    * Manages a set of WidgetView objects in a Widget instance.
    * @class WidgetViewManager
    * @namespace co2calc.widget
    * 
    */
    co2calc.widget.WidgetViewManager = (function() {
        /**
        * Extends the instance with the opts parameter; assigns WidgetViewManager.jI.
        * @for WidgetViewManager
        * @constructor
        * @param opts {Object} This object's properties are copied to the WidgetViewManager instance.
        */
        function WidgetViewManager(opts) {
            var I = this;
            I.opts = opts;
            $j.extend(I, I.opts);
			I.jI=$j(I);
        }

        WidgetViewManager.prototype = {
            /**
             * This instance wrapped in a jQuery object. Assigned in the constructor. Used primarily for binding and triggering events.
             * @property jI
             * @type jQuery
             */
			jI:null,
			/**
			 * The name of this object's class.
			 * @property className
			 * @type String
			 */
			className:"WidgetViewManager",
			/**
			 * The original opts parameter passed to the constructor.
			 * @property opts
			 * @type Object
			 * @default null
			 */
			opts: null,
			/**
			 * The Widget using this WidgetViewManager.
			 * @property widget
			 * @type Widget
			 * @default null
			 */
            widget: null,
			/**
			 * The active/visible WidgetView managed by this WidgetViewManager.
			 * @property activeView
			 * @type WidgetView
			 * @default null
			 */
            activeView: null,
			/**
			 * Adds a WidgetView to this WidgetViewManager.
			 * @method add
			 * @param view {WidgetView} The WidgetView to add to this WidgetViewManager.
			 * @param isVisible {Boolean} Determines whether the WidgetView is made visible when it is added.
			 * @return WidgetViewManager This WidgetViewManager instance.
			 */
            add: function(view, isVisible) {
                var I = this;
                view.widget = I.widget;
                I[view.name] = view;
				
                if (isVisible) I.show(view.name);
                else I.hide(view.name);
				return I;
            },
			/**
			 * Removes a WidgetView from this WidgetViewManager.
			 * @method remove
			 * @param viewName {String} The name of the WidgetView to remove. See WidgetView.name. 
			 * @return WidgetViewManager This WidgetViewManager instance.
			 */
            remove: function(viewName) {
                delete this[viewName];
				return this;
            },
			/**
			 * Shows a WidgetView in this WidgetViewManager. Hides the current WidgetView and calls Widget.update().
			 * @param {Object} viewName the name of the WidgetView to show. See WidgetView.name.
			 * @return WidgetViewManager This WidgetViewManager instance.
			 */
            show: function(viewName) {
                var I = this,
                view = I[viewName];
                if (I.activeView && view.name == I.activeView.name) return view;

                view.container.css({ display: "block" });
                if (view.trigger) view.trigger.addClass("active");

                if (I.activeView != null) I.hide(I.activeView.name);

                I.activeView = view;

				I.widget.update();
				
				/**
				 * Fired when the WidgetViewManager.show() method is called.
				 * @event WidgetViewManager.show
				 * @param view {WidgetView} The WidgetView shown.
				 */
				I.jI.trigger(I.className+".show", view);
				
                return I;

            },
			/**
			 * Hides a WidgetView in this WidgetViewManager.
			 * @param {Object} viewName the name of the WidgetView to show. See WidgetView.name.
			 * @return WidgetViewManager This WidgetViewManager instance.
			 */
            hide: function(viewName) {
                var I = this,
                view = I[viewName];
                view.container.css({ display: "none" });

                if (view.trigger) view.trigger.removeClass("active");
				
				/**
				 * Fired when the WidgetViewManager.hide() method is called.
				 * @event WidgetViewManager.hide
				 * @param view {WidgetView} The WidgetView hidden.
				 */
				I.jI.trigger(I.className+".hide", view);
                return I;
            },
			/**
			 * Creates an Array of the WidgetViews in this WidgetViewManager.
			 * @method list
			 * @return Array The WidgetViews in this WidgetViewManager.
			 */
			list:function(){
				var I=this,
				viewList=[], 
				propName, 
				view;
				for (propName in I) {					
					view = I[propName];
					if (view.className && view.className==co2calc.widget.WidgetView.prototype.className) {
						viewList.push(view);
					}
				}
				//console.dir(viewList);
				return viewList;
			}


        }

        return WidgetViewManager;


    })();
	 
	
	
	/**
    * The message box for a WidgetView.
    * @class WidgetViewMessageBox
    * @namespace co2calc.widget
    * @extends co2calc.util.MessageBox
    */
    co2calc.widget.WidgetViewMessageBox = (function() {
        /**
        * Represents the message box for a WidgetView.
        * @for WidgetViewMessageBox
        * @constructor
        * @param {Object} opts This object's properties are copied to the WidgetViewManager instance.
        */
        function WidgetViewMessageBox(opts) {
            var I = this;
            co2calc.util.MessageBox.apply(I, arguments);

        }

        $j.extend(WidgetViewMessageBox.prototype, co2calc.util.MessageBox.prototype, {
            /**
			 * The name of this object's class.
			 * @property className
			 * @type String
			 */
			className:"WidgetViewMessageBox",
						
			/**
			 * The WidgetView related to this WidgetViewMessageBox.
			 * @property view
			 * @type WidgetView
			 * @default null
			 */
			view: null,
			
			/**
			 * Determine's whether the matte covers the entire document; Overrides WidgetViewMessageBox.matteFullScreen.
			 * @property matteFullScreen
			 * @type Boolean
			 * @default false
			 */
			matteFullScreen:false,
			
			/**
			 * Determines the speed at which the matte is shown/hidden.
			 * @property matteSpeed
			 * @type Number
			 * @default 400
			 */
			matteSpeed:400,
			/**
			 * Determines the opacity of the matte.
			 * @property matteOpacity
			 * @type Number
			 * @default .8
			 */
			matteOpacity:.8,
			/**
			 * When true, the WidgetViewMessageBox position will be adjusted when the window is scrolled.
			 * @property followScroll
			 * @type Boolean
			 * @default true
			 */
			followScroll:true,
			/**
			 * When true, the WidgetViewMessageBox position will be adjusted when the window is resized.
			 * @property followResize
			 * @type Boolean
			 * @default true
			 */
			followResize:true
			
			

        });

        return WidgetViewMessageBox;


    })();
	
	
	
	



})(jQuery, tbelt);


