// Seattle Opera Event Tracking API
var OperaEventTracking = {
	
	// Track user clicking to view video / begin playback
	VideoStart: function(video){
		var args = {
			category: 'video+flash', 
			action: 'video+start', 
			label: video
		}
		OperaEventTracking._trackEvent(args);
	},

	// Track user viewing 50% of a video
	VideoHalf: function(video){
		var args = {
			category: 'video+flash',
			action: 'video+played+halfway',
			label: video
		}
		OperaEventTracking._trackEvent(args);
	},

	// Track user completing viewing a video
	VideoEnd: function(video){
		var args = {
			category: 'video+flash',
			action: 'video+played+complete',
			label: video
		}
		OperaEventTracking._trackEvent(args);
	},

	
	// Private
	_trackEvent: function(oArgs) {
		//var _source = oArgs.source || document.location.pathname+document.location.search+document.location.hash;
		var _source = oArgs.source || document.location.pathname;
		var _category = oArgs.category || '';	// RIA object
		var _action = oArgs.action || ''; 		// what is happening
		var _label = oArgs.label || '';			// what is being viewed

		// Instantiate GA tracking call
		// var sReport = encodeURI('/_event/category='+_category+'/action='+_action+'/label='+_label);
		var sReport = encodeURI(_source+'?utm_category='+_category+'&utm_action='+_action+'&utm_label='+_label);
				
		try{
			urchinTracker(sReport);
			// Only uncomment during debugging
			//console.log("urchinTracker being called with: %s", sReport);
			//console.dir(oArgs);
		}
		catch(e){}
	}
}

/* Sample tracking calls
Under Construction
*/

// prevent errors from console calls to browsers that don't provide firebug's debugging console.
if (!window.console || !console.firebug)
{
	var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
	"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

	window.console = {};
	for (var i = 0; i < names.length; ++i)
		window.console[names[i]] = function() {}
}

