
//legal confirm for external links
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);	
}

//legal confirm for download links
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 openCenteredWindow(url, name, width, height){
    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 : '');
   
	window.open(url, name, properties);
	return false;
}

//global toggle show/hide of an element (pass any DOM object to show/hide)
function toggle(obj) {
	obj.style.display = (obj.style.display != 'none' ? 'none' : '' );
}

//video embed function
function setupFeaturesVideo() {
	var media = $('mdow').getElement(".mediaURL");
	var mediaURL = media.innerHTML;
	media.innerHTML = "";
	var mediaKids = media.getChildren();
	media.id = "mdowMediaPlayer";
	media.grab(new Element('div', { id: "mdowMediaPlayer", html: 'You don\'t have the latest version of Flash Player, you can download it <a target="flashdownload" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">here</a>.'}));
	var flashvars = {
		itemID: "",
		pageName: s_ea.pageName,
		s_account: s_account,
		cname: "eaeacom.112.2o7.net",
		namespace: "",
		cdPath: "http://ll-100.ea.com/cem/u/f/GPO/crossdomain.xml,http://ll-100.ea.com/nawp/crossdomain.xml",
		media: encodeURIComponent(mediaURL),
		autoplay: true
	};
	swfobject.embedSWF("_swf/2010/StandAloneMediaPlayer.swf", "mdowMediaPlayer", "640", "360", "9.0.115", "_swf/expressInstall.swf", flashvars, { wmode: "transparent", allowFullScreen: true }, false);
}

/*
Script: FilmStrip.js
	An mootools extension which allows you to easily create a film strip carosel.

License:
	MIT-style license.
*/

var FilmStrip = new Class({
	Implements: [Options],				   
	options: {
		viewPort: '.viewPort',
		filmStrip: '.filmStrip',
		btnNext: '.btnNext',
		btnPrev: '.btnPrev',
		scrollDir: 'horizontal',
		items: 'li',
		itemsPerPage: 4,
		duration: 'short',
		initialPage: 0,
		version: '1.2.2'
	},							  
    initialize: function(containerId, options){
		this.container = $(containerId);
		this.setOptions(options);		
		
		// initalize elements and there sizes
		this.initElms();
		
		// initalize paging
		this.initPaging();
				
		// set film strips height or width
		if(this.options.scrollDir == 'horizontal'){
			this.styleType = 'left';
			//if the inital page is not 0 then set intial left
			if(this.curPage != 0){
				this.filmStrip.setStyle(this.styleType, this.viewPort.getSize().x * -(this.curPage));		
			}
			this.filmStrip.setStyle('width', this.pages*this.viewPort.getSize().x + 'px');			
		} else if(this.options.scrollDir == 'vertical'){
			this.styleType = 'top';
			//if the inital page is not 0 then set intial top
			if(this.curPage != 0){
				this.filmStrip.setStyle(this.styleType, this.viewPort.getSize().y * -(this.curPage));		
			}			
			this.filmStrip.setStyle('height', this.pages*this.viewPort.getSize().y + 'px');	
		}
		
		// intialize classes for showing or hiding the pagination controls
		this.setPaginationControls();

		// attach all the click handlers to the next and previous buttons
		this.btnNext.addEvent('click', function(e) { 
			e.stop();
			this.setPage(1); 
		}.bind(this));
		
		this.btnPrev.addEvent('click', function(e) { 
			e.stop();
			this.setPage(-1); 
		}.bind(this));	
	},
	initElms: function(){
		this.viewPort = this.container.getElement(this.options.viewPort);
		this.viewPort.setStyles({
			position: 'relative',
			overflow: 'hidden'
		});	
		this.filmStrip = this.container.getElement(this.options.filmStrip);
		this.filmStrip.setStyles({
			position: 'absolute',
			left: 0,
			top: 0
		});	
		this.btnNext = this.container.getElement(this.options.btnNext);
		this.btnPrev = this.container.getElement(this.options.btnPrev);		
	},
	initPaging: function() {
		this.curPage = this.options.initialPage;
		this.numElms = this.filmStrip.getElements(this.options.items).length;
		this.pages = Math.ceil(this.numElms/this.options.itemsPerPage);	
	},
	setPage: function(direction) {
		if(direction == 1 && !(this.curPage == (this.pages-1) || this.numElms == 0)) {
			this.curPage++;									
		} else if (direction == -1 && this.curPage != 0) {
			this.curPage--;
		}

		// determine the pages new left value
		var filmstripScrollPosition;
		if(this.options.scrollDir == 'horizontal'){
			 filmstripScrollPosition = this.viewPort.getSize().x * -(this.curPage);
		} else if(this.options.scrollDir == 'vertical') {
			filmstripScrollPosition = this.viewPort.getSize().y * -(this.curPage);
		}
		//this.filmStrip.tween(this.styleType, filmstripScrollPosition);
		this.filmStrip.get('tween', {property: this.styleType, duration: this.options.duration }).start(filmstripScrollPosition);

		// set the pagination controls
		this.setPaginationControls();	
	},
	setPaginationControls: function() {
		if (this.curPage == 0) {
			if(this.btnPrev.hasClass('isActive')){ this.btnPrev.removeClass('isActive'); }
			this.btnPrev.addClass('inActive');			
		} else {
			if(this.btnPrev.hasClass('inActive')){ this.btnPrev.removeClass('inActive'); }
			this.btnPrev.addClass('isActive');
		}
		if (this.curPage == (this.pages-1) || this.numElms == 0) {
			if(this.btnNext.hasClass('isActive')){ this.btnNext.removeClass('isActive'); }
			this.btnNext.addClass('inActive');			
		} else {
			if(this.btnNext.hasClass('inActive')){ this.btnNext.removeClass('inActive'); }
			this.btnNext.addClass('isActive');
		}		
	}	
});

/*
Script: mindow.js
	An mootools extension which allows you to easily create overlay pop-ups.

License:
	MIT-style license.
*/

var Mindow = new Class({ 
	Implements: [Options],				   
	options: {
		overlayColor: '#000',
		opacity: 0.7,
		scrolling: false,
		isOpen: false,
		height: 400,
		width: 600,
		version: '0.5b',
		closeBtn: 'mdowClose',
		mdowClass: ''
	},	
	initialize: function(source, options){
		// read in params
		this.source = source;
		this.setOptions(options);

		// determine scrolling
		(this.options.scrolling) ? this.scrolling = 'auto' : this.scrolling = 'hidden';
		// intialize the elements
		this.initHTML();
		
		// set trigger to fire mindow, if no trigger is passed window will open
		this.trigger = $(this.options.trigger);
		if(this.trigger){
			this.trigger.addEvent('click', function(e) {
				e = new Event(e).stop();
				this.openWindow();	
			}.bind(this));
		} else {
			this.openWindow();	
		}
		
		// if you want window to be opened on load
		if (this.options.isOpen) {
		    this.openWindow();
		}
		
		// if IE6, move mindow when user scrolls
		if((Browser.Engine.trident) && (Browser.Engine.version <= 4)){
			window.addEvent('scroll', function(e) {
				if(this.mdowContainer.getStyle('display') == 'block') {
					this.setWindowScroll();
				}
			}.bind(this));
		}
		
		// move mindow when user resizes 			
		window.addEvent('resize', function(e) {
			if(this.mdowContainer.getStyle('display') == 'block') {			
				this.overlay.setStyle('height', 0);
				this.overlay.setStyle('height', window.getScrollSize().y);
		    	this.setWindowScroll();
			}
		}.bind(this));					

	},
	initHTML: function(){
		// create overlay		
		if(!$('mdowOverlay')){
			this.overlay = new Element('div', { 
				'id':'mdowOverlay',
				'styles': { 
					'height':0,
					'position': 'absolute',
					'top': 0,
					'left': 0,
					'z-index': 100000001,
					'visibility': 'visible',
					'width': '100%',
					'overflow': 'hidden',
					'cursor': 'pointer',
					'opacity':0,
					'backgroundColor': this.options.overlayColor
				},
				'events': {
					'click': function(e){
						e = new Event(e).stop();
						this.closeWindow();	
					}.bind(this)
				}				
			}).inject($(document.body));	
			
		} else {
			this.overlay = $('mdowOverlay');	
		}
	
		// create mindow & close button
		if (!$('mdow')) {
			
			// IE 6 position fix
			((Browser.Engine.trident) && (Browser.Engine.version <= 4)) ? position = 'absolute' : position = 'fixed';
			
		    this.mdowContainer = new Element('div', {
		        'id': 'mdowContainer',
		        'styles': {
		            'display': 'none',
					'position': 'absolute',
					'z-index':100000002,
					'top': '50%',
					'left': 0,
					'width': '100%',
					'height': 1,
					'overflow': 'visible',
					'visibility': 'visible'
		        }
		    }).inject($(document.body));
		    
			this.mindow = new Element('div', {
				'id':'mdow',
				'class': this.options.mdowClass,
				'styles': {
					'display':'none',
					'position': position,
					'left': '50%'					
				}
            }).inject(this.mdowContainer);	
			
		} else {
			this.mdowContainer = $('mdowContainer');
			this.mindow = $('mdow');
		}
	
	},
	loadWindow: function(source){
		
		this.setWindowScroll();
				
		this.mindow.setStyles({
		  	width: this.options.width,
		  	height: this.options.height,
			marginLeft: -(this.options.width / 2),
			overflow: this.scrolling 
		});			
		
		// check to see if the souce is url or not
		if(source.indexOf('http') > -1){
			(this.scrolling == 'auto') ? this.iframescroll = 'yes' : this.iframescroll = 'no';
			this.myIframe = new Element('iframe', { 
				'id':'mdowIframe',
				'src': source,
				'frameborder': 0,
				'marginwidth': 0,
				'marginheight': 0, 
				'scrolling': this.iframescroll,
				'styles': { 
					'border': 0,
					'margin': 0,
					'width': this.options.width,
					'height': this.options.height
				}
			}).inject(this.mindow);	
		} else {
			// is div on page
			this.mindow.set('html', $(source).innerHTML);
			if (this.options.onSetHTML)
				this.options.onSetHTML();
		}	
		
		// create and inject the  close button
		this.btnclose = new Element('a',{
			'id': this.options.closeBtn,
			'text': 'Close',
			'href': '#',
			'title':'Close',
			'events': {
				'click': function(e){
					e = new Event(e).stop();
					this.closeWindow();	
				}.bind(this)
			}			
		}).inject(this.mindow, 'top');
	},
	setWindowScroll: function(){
		var containerTop = window.getScroll().y;	

		(this.options.height > window.getSize().y) ? this.mindowTop = 30 : this.mindowTop = ((window.getSize().y - this.options.height)/2);	
		
		// popup is larger then view area
		if(this.options.height > this.overlay.getSize().y){
			containerTop = 0;	
		}
		// at the bottom of content
		else if((containerTop + this.options.height) > this.overlay.getSize().y){
			containerTop = this.overlay.getSize().y - this.options.height - 60;
		}
		
		this.mdowContainer.setStyle('top', containerTop);
		this.mindow.setStyle('top',  this.mindowTop + 'px')
	},
	openWindow: function() {
		// show overlay
		(this.options.height > window.getScrollSize().y) ? this.overlay.setStyle('height', this.options.height + 60) : this.overlay.setStyle('height', window.getScrollSize().y);
		this.overlay.tween('opacity',this.options.opacity);

		// show box
		this.mdowContainer.setStyle('display', 'block');
		this.mindow.setStyle('display','block');
		
		//Multiple Mindows per page fix
	    if(this.options.mdowClass != ''){
	    	this.mindow.set('class', this.options.mdowClass);
	    }
		
		this.loadWindow(this.source);
	},
	closeWindow: function(){
	    // hide box
	    this.mdowContainer.setStyle('display', 'none');
		this.mindow.setStyle('display','none');
		
		//Multiple Mindows per page fix
		this.mindow.set('class', '')
		
		this.mindow.set('html', '');
		
		// hide overlay
		this.overlay.set('tween', {
			onComplete: function(e) {
				if(this.overlay.getStyle('opacity') == 0) {
					this.overlay.setStyle('height', '0');
				}
			}.bind(this)
		});
		this.overlay.tween('opacity', '0');		
	}	
});

HoverMenu = new Class({
	Implements: [Options],
	options: {},
	initialize: function(source, options) {
		this.setOptions(options);
		this.source = $(source);
		this.subNav = this.source.getElement(".subNav");
		this.button = this.source.getElement(".btn");
		this.subNavWrapper = this.source.getElement(".subNavWrapper");
		if (!this.source.hasClass("hoverMenu")) {
			this.source.addEvent('mouseenter', (function() {
				$$(".subNav").each(function(el) { el.setStyle('display', 'none');; });
				this.subNavWrapper.setStyles({zIndex: 2})
				this.subNav.setStyles({visibility: 'hidden', display: ''});
				this.source.addClass("hoverMenu");
				this.subNav.setStyles({
					left: Math.min(this.source.offsetLeft - Math.floor((this.subNav.clientWidth - this.source.clientWidth)/2), this.source.offsetParent.clientWidth - this.subNav.clientWidth),
					visibility: 'visible'
				});
			}).bind(this));
			this.source.addEvent('mouseleave', (function() {
				this.source.removeClass("hoverMenu");
				this.subNavWrapper.setStyles({zIndex: 1})
				$$(".subNav").each(function(el) { el.setStyle('display', ''); });
			}).bind(this));
		}
	}
});

var Dropdown = new Class({
	initialize: function(container) {
		var trigger 	= container.getElement('.trigger');
		var links 		= container.getElements('.filter a');
		var caption 	= container.getElement('.caption span');
		
		container.addEvent('mouseleave', function(e) {
			container.removeClass('on');
		});
		
		trigger.addEvent('click', function(e) {
			e.stop();
			container.addClass('on');
		});
				
		links.each(function(item, index){
			item.addEvent('click', function(e) {
				e.stop();
				window.location = item;
				container.removeClass('on');
			});
		});
	}	
});

window.addEvent('domready', function() {
	
	if (window.videoEmbeds) {
		for (var i = 0; i < window.videoEmbeds.length; i++) {
			var flashvars = {
				itemID: "",
				pageName: s_ea.pageName,
				s_account: s_account,
				cname: "eaeacom.112.2o7.net",
				namespace: "",
				cdPath: "http://ll-100.ea.com/cem/u/f/GPO/crossdomain.xml,http://ll-100.ea.com/nawp/crossdomain.xml",
				media: encodeURIComponent(window.videoEmbeds[i].video)
			};
			$(window.videoEmbeds[i].element).grab(new Element('div', {id: "videoEmbed_"+i, html: 'You don\'t have the latest version of Flash Player, you can download it <a target="flashdownload" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">here</a>.'}));
			swfobject.embedSWF("_swf/2010/StandAloneMediaPlayer.swf", "videoEmbed_"+i, "640", "360", "9.0.115", "_swf/expressInstall.swf", flashvars, { wmode: "transparent", allowFullScreen: true }, false);				 
		}
	}
	$$("#header .navBarTop div.btn").each(function(btn) { new HoverMenu(btn.parentNode); });
	
	var links = $$('#featuresList .mediaTarget');
	var id = 0;
	links.each(function(link, index) { 
		var media = link.getParent().getElement(".media");
		link.id = "video_"+id;
		media.id = link.id + "_container"; 
		id++;
		new Mindow(media.id, { 
			trigger: link.id,
			mdowClass: 'mindowFeatureOverlay',
			width: 640, 
			height: 360, 
			onSetHTML: setupFeaturesVideo.bind(link) 
		});
	});
	
	var orderLinks = $$('.orderOverlay');
	orderLinks.each(function(link, index){
		new Mindow('myOrderOverlay', {
			trigger: link,
			mdowClass: 'mindowOrderOverlay',
			width: 718, 
			height: 468			
		});
	});
	
});
