

var Omniture = new Object;

//**************************
//CONFIG BELOW
//**************************

	Omniture.live = true; //force omniture to goto the live suite. leaving false wont stop it from sending to the live suite if the site is on the live server. 
	Omniture.livesite = /nintendo\.com$/; //regexp of site live url.
	Omniture.channel  = ""; //Site Section
	Omniture.prop1=""; //Product name
	Omniture.prop2=""; //Content type
	Omniture.prop5=""; //search keywords
	Omniture.prop6="us:en"; //Locale
	Omniture.prop7=""; //Compel product ID
	Omniture.prop10=""; //Game Title
	Omniture.prop11=""; //Game Genre
	Omniture.prop12=""; //Game Publisher
	Omniture.prop14=""; //Game detail type
	Omniture.prop16="us:nintendo"; //site name
	Omniture.prefix="us:ncom:";	
	Omniture.locale="us";

	
	var link_clubN = "http://club.nintendo.com";
	var link_newsletter = "http://www.nintendo.com/newsletters";
	var link_twitter = "http://twitter.com/home?status=";
	
//**************************
//END CONFIG - NO OTHER EDITING NECESSARY
//**************************


//INIT
if(!Omniture.live) {
	s=s_gi("ncomdev");
}

/*
if (window.location.host.toString().match(Omniture.livesite) || Omniture.live) {
		// AUTO
		document.write('<scr'+'ipt language="JavaScript" type="text/javascript" src="http://www.nintendo.com/consumer/assets/js/s_code.js"><\/scr'+'ipt>');
	} else {
		// ncomdev		
		document.write('<scr'+'ipt language="JavaScript" type="text/javascript" src="js/omniture/s_code.js"><\/scr'+'ipt>');
}
*/
//change reporting suite locale and reset default props. ie: prop6, prop16;
Omniture.setLocale = function (which) {
	var changeSuite;
	var changePrefix;
	switch(which) {
		case "us":
			changeSuite= "ncomglobal,ncomprod";
			changePrefix="us:ncom:";
			Omniture.prop6="us:en";
			Omniture.prop16="us:nintendo";
			Omniture.locale = "us";
			break;
		case "ca":
			changeSuite= "ncomglobal,ncomcaprod";
			changePrefix="ca:ncom:";
			Omniture.prop6="ca:en";
			Omniture.prop16="ca:nintendo";
			Omniture.locale = "ca";
			break;
		case "fr":
			changeSuite= "ncomglobal,ncomn3dsfr";
			changePrefix="ca:ncom:";
			Omniture.prop6="ca:en";
			Omniture.prop16="ca:nintendo";
			Omniture.locale = "fr";
			break;
		case "es":
			changeSuite= "ncomglobal,ncomn3dssp";
			changePrefix="mx:ncom:";
			Omniture.prop6="mx:en";
			Omniture.prop16="mx:nintendo";
			Omniture.locale = "es";
			break;	
		case "po":
			changeSuite= "ncomglobal,ncom3dsportuguese";
			changePrefix="br:ncom:";
			Omniture.prop6="br:po";
			Omniture.prop16="br:nintendo";
			Omniture.locale = "po";
			break;	
	}	
	
	s = (!Omniture.live) ? s_gi("ncomdev") : s_gi(changeSuite);
	
	Omniture.prefix=changePrefix;
}
//config common chan and props for each site section
Omniture.config = function () {	
	Omniture.clear();
	switch(arguments[0]) {
		case "country":
			Omniture.channel  = Omniture.prefix + 'country selector';
			Omniture.prop2= 'country selector';
			break;
		case "home":
			Omniture.channel  = Omniture.prefix + 'home';
			Omniture.prop2= 'site:home';
			break;
		case "sitemap":
			Omniture.channel  = Omniture.prefix + 'sitemap';
			Omniture.prop2= 'site:sitemap';
			break;
		case "esrb":
			Omniture.channel  = Omniture.prefix + 'esrb';
			Omniture.prop2= 'site:esrb';
			break;
		case "wii":
			Omniture.channel  = Omniture.prefix + 'wii';
			Omniture.prop1  = Omniture.prefix + 'wii hardware';
			Omniture.prop2= arguments[1]; //Section: wii:home, wii:console, wii:online, wii:channels, wii:channels			
			break;
		case "ds":
			Omniture.channel  = Omniture.prefix + 'ds';
			Omniture.prop1  = Omniture.prefix + 'ds hardware';
			Omniture.prop2= arguments[1]; //Section: ds:home, ds:systems, ds:online
			break;			
		case "3ds":
			Omniture.channel  = Omniture.prefix + '3ds';
			Omniture.prop1  = Omniture.prefix + 'ds hardware';
			Omniture.prop2= arguments[1]; //Section:  ds:systems
			break;
		case "games":
			Omniture.channel = Omniture.prefix + 'games';			
			Omniture.prop2= arguments[1]; //Content type: set to 'games:home', games:touch generations, games:wifi, games:nintendo points card
			break;
		case "games-giftfinder":
			Omniture.channel = Omniture.prefix + 'games';			
			Omniture.prop2= 'games:giftfinder';
			Omniture.prop4= 'giftfinder';
			break;
		case "games-guide":
			Omniture.channel = Omniture.prefix + 'games';			
			Omniture.prop2= 'games:gameguide';
			Omniture.prop4= 'gameguide'; 
			break;
		case "games-detail":
			Omniture.channel  = Omniture.prefix + 'games';	
			Omniture.prop1 = Omniture.prefix + ''+arguments[1].toLowerCase()+':'+arguments[3].toLowerCase(); //product name: e.g: us:ncom:<console>:<game title>
			Omniture.prop2 = "game:details";
			Omniture.prop7= arguments[2]; //compel id
			Omniture.prop10= arguments[3].toLowerCase(); //game title
			Omniture.prop11= arguments[4].toLowerCase(); //genre
			Omniture.prop12= arguments[5].toLowerCase(); //publisher
			Omniture.prop14= "home"; //game content type: set to 'HOME'
			Omniture.prop22= jQuery.trim(arguments[6].toLowerCase()); //platform: wii, ds, 3ds, wiiware, dsiware

			break;
		case "games-search":
			Omniture.channel  = Omniture.prefix + 'games';	
			Omniture.prop2 = "games:gameguide:search";
			Omniture.prop4 = "gameguide";
			if(typeof(arguments[1]) != 'undefined') {
				var keyTxt = arguments[1].toLowerCase(); //search keyword
			}else {
				var keyTxt = "";	
			}
			Omniture.prop5 = keyTxt;
			s.eVar5 = keyTxt;			
			break;
		case "release":
			Omniture.channel  = Omniture.prefix + 'games';
			Omniture.prop2  = 'release calendar ';
			break;
		case "whatsnew":
			Omniture.channel  = "us:ncom:what's new";	
			Omniture.prop2= 'article:home';
			break;
		case "whatsnew-article":
			Omniture.channel  = "us:ncom:what's new";	
			Omniture.prop2= 'article:article';
			//Omniture.prop7= arguments[1]; //Product compel ID
			Omniture.prop8= arguments[1].toLowerCase(); //article name
			break;
		case "search":
			Omniture.channel  = Omniture.prefix + 'search';			
			var keyTxt = arguments[1].toLowerCase(); //search keyword
			Omniture.prop5 = keyTxt;
			s.eVar5 = keyTxt;
			break;
		case "leaving":
			Omniture.channel = Omniture.prefix + 'leaving nintendo';			
			Omniture.prop2= 'leaving nintendo';
			break;
	}
	
}


//track the page
Omniture.pageTrack = function (pageName, isHome, checkVanityURL) {
	s.pageName = Omniture.prefix+pageName;
	s.channel=Omniture.channel;
	for (ei=0; ei<23; ei++) {
		s['prop'+ei.toString()] = Omniture['prop'+ei.toString()]; 
	}
	
	if(isHome) {
		s.events="event13";
	} else {
		s.events= "";
	}
	if(checkVanityURL){
		var thisDomain = document.domain;
		s.prop24=thisDomain;
	} else {
		s.prop24= "";
	}
	
    var s_code=s.t();if(s_code)document.write(s_code);
}

//MANUAL TRACKING
//tracks a custom click.
//additionalProps is an multideminsional array formated as [[propName, value],[propName, value]]
Omniture.trackLink = function (eVar, eVarData, eventN, name, openURL, additionalProps, popWin) {	
	//set vars
	var events = "event" + eventN.toString();	
	var addProps = 'eVar'+eVar.toString()+',events'; //string used in linkTrackVars
	
	//Check if popup variable is passed, if not, default to false
	if(popWin == undefined){
		popWin = false;
	}
	
	if(additionalProps != undefined) {
		for (aP = 0; aP< additionalProps.length; aP++){
			addProps += ","+additionalProps[aP][0] //grab propname
			s[additionalProps[aP][0]] = additionalProps[aP][1];  //set prop
		}
	}
	//set omniture
	s.linkTrackVars = addProps; 
	s.linkTrackEvents = events;
	s['eVar'+eVar.toString()] = eVarData;	
	s.events=events; 
	s.tl(true, 'o', name);
	
	//if url supplied
	if((openURL != undefined)){
		Omniture.openUrlVar = openURL;
		if(popWin == false) {		
			var timer = setTimeout("Omniture.openUrl()", 500);
		} else {
			var timer = setTimeout("Omniture.openUrl('_blank')", 500);	
		}
	} 

	//clear
	s.linkTrackVars = "";
	s.linkTrackVars = "";
	s.events=""; 
	s['eVar'+eVar.toString()] = "";
	if(additionalProps != undefined) {
		for (aP = 0; aP< additionalProps.length; aP++){
			s[additionalProps[aP][0]] = "";  //clear prop
		}	
	}
}


Omniture.trackCuratedListClick = function (gameName, promoID, location, curatedListTitle, openURL, type) {	
		s.eVar12=gameName;
		s.prop26=location;
		s.prop27=curatedListTitle;
	//Official
	if (type != "learnmore" && type != "learnmore_giftfinder") {		
		if(promoID != undefined && promoID != "") {			
			if(type == "official_giftfinder") {
				s.eVar23=promoID; 
				s.linkTrackVars='eVar12,eVar23,prop26,prop27,events'; 
				s.linkTrackEvents='event17,event31';				
				s.events='event17,event31';
			} else {
				s.eVar16=promoID; 
				s.linkTrackVars='eVar12,eVar16,prop26,prop27,events'; 
				s.linkTrackEvents='event17,event30';
				s.events='event17,event30';
			}					 
		} else {
			s.linkTrackVars='eVar12,prop26,prop27,events'; 		
			s.linkTrackEvents='event17';
			s.events='event17';
		}
		s.tl(true, 'o', "official site");
	//	alert("Curated List CLick: ( evar12 - "+s.eVar12+") ( evar16 - "+s.eVar16+")  ( prop26 - "+s.prop26+") ( prop27 - "+s.prop27+")");
		
	} else {
	//learn more
		if(promoID != undefined && promoID != "") {			
			if(type == "learnmore_giftfinder") {
				s.eVar23=promoID; 
				s.linkTrackVars='eVar12,eVar23,prop26,prop27,events'; 
				s.linkTrackEvents='event27,event31';
				s.events='event27,event31'; 
			} else {
				s.eVar16=promoID; 
				s.linkTrackVars='eVar12,eVar16,prop26,prop27,events'; 
				s.linkTrackEvents='event27,event30';
				s.events='event27,event30'; 
			}			
		} else {
			s.linkTrackVars='eVar12,prop26,prop27,events'; 
			s.linkTrackEvents='event27';
			s.events='event27';
		} 
		s.tl(true, 'o', "learn more");		
	}

	//open url
	Omniture.openUrlVar = openURL;
	var timer = setTimeout("Omniture.openUrl()", 500);

}




Omniture.exitLink = function (whichURL) {
	s.linkTrackVars="None";
	s.linkTrackEvents="None";
	s.tl(whichURL, 'e', whichURL);
}

//PREDEFINED TRACKING METHODS
Omniture.trackClubN = function(openURL) {
	if (openURL==true){
		var tempURL = link_clubN;
	}
	Omniture.trackLink(11, Omniture.prop10, 16, "Club Nintendo", tempURL);
}

Omniture.trackNewsletter = function(openURL) {
	if (openURL==true){
		var tempURL = link_newsletter;
	}
	Omniture.trackLink(11, "Newsletter", 26, "Newsletter", tempURL);
}
Omniture.trackNsignup = function(npath) {
	if (npath != ''){
		var tempURL = npath;
	}
	window.open (tempURL,"newsletter","menubar=1,resizable=1,scrollbars=1,location=yes,width=690,height=720");
	var wpopup = true;
	Omniture.trackLink(11, "Newsletter", 26, "Newsletter", tempURL, "", wpopup);
}

Omniture.trackTwitter = function(copy) {
	var tempStr = "No Twitter Copy Supplied";
	if(copy != undefined) {
		tempStr = copy;
	} 
	Omniture.trackLink(22, "Twitter", 24, "Twitter");
	
	//open url
	Omniture.openUrlVar = link_twitter+tempStr;
	var timer = setTimeout("Omniture.openUrl('_blank')", 500);
}

Omniture.trackFacebook = function(openURL) {
	Omniture.trackLink(22, "Facebook", 24, "Facebook");
	if (openURL==true){
		fbs_click();
	}	
}

Omniture.trackTwitterNOA = function() {
	Omniture.trackLink(22, "Twitter-NOA", 24, "Twitter-NOA");
}

Omniture.trackYouTube = function() {
	Omniture.trackLink(22, "YouTube", 24, "YouTube");
}

Omniture.trackPromo = function(promoTitle, promoURL, locationStr) {
	//additional prop
	if(locationStr == undefined){
		locationStr = "No_Location_Provided"
	}
	var addProp = [["prop26", locationStr]]
	
	Omniture.trackLink(13, promoTitle, 34, promoURL, promoURL, addProp);	
}

Omniture.trackGamesPromo = function(promoTitle, promoURL, locationStr) {
	//additional prop
	if(locationStr == undefined){
		locationStr = "No_Location_Provided"
	}
	var addProp = [["prop26", locationStr]]
	
	Omniture.trackLink(16, promoTitle, 30, promoURL, promoURL, addProp);	
	
	//official site
	/*
	event17 evar 12
	*/	
}

Omniture.wishlistFirstUse = function() {	
	s.linkTrackVars='events'; 
	s.linkTrackEvents='event23', 
	s.events='event23'; 
	s.tl(this, 'o', "Wishlist");	
}


Omniture.shareLink = function(propData) {	
	s.linkTrackVars='prop28'; 
	s.prop28 = propData;
	s.tl(this, 'o', "Product Share");	
}

//OTHER METHODS
//clears config variables
Omniture.clear = function () {
	Omniture.channel  = "";		
	for (ei=0; ei<22; ei++) {
		Omniture['prop'+ei.toString()] = ""; 
		s['eVar'+ei.toString()] = ""; 
	}
	
	//default settings
	//Omniture.prop6="us:en"; //Locale
	//Omniture.prop16="us:nintendo"; //site name
	Omniture.setLocale(Omniture.locale)	
	
}

Omniture.openUrl = function (windowType) {	
	if(windowType == undefined) {
		windowType = "_self"
	}
	//if url domain is not our site domain
	if(Omniture.openUrlVar.match(Omniture.livesite)) {
		Omniture.exitLink(Omniture.openUrlVar);//track as exit link
	}
	window.open(Omniture.openUrlVar, windowType);	
}

// Facebook Sharing
function fbs_click(){
	u=location.href;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&'+(new Date).valueOf(),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
};



