// <script>

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	//  Notification Area
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
	var Notification = new Object();
	
	Notification.Area = Class.create();
	Notification.Area.prototype = {
	
		initialize : function(options) {
			// apply default options
			this.options = Object.extend( {
				id          : "notificationArea",
				parent      : document.getElementsByTagName("body")[0],
				insertion   : "Bottom",
				showEffect  : "none",
				showOptions : {},
				hideEffect  : "none",
				hideOptions : {},
				alwaysShow  : false
			}, options || {});
			
			// apply default effect options for hide
			this.hideOptions = Object.extend( {
				afterFinish : this.clearContents
			}, this.options.hideOptions)
			
			this.parent = $(this.options.parent);
			
			if (this.options.insertion.toLowerCase() != "none") this.insertNotificationArea();
			this.element = $(this.options.id);
		},
		
		insertNotificationArea : function() {
			var html = "<div id='" + this.options.id + "' style='display:none'></div>";
			new Insertion[this.options.insertion](this.parent, html);
		},
		
		update : function(content) {
			this.clearContents();
			this.append(content);
		},
		
		append : function(content) {
			new Insertion.Bottom(this.element, content);
			if (this.isHidden()) {
				if (this.options.showEffect.toLowerCase() != "none") {
					Effect[this.options.showEffect](this.element, this.options.showOptions);
				} else {
					this.element.show();
				}
			}
		},
		
		clear : function() {
			if (this.options.hideEffect.toLowerCase() != "none") {
				Effect[this.options.hideEffect](this.element, this.options.hideOptions);
			} else {
				if (!this.options.alwaysShow) this.element.hide();
				this.clearContents();
			}
		},
		
		clearContents : function() {
			this.element.update("");
		},
		
		isHidden : function() {
			return (!this.element.visible());
		},
		
		remove : function() {
			this.element.remove();
		},
		
		handleValidationErrors : function(errors){
		
			var output = '';
			
			// remove undefined errors		
			var _errors = errors.findAll(function(error){
				return (typeof error != 'undefined');
			});
			
			// build li's
			_errors.each(function(error, index){
				if (_errors.length==1){
					output += "<li class='only'>" + error.message + "</li>";
				}
				else if(index==0){
					output += "<li class='first'>" + error.message + "</li>";
				}
				else if ((index-1)==_errors.length){
					output += "<li class='last'>" + error.message + "</li>";
				}
				else{
					output += "<li>" + error.message + "</li>"
				}
			});
			
			output = "<ul>" + output + "</ul>"
			
			this.update(output);
				
			if (errors.length == 0) this.clear();
		}
	
	}; // end Notification.Area
	
	
