/*=============================================================================

			 	 TITLE:		NetMediaOne - Core Library
		  MODIFIED:		2009.01.15
		 AUTHOR(S): 	Graham Wheeler - NetMediaOne - www.netmediaone.com
		  REQUIRES:		jQuery 1.3

=============================================================================*/

var NMO = {
	
	version: "2.0",
	rootPath: "",
	devMode: false,
	resizeTimer: null,
	documentMouseX: 0,
	documentMouseY: 0,
	windowMouseX: 0,
	windowMouseY: 0,
 
	newInstance: function(obj) {
		function F() {};
		F.prototype = obj;
		return new F();
	},
	
	exceptionTypes: {
		
		INVALID_FILE_TYPE: new Error("The specified file type is unknown or invalid!"),
		DON_QUIXOTE: new Error("JS interpreter appears to be operating in Quixotic Mode (reached the unreachable code)")
		
	},

	log: function( msg ) {

		if ( console != undefined ) {
			console.log(msg);
		} else if (devMode) {
			alert(msg);
		}
		
	},

	// Injects a resource reference (such as a script or stylesheet) into the document
	require: function( fileName, fileType ) {
		
		try {

			if ( fileType == undefined ) {
				if ( fileName.indexOf(".css") != -1 ) { fileType = "CSS"; }
				else if ( fileName.indexOf(".js") != -1 ) { fileType = "JS"; }
				else {
					throw( this.exceptionTypes.INVALID_FILE_TYPE );
				}
			}

			var isRemote = ( fileName.indexOf("http") == 0 );
	
			switch ( fileType ) {
	
				case "CSS": {
					
					if ( $("link[href*="+fileName+"]").length > 0 ) {
						return;
					} else {
						$("head").append('<link rel="stylesheet" type="text/css" href="'+((isRemote)?'':NMO.rootPath)+fileName+'">');
					}
					break;
					
				} 
				
				case "JS": {
		
					if ( $("script[src*="+fileName+"]").length > 0 ) {
						return;
					} else {
						$("head").append('<script type="text/javascript" src="'+((isRemote)?'':NMO.rootPath)+fileName+'"></script>');
					}
					break;
					
				} 
				
				default: {
					throw( this.exceptionTypes.DON_QUIXOTE );
					break;
				}
				
			}
			
		} catch(ex) {

			this.log("Error in NMO.require(): "+ex.message );
			
		}

	},	

	init: function() {

		$("body").addClass("HasJS");

		$(document).mousemove( function(e) {
			NMO.documentMouseX = e.pageX;
			NMO.documentMouseY = e.pageY;
			NMO.windowMouseX = e.clientX;
			NMO.windowMouseY = e.clientY;
		} );
		
		$("*:first-child").addClass("FirstChild");
		$("*:last-child").addClass("LastChild");

		$("table.Striped tbody > tr:visible:even").addClass("Even").removeClass("Odd");
		$("table.Striped tbody > tr:visible:odd").addClass("Odd").removeClass("Even");
		$("ul.Striped > li:visible:even").addClass("Even").removeClass("Odd");
		$("ul.Striped > li:visible:odd").addClass("Odd").removeClass("Even");

	}
	
};

//
// DEPRICATED
//
function viewPhoto( strURL, width, height ) {
	var picViewer = window.open( strURL, "photoWin", "toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width=" + width + ",height=" + height +",left=" + ((screen.width - width) / 2) + ",top=" + ((screen.height - height) / 2) );
	picViewer.focus();
}

$( function() { NMO.init(); } );
