/****************************************************
 * Creates a modal popup box for Static events.		*
 * Must be instatiated as an object (new stc.modal)	*
 ****************************************************/
 
 
 // If the stc namespace doesn't already exist, create it.
 
 if(!stc) var stc = new Object();
 
 // Create the class constructor
 stc.modal = function(){
 	
 }
 
 // Attach the properties
 stc.modal.prototype = {
 	
 	// Future-proofing by allowing the css namespace to be modified :-)
 	cssName: "static",
 	
 	// Let's give the box a title, mmkay?
 	boxTitle: this.cssName+" modal dialogue box",
 	
 	// Initialize the content variable
 	content: "",
 	
 	// Initialize and create the modal box
 	create: function() {
 		
 		// Check to see if there's already a modal box open
 		if(document.getElementById(this.cssName+"_modal_bounder")) {
 			this.flash();
 			return false;
 		}
 		
 		// Check to make sure content has been specified
 		if(this.content == "") {
 			return;
 		}
 		
 		// Create the bounding box
 		var bounder = document.createElement("div");
 		bounder.id = this.cssName+"_modal_bounder";
 		YAHOO.util.Dom.setStyle(bounder, "opacity", "0");
 		YAHOO.util.Dom.setStyle(bounder, "position", "absolute");
 		
 		// Create the content holder
 		var contHolder = document.createElement("div");
 		contHolder.id = this.cssName+"_modal_content";
 		contHolder.innerHTML = '<div class="roundedBorder"><table><tbody><tr><td class="tl"></td><td class="b"></td><td class="tr"></td></tr><tr><td class="b"></td><td class="body"><div id="'+this.cssName+'_modal_closer"><a href="#"><span>close</span></a></div><div id="'+this.cssName+'_modal_title"><span>'+this.boxTitle+'</span></div>'+this.content+'</td><td class="b"></td></tr><tr><td class="bl"></td><td class="b"></td><td class="br"></td></tr></tbody></table></div>';
 		
 		bounder.appendChild(contHolder);
 		
 		document.body.appendChild(bounder);
 		var closerBox = document.getElementById(this.cssName+'_modal_closer');
 		YAHOO.util.Event.addListener(closerBox, "click", this.destroy, bounder);
 		this.appear();
 		return true;
 	},
 	
 	// Let's make the box show up now.
 	appear: function() {
 		var modalBox = document.getElementById(this.cssName+"_modal_bounder");
 		
 		var boxBounds = YAHOO.util.Dom.getRegion(modalBox);
 		var contBounds = YAHOO.util.Dom.getViewportWidth();
 		var scrollPos = YAHOO.util.Dom.getDocumentScrollTop();
 		
 		var boxMid = (boxBounds.right-boxBounds.left)/2;
 		var contMid = contBounds/2;
 		var boxLeft = contMid-boxMid;
 		var boxTop = scrollPos+100;
 		YAHOO.util.Dom.setStyle(modalBox, "left", boxLeft+"px");
 		YAHOO.util.Dom.setStyle(modalBox, "top", boxTop+"px");
 		
 		
 		var newAttributes = {
		   opacity: { from:0, to: 1 }
		};
		
		var newAnim = new YAHOO.util.Anim(modalBox, newAttributes);
		newAnim.duration = .5;
		newAnim.animate();	
 	},
 	
 	// If there's already a modal window open of the current instance, flash the open window.
 	flash: function() {
 		var modalBox = document.getElementById(this.cssName+"_modal_bounder");
 		var flashAmt = 200;
 		YAHOO.util.Dom.setStyle(modalBox, 'opacity', '.5');
 		var flashTimer = setTimeout(function(){
 			YAHOO.util.Dom.setStyle(modalBox, 'opacity', '1');
 			var flashTimer1 = setTimeout(function(){
 				YAHOO.util.Dom.setStyle(modalBox, 'opacity', '.5');
 				var flashTimer2 = setTimeout(function(){
 					YAHOO.util.Dom.setStyle(modalBox, 'opacity', '1');
 				}, flashAmt);
 			}, flashAmt);
 		}, flashAmt);
 	},
 	
 	// Fade out and remove it from the DOM
 	destroy: function(e,contObj) {
 		if(e) YAHOO.util.Event.preventDefault(e);
 		var modalBox = this.cssName?document.getElementById(this.cssName+"_modal_bounder"):contObj;
 		var newAttributes = {
		   opacity: { from:1, to: 0 }
		};
		
		var newAnim = new YAHOO.util.Anim(modalBox, newAttributes);
		newAnim.duration = .5;
		newAnim.onComplete.subscribe(function(){modalBox.parentNode.removeChild(modalBox);});
		newAnim.animate();	
 	}
 	
 };