/*=============================================================================

			 	 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: "",
	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").removeClass("Odd");
		$(selector + " tr:visible:odd").addClass("Odd").removeClass("Even");
	},
	
		
	init: function() {

		$("body").addClass("HasJS");

		$("body *:first-child").addClass("FirstChild");
		$("body *:last-child").addClass("LastChild");

		NMO.stripeTable(".Striped tbody");
		
		$(document).mousemove( function(e) {
			NMO.documentMouseX = e.pageX;
			NMO.documentMouseY = e.pageY;
			NMO.windowMouseX = e.clientX;
			NMO.windowMouseY = e.clientY;
		} );
		
		$("dl.Expandable dt").each( function() {
		
			$(this).click( function(e) {
			
				$(this).next().slideToggle("fast");
			
			} );
		
		} );
		
		if ( $.facebox ) {
			$("a[rel*=facebox]").facebox();
		}
		
		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.html("");
	},
	
	Add: function( msg, css, err ) {
		
		var message = new StringBuffer('<div class="StatusMessage ').append(css).append('">\n');
		message.append('  <a onclick="jQuery(this.parentNode).slideUp(\'slow\', function() { this.remove(); } );" class="CloseLink">X</a>\n');
		message.append(msg).append('\n');
		message.append('<!-- ').append(err).append(' -->\n');
		message.append('</div>\n');
		this.container.append( message.toString() );
		this.Show();
		
	},
	
	Show: function() {
		
		this.container.find(".StatusMessage").slideDown( "slow", function() {
			var el = this;																																				
			setTimeout( function() { 
				$(el).not(".Sticky").slideUp( "slow", function() {
					$(el).remove();
				}	);
			}, 4000 );
		} );
		
	}

};


$( function() { NMO.init(); } );
