/*=============================================================================

			 	 TITLE:		NetMediaOne - Core Library
		  MODIFIED:		2007.09.12
		 AUTHOR(S): 	Graham Wheeler - NetMediaOne - www.netmediaone.com
	DEPENDENCIES:		jQuery 1.2
									
=============================================================================*/

var NMO = {
	
	version: "1.2.0",
	rootPath: "",
	resizeTimer: null,
 
	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:{},
	
	onViewportResize: function() {
		if (NMO.resizeTimer) {
			clearTimeout(NMO.resizeTimer);
		}
		NMO.resizeTimer = setTimeout( function() { NMO.onViewportResizeDone(); }, 20 );
	},
	
	onViewportResizeDone: function() {
		// Toggle layout width between 760 and 960 pixels depending on viewport size, and show/hide select content
		var vw = $(window).width();
		if ( vw < 970 ) {
			$("#layoutWrapper").removeClass("Expanded");
			$("#layoutWrapper").addClass("Collapsed");
		} else {
			$("#layoutWrapper").addClass("Expanded");
			$("#layoutWrapper").removeClass("Collapsed");
		}
	},
	
	stripeTable: function(selector) {
		$(selector + " tr:visible:even").addClass("AltRow");
		$(selector + " tr:visible:odd").removeClass("AltRow");
	},
	
	updateCart: function() {
		
		var items = "-1:0";
		
		$(".CartItem tbody tr").each( function() {
		
			var partNum = $(this).attr("id").replace("","");
			var qty = $(this).find("input").get(0).value || 0;
			items += "|" + partNum + ":" + qty ;
		} );
		
		$("#txtCartItems").val(items);

	},
	
	init: function() {

		$(window).resize(NMO.onViewportResize);
		NMO.onViewportResizeDone();
		
		$(window).mousemove( function(e) {
			NMO.mouseX = e.clientX;
			NMO.mouseY = e.clientY;
		});
		
		NMO.stripeTable(".Chart tbody");
		
		$(".RoundedCorners").append('\n\t<div class="CornerTL"></div><div class="CornerTR"></div><div class="CornerBL"></div><div class="CornerBR">\n');
		
		$("body *:first-child:not(:only-child)").addClass("FirstChild");
		$("body *:last-child:not(:only-child):not(.Column)").addClass("LastChild");
		
		$("#notificationBox").fadeIn( "fast", 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("");
	}

};

jQuery( function() { NMO.init(); } );

