// GUS.js start

var quickNav = new Class({
    initialize: function(containerID){
		this.navBox = $(containerID);
		if(!this.navBox) {
			return;	
		}		
		this.trigger = this.navBox.getElement('.starter');
		this.menu = this.navBox.getElement('.secondary');
		this.menuEffect = new Fx.Slide(this.menu, {
			duration: 300,
			transition: Fx.Transitions.Cubic.easeIn
		});

		this.menuEffect.hide();
		this.menu.style.visibility = "visible";

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

	}
});

function personaRedirect() {
	var returnTo = encodeURIComponent(this.document.location);
	var personaLink = $('gusChangePersona').get('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').get('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').get('href');
	this.document.location = loginLink + "&surl=" + returnTo; 
} 
function registerRedirect() {
	var returnTo = encodeURIComponent(this.document.location);
	var regLink = $('gus_register_link').get('href');
	this.document.location = regLink + "&surl=" + returnTo; 
}

window.addEvent('domready', function() {
	var gusNavEAMenu = new quickNav('gus_ea');
	if (loggedinMenuActive) var gusNavWelcomeMenu = new quickNav('gus_welcome');
});

// gus.js end

//legal confirm for external links
function confirmExtLegal() {
	var acceptsTerms = window.localizedLegalTerms
			|| "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);
}

//legal confirm for download links
function confirmLegal() {
	var acceptsTerms = window.localizedDownloadTerms
			|| "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) {
	return openPopup(url, name, width, height, status, scrollbars,
			moreProperties);
}

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

// GLOBAL WINDOW POPUP (Used everywhere there's a popup.)
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 : '');

	var newWindow = window.open(url, name, properties);
	return !!newWindow;
}

///* FOOTER TABS */	
// var footerTabs = new Class({
// initialize: function(){
// this.tabBtns = $("tabs").getElements("a");
// this.tab = $$("div.tab");
// this.tab[0].setStyle('display', 'block');
//	 
// this.tabBtns.each(function(linkItem, index) {
// linkItem.addEvent("click", function(event) {
// event = new Event(event).stop();
//				
// this.selectedTab = $$(".btn");
//				
// //resetting selected states
// this.selectedTab.each(function(s) {
// s.className = "btn";
// });
//				
// //resetting selected tabs
// this.tab.each(function(t) {
// t.setStyle('display', 'none');
// });
// this.selectedTab[index].className = "btn selectedTab";
// this.tab[index].setStyle('display', 'block');
//				
// }.bind(this));
// }.bind(this));
// }
// });



// Comments js
function loadComments(commentId, targetId) {
	new Request.HTML({
		url : 'comment.action?workflow=GetCommentsForAssetIdWorkflow&assetId=http%3A//ea.com/fifa10/' + commentId,
		onSuccess : function(responseTree, responseElements,responseHTML, responseJavaScript) {
			$(targetId).set('html', responseHTML);
			eval(responseJavaScript);
		},
		onFailure : function() {
			$(targetId).set('text', 'The request failed.');
		}
	}).send();
}
function postComment(){
	console.log('click')
	return false;
}
window.addEvent('domready', function() {
	$$('a.btnSubmitComment').addEvent('click', function(e){
		e.preventDefault();
		console.log('click')
	});
	
});

// handle global flash?
function handleFlashready() {
	$("header").fade('in');
}

// show teaser over call from flash
function showTeaserOverlay(type, url) {

	if (type == "preorder") {
		omniLinkCall(this, 'flash_preorder_link_click');
		if ($type($('preorderTarget'))) {
			var myMindow = new Mindow('preorderOverLay', {
				height : 456,
				width : 680
			});
		}
	}

}

window.addEvent('domready', function() {
	$$(".hoverable").addEvent('mouseenter', function() {
		this.addClass("hover");
	}).addEvent('mouseleave', function() {
		this.removeClass("hover");
	});

	new Dropdown("localeDropdown", {
		onShowList : function() {
			if (!this.scrollbar) {
				this.scrollbar = new ScrollBar('localeScroll',
						'localeScrollTrack', 'localeScrollScrub');
				$('localeDropdown').addEvent('click', function(e) {
					e.stopPropagation();
				});
			}
		}
	});
	if ($type($("versionDropDown"))) {
		new Dropdown("versionDropDown");
	}

	// Add behavior to "Share This" links
	var addthis_pub = window.localeAddThisPub || "4a146ac042eaeefa"; // From
																		// alfresco,
																		// set
																		// in
																		// header
	var addthis_hover_delay = 500;
	$$("a.share").addEvent('click', function(e) {
		if (!addthis_open(this, 'more'))
			e.preventDefault();
	});

	// set gus login link to proper "authenticationSource"
	if ($('gus_login')) {
		var gusLogin = $('gus_login').getElement('a');
		gusLogin.href = gusLogin.href.replace('registrationSource','authenticationSource');
	}

});
