var MONITUS = {
	_version: 4,
	_objectQueue: new Array(),
	internal: {
		_test_object: function(pObjectName) {
			try {
				eval("var vObject = window." + pObjectName + ";");
				//window.DEBUG += '[test - OK]';
				return vObject;
			} catch(e) {
				//window.DEBUG += '[test - ERR ['+e+']]';
				return null;
			}
		},
		_wait_object: function(pQueueIndex) {
			if((pQueueIndex >= 0) && (pQueueIndex < MONITUS._objectQueue.length)) {
				var vSpecs = MONITUS._objectQueue[pQueueIndex];
				var vObject = MONITUS.internal._test_object(vSpecs.object);
				//window.DEBUG += '[['+pQueueIndex+' / '+MONITUS._objectQueue.length+'][MONITUS.internal._wait_object(' + pQueueIndex + ');]['+vObject+']]';
				if(!vObject) window.setTimeout("MONITUS.internal._wait_object(" + pQueueIndex + ");", 1000);
				else {
					MONITUS._objectQueue.splice(pQueueIndex, 1);
					vSpecs.args.unshift(vObject);
					vSpecs.callback.apply(this, vSpecs.args);
				}
			}
		}
	},
	
	community: {
		utilities: {
			non_null_string: function(pString, pDefault) {
				if(!pDefault) pDefault = "";
				return (pString ? pString : pDefault);
			},
			wait_object: function(pObjectName, pCallBack, pArguments) {
				var vObject = MONITUS.internal._test_object(pObjectName);
				if(vObject) {
					pArguments.unshift(vObject);
					pCallBack.apply(this, pArguments);
				} else {
					var vIndex = MONITUS._objectQueue.length;
					MONITUS._objectQueue[vIndex] = {object: pObjectName, callback: pCallBack, args: pArguments};
					setTimeout("MONITUS.internal._wait_object(" + vIndex + ");", 10);
				}
			}
		},
		
		ga: {
			track_event: function(pTrackerObject, pEventCategory, pEventAction, pEventLabel) {
				if(pEventCategory && pEventAction && (pEventCategory != "") && (pEventAction != "")) {
					if(!pTrackerObject || (typeof(pTrackerObject) == "undefined") || (typeof(pTrackerObject._trackEvent) != "function")) MONITUS.community.utilities.wait_object(pTrackerObject, MONITUS.community.ga.track_event, [pEventCategory, pEventAction, MONITUS.community.utilities.non_null_string(pEventLabel)]);
					else pTrackerObject._trackEvent(pEventCategory, pEventAction, MONITUS.community.utilities.non_null_string(pEventLabel));
				}
			}
		},
		
		gwo: {
			track_variation_as_event: function(pTrackerObject, pExperimentName, pVariationName) {
				window.DEBUG = '';
				MONITUS.community.ga.track_event(pTrackerObject, pExperimentName, pVariationName);
			}
		},
		
		yahoo: {
			page_id: function() {
				var vTokens;
				if(window.location.search && (window.location.search.match(/(sectionId\=[^&]*)/) || window.location.pathname.match(/\/wg\-order/))) {
					vTokens = window.location.search.match(/(sectionId\=[^&]*)/);
					if(vTokens) return vTokens[1];
					else return "ysco.cart";
				} else {
					vTokens = window.location.pathname.match(/([^\/\.]+)\..+?$/);
					if(vTokens) return vTokens[1];
					else return "homepage";
				}
			},
			track_add_to_cart: function(pTrackerObject, pOptionalEventAction, pOptionalEventLabel, pOptionalEventCategory) {
				MONITUS.community.ga.track_event(pTrackerObject, MONITUS.community.utilities.non_null_string(pOptionalEventCategory, "Add to Cart"), MONITUS.community.utilities.non_null_string(pOptionalEventAction, MONITUS.community.yahoo.page_id()), MONITUS.community.utilities.non_null_string(pOptionalEventLabel));
				return true;
			},
			track_click_to_enlarge: function(pTrackerObject, pOptionalEventAction, pOptionalEventLabel, pOptionalEventCategory) {
				MONITUS.community.ga.track_event(pTrackerObject, MONITUS.community.utilities.non_null_string(pOptionalEventCategory, "Click to enlarge"), MONITUS.community.utilities.non_null_string(pOptionalEventAction, "clicked"), MONITUS.community.utilities.non_null_string(pOptionalEventLabel, MONITUS.community.yahoo.page_id()));
				return true;
			}
		}
	}
};