	////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		function copyPrototype(descendant, parent) { 
			var sConstructor = parent.toString(); 
			var aMatch = sConstructor.match( /\s*function (.*)\(/ ); 
			if ( aMatch != null ) { descendant.prototype[aMatch[1]] = parent; } 
			for (var m in parent.prototype) { 
				descendant.prototype[m] = parent.prototype[m]; 
			} 
		};
		
		copyPrototype(ErrorLayer, Layer); 
		
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//	LAYER 
	//	OBJECT
	//
		
		function Layer(name, mgmt, depth, parent_element, useCover, animate){
			this.isActive = false;
			this.activeContent = null;
			this.activeObject = null;
			this.useCover = false;
			this.animate = false;
			this.content = new Array();
			this.assoc = new Array();
			this.setParams(name, mgmt, depth, parent_element, useCover, animate);
			this.build(parent_element);
			this.ie = ($.browser.msie) ? true : false;
		}
		
		Layer.prototype = {
			//
			//	INITIALIZE PARAMETERS
			//
				setParams: function(name, mgmt, depth, parent_element, useCover, animate){
					this.mgmt = mgmt;
					this.animate = animate;
					this.useCover = useCover;
					this.name = name;
					this.error_box = null;
					this.test = "test"+mgmt.layer_count;
					this.parent_element = parent_element;
					this.depth = depth;
				},
				
			//	
			//	BUILD ELEMENTS
			//
				build: function(parent_element){
					//----	container elment
					var div = document.createElement('div');
					div.setAttribute("class", "layer");
					div.className = "layer";
					div.setAttribute('id', this.name + "_layer");
					div.id = this.name + "_layer";
					div.style.zIndex = String((this.depth*10) + 2);
					
					//---	display layer
					var display = document.createElement('div');
					display.setAttribute("class", "display_layer");
					display.className = "display_layer";
					display.setAttribute('id', this.name + "_display");
					display.id = this.name + "_display";
					display.style.display = "none";
					display.style.zIndex = String((this.depth*10) + 3);
					this.display = display;
					
					//---	display footer
					var footer = document.createElement('div');
					footer.setAttribute("class", "footer_layer");
					footer.className = "footer_layer";
					this.footer = footer;
					
					//---	display content
					var display_content = document.createElement('div');
					display_content.setAttribute("class", "content_layer");
					display_content.className = "content_layer";
					this.display_content = display_content;
					
					//---	cancel button
					var cancel = document.createElement('a');
					cancel.setAttribute("class", "cancel_btn");
					cancel.className = "cancel_btn";
					cancel.setAttribute('id', this.name + "_cancel");
					cancel.id = this.name + "_cancel";
					cancel.setAttribute('href', '#');
					cancel.href = "#";
					cancel.innerHTML = "cancel";
					cancel.setAttribute("onclick", this.mgmt.name + ".getLayer('" + this.name + "').hideContent()");
					
					if(cancel.attachEvent){
						var layer = this;
						var layer_mgmt = this.mgmt.name;
						cancel.attachEvent("onclick", function(){ layer.cancel_click(); } );
					}
					//cancel.onclick = "alert( " + cancel.className + "); ";//this.mgmt.name + ".getLayer('" + this.name + "').hideContent()";
					this.cancel = cancel;
					
					
					//---	ancor element
					var a = document.createElement('a');
					a.setAttribute('href', '#');
					a.href="#";
					a.style.display = "none";
					a.setAttribute("onclick", "layer_manager.getLayer('" + this.name + "').showError('<h1>showing error</h1>', 0)");
					a.onclick = "layer_manager.getLayer('" + this.name + "').showError('<h1>showing error</h1>', 0)";
					
					a.innerHTML = "here";
					
					//---	other content
					var messages = document.createElement('div');
					messages.style.display = "none";
					messages.setAttribute('class', 'messages');
					messages.className = "messages";
					
					var h2 = document.createElement('h2');
					messages.appendChild(h2);
					var message_cancel = document.createElement('a');
					message_cancel.setAttribute("class", "msg_cancel");
					message_cancel.className ="msg_cancel";
					message_cancel.innerHTML = "Cancel";
					if(message_cancel.attachEvent){
						var layer = this;
						message_cancel.attachEvent("onclick", function(){ layer.cancel_click(); } );
					}else{
						message_cancel.setAttribute("onclick", this.mgmt.name + ".getLayer('" + this.name + "').hideContent()");
					}
					//message_cancel.onclick = "onclick", this.mgmt.name + ".getLayer('" + this.name + "').hideContent()";
					
					var message_confirm = document.createElement('a');
					message_confirm.setAttribute("href", "#");
					message_confirm.href = "#";
					message_confirm.setAttribute("class", "msg_confirm");
					message_confirm.className = "msg_confirm";
					message_confirm.setAttribute("onclick", this.mgmt.name + ".getLayer('" + this.name + "').hideContent()");
					if(message_confirm.attachEvent){
						var layer = this;
						message_confirm.attachEvent("onclick", function(){ layer.cancel_click(); } );
					}
					//message_confirm.onclick = this.mgmt.name + ".getLayer('" + this.name + "').hideContent()";
					message_confirm.innerHTML = "Confirm";
					messages.appendChild(message_cancel);
					messages.appendChild(message_confirm);
					this.message_confirm = message_confirm;
					messages.style.zIndex = String((this.depth*10) + 4);
					
					div.appendChild(messages);
					div.appendChild(a);
					
					//---	associate instance vars
					this.messages_txt = h2;
					this.messages = messages;
					this.div = div;
					
					//---	setup cover if applicable
					if(this.useCover){
						var cover = document.createElement('div');
						cover.setAttribute('class', 'cover off');
						cover.className = "cover off";
						cover.setAttribute('id', this.name + '_cover');
						cover.id = this.name + "_cover";
						cover.style.zIndex = String((this.depth*10) + 1);
						this.cover = cover;
						this.div.appendChild(this.cover);
					}
					
					//---	add container to DOM
					this.footer.appendChild(this.cancel);
					this.display.appendChild(this.display_content);
					this.display.appendChild(this.footer);
					this.div.appendChild(this.display);
					this.parent_element.appendChild(this.div);
				},
			
			//
			//	TURN COVER ON
			//	
				cancel_click: function(){
					this.hideContent();
				},
				
			//
			//	TURN COVER ON
			//	
				cancel_test: function(l){
					l.hideContent();
				},	
			
			//
			//	TURN COVER ON
			//	
				coverOn: function(n, selected_content, content_array){
					var size = getPageSize();
					this.cover.setAttribute('class', 'cover on');
					this.cover.className = "cover on";
					var offset = this.ie ? -20 : -20;
					this.cover.style.height = (size[2] + offset) + 'px';
					//this.mgmt.setCover(this.cover);
					//this.cover.style.opacity = 0;
					$(this.cover).css("opacity", "0");
					var tmp = this;
					
						if(selected_content){
							$(this.cover).animate(
								{ 
								opacity: .8 
								},
								500, 
								function(){
									if(this.isError){
										tmp.createError("<h1>what?</h1>",0); 
									}else{
										var c = tmp.getContent(n);
										var a = tmp.getAssoc(n);
										if(!a&&!c){
											alert("No such content: animate");
										}else{
											tmp.displayContent(selected_content);
										}
									}
								}
							);
						}else{
							$(this.cover).animate(
								{ 
								opacity: .5 
								},
								500
							);
						}
					},
				
				//
				//	TURN COVER OFF
				//
					coverOff: function(){
						var tmp = this;
						$(this.cover).animate(
								{ 
								opacity: 0 
								},
								500, 
								function(){
									tmp.cover.setAttribute('class', 'cover off');
									tmp.cover.className = "cover off";
									tmp.mgmt.removeCover();
								}
						);
					},
					
				//
				//	FADE OUT CONTENT
				//
					contentOff: function(){
						var tmp = this;
						this.deleteContent();
						this.deleteMessage();
						if(!this.ie && this.activeContent){
							$(this.activeContent).animate(
									{ 
									opacity: 0 
									},
									500, 
									function(){
										tmp.deleteContent();
									}
							);
						}else{
							tmp.deleteContent();
						}
					},
					
				//
				//	FADE IN CONTENTthis.messages_txt.innerHTML = msg;
				//
					contentOn: function(c){
						var tmp = this;
						c.style.display = "block";
						c.style.visibility = "visible";
						this.activeContent = c;
						c.style.zIndex = this.display.style.zIndex;
						//$("#"+c.id).show();
						//c.opacity = 0;
						if(!this.ie){
							c.style.opacity = 0;
							$(c).animate(
									{ 
									opacity: 1
									},
									500, 
									function(){
									}
							);
						}else{
								
						}
					},	
					
				//
				//	FADE IN CONFIRM BOX
				//
					confirmOn: function(msg, follow, params){
						var tmp = this;
						this.messages.style.opacity = 0;
						this.messages.style.display = "block";
						this.messages.style.zIndex = (this.depth*10) + 8;
						this.messages_txt.innerHTML = msg;
						if(this.message_confirm.attachEvent){
							var layer = this;
							this.message_confirm.attachEvent("onclick", function(){ alert("hit"); } );
						}else{
							//this.message_confirm.setAttribute("onclick",  this.mgmt.name + ".getLayer('" + this.name + "').confirmMessage(" + follow + ", " + this.printParams(params) +")");
							this.message_confirm.setAttribute("onclick", this.mgmt.name + ".getLayer('" + this.name + "').confirmMessage(" + follow + ", " + this.printParams(params) +")");
						}
						
						//this.message_confirm.onclick = this.mgmt.name + ".getLayer('" + this.name + "').confirmMessage(" + follow + ", " + this.printParams(params) +")";
						$(this.messages).animate(
								{ 
								opacity: 1 
								},
								500, 
								function(){
								}
						);
					},
					
				//
				//	FADE IN ALERT BOX
				//
					alertOn: function(msg){
						var tmp = this;
						if(!this.alertBox){
							this.createAlertBox();
						}
						this.alertBox.style.opacity = 0;
						this.alertBox.style.display = "block";
						this.alertBox_txt.innerHTML = msg;
						//this.alertBox.setAttribute("onclick",  this.mgmt.name + ".getLayer('" + this.name + "').confirmMessage(" + follow + ", " + this.printParams(params) +")");
						$(this.alertBox).animate(
								{ 
								opacity: 1 
								},
								500, 
								function(){
								}
						);
					},	
					
					createAlertBox: function(msg){
						var alertBox = document.createElement('div');
						alertBox.style.display = "none";
						alertBox.setAttribute('class', 'messages');	
						alertBox.className = "messages";
						var alert_txt = document.createElement('h2');
						alertBox.appendChild(alert_txt);
						
						var ok = document.createElement('a');
						ok.setAttribute("href", "#");
						ok.href = "#";
						ok.setAttribute("class", "msg_confirm alert_ok");
						ok.className = "msg_confirm alert_ok";
						ok.setAttribute("onclick", this.mgmt.name + ".getLayer('" + this.name + "').hideContent()");
						if(ok.attachEvent){
							var layer = this;
							ok.attachEvent("onclick", function(){ layer.cancel_click(); } );
						}
						ok.innerHTML = "OK";
						alertBox.appendChild(ok);
						alertBox.style.zIndex = String((this.depth*10) + 4);
						this.alertBox = alertBox;
						this.alertBox_txt = alert_txt;
						this.div.appendChild(this.alertBox);
					},
					
				//
				//	ASSOCIATE CONTENT
				//
					associate: function(o){
						//alert(o.reference);
						var cancel = document.createElement('a');
						cancel.setAttribute("class", "cancel_btn");
						cancel.className = "cancel_btn";
						cancel.setAttribute('id', this.name + "_cancel");
						cancel.id = this.name + "_cancel";
						cancel.setAttribute('href', '#');
						cancel.href = "#x";
						cancel.innerHTML = "cancel";
						cancel.setAttribute("onclick", this.mgmt.name + ".getLayer('" + this.name + "').hideContent()");
						
						if(cancel.attachEvent){
							var layer = this;
							var layer_mgmt = this.mgmt.name;
							cancel.attachEvent("onclick", function(){ layer.cancel_click(); } );
						}
						
						if(o.hide){
							o.html.style.display = "none";
							o.html.style.opactiy = 0;
						}
						
						if(o.cancel && $("#"+o.reference + " " + o.cancel).length > 0 ){
							this.cancel_container = "#"+o.reference + " " + o.cancel;
							$(this.cancel_container).html(cancel);
							//$(this.cancel_container).append(this.cancel);
						}else{
							$("#"+o.reference+ " .wrap").append(this.cancel);	
						}
						o.html.style.zIndex = this.display.style.zIndex;
						var c = o;
						//c.html = html;
						//c.name = name;
						this.assoc.push(c);
					},
					
				//
				//	ADD CONTENT
				//
					addContent: function(o){
						var c = o;
						//c.html = html;
						//c.name = name;
						this.content.push(c);
					},
					
				//
				//	RETRIEVE CONTENT
				//
					getContent: function(name){
						for(i=0; i<this.content.length; i++){
							if(this.content[i].name==name){
								return this.content[i];
							}
						}
						return false;
					},
					
				//
				//	RETRIEVE ASSOCIATED CONTENT
				//
					getAssoc: function(name){
						for(i=0; i<this.assoc.length; i++){
							if(this.assoc[i].name==name){
								return this.assoc[i];
							}
						}
						return false;
					},
					
				//
				//	SHOW CONTENT
				//
					showContent: function(n){
						var c = this.getContent(n);
						if(c){
							
							if(this.useCover){
								this.coverOn(n, c, this.content);
							}
							
							if(!this.isActive){
								this.mgmt.showLayer(this.name);
							}
							return c;
						}else{
							alert(n + " not found.");
							return false;
						}
					},
					
				//
				//	SHOW ASSOCIATED CONTENT
				//
					showAssoc: function(n){
						var c = this.getAssoc(n);
						if(c){
							
							if(this.useCover){
								this.coverOn(n, c, this.assoc);
							}else{
								this.displayContent(c);
							}
							
							if(this.cancel_container){
								//$(this.cancel_container).append(this.cancel);
							}
							
							if(!this.isActive){
								this.mgmt.showLayer(this.name);
							}
							
						}else{
							alert(n + " not found.");
							return false;
						}
					},	
					
				//
				//	SHOW MESSAGE
				//
					showMessage: function(msg, follow, params){
						
						if(this.useCover){
							this.coverOn();
						}
						if(!this.isActive){
							this.mgmt.showLayer(this.name);
						}
						if(follow){
							this.confirmOn(msg, follow, params);
						}else{
							this.alertOn(msg);	
						}
					},
					
				//
				//	EXECUTE CONFIRMATION FUNCTION
				//
					confirmMessage: function(func, params){
						func(params);
						this.hideContent();
					},	
					
				//
				//	PRINT OBJECT PARAMETERS FOR ONCLICK FUNCTION
				//
					printParams: function(params){
						var param_string = "";
						var param_arr = new Array();
						for(v in params)
						{
							param_arr.push(String(v +": \""+params[v]+"\""));
						}
						return "{"+param_arr.join(", ")+"}";
					},	
					
				//
				//	HIDE CONTENT
				//	
					hideContent: function(name){
						this.isActive = false;
						this.contentOff();
						if(this.useCover){
							this.coverOff();
						}
						if(this.activeContent && this.activeObject.onHide){
							this.activeObject.onHide.call();	
						}
					},
					
				//
				//	ADD CONTENT TO DISPLAY LAYER
				//	
					displayContent: function(c){
						c.html.style.zIndex = this.display.style.zIndex;
						this.activeObject = c;
						//c.html.style.display = "block";
						this.contentOn(c.html);
						if(c.init){ c.init.call() };
						//alert(c.html.style.zIndex);
						/*
						this.display_content.innerHTML = String(c.html);//html;
						if(c.init){ c.init.call() };
						this.contentOn();
						*/
					},
					
				//
				//	REMOVE CONTENT FROM DISPLAY LAYER
				//	
					deleteContent: function(c){
						if(this.activeContent){
							this.activeContent.style.display = "none";
						}
					},
					
				//
				//	REMOVE CONTENT FROM DISPLAY LAYER
				//	
					deleteMessage: function(c){
						this.messages.style.display = "none";
						this.messages_txt.innerHTML = "";
						if(this.alertBox){
							this.alertBox.style.display = "none";
							this.alertBox_txt.innerHTML = "";
						}
					}
		}
		
		
	//
	//	ERROR
	//	LAYER
	//	CLASS
	//
	
		function ErrorLayer(name, mgmt, depth, parent_element, useCover, animate){
		}
		
		ErrorLayer.prototype = {
			
			/////////////////////////////////////////////////
			//	OVERRIDING FUNCTIONS
			/////////////////////////////////////////////////
			
			//
			//	ASSOCIATE CONTENT
			//
				addContent: function(msg, name, type){
					var c = {};
					c.html = msg;//new ErrorBox(msg, type, div, this, (this.depth*10) + 2);
					c.name = name;
					c.type = type;
					this.content.push(c);
				},
				
			//
			//	SHOW ERROR
			//	
				showError: function(msg, type){
					if(this.useCover){
						this.coverOn();
					}
					if(!this.isActive){
						this.mgmt.showLayer(name);
					}
					//var error_box = new ErrorBox(msg, type, div, this, (depth*10) + 2);
					//this.error_box = error_box;
				},
			
			//
			//	CREATE ERROR
			//
				createError: function(msg, type){
					var error_box = new ErrorBox(msg, type, div, this, (this.depth*10) + 2);	
					this.error_box = error_box;
				},
				
			//
			//	CLOSE ERROR
			//
				
				closeError: function(){
					if(this.error_box){
						this.error_box.error_close();
						this.error_box = null;
						this.coverOff();
					}
				}
		}
		
		
	//
	//	LAYER
	//	MANAGER
	//	CLASS
	//
	
		function LayerManager(p, name){
			if(p=="body"){
				p = document.body;
			}
			this.name = name;
			this.layers = new Array();
			this.layer_count = 0;
			this.coverOn = false;
			this.activeCover = null;
			this.timeout = null;
			this.addLayer = function(name, type, cover){
				if(cover == undefined){ cover = true; }
				var layer = new Layer(name, this, this.layer_count+1, p, cover);
				this.layers.push(layer);
				//alert(this.layers[this.layers.length-1].name);
				this.layer_count++;
				return layer;
			}
			this.getLayer = function(name){
				//alert(name);
				for(i=0; i<this.layers.length ;i++){
					if(this.layers[i].name==name){
						return this.layers[i];
					}
				}
				return false;
			}
			LayerManager.prototype.showLayer = function(name){
				var active = this.getLayer(name);
				active.isActive = true;
				active.div.style.display = "block";
			}
			LayerManager.prototype.setCover = function(c){
				this.activeCover = c;
				this.timeout = setTimeout("check_docHeight()", 50);
			}
			LayerManager.prototype.removeCover = function(){
				this.activeCover = null;
				clearTimeout(this.timeout);
			}
			LayerManager.prototype.list_layers = function(){
				//alert(this.layers.length);
				for(i=0;i<this.layers.length;i++){
					//alert(this.layers[i].name);	
				}
			}
			LayerManager.prototype.layer_resize = function(){
				//alert(this);
				if(this.coverOn){
				}
			}
			monitor_layer = this;
		}
		
		
	//
	//	ERROR
	//	BOX
	//	CLASS
	//
	
		function ErrorBox(message, type, parent_element, parent_object, depth){
			
			//	CREATE INSTANCE DIV
			var div = document.createElement('div');
			div.setAttribute('class', 'error_box');
			div.className = "error_box";
			div.style.zIndex = depth+1;
			
			//	SET TEXT
			div.innerHTML=message;
			
			//	CREATE BUTTON
			var btn = document.createElement('a');
			btn.setAttribute('href', '#');
			btn.href= "#";
			btn.innerHTML = "CLOSE";
			this.btn = btn;
			div.appendChild(btn);
			
			//	ADD TO DOM
			div.style.opacity = 0;
			parent_element.appendChild(div);
			$(div).animate(
								{ 
								opacity: .8 
								},
								500, 
								function(){
								}
						);
			
			//	INSTANCE VARS
			ErrorBox.prototype.div = div;
			ErrorBox.prototype.parent_element = parent_element;
			
			//	INSTANCE METHODS
			this.error_close = function(){
				var tmp = this;
				$(this.div).animate(
								{ 
								opacity: 0
								},
								500, 
								function(){
									tmp.parent_element.removeChild(tmp.div);
								}
						);
			}
			
			this.btn.setAttribute("onclick", "layer_manager.getLayer('" + parent_object.name + "').closeError()");
			this.btn.onclick = "layer_manager.getLayer('" + parent_object.name + "').closeError()";
			return this;
		}
	
	
	//
	//	CONTENT
	//	LAYER
	//	CLASS
	//
	
		function ContentLayer(html, parent_element){
			
			//	CREATE INSTANCE DIV
			var div = document.createElement('div');
			div.setAttribute('class', 'content_layer');
			div.className = "content_layer";
			
			//	SET TEXT
			div.innerHTML=html;
			
			//	CREATE BUTTON
			var btn = document.createElement('a');
			btn.setAttribute('href', '#');
			btn.href = "#";
			this.btn = btn;
		}
		
		
	/////////////////////////////////////////////////////////////////////////////////////////////////	
		
		function getPageSize(){
	
			var xScroll, yScroll;
			
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = document.body.scrollWidth;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				windowWidth = self.innerWidth;
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
		
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = windowWidth;
			} else {
				pageWidth = xScroll;
			}
		
		
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		}
		
		function check_docHeight(){
			var size = getPageSize();
			monitor_layer.getLayer("error").messages_txt.innerHTML = size[1];
			monitor_layer.activeCover.style.height = (size[1]-0)+ 'px';
			monitor_layer.timeout = setTimeout("check_docHeight()", 50);/**/
		}