/*=============================================================================

			 	 TITLE:		NetMediaOne - Core Library
		  MODIFIED:		2007.09.12
		 AUTHOR(S): 	Graham Wheeler - NetMediaOne - www.netmediaone.com
		  REQUIRES:		$ 1.2

=============================================================================*/


jQuery.fn.hoverClass = function(c) {
	return this.each(function(){
		jQuery(this).hover(
			function() { jQuery(this).addClass(c); },
			function() { jQuery(this).removeClass(c); }
		);
	});
};

var NMO = {
	
	version: "1.2.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");
		$(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(".Striped tbody");
		
		$(document).mousemove( function(e) {
			NMO.documentMouseX = e.pageX;
			NMO.documentMouseY = e.pageY;
			NMO.windowMouseX = e.clientX;
			NMO.windowMouseY = e.clientY;
		} );

		jQuery(".DropDownMenu").after('<div class="DropDownMenuShadow"></div>');

		jQuery(".HasMenu").hover(
			function() {
				var m = jQuery(".DropDownMenu", this);
				var mS = jQuery(".DropDownMenuShadow", this);
				var h = m.height();
				var img = $(this).find("> a > img").get(0);
				img.src = img.src.replace(/_(off|on)\./, "_on.");
				m.fadeIn("fast");
				mS.height(h).show().fadeTo("fast", .25);
			},
			function() {
				var img = $(this).find("> a > img").get(0);
				img.src = img.src.replace( "_on.", (jQuery(this.parentNode).hasClass("Active"))?"_on.":"_off.");
				jQuery(".DropDownMenu, .DropDownMenuShadow", this).hide();
			}
		);

		jQuery(".NavButton:not(.HasMenu) a:not(.Active) img").hover(
			function() { this.src = this.src.replace("_off.", "_on."); },
			function() { this.src = this.src.replace("_on.", "_off."); }
		);
		
		$("#notificationBox").fadeIn( "slow", function() {
			setTimeout( function() { $("#notificationBox:not(.Sticky)").fadeOut("slow"); }, 4000 );
		} );

	}
	
};


// 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() { NMO.init(); } );

