/*=============================================================================

			 	 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");
		$(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).pngFix();
		
		$("a.ViewerLink, .ViewerLinkCollection a, .lazyest_thumb_view a").fancybox({
			overlayColor: '#000',
			overlayOpacity: 0.80,
			padding: 30,
			'hideOnContentClick': true,
			titlePosition: 'inside',
			titleFormat: function(title, currentArray, currentIndex, currentOpts) {
				return '';
			}
		});
		
		$(document).mousemove( function(e) {
			NMO.documentMouseX = e.pageX;
			NMO.documentMouseY = e.pageY;
			NMO.windowMouseX = e.clientX;
			NMO.windowMouseY = e.clientY;
		} );
		
		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).fadeOut(\'slow\');" 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").show().each( function() {
			var el = this;																																				
			setTimeout( function() { 
				$(el).not(".Sticky").fadeOut( 5000, function() {
					$(el).remove();
				}	);
			}, 1000 );
		} );
		
	}

};


$( function() { NMO.init(); } );

