function omniLinkCall(link,linkName) {
	setOmniValues(link,'o',linkName,'','','',0,'','');
}

// san van flash omniture page request
function omniPage(sectionName) {
	var sectionUpper = sectionName.toUpperCase();
	setOmniValues('', '', '', 'contenttype=Editorial : Game Information : Feature Detail : Features New San Van : Location : '+sectionName+',contenttitle='+sectionName+' Location', '', '', 1, '', '', 'NA:US:EA:SKATE:SKATE2:FEATURES');
}

// gus functions
function personaRedirect() {
	var returnTo = encodeURIComponent(this.document.location);
	var personaLink = $('gusChangePersona').getProperty('href');
	if (personaLink.indexOf('?') > -1) {
		if (personaLink.indexOf('&') > -1) {
			personaLink = personaLink + "&";
		}
	} else {
		personaLink = personaLink + "?";
	}
	this.document.location = personaLink + "surl=" + returnTo; 
} 
function logoutRedirect() {
	var returnTo = encodeURIComponent(this.document.location);
	var logoutLink = $('gus_logout_link').getProperty('href');
	if (logoutLink.indexOf('?') > -1) {
		if (logoutLink.indexOf('&') > -1) {
			logoutLink = logoutLink + "&";
		}
	} else {
		logoutLink = logoutLink + "?";
	}
	this.document.location = logoutLink + "&surl=" + returnTo; 
} 
function loginRedirect() {
	var returnTo = encodeURIComponent(this.document.location);
	var loginLink = $('gus_login_link').getProperty('href');
	this.document.location = loginLink + "&surl=" + returnTo; 
} 
function registerRedirect() {
	var returnTo = encodeURIComponent(this.document.location);
	var regLink = $('gus_register_link').getProperty('href');
	this.document.location = regLink + "&surl=" + returnTo; 
}

// blog and news flash embed code workaround
var flashEmbed = new Class({
	initialize: function(elements){
		this.myelements = elements;
		this.myelements.each(function(elementItem,index) {
			var flashSrc = elementItem.innerHTML;
			var width = elementItem.getProperty('width');
			var height = elementItem.getProperty('height');
			if (!width) {
				var width = 540};
			if (!height) {
				var height = 322};
			elementItem.id = "flashObject"+index;
			this.writeEmbed(flashSrc,width,height,index,elementItem.id);
		}.bind(this));
	},
	writeEmbed: function(flashSrc,width,height,id,container) {
		//write flash player
		//swfobject 2.0
		var flashvars = {
			videoURL: flashSrc,
			type:"blog"
		};	
		var params = {
			wmode: "transparent",
			allowFullScreen: "true",
			allowScriptAccess: "sameDomain",
			base: "http://skate.ea.com/swf/"
		};

		var attributes = {
			id: "flashVideo"+id
		};

		swfobject.embedSWF("http://skate.ea.com/swf/videoplayer.swf",container, width, height, "9.0.115","http://skate.ea.com/swf/expressInstall.swf", flashvars, params, attributes);
	}
});

var getLocale = new Class({
	initialize: function(targetId){
		this.myTarget = $(targetId);
		this.myCookieValue = Cookie.get('skate2_locale');
		if (this.myCookieValue) {
			if ((this.myCookieValue != "en_CA" ) && (this.myCookieValue != "en_US" )) {		
				var redirect = localeRedir[this.myCookieValue];
				window.location=redirect;
			}
		} else {
			var myGlobalOverlay = new globalOverlay('globalOverlay','globalOverlay','true');
		}
	}
});


/*** 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.menuEffect = new Fx.Slide(this.menu, {
			duration: 300,
			transition: Fx.Transitions.Cubic.easeIn
		});

		this.menuEffect.hide();
		this.menu.style.visibility = "visible";
		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));
		}
	}
});

/**
* Menuslider
*/
var menuSlider = new Class({
	activeSlider: null,
	chainedEffect: null,
	allSliders: new Object(),
	
	initialize: function(theSliders) {
		this.allSliders = theSliders;
				
		$each(theSliders, function(containerId,clickId) {
			if($(containerId) != null && $(clickId) != null){
				this.allSliders[clickId] = new Fx.Slide(containerId, {duration: 500, onComplete: this.fireChainedEffect.bind(this)});
				this.allSliders[clickId].hide();
				this.setSlider(clickId, this.allSliders[clickId]);
			}
		}.bind(this));
	},
	fireChainedEffect: function() {
		if(this.chainedEffect != null) {
			this.activeSlider = this.chainedEffect;
			this.activeSlider.toggle();
			this.chainedEffect = null;
		}	
	},
	setSlider: function(curId, curSlider){
		$(curId).addEvent('click', function(e){
			e = new Event(e);
			$(curSlider.element.id).setStyle("visibility","visible");
			if(this.activeSlider != null && this.activeSlider != curSlider){
				this.chainedEffect = curSlider;
				this.activeSlider.stop();
				this.activeSlider.slideOut();
			} else {
				this.activeSlider = curSlider;
				this.activeSlider.toggle();
			}
			e.stop();
		}.bind(this));	
	}
});

var globalOverlay = new Class({
	initialize: function(triggerId,targetId,active) {
		this.myTrigger = $(triggerId);
		this.myTarget = $(targetId);
		this.feedConduit = "globalselector.action?destination=global";
		this.myTrigger.addEvent("click", function(event) {
			this.loadSelector();
			event = new Event(event).stop();
		}.bind(this));	
		if (active == "true") {
			this.loadSelector();
		} 
	},
	loadSelector: function() {
		var myAjax = new Ajax(this.feedConduit, {
			method: 'get',
			evalScripts: true,
			update: this.myTarget,
			onRequest: function(data) {
				this.myTarget.setHTML('<p class="error">Loading...</p>');
			}.bind(this),
			onFailure: function(data) {
				this.myTarget.setHTML('<p class="error">Could not load asset.</p>');
			}.bind(this),
			onSuccess: function(data) {
				this.showOverlay();
			}.bind(this)
			
			
		}).request();
	},
	showOverlay: function() {
		this.myTarget.setStyle('display','block');
	}
});

var selectLocale = new Class({
	initialize: function(selectorId,targetId) {
		(document.location.href.search(/ea.com/) > 0) ? this.myDomain = ".ea.com" : this.myDomain = "";
		this.mySelector = $(selectorId);
		this.myTarget = $(targetId);
		this.myClose = $(targetId).getElement('.close');
		this.myLinks = this.mySelector.getElements('a');
		this.myClose.addEvent("click", function(event) {
			this.hideOverlay();
			event = new Event(event).stop();
		}.bind(this));
		this.myLinks.each(function(linkItem) {
			linkItem.addEvent("click", function(event) {
				var localeCode = linkItem.hreflang;
				this.setLocale(localeCode);
				if (linkItem.href == "http://skate.ea.com/") {
					this.hideOverlay();
					event = new Event(event).stop();
				} else {
					location.href = linkItem.href;
					this.hideOverlay();
					event = new Event(event).stop();
				}
			}.bind(this));
		}.bind(this));
	},
	setLocale: function(localeCode) {
		Cookie.set('skate2_locale', localeCode, {duration: "14", domain: this.myDomain});
	},
	hideOverlay: function() {
		this.myTarget.setStyle('display','none');	
	}
});

function confirmExtLegal(){
	var acceptsTerms = "You are about to leave the Electronic Arts website and go to a website owned by a third party.  Electronic Arts is not responsible for content on third party sites, and our privacy policy does not apply to their information collection practices.  Press OK to access the linked site or press CANCEL to return to your original page.";
	return confirm(acceptsTerms);	
}
function confirmLegal(){
	var acceptsTerms = "Terms & Conditions of Downloading Materials\n\nThe materials provided on this web site are provided \"as is\" without warranties of any kind.  Electronic Arts Inc., its subsidiaries, divisions, affiliates and licensors (\"EA\") disclaim all warranties, either express of implied, including but not limited to, warranties of merchantability and fitness for a particular purpose. To the extent allowed by applicable law, in no event will EA be liable for damages of any kind to your hardware, peripherals or software programs as a result of your download or use of our materials.\n\n You may download one copy of the materials onto a single computer for your personal, non-commercial, home use only, provided you keep intact all copyright, trademark and other proprietary notices.  No materials from this web site may be copied, reproduced, modified, republished, uploaded, posted, transmitted, broadcast or distributed in any way without the express written consent of EA.  Unauthorized use of the materials is a violation of EA's copyright and constitutes infringement of EA's proprietary rights.\n\nTo use these materials, you must agree to the above terms and conditions.  To accept this agreement and proceed with the download, click \"OK\" or click \"Cancel\" to decline.";	
	return confirm(acceptsTerms);
}

function openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {
	openPopup(url, name, width, height, status, scrollbars, moreProperties);
}

function popWallpaper(url, width, height) {
   if(confirmLegal()){
      openCenteredWindow(url,'pop', width, height,'yes');
   }
}

function  openCenteredWindow(url, name, width, height){
	      openPopup(url, name, width, height,'yes');
	}

/*************************************
   Confirm legal box for flash downloads
*************************************/

	function flashLegal(url) {
		if (confirmLegal()) {
			window.location=url;
		} 
	}

function openPopup(url, name, width, height, status, scrollbars, moreProperties) {
	var agent = navigator.userAgent.toLowerCase();
	var x, y = 0;
	if (screen) {
      x = (screen.availWidth - width) / 2;
      y = (screen.availHeight - height) / 2;
   }
   if (!status) status = '';

	// Adjust width if scrollbars are used (pc places scrollbars inside the content area; mac outside) 
	width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 16 : 0;

	var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') + ((moreProperties) ? ',' + moreProperties : '');
   
	window.open(url, name, properties);
	return false;
} 


window.addEvent('domready', function() {
	var myGetLocale = new getLocale('globalOverlay');
	var gusNavEAMenu = new quickNav('gus_ea','click');
	if (loggedinMenuActive) var gusNavWelcomeMenu = new quickNav('gus_welcome','click');
	// intialize sliders
	//var mySliders = new menuSlider ({ gus_ea: 'gusEA', gus_welcome: 'gusWelcome' });
	var quickNavMenu = new quickNav('quickNav','hover');
});