

/**
 * Returns TRUE if the string is completely empty
 */
String.prototype.Empty = function() { return (this.replace(/^\s+|\s+$/g,"") == "" ? true : false); }



/**
 * Blackboard object
 */
var Blackboard = {

	/**
	 * Width of chalk/content area
     * @access public
	 * @var integer
	 */
	width : 520,
	
	/**
	 * Height of chalk/content area
     * @access public
	 * @var integer
	 */
	height : 452,
	
	/**
	 * Border total left & right or top & bottom
     * @access public
	 * @var integer
	 */
	border : 0,

	/**
     * @access public
	 * @var string
	 */
	information : "",

	/**
     * @access public
	 * @var string
	 */
	join_now : "",

	/**
     * @access public
	 * @var string
	 */
 	buy_ticket : "",

	/**
     * @access public
	 * @var string
	 */
	textarea : "",
	
	/**
     * @access public
	 * @var string
	 */
	button : "",

	/**
     * @access public
	 * @var string
	 */
	capture : false,

	/**
     * @access public
	 * @var string
	 */
	captured_data : "",
	
	
	/**
	 * Returns the amount of height/width the user has travelled down/across the page
	 * @return integer
	 */
	ScrollTop : function()
	{
		var scroll = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
		return (scroll ? scroll : 0);
	},

	/**
	 * Returns the amount of height/width the user has travelled down/across the page
	 * @return integer
	 */
	ScrollLeft : function()
	{
		var scroll = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft;
		return (scroll ? scroll : 0);
	},

	/**
	 * Returns the inner height or width
	 * @return integer
	 */
	InnerHeight : function()
	{	
		// window.innerWidth/Height = Non-IE 
		// document.documentElement.clientWidth/Height = IE6+ in 'standards compliant mode'
		// document.body.clientWidth/Height = IE4 Compatible
		var dim = window.innerHeight || (document.documentElement && document.documentElement.clientHeight) || (document.body && document.body.clientHeight);
		return (dim ? dim : 0);
	},

	/**
	 * Returns the inner height or width
	 * @return integer
	 */
	InnerWidth : function()
	{	
		// window.innerWidth/Height = Non-IE
		// document.documentElement.clientWidth/Height = IE6+ in 'standards compliant mode'
		// document.body.clientWidth/Height = IE4 Compatible
		var dim = window.innerWidth || (document.documentElement && document.documentElement.clientWidth) || (document.body && document.body.clientWidth);
		return (dim ? dim : 0);
	},

	/**
	 * Return the amount of hieght the user has traveled down the page
	 * @return integer
	 */
	FullHeight : function()
	{	
		var dim = this.InnerHeight();				
		if (document.body.offsetHeight > dim) dim = document.body.offsetHeight;
		return (dim ? dim : 0);
	},

	/**
	 * Return the amount of hieght the user has traveled down the page
	 * @return integer
	 */
	FullWidth : function()
	{	
		var dim = this.InnerWidth();
		if (document.body.offsetWidth > dim) dim = document.body.offsetWidth;
		return (dim ? dim : 0);
	},

	/**
	 * Return the amount of hieght the user has traveled down the page
	 * @return integer
	 */
	Capture : function()
	{	
		this.captured_data = $("blackboard_textarea").value;
	},

	/**
	 * Return the amount of hieght the user has traveled down the page
	 * @return integer
	 */
	GetCaptured : function()
	{	
		return this.captured_data;
	},
	
	/**
	 * Create/append the outlay that will blank out the entire page
	 * @param object obj
	 */
	Overlay : function()
	{
		// locate the body node
		var body = document.getElementsByTagName("body")[0];
		
		// generate a new overlay DIV
		var div = document.createElement("div");
			div.id = "blackboard";
			div.style.height = this.FullHeight() + "px";
						
		// place an iframe of equal size inside the DIV- this is a hack for IE6, drop-down boxes appear above DIV's
		var iframe = document.createElement("iframe");
			iframe.setAttribute("frameborder", 0);
			iframe.setAttribute("width", 100 + "%");//this.Full("width"));
			iframe.setAttribute("height", this.FullHeight());
					
		// append the iframe to the DIV
		div.appendChild(iframe);
		
		// append the DIV to the body, this will overlay the entire veiwable area
		body.appendChild(div);
	},
		
	
	/**
	 * Updates the GLOBAL CURRENCY
	 * @param object obj
	 */
	Show : function()
	{
		// no blackboards can already exist
		if ($("blackboard") == null)
		{
			
			// if an object has been parsed, run through the elements to see if that can bee asssigned
			if (arguments[0] != null && typeof(arguments[0]) == "object")
			{
				if (arguments[0]["width"] != null && arguments[0]["width"].toString().IsInteger()) this.width = arguments[0]["width"];
				if (arguments[0]["height"] != null && arguments[0]["height"].toString().IsInteger()) this.height = arguments[0]["height"];
				if (arguments[0]["border"] != null && arguments[0]["border"].toString().IsInteger()) this.border = arguments[0]["border"];
				if (arguments[0]["title"] != null) this.title = arguments[0]["title"];
				if (arguments[0]["message"] != null) this.message = arguments[0]["message"];
				if (arguments[0]["textarea"] != null) this.textarea = arguments[0]["textarea"];
				if (arguments[0]["button"] != null) this.button = arguments[0]["button"];
				if (arguments[0]["capture"] != null) this.capture = arguments[0]["capture"];
				
				if (arguments[0]["information"] != null) this.information = arguments[0]["information"];
				if (arguments[0]["buy_ticket"] != null) this.buy_ticket = arguments[0]["buy_ticket"];
				if (arguments[0]["join_now"] != null) this.join_now = arguments[0]["join_now"];				
			}
			
			// overlay the entire page with a grey mist
			this.Overlay();
			
			// locate the body node
			var body = document.getElementsByTagName("body")[0];

			// content area
			var content = document.createElement("div");
				content.setAttribute("id", "chalk_content");
						
				content.innerHTML = this.information + 
									"<p><a href=\"" + this.join_now + "\">Join Now</a> <a href=\"" + this.join_now + "\" class=\"join_link\">Join Now</a></p>" +
									"<p class=\"last\"><a href=\"" + this.buy_ticket + "\">Continue to BUY TICKET</a> &nbsp;or&nbsp; <a href=\"#\" onclick=\"Blackboard.Kill();\">Close</a></p></div>";

				if (!this.textarea.Empty()) content.appendChild(textarea);
				if (!this.button.Empty()) content.appendChild(button);
			
				
			// entire chalk container
			var container = document.createElement("div");
				container.id = "chalk";
				container.style.height = this.height + "px";
				container.style.width = this.width + "px";
				container.style.borderWidth = this.border + "px "+ this.border +"px "+ this.border +"px "+ this.border +"px";
				
			// calculate the margin (distance) from the top of page to the top of the box
			var marginTop =  ( (this.InnerHeight()/2) - ((this.height)/2) + this.ScrollTop())-this.border;
				container.style.marginTop = (marginTop < 0 ? 0 : marginTop) + "px";
			
			// calculate the margin (distance) from the left of page to the left of the box
			var marginLeft = ( (this.InnerWidth()/2) - ((this.width)/2) + this.ScrollLeft())-this.border;
				container.style.marginLeft = (marginLeft < 0 ? 0 : marginLeft) + "px";
			
			container.appendChild(content); // first append the content

			body.appendChild(container); // append container to the body tag
		}		
	},
	
	
	/**
	 * Kill the blackboard
	 */
	Kill : function()
	{
		var body = document.getElementsByTagName("body")[0];
		if ($("blackboard") != null) body.removeChild($("blackboard"));
		if ($("chalk") != null) body.removeChild($("chalk"));
		
		this.width = 520;
		this.height = 452;
		this.border = 3;
		this.title = "title";
		this.message = "message";
		this.textarea = "";
		this.button = "";
		this.capture = false;		
	},
	
	
	Calibrate : function()
	{
		// re-calculate the top margin for the chalk board
		var marginTop =  ( (this.InnerHeight()/2) - ((this.height)/2) + this.ScrollTop())-this.border;
		if ($("chalk") != null) $("chalk").style.marginTop = (marginTop < 0 ? 0 : marginTop) + "px";
		
		// re-calculate the left margin for the chalk board
		var marginLeft = ( (this.InnerWidth()/2) - ((this.width)/2) + this.ScrollLeft())-this.border;
		if ($("chalk") != null) $("chalk").style.marginLeft = (marginLeft < 0 ? 0 : marginLeft) + "px";
		
		// make sure the blackboard is re-sized, so in all browsers like Opera it covers the entire back screen
		if ($("blackboard") != null && this.FullHeight() > $("blackboard").style.height.replace(/px/, ""))
			$("blackboard").style.height = this.FullHeight() + "px";
	}	
	
	
}