/* NoJs Remover 											 */
/* Removes all classes of "nojs" from all elements 			 */ 
/* to allow for alternate styling for JS and non-JS visitors */

var NoJsRemover = {
	initialize: function(){
		var noJsEls = $$(".nojs");
		noJsEls.each(function(currentEl){
			currentEl.removeClass("nojs");
		});
	}
}
$(window).addEvent('domready', function() {
	NoJsRemover.initialize();
});


/* multibox */
window.addEvent('domready', function() {
	var initMultiBox = function() {
		var boxList = {};
		boxList = new MultiBox("mb", {
			useOverlay:true,
			descClassName:'multiBoxDesc'
		});
		var boxListNews = {};
	    boxListNews = new MultiBox("mbBuyIt", {useOverlay:true});
	}
		initMultiBox();
});

/* navbar */


$(window).addEvent('domready', function() {
	
	var timer = null; // Timer object for showing/hiding navbar active (hover) backgrounds
	
   $$('div#navbar li').each(function(li) {
   	
   	   // if the li has a class of active, do not animate
   	   if (li.hasClass("active") == true){ return; }
   	   
       var img = li.getElements('img.hover')[0];

       var slideIn = new Fx.Style(img, 'top', {
           wait: false,
           duration: 1000,
           transition: Fx.Transitions.Elastic.easeOut
       });
	   
	   var slideOut = new Fx.Style(img, 'top', {
           wait: false,
           duration: 500,
           transition: Fx.Transitions.Back.easeIn
       });
	   
       li.addEvents({
           'mouseenter': function() {
		   	    if (timer) clearTimeout(timer);
				timer = setTimeout(function() {
  				    slideIn.start(73, 7);					
				}, 200);
			},
           'mouseleave': function() {
		   	    if (timer) clearTimeout(timer);
				slideIn.stop();
		   		slideOut.start(7, 73);
			}
       });
   });
});


/*** QUICKNAV CODE ***/
var quickNav = new Class({
    initialize: function(containerID,eTrigger){
		this.navBox = $(containerID);
		if(!this.navBox) {
			return;	
		}		
		this.trigger = this.navBox.getElement('.starter');
		this.menu = this.navBox.getElement('.secondary');
		this.outerMenu = this.navBox.getElement('.triggerBox');
		this.menu.style.visibility = "visible";

		this.menuEffect = new Fx.Slide(this.menu, {
			duration: 300,
			transition: Fx.Transitions.Cubic.easeIn
		});

		this.menuEffect.hide();

		if (eTrigger == "hover") {

			this.trigger.addEvent("mouseenter", function(e) {
				
				this.menuEffect.stop();		
				this.outerMenu.addClass('openTrigger');
				if(!this.trigger.hasClass('isActive')){
					this.trigger.addClass('isActive');
				}
				this.menuEffect.slideIn();
			}.bind(this));

			this.outerMenu.addEvent("mouseleave", function(e) {
				this.menuEffect.stop();										   
				this.menuEffect.slideOut().chain(function() {
					this.outerMenu.removeClass('openTrigger');
				}.bind(this));
				if(this.trigger.hasClass('isActive')){
					this.trigger.removeClass('isActive');
				}
			}.bind(this));

		} else if (eTrigger == "click") {

			this.trigger.addEvent("click", function(e) {
				e = new Event(e);													
				this.menuEffect.toggle();
				e.stop();
			}.bind(this));

		}


	}

});

// Tooltip triggers must be given the class 'tooltip-trigger' unless overridden through options
// Tooltip triggers must have the ID 'trigger-<id>' where <id> is the id of the tooltip to show, e.g. 'tooltip-mia'
// Tooltips themselves must have the ID 'tooltip-<id>'


var ToolTip = new Class({    

    initialize: function(options) {
        this.trigger = options.trigger || '.tooltip-trigger'; // the CSS selector (class) of the html elements which triggers the tooltip
        this.offsetX = options.offsetX || 0;    
        this.offsetY = options.offsetY || 0;
        this.mouseleaveDelay = 500;
        this.mouseenterDelay = 500;
        this.registerEventHandlers();
        this.timer = null; // setTimeout creates a timer object in the mouseenter and mouseleave event handlers
    },
    
    registerEventHandlers: function(){

    
        $$(this.trigger).each(function(trigger) {
            var id = 'tooltip-' + trigger.id.split('-')[1]; // e.g. 'tooltip-mia'
            var tooltip = $(id);

            trigger.addEvent('mouseenter', function() {
				if (typeof openToolTip != "undefined") {
					this.hideTooltip(openToolTip);
				}
				clearTimeout(this.timer);
                this.timer = null;
                this.timer = setTimeout(function() {
                    this.showTooltip(tooltip, trigger)
                }.bind(this), this.mouseenterDelay);
            }.bind(this));
            

            trigger.addEvent('mouseleave', function() {
				
				clearTimeout(this.timer);
                this.timer = null;
                this.timer = setTimeout(function() {
                    this.hideTooltip(tooltip, trigger)
                }.bind(this), this.mouseleaveDelay);
            }.bind(this));        


            tooltip.addEvent('mouseenter', function() {
                clearTimeout(this.timer);
                this.timer = null;
            }.bind(this));

            tooltip.addEvent('mouseleave', function() {
				                clearTimeout(this.timer);
                this.timer = null;
                this.timer = setTimeout(function() {
                    this.hideTooltip(tooltip, trigger)
                }.bind(this), this.mouseleaveDelay);
            }.bind(this));                  
        }.bind(this));
    },

    // showTooltip
    // id | string | the id of the tooltip to show
    // trigger | HTMLObject | the element that triggers the tooltip to show (used for positioning)

    showTooltip: function(tooltip, trigger) {
        if (typeof openToolTip != "undefined") {
			this.hideTooltip(openToolTip);
		}
		var position = trigger.getPosition(); //  e.g. {x: 500, y: 250}
      
        tooltip.set('styles', {
            left: position.x + this.offsetX + 'px',
            top: position.y + this.offsetY + 'px',
			visibility: "visible"
        });
		openToolTip = tooltip;  
    },
    hideTooltip: function(tooltip) {
        tooltip.set('styles', {
            left: "-9999px",
			visibility: "hidden"
        });
    }
});

if (document.body.id == "home") {
	var TimedSwitcher = new Class({
		initialize: function(options){
			this.CONTAINER = options ? (options.CONTAINER_ID) : $("imageRotator");
			this.ITEMS = this.CONTAINER.getElements("div");
			this.INTERVAL = 3000;
			this.index = 0; // which item is being displayed
			this.timer = setInterval(this.next.bind(this), this.INTERVAL);
//			this.preload();
		},  
		
//		preload: function(items) {
//			var images1 = new Image();
//			images1.src = "http://pc-alexg/celebritySportsLaunch/_ui/img/imageRotator/reggie.png";
//			console.log(images1.src)
//		}, 
		
		fadeIn: function(index){
			this.ITEMS[index].fade(0, 1);
		},
		
		//	show: function(index) {
		//		this.hide(this.index);
		//		this.index = index; // update current index
		//		this.ITEMS[index].setStyles({"opacity": 1, "display": "block"});
		//	},
		
		hide: function(index){
			this.ITEMS[index].setStyles({
				'visibility': 'hidden'
			});
		},
		
		show: function(index){
			this.ITEMS[index].setStyles({
				'visibility': 'visible'
			});
		},		
		next: function(){
			this.hide(this.index);
			this.index++;
			if (this.index >= this.ITEMS.length) {
				this.index = 0;
			}
			this.show(this.index);
//			if (Browser.Engine.trident)	{
//				// IE cannot handle fading PNG's so simply show image
//				this.show(this.index);
//			} else {
//				this.fadeIn(this.index);
//			}
		}
	})
}
/*
Author:
	luistar15, <leo020588 [at] gmail.com>
License:
	MIT-style license.
 
Class
	noobSlide (rev.17-04-08)

Arguments:
	options - see Options below

Options:
	box: dom element | required
	items: dom collection | required
	size: int | item size (px) | default: 240
	mode: string | 'horizontal', 'vertical' | default: 'horizontal'
	interval: int | for peridical | default: 5000
	buttons:{
		previous: single dom element OR dom collection| default: null
		next:  single dom element OR dom collection | default: null
		play:  single dom element OR dom collection | default: null
		playback:  single dom element OR dom collection | default: null
		stop:  single dom element OR dom collection | default: null
	}
	button_event: string | event type | default: 'click'
	handles: dom collection | default: null
	handle_event: string | event type| default: 'click'
	fxOptions: object | Fx.Style options | default: {duration:500,wait:false}
	autoPlay: boolean | default: false
	onWalk: event | pass arguments: currentItem, currentHandle | default: null
	startItem: int

Properties:
	box: dom element
	items: dom collection
	size: int
	mode: string
	interval: int
	buttons: object
	button_event: string
	handles: dom collection
	handle_event: string
	previousIndex: int
	nextIndex: int
	fx: Fx.style instance
	autoPlay: boolean
	onWalk: function
	
Methods:
	previous(manual): walk to previous item
		manual: bolean | default:false
	next(manual): walk to next item
		manual: bolean | default:false
	play (delay,direction,wait): auto walk items
		delay: int | required
		direction: string | "previous" or "next" | required
		wait: boolean | required
	stop(): sopt auto walk
	walk(item,manual): walk to item
		item: int | required
		manual: bolean | default:false
	addHandleButtons(handles):
		handles: dom collection | required
	addActionButtons(action,buttons):
		action: string | "previous", "next", "play", "playback", "stop" | required
		buttons: dom collection | required

*/

/* For noobslide a tag controls when the a tag has a hover. (ie hand holding) */
$(window).addEvent('domready', function(){
	$$(".control a").addEvent('click', function(e) {
		e.stop();
	});
});

if (document.body.id != "features") {
	var noobSlide = new Class({
	
		initialize: function(params){
			this.items = params.items;
			this.mode = params.mode || 'horizontal';
			this.modes = {
				horizontal: ['left', 'width'],
				vertical: ['top', 'height']
			};
			this.size = params.size || 240;
			this.box = params.box.setStyle(this.modes[this.mode][1], (this.size * this.items.length) + 'px');
			this.button_event = params.button_event || 'click';
			this.handle_event = params.handle_event || 'click';
			this.interval = params.interval || 5000;
			this.buttons = {
				previous: [],
				next: [],
				play: [],
				playback: [],
				stop: []
			};
			if (params.buttons) {
				for (var action in params.buttons) {
					this.addActionButtons(action, $type(params.buttons[action]) == 'array' ? params.buttons[action] : [params.buttons[action]]);
				}
			}
			this.handles = params.handles || null;
			if (this.handles) {
				this.addHandleButtons(this.handles);
			}
			this.fx = new Fx.Style(this.box, this.modes[this.mode][0], params.fxOptions ||
			{
				duration: 500,
				wait: false
			});
			this.onWalk = params.onWalk || null;
			this.currentIndex = params.startItem || 0;
			this.previousIndex = null;
			this.nextIndex = null;
			this.autoPlay = params.autoPlay || false;
			this._auto = null;
			this.box.setStyle(this.modes[this.mode][0], (-this.currentIndex * this.size) + 'px');
			if (params.autoPlay) 
				this.play(this.interval, 'next', true);
			
		},
		
		previous: function(manual){
			this.currentIndex += this.currentIndex > 0 ? -1 : this.items.length - 1;
			this.walk(null, manual);
		},
		
		next: function(manual){
			this.currentIndex += this.currentIndex < this.items.length - 1 ? 1 : 1 - this.items.length;
			this.walk(null, manual);
		},
		
		play: function(delay, direction, wait){
			this.stop();
			if (!wait) {
				this[direction](false);
			}
			this._auto = this[direction].periodical(delay, this, false);
		},
		
		stop: function(){
			$clear(this._auto);
		},
		
		walk: function(item, manual){
			if ($defined(item)) {
				if (item == this.currentIndex) 
					return;
				this.currentIndex = item;
			}
			this.previousIndex = this.currentIndex + (this.currentIndex > 0 ? -1 : this.items.length - 1);
			this.nextIndex = this.currentIndex + (this.currentIndex < this.items.length - 1 ? 1 : 1 - this.items.length);
			if (manual) {
				this.stop();
			}
			this.fx.start(-this.currentIndex * this.size);
			if (this.onWalk) {
				this.onWalk(this.items[this.currentIndex], (this.handles ? this.handles[this.currentIndex] : null));
			}
			if (manual && this.autoPlay) {
				this.play(this.interval, 'next', true);
			}
		},
		
		addHandleButtons: function(handles){
			for (var i = 0; i < handles.length; i++) {
				handles[i].addEvent(this.handle_event, this.walk.bind(this, [i, true]));
			}
		},
		
		addActionButtons: function(action, buttons){
			for (var i = 0; i < buttons.length; i++) {
				switch (action) {
					case 'previous':
						buttons[i].addEvent(this.button_event, this.previous.bind(this, true));
						break;
					case 'next':
						buttons[i].addEvent(this.button_event, this.next.bind(this, true));
						break;
					case 'play':
						buttons[i].addEvent(this.button_event, this.play.bind(this, [this.interval, 'next', false]));
						break;
					case 'playback':
						buttons[i].addEvent(this.button_event, this.play.bind(this, [this.interval, 'previous', false]));
						break;
					case 'stop':
						buttons[i].addEvent(this.button_event, this.stop.bind(this));
						break;
				}
				this.buttons[action].push(buttons[i]);
			}
		}
		
	});
}
if (document.body.id == "home") {
	$(window).addEvent('domready', function(){
		//SAMPLE 8
		var hs8 = new noobSlide({
			box: $('box8'),
			startItem: 1,
			items: $ES('div', 'box8'),
			size: 862,
			handles: $ES('span', 'handles8'),
			buttons: {
				previous: $('prev8'),
				next: $('next8')
			},
			onWalk: function(currentItem, currentHandle){
				//style for handles
				/*
				 don't  do some like that
				 this.handles.extend(handles8_more).removeClass('active');
				 because every walk event "this.handles" is extend permanently, use:
				 $extend(hthis.handles,andles8_more).removeClass('active'); OR
				 $$(this.handles,handles8_more).removeClass('active');
				 */
				$$(this.handles, handles8_more).removeClass('active');
				$$(currentHandle, handles8_more[this.currentIndex]).addClass('active');
			}
		});
		//more "previous" and "next" buttons
		hs8.addActionButtons('previous', $ES('.prev', 'box8'));
		hs8.addActionButtons('next', $ES('.next', 'box8'));
		//more handle buttons
		var handles8_more = $ES('span', 'handles8_more');
		hs8.addHandleButtons(handles8_more);
		//
		hs8.walk(0);
	});
}

$(window).addEvent('domready', function() {
	var quickNavMenu = new quickNav('quickNav','hover'); 
});

//////////////////////////////////////////////////////////////////////////////////////
// Omniture Wrapper
// Written By: Michael Johns mjohns(at)ea.com
// Date: 04/06
//
// Purpose: the following wrapper was created to abstract business names from logical
// names. This eliminates the touching of every Omniture call if for some reason the
// use of props, evars or events change. It also creates a means to select the type
// of reporting desired (custom link or Psuedo HTTP request). 
//
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
// Global Variables and Array declarations
//////////////////////////////////////////////////////////////////////////////////////
var prefix 							= "s_ea.";//object name
var eventArr           				= "eventsAssignmentArray";
var addValuesArr					= "additionalValuesAssignmentArray";
var eventsAssignmentArray 			= new Array();
var propsAssignmentArray 			= new Array();
var evarsAssignmentArray 			= new Array();
var additionalValuesAssignmentArray	= new Array();
var trackingItems      				= new Array(4);
trackingItems[ 0 ]     				= "props";
trackingItems[ 1 ]     				= "evars";
trackingItems[ 2 ]     				= "events";
trackingItems[ 3 ]     				= "additionalValues";
var eventString						= "";// holds the events
var extendOmniSession 				= 0;// flag set for omniKeepSessionAlive function

//////////////////////////////////////////////////////////////////////////////////////
// Function setOmniValues
//
// Description: This function separates the business names from the logical
// and takes in all the possible values associated with custom links and 
// standard HTTP requests. It will populate and evaluate the params being
// passed in and map to appropriate Omniture values.
//
// link - "this" passes link object
//
// type - type of link (mandatory for custom link reporting)
// 			'o' for Custom Link
// 			'd' to include in the File Downloads report
// 			'e' to include in the Exit Links report
//
// linkName - without a Link Name, the link will be reported by URL
//
// props - list of props and values, example:
// 			'userid=prop1value,sitecode=prop2value' 
// 		 	*** never use actual param name, always the business name (userid instead of prop1)
// 			*** See omnitureMapping function for business names (*not case sensitive)
//
// evars - list of evars and values, example:
// 			'userid=evar1value,sitecode=evar2value' 
// 		 	*** never use actual param name, always the business name (userid instead of evar1)
// 			*** See omnitureMapping function for business names (*not case sensitive)
//
// events - list of events to trigger example:
// 			'successdownload,successregistration'
// 			*** never use actual param name, always the business name (successdownload instead of event2)
// 			*** See omnitureMapping function for business names (*not case sensitive)
//
// reportPageView - flag to report data as cutomlink (0) or a psuedo HTTP request (1)
//
// productDetails - list of products example:
// 					'categoryValue2; productName1 (id1),categoryValue2; productName2 (id2)
//
// additionalValues - used to report any additional values that need to be set example:
// 					'campaign=campaignValue,state=stateValue,zip=zipValue,cc=USD'	
// 					*** See omnitureMapping function for business names (*not case sensitive)
//
// pageName - used to override the pageName (s_ea.pageName) example:
//            'myNewPageName'
//            *** if blank or null the pageName will not change
// 
// Called By: external links
//
//////////////////////////////////////////////////////////////////////////////////////
function setOmniValues(link, type, linkName, props, evars, events, reportPageView, productDetails, additionalValues, pageName){
	
	// re-intialize arrays/strings
	propsAssignmentArray.length 			= 0;
	evarsAssignmentArray.length 			= 0;
	eventsAssignmentArray.length 			= 0;
	additionalValuesAssignmentArray.length	= 0;
	eventString								= "";
	
	//reinitialize object
	s_ea = s_gi(s_account);
	//check if pageName needs to be overridden
	if(isNotEmpty(pageName)) {
		s_ea.pageName = pageName;
	}
	          
    // put raw split data in named arrays
	// example propsAssignmentArray --> userid=prop1value,sitecode=prop2value,brand=prop3value
	for (i = 0; i<=3; i++) {
    	if(isNotEmpty(eval(trackingItems[ i ]))){
			var chunk = eval(trackingItems[ i ]);
			var currArrayName = trackingItems[ i ] + "AssignmentArray";
			eval(currArrayName + " = chunk.split(',')");
		    // split assigned values into two-dimensional array
			// DO NOT need to do anything to events since values are driven by
			// evar and events are only comma "," delimited
			if( currArrayName != eventArr){
				var currArraySegmentedName = trackingItems[ i ] + "Array";
				for (var j=0; j < eval(currArrayName).length; j++) {
					// example of currArraySegmentedName -->  userid,prop1value
					currArraySegmentedName = eval(currArrayName)[ j ].split("=");
					// convert business names to omniture names
					// example --> userid switched to prop1
					currArraySegmentedName[ 0 ] = omnitureMapping(currArraySegmentedName[ 0 ], trackingItems[ i ]);
					// swapping in array example --> userid=prop1Value becomes prop1,prop1Value
					eval(currArrayName)[ j ] = currArraySegmentedName;
				}
			}else{
				for (var j=0; j < eval(currArrayName).length; j++) {
					// for event array example --> successdownload set to event2
					// also builds up string of events for assignment to
					// _ea.linkTrackEvents and s_ea.events
					eventString += eval(currArrayName)[ j ] = omnitureMapping(eval(currArrayName)[ j ], trackingItems[ i ]);
					
					if(j < eval(currArrayName).length - 1){
		 				eventString += ",";
		 			}
				}
			}
			
			// set individual variable assignment
			if( currArrayName != eventArr){
				assignValuestoParams(i);
			}
		}
	}
	
	//get events if any
	var currEvents = assignEvents(reportPageView);
		
	//assign to s_ea.linkTrackVars 
    assignLinkTrackVars(reportPageView, currEvents, productDetails);
	
	//assign to s_ea.products 
    assignProducts(reportPageView, productDetails);
		
	//call appropriate reporting function
	reportData(link, type, linkName, reportPageView);
	
};

//////////////////////////////////////////////////////////////////////////////////////
// Function omniLinkCall
//
// Description: This function reports a custom link name without changing any other
// parameters. This is equivalent to using the setOmniValues. Either method is 
// acceptable.
//
// link - "this" passes link object
//
// linkName - without a Link Name, the link will be reported by URL
//
// Called By: external links
//
//////////////////////////////////////////////////////////////////////////////////////
function omniLinkCall(link,linkName) {
	setOmniValues(link,'o',linkName,'','','',0,'','');
};

//////////////////////////////////////////////////////////////////////////////////////
// Function assignEvents
//
// Description: Assigns new values from array to s_ea.linkTrackEvents and 
// s_ea.events variable based on the type of reporting selected. 
//
// reportPageView - flag to report data as cutomlink (0) or a psuedo HTTP request (1)
//
// returns: "None" or "events"
//
// Called By: setOmniValues
//
//////////////////////////////////////////////////////////////////////////////////////
function assignEvents(reportPageView){

	s_ea.linkTrackEvents = "None";
	s_ea.events = "";
	
	if((reportPageView)&&(eventsAssignmentArray.length > 0)){
		s_ea.events = eventString;
		return "None";
	}
	
	if((!reportPageView)&&(eventsAssignmentArray.length > 0)){
		s_ea.linkTrackEvents = eventString;
		s_ea.events = eventString;
		return "events";
	}
	return "None";
};

//////////////////////////////////////////////////////////////////////////////////////
// function reportData
//
// Description: calls the appropriate function:
// 				s_ea.t() psuedo HTTP request or s_ea.tl() Custom Link
// to trigger the correct type of reporting
//
// link - "this" passes link object
//
// type - type of link (mandatory for custom link reporting)
// 			'o' for Custom Link
// 			'd' to include in the File Downloads report
// 			'e' to include in the Exit Links report
//
// linkName - without a Link Name, the link will be reported by URL
//
// reportPageView - flag to report data as cutomlink (0) or a psuedo HTTP request (1)
//
// Called By: setOmniValues
//
//////////////////////////////////////////////////////////////////////////////////////
function reportData(link, type, linkName, reportPageView){

	if(reportPageView){
		s_ea.t();
	}else{
		linkName = s_ea.pageName+":"+linkName;//add pageName to Link Name
		s_ea.tl(link, type, linkName);
	}
};

//////////////////////////////////////////////////////////////////////////////////////
// Function assignProducts
//
// Description: sets s_ea.products to actual product data
//
// reportPageView - flag to report data as cutomlink (0) or a psuedo HTTP request (1)
//
// productDetails - string containg product details
//
// Called By: setOmniValues
//
//////////////////////////////////////////////////////////////////////////////////////
function assignProducts(reportPageView, productDetails){

	s_ea.products = "";
	
	if(isNotEmpty(productDetails)){
		s_ea.products = productDetails;
	}
};

//////////////////////////////////////////////////////////////////////////////////////
// Function assignLinkTrackVars
//
// Description: Assigns new values from arrays to s_ea.linkTrackVars variable
//
// reportPageView - flag to report data as cutomlink (0) or a psuedo HTTP request (1)
//
// currEvents - string containg "None" or "events" set by assignEvents()
//
// productDetails - string of product details passed in from link
//
// Called By: setOmniValues
//
//////////////////////////////////////////////////////////////////////////////////////
function assignLinkTrackVars(reportPageView, currEvents, productDetails){

	if(reportPageView){
		//props and evars do NOT needs to be set since s_ea.t() sends everything (props/evars)
		s_ea.linkTrackVars = "None";
		
	}else{
		var currProps 				= getLinkTrackVarsValues("propsAssignmentArray");
		var currEvars 				= getLinkTrackVarsValues("evarsAssignmentArray");
		var currAdditionalValues 	= getLinkTrackVarsValues("additionalValuesAssignmentArray");
				
		if(isNotEmpty(productDetails)){
			currProductDetails = "products";
		}else{
			currProductDetails = "None";
		}
		s_ea.linkTrackVars = buildLinkTrackVarsValues(currProps, currEvars, currAdditionalValues, currEvents, currProductDetails);
	}
};

//////////////////////////////////////////////////////////////////////////////////////
// Function buildLinkTrackVarsValues
//
// Description: compiles new values from arrays to be assigned to s_ea.linkTrackVars
// variable
//
// currProps - string of props being reported
// currEvars - string of evars being reported
// currAdditionalValues - string of aditional values being reported
// currEvents - string "None" or "events"
// currProductDetails - string "None" or "products"
//
// Called By: assignLinkTrackVars
//
// Returns: arr (aggregated array of all values for linkTrackVars)
//
//////////////////////////////////////////////////////////////////////////////////////
function buildLinkTrackVarsValues(currProps, currEvars, currAdditionalValues, currEvents, currProductDetails){
	
	var arr = new Array();
	if(currProps != "None") arr.push(currProps);
	
	if(currEvars != "None") arr.push(currEvars);
	
	if(currAdditionalValues != "None") arr.push(currAdditionalValues);
	
	if(currEvents != "None") arr.push(currEvents);
	
	if(currProductDetails != "None") arr.push(currProductDetails);
	
	if(arr.length == 0) {
		return 'None';
	} else {
		return arr.join(",");
	}
};

//////////////////////////////////////////////////////////////////////////////////////
// Function getLinkTrackVarsValues
//
// Description: pulls and assigns new values from arrays to s_ea.linkTrackVars variable 
//
// arrayName - name of array to be used to pull values from
//
// Called By: assignLinkTrackVars
//
// Returns: linkTrackVarsValues (string of all values for linkTrackVars)
//
//////////////////////////////////////////////////////////////////////////////////////
function getLinkTrackVarsValues(arrayName){

	if(eval(arrayName).length > 0){
		linkTrackVarsValues = "";
		// populate s_ea.s_linkTrackVars with array data
		for (var i=0; i < eval(arrayName).length; i++) {
		 	linkTrackVarsValues += eval(arrayName)[i][0];
		 	// need to add "," between values except last one
		 	if(i < eval(arrayName).length - 1){
		 		linkTrackVarsValues += ",";
		 	}
		}
	}else{
		linkTrackVarsValues = "None";
	}
 return linkTrackVarsValues;

};

//////////////////////////////////////////////////////////////////////////////////////
// Function assignValuestoParams
//
// Description: resolves values from array and assigns to appropriate omniture variable
//
// Called By: setOmniValues
//
//////////////////////////////////////////////////////////////////////////////////////
function assignValuestoParams(arrayPos){

	var currMultiDimArrayName = eval(trackingItems[ arrayPos ] + "AssignmentArray");
	var arrName = trackingItems[ arrayPos ] + "AssignmentArray";
		
	for (var m=0; m < currMultiDimArrayName.length; m++) {
		// assigns value to params example --> s_ea.prop1 = prop1Value
		eval(prefix + currMultiDimArrayName[m][0] + "= currMultiDimArrayName[m][1]");
	}
	
};

//////////////////////////////////////////////////////////////////////////////////////
// Function isNotEmpty
//
// Checks if the string is null or contains spaces only
//
// val - any string/array
//
// Called By: setOmniValues, assignProducts, assignLinkTrackVars
//
// Returns: true or false
//
//////////////////////////////////////////////////////////////////////////////////////
function isNotEmpty(val){

     re = /^ *$/
     if(re.exec(val)||(val == null)){
          return false;
     }else{
          return true;
     }
};

//////////////////////////////////////////////////////////////////////////////////////
// Function modifyOmniRSI
//
// updates report suite Id(s) of current page object
//
// newRSI - total string of comma separated RSIs
//
// sendBroadcast - flag to send broadcast, (0) don't send and (1) send. 
//                 If no parameter then defaults to (0), don't send
//
// Called By: page
//
//////////////////////////////////////////////////////////////////////////////////////
function modifyOmniRSI(newRSI,sendBroadcast){
	
	s_account = newRSI;
	s_ea.sa(newRSI);
	if(isNotEmpty(sendBroadcast)) {
		if(sendBroadcast){
			setOmniValues('','','','','','',1,'','');
		}
	}
};

////////////////////////////////////////////////////////////////////////////////////////
// Function omnitureMapping
//
// Description: Remaps business names to omniture names or returns "notFound"
//
// currValue - current array being populated:
//				propsAssignmentArray
//				evarsAssignmentArray
//				additionalValuesAssignmentArray
//				eventsAssignmentArray
//
// typeOfValue - type of array value being passed in
//				"props"
//				"evars";
//				"events";
//				"additionalValues";
//
// Called By: setOmniValues
//
// Returns: Omniture logical value of parameter
//
//////////////////////////////////////////////////////////////////////////////////////
function omnitureMapping(currValue, typeOfValue){

	currValue = currValue.toLowerCase();
 
	var lookupTable = new Array();
	// eVars	
	if(typeOfValue == "evars"){
		lookupTable["userid"]						= "eVar1";
		lookupTable["sitecode"]						= "eVar2";
		lookupTable["game"]							= "eVar3";
		lookupTable["newslettertype"]				= "eVar4";
		lookupTable["intcmp"]						= "eVar5";
		lookupTable["registrationlevel"]			= "eVar6";
		lookupTable["supporteventtype"]				= "eVar7";
		lookupTable["downloadtype"]					= "eVar8";
		lookupTable["gamespecifictype"]				= "eVar9";
		lookupTable["registrationtype"]				= "eVar10";
		lookupTable["purchaseintentaction"]			= "eVar11";
		lookupTable["extcampaignid"]				= "eVar14";
		lookupTable["entitlementtype"]				= "eVar15";
		lookupTable["territory"]					= "eVar18";
		lookupTable["abtest"]						= "eVar19";
		lookupTable["intsearchterms"]				= "eVar20";
		lookupTable["prodfindingmethod"]			= "eVar22";
		lookupTable["merchcategorybrowse"]			= "eVar23";
		lookupTable["crossselltype"]				= "eVar24";
		lookupTable["originatingpage"]				= "eVar25";
		lookupTable["promocode"]					= "eVar26";
		lookupTable["shipmethod"]					= "eVar27";
		lookupTable["paymentmethod"]				= "eVar28";
	}
			
	//sProps
	if(typeOfValue == "props"){
		lookupTable["userid"]						= "prop1";
		lookupTable["sitecode"]						= "prop2";
		lookupTable["brand"]						= "prop3";
		lookupTable["franchise"]					= "prop4";
		lookupTable["game"]							= "prop5";
		lookupTable["platform"]						= "prop6";
		lookupTable["longpagename"]					= "prop7";
		lookupTable["registrationlevel"]			= "prop8";
		lookupTable["gamespecifictrafficvalue"]		= "prop9";
		lookupTable["contenttitle"]					= "prop10";
		lookupTable["territory"]					= "prop11";
		lookupTable["language"]						= "prop12";
		lookupTable["contentmediatype"]				= "prop13";
		lookupTable["contentcategory"]				= "prop14";
		lookupTable["contentbucket"]				= "prop15";
		lookupTable["contenttype"]					= "prop16";
		lookupTable["country"]						= "prop17";
		lookupTable["localpagename"]				= "prop18";
		lookupTable["abtest"]						= "prop19";
		lookupTable["intsearchterms"]				= "prop20";
		lookupTable["searchnoresults"]				= "prop21";
		lookupTable["searchcategory"]				= "prop22";
		lookupTable["pagedetailviews"]				= "prop23";
		lookupTable["pagenamesdetailviews"]			= "prop24";
		lookupTable["prodregplatform"]				= "prop25";
		lookupTable["prodreggametitle"]				= "prop26";
		lookupTable["prodregcountry"]				= "prop27";
		lookupTable["gfcategory"]					= "prop28";
		lookupTable["gfcomponent"]					= "prop29";
		lookupTable["gfsearchterm"]					= "prop30";
		lookupTable["gfsorttype"]					= "prop31";
		lookupTable["gfpagepath"]					= "prop32";
		lookupTable["server"]						= "server";
	}
	
	//events 
	if(typeOfValue == "events"){
		//custom events below
		lookupTable["htmlopens"] 					= "event1";
		lookupTable["successdownload"] 				= "event2";
		lookupTable["successregistration"] 			= "event3";
		lookupTable["passalong"] 					= "event4";
		lookupTable["successentitlementexpiration"] = "event5";
		lookupTable["successentitlement"] 			= "event6";
		lookupTable["totalclicks"] 					= "event7";
		lookupTable["successgamespecific"] 			= "event9";
		lookupTable["searches"] 					= "event10";
		lookupTable["successsupport"] 				= "event11";
		lookupTable["successfindastore"] 			= "event12";
		lookupTable["proddetailviews"] 				= "event13";
		lookupTable["logins"] 						= "event14";
		lookupTable["successpurchaseintent"] 		= "event15";
		lookupTable["successnewsletter"] 			= "event16";
		lookupTable["successcancelsubscription"] 	= "event17";
		lookupTable["acctcreation"] 				= "event18";
		lookupTable["shipping"] 					= "event19";
		lookupTable["tax"] 							= "event20";
				
		// standard events below
		lookupTable["successproductview"] 			= "prodView";
		lookupTable["successscopen"] 				= "scOpen";
		lookupTable["successscadd"] 				= "scAdd";
		lookupTable["successsccheckout"] 			= "scCheckout";
		lookupTable["successpurchase"] 				= "purchase";
	}
	
	//additionalvalues
	if(typeOfValue == "additionalValues"){
		lookupTable["zip"]							= "zip";
		lookupTable["campaign"]						= "campaign";
		lookupTable["state"]						= "state";
		lookupTable["usd"]							= "USD";
        lookupTable["charset"]						= "charSet";
		lookupTable["purchaseid"]					= "purchaseID";
	}
	
	var omniValue = lookupTable[currValue];
	if (omniValue == null){
		omniValue = "notFound";
	}
	return omniValue;
};

//////////////////////////////////////////////////////////////////////////////////////
// Function buildContentType
//
// Description: Builds content type of the base tagging
//
// content_type_media - top level categorization of content type
//				
// content_type_classification - combined (with ::) secondary and ternary level
//                               categorization of content type
//
// content_type_title - title of content type
//
// content_type - aggregate of content_type_media, content_type_classification (split)
//                and content_type_title (colon delimited)
//
// Called By: various dynamic page components
//
// Calls: setOmniValues with 3 pieces of content type categorization and title  
//        or "Unset" if DCR does not pass in valid parameters.
//////////////////////////////////////////////////////////////////////////////////////
function buildContentType(content_type_media, content_type_classification, content_type_title){
		
	if((content_type_media == "<ADD CONTENT>") || (!isNotEmpty(content_type_media)) || (content_type_media == "undefined")){
		content_type_media = "Unset";
	}
	
	if((!isNotEmpty(content_type_title)) || (content_type_title == "undefined")){
		content_type_title = "Unset";
	}
	
	if((content_type_classification == "<ADD CONTENT>") || (content_type_classification == "undefined")){
		classification_category = "Unset";
		classification_subcategory = "Unset";
	} else {
		var ct_pieces = content_type_classification.split("::");

		classification_category = ct_pieces[0];
		classification_subcategory = ct_pieces[1];
	}
	
	setOmniValues('','','','contentmediatype='+content_type_media+',contentcategory='+classification_category+',contentbucket='+classification_subcategory+',contenttitle='+content_type_title+',contenttype='+content_type_media+' : '+classification_category+' : '+classification_subcategory+' : '+content_type_title,'', '', 1)
};

//////////////////////////////////////////////////////////////////////////////////////
// Function omniUpdateContentType
//
// Description: updates content types and sends broadcast
//
// content_type_media - top level categorization of content type
//				
// content_type_category - secondary level categorization of content type
//
// content_type_contentbucket - ternary level categorization of content type
//
// content_type_title - title of content type
//
// content_type - aggregate of content_type_media, content_type_category
//                content_type_contentbucket and content_type_title (colon delimited)
//
// Called By: various dynamic page components
//
// Calls: setOmniValues with 4 pieces of content type categorization and title  
//        or maintains previously set value if not passed in valid parameter or null.
//////////////////////////////////////////////////////////////////////////////////////
function omniUpdateContentType(content_type_media, content_type_category, content_type_contentbucket, content_type_title){
		
	if((!isNotEmpty(content_type_media)) || (content_type_media == "undefined") || (content_type_media == null)){
		content_type_media = eval(prefix + omnitureMapping("contentmediatype", "props"));
	}
	
	if((!isNotEmpty(content_type_category)) || (content_type_category == "undefined") || (content_type_category == null)){
		content_type_category = eval(prefix+ omnitureMapping("contentcategory", "props"));
	}
	
	if((!isNotEmpty(content_type_contentbucket)) || (content_type_contentbucket == "undefined") || (content_type_contentbucket == null)){
		content_type_contentbucket = eval(prefix + omnitureMapping("contentbucket", "props"));
	}
	
	if((!isNotEmpty(content_type_title)) || (content_type_title == "undefined") || (content_type_title == null)){
		content_type_title = eval(prefix + omnitureMapping("contenttitle", "props"));
	}
		
	setOmniValues('','','','contentmediatype='+content_type_media+',contentcategory='+content_type_category+',contentbucket='+content_type_contentbucket+',contenttitle='+content_type_title+',contenttype='+content_type_media+' : '+content_type_category+' : '+content_type_contentbucket+' : '+content_type_title,'', '', 1)
};

//////////////////////////////////////////////////////////////////////////////////////
// Function checkAllValues
//
// Description: utility function to be called via address bar:
// javascript:checkAllValues();
// which alerts the current values
//
// Called by: address bar (utility function)
//
//////////////////////////////////////////////////////////////////////////////////////
function checkAllValues(){

	var allParamsAvail = "";
	for (i = 1; i<=20; i++) {
	    allParamsAvail += '\n prop'+i+':' + eval("s_ea.prop"+i) + ' <----> eVar'+i+':' + eval("s_ea.eVar"+i);
	}
	allParamsAvail += '\n\n';
	allParamsAvail += '\n\n s_ea.linkTrackEvents:'+s_ea.linkTrackEvents;
	allParamsAvail += '\n\n';
	allParamsAvail += '\n\n s_ea.linkTrackVars:'+s_ea.linkTrackVars;
	allParamsAvail += '\n\n';
	allParamsAvail += '\n\n s_ea.events:'+s_ea.events;
	allParamsAvail += '\n\n';
	allParamsAvail += '\n\n s_ea.products:'+s_ea.products;
	allParamsAvail += '\n\n';
	allParamsAvail += '\n\n s_ea.state:'+s_ea.state;
	allParamsAvail += '\n\n';
	allParamsAvail += '\n\n s_ea.zip:'+s_ea.zip;
	allParamsAvail += '\n\n';
	allParamsAvail += '\n\n s_ea.campaign:'+s_ea.campaign;
	allParamsAvail += '\n\n';
	allParamsAvail += '\n\n s_ea.pageName:'+s_ea.pageName;
	
	alert(allParamsAvail);
	} ;
	
//////////////////////////////////////////////////////////////////////////////////////
// Function omniKeepSessionAlive
//
// Description: utility function recursively called. This function extends the user 
// session by sending out a custom link broadcast at approx 28-29 mins. of the session
// since the session will end at 30 min.
//
//////////////////////////////////////////////////////////////////////////////////////	
function omniKeepSessionAlive(){
	setTimeout("omniKeepSessionAlive()",1700000);
	if(extendOmniSession){
		omniLinkCall(this,'extendSession');
	}
	extendOmniSession = 1;
};

omniKeepSessionAlive();//kicks off timer onload
//////////////////////////////////////////////////////////////////////////////////////
// END OF CODE
//////////////////////////////////////////////////////////////////////////////////////


