/*Configure Omniture Account*/
com.mtvi.reporting.Account={
	name:'viamtvtr3s',
	dynamic:'true',
	list:'viamtvtr3sdev=mtvtr3s-jd,mtvtr3s-jq,mtvtr3s-new-d,mtvtr3s-new-q,mtvtr3sx-jd',
	filters:'javascript:,mtvtr3s.com,mtvi.com',
	trackExternalLinks: true,
	trackInlineStats: true
};
var dispatcher = new com.mtvi.reporting.Dispatcher();
com.mtvi.config.qs=com.mtvi.util.queryStringToHash(window.location.search);
com.mtvi.util.addOnloadEvent(function(){dispatcher.registerLinks()});

var grdFlg = 0;

var REPORTING = {
	events : { },
	makeCall : function() { },
	repeatCall : function() { }
};

var EVENT_ID = null;
var DATA_OBJECT = null;
// called by the app

REPORTING.makeCall = function (event_id, data_object) {
	// store these in global variables
	EVENT_ID = event_id;
	DATA_OBJECT = data_object;
	// bail out if event_id is unknown
	if (typeof(this.events[event_id]) == "undefined") return false;

	// setup page variables
	this.events[event_id].populateData(data_object);
	this.events[event_id].setPageVariables();

	dispatcher.setAttribute("pageName",this.events[event_id].generatePageName());

	dispatcher.setAttribute("currencyCode","USD");
	// send page event
	if (this.events[event_id].event_type == "PAGE") {
		// zero-out link event stuff
		dispatcher.setAttribute("linkType","");
		dispatcher.setAttribute("lnk","");

		var pageURL = this.events[event_id].generatePageURL();

		var hier1 = (pageURL.charAt(0) == "/") ? pageURL.substring(1, pageURL.length) : pageURL;
		hier1 = (hier1.charAt(hier1.length) == "/") ? hier1.substring(0, hier1.length - 1) : hier1;
		dispatcher.setAttribute("hier1",hier1);


	// send link event
	} else if (this.events[event_id].event_type == "LINK") {
	
		dispatcher.setAttribute("linkType","o");
		//s_lnk = s_co(s_wd); // this is no good
		dispatcher.setAttribute("hier1","");
	// unknown event type
	} else {
		return false;
	}

	dispatcher.sendCall();

	// reset data for next call
	this.events[event_id].clearPageVariables();

	return true;
} // END: makeCall()
REPORTING.repeatCall = function () {
	REPORTING.makeCall(EVENT_ID,DATA_OBJECT);
}

function ReportingEvent(event_type, page_name_function, page_url_function, page_variable_function) {
	this.event_type = event_type; // "PAGE" or "LINK"

	this.generatePageName = page_name_function;
	this.generatePageURL = page_url_function;
	this.setPageVariables = page_variable_function;

	this.data = {}; // holds a copy of the data passed in (for use by methods of this object)
} // END: ReportingEventType()


ReportingEvent.prototype.populateData = function(data) {
	//var safePropNames2Clean=new Array("artist");
	for (var i in data) this.data[i] = data[i];//cleanData(data[i],safePropNames2Clean);
}; // END: populateData()


ReportingEvent.prototype.clearPageVariables = function() {
	this.data = { }; // reset data passed in by app
	dispatcher.clearProps();
	dispatcher.setAttribute("linkType","");
	dispatcher.setAttribute("lnk","");
	dispatcher.setAttribute("hier1","");
}; // END: clearPageVariables()

// =============================================================================

REPORTING.events['fbml_pv'] = new ReportingEvent(
	"PAGE",

	function() { // generatePageName()
		var fbmlParams;
		var fbmlVid = "";
		var pth = new Array();
		for (i in this.data){
			if (typeof this.data[i] != "object")
				pth.push(this.data[i]);
			else fbmlParams = this.data[i];
		}
		if(typeof pth[pth.length-1] == "undefined") pth.pop();
		if(typeof fbmlParams["videoVals"] != "undefined")
			fbmlVid = fbmlParams["videoVals"];
		// Akamai GUID
		var guid = new Image(); guid.src = "/global/guid/index.jhtml";
		
		return "/" + pth.join('/') + fbmlVid;
	},

	function() { // generatePageURL()
		var pth = new Array();
		for (i in this.data){
			if (typeof this.data[i] != "object")
				pth.push(this.data[i]);
		}
		if(typeof pth[pth.length-1] == "undefined") pth.pop();
		return pth.join('/');
	},

	function() { // setPageVariables()
		if (this.data['pageName'] == "index.jhtml") grdFlg = 0;
		else grdFlg += 1;
		if (grdFlg > 1) dispatcher.setAttribute("prop8","");
		dispatcher.setAttribute("channel",this.data['section_0']);
		for (i in this.data){
			if(typeof this.data[i] == "object"){
				dispatcher.setAttribute("prop1",typeof this.data[i]['artist']!='undefined'?this.data[i]['artist']:"");
				dispatcher.setAttribute("prop4",typeof this.data[i]['login']!='undefined'?this.data[i]['login']:"");
				dispatcher.setAttribute("prop5",typeof this.data[i]['zyg']!='undefined'?this.data[i]['zyg']:"");
				dispatcher.setAttribute("prop6",typeof this.data[i]['span']!='undefined'?this.data[i]['span']:"");
				dispatcher.setAttribute("prop7",typeof this.data[i]['demo']!='undefined'?this.data[i]['demo']:"");
				dispatcher.setAttribute("prop12",typeof this.data[i]['vidOrigin']!='undefined'?this.data[i]['vidOrigin']:"");
				dispatcher.setAttribute("prop16",typeof this.data[i]['partner']!='undefined'?this.data[i]['partner']:"");
				dispatcher.setAttribute("prop17",typeof this.data[i]['source']!='undefined'?this.data[i]['source']:"");
				dispatcher.setAttribute("prop18",typeof this.data[i]['story']!='undefined'?this.data[i]['story']:"");
				dispatcher.setAttribute("prop19",typeof this.data[i]['storyDate']!='undefined'?this.data[i]['storyDate']:"");
				dispatcher.setAttribute("prop22",typeof this.data[i]['rollUp']!='undefined'?this.data[i]['rollUp']:"");
				dispatcher.setAttribute("prop24",typeof this.data[i]['bps']!='undefined'?this.data[i]['bps']:"");
				dispatcher.setAttribute("prop25",typeof this.data[i]['fla']!='undefined'?this.data[i]['fla']:"");
				dispatcher.setAttribute("prop31",typeof this.data[i]['siteFormat']!='undefined'?this.data[i]['siteFormat']:"");
				dispatcher.setAttribute("eVar2",typeof this.data[i]['searchterm']!='undefined'?this.data[i]['searchterm']:"");
				dispatcher.setAttribute("eVar3",typeof this.data[i]['searchtype']!='undefined'?this.data[i]['searchtype']:"");
				dispatcher.setAttribute("eVar4",typeof this.data[i]['failedsearchterm']!='undefined'?this.data[i]['failedsearchterm']:"");
				dispatcher.setAttribute("campaign",com.mtvi.config.qs.extcmp?com.mtvi.config.qs.extcmp:"");

            if(typeof this.data[i]['votes']!= 'undefined'){
               if(typeof this.data[i]['gamename']!= 'undefined'){
				  dispatcher.setAttribute("prop11",this.data[i]['gamename'] + " : " + this.data[i]['votes']);
               } else {
				  dispatcher.setAttribute("prop11",'unknown gamename' + " : " + this.data[i]['votes']);
               }
            } 

            if(typeof this.data[i]['gamename']!= 'undefined'){
 			  dispatcher.setAttribute("prop22",this.data[i]['gamename']);
           }

			}
		}
		return;
	}
); // END: fbml_pv


REPORTING.events['fbml_grid'] = new ReportingEvent(
	"LINK",

	function() { // generatePageName()
		return "";
	},

	function() { // generatePageURL()
		return "";
	},

	function() { // setPageVariables()
		return;
	}
); // END: fbml grid

REPORTING.events['fbml_lev'] = new ReportingEvent(
	"LINK",

	function() { // generatePageName()
		var clkThru = typeof this.data['clickthru']!='undefined'?this.data['clickthru']:"";
		return clkThru;
	},

	function() { // generatePageURL()
		return;
	},

	function() { // setPageVariables()
		dispatcher.setAttribute("linkName",this.data['lev']);
		return;
	}
); // END: fbml grid
