/*=============================================================================

			 	 TITLE:		NetMediaOne - Core Library
		  MODIFIED:		2008.04.09
		 AUTHOR(S): 	Graham Wheeler - NetMediaOne - www.netmediaone.com
		  REQUIRES:		jQuery 1.2

=============================================================================*/

var NMO = {
	
	version: "1.5.0",
	rootPath: "",
	I18N: { 
		lang: "EN",
		EN: {},
		ES: {}
	},
	resizeTimer: null,
	documentMouseX: 0,
	documentMouseY: 0,
	windowMouseX: 0,
	windowMouseY: 0,
 
	newInstance: function(obj) {
		function F() {};
		F.prototype = obj;
		return new F();
	},
	
	// Inter-Context Communicator - Holds objects addressable across IFRAME boundaries
	ICC: (parent.NMO != null)?parent.NMO.ICC:{},

	stripeTable: function(selector) {
		$(selector + " tr:visible:even").addClass("Even");
		$(selector + " tr:visible:odd").removeClass("Odd");
	},
	
	//
	// getPageScroll()
	// Returns array with x,y page scroll values.
	// Core code from - quirksmode.org
	//
	getPageScroll: function() {
	
		var yScroll;
	
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {
			yScroll = document.documentElement.scrollTop;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
		}
	
		arrayPageScroll = new Array('',yScroll) 
		return arrayPageScroll;
	},
	
	init: function() {

		$("body").addClass("HasJS");

		$("body *:first-child").addClass("FirstChild");
		$("body *:last-child").addClass("LastChild");

		NMO.stripeTable(".Chart tbody");
		
		$(document).mousemove( function(e) {
			NMO.documentMouseX = e.pageX;
			NMO.documentMouseY = e.pageY;
			NMO.windowMouseX = e.clientX;
			NMO.windowMouseY = e.clientY;
		} );
		
		$(".OtherOptionDescription").css('visibility','hidden');
		$(".OtherOption").click( function() {
			var desc = $(this).next(".OtherOptionDescription");
			if ( this.checked ) {
				desc.css('visibility','visible').addClass("Required");
			} else {
				desc.css('visibility','hidden').removeClass("Required");
			}	
		});
		
		NMO.Alerts = new AlertBox("#alerts");
		NMO.Alerts.Show();

	}
	
};


// Simple StringBuffer Class
function StringBuffer(str) {
	this.buffer = [];
	this.buffer.push(str);
	return this;
};
StringBuffer.prototype = {

	append: function(str) {
		this.buffer.push(str);
		return this;
	},
	
	clear: function() {
		this.buffer.clear();
		return this;
	},
	
	toString: function() {
		return this.buffer.join("");
	}

};

function AlertBox(elementRef) {
	this.container = $(elementRef);
	return this;
};
AlertBox.prototype = {
	
	Clear: function() {
		this.container.aspx("");
	},
	
	Add: function( msg, css, err ) {
		
		var message = '<div class="StatusMessage '+css+'" style="display: none;">\n';
		message += '<a onclick="jQuery(this.parentNode).slideUp(\'slow\', function() { jQuery(this).remove();});" class="CloseLink" title="Hide Notification"><img src="'+NMO.rootPath+'design/notification_close.png" alt="Hide Notification"></a>';
		message += '<p class="Msg">'+msg+'</p>\n';
		if ( error != undefined ) {
			message += '<a onclick="jQuery(this.parentNode).find(\'.ExceptionDetails\').slideToggle(\'slow\');" class="ShowDetailsLink" title="Show Details"><img src="'+NMO.rootPath+'design/notification_details.png" alt="Show Details"></a>\n';
			message += '<p class="ExceptionDetails">'+err+'</p>\n';
		}
		message += '</div>\n';
		this.container.append( message );
		this.Show();
		
	},
	
	Show: function() {
		this.container.find(".StatusMessage").fadeIn("slow").each( function() {
			var el = this;
			//$(this).hide().show();
			setTimeout( function() { 
				$(el).not(".Sticky").slideUp( "normal", function() {
					$(el).remove();
				}	);
			}, 5000 );
		} );
	}

};

$( function() { NMO.init(); } );
