//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;
} 

//OMNITURE Custom Links for Retailer Overlays
function setCustomPage(pageID,linkID) {
	var pageName = s_ea.pageName.substr(0,s_ea.pageName.lastIndexOf(":")) + ":" + pageID;
	if (linkID != ''){
		setOmniValues(this,'o',linkID,'','','',0,'','',pageName);
	}else{
		setOmniValues(this,'o','','','','',0,'','',pageName);
	}
}

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");
		if (!this.source.hasClass("hoverMenu")) {
			this.source.addEvent('mouseenter', (function() {
				$$(".subNav").each(function(el) { el.setStyle('display', 'none');; });
				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");
				$$(".subNav").each(function(el) { el.setStyle('display', ''); });
			}).bind(this));
		}
	}
});


/*
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': '35%',
					'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 = 20 : 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() {
		// Hide things that need to be hidden
		$$(".mindowHide").setStyle('visibility','hidden');
		
		// 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');
		$$(".mindowHide").setStyle('visibility','');
	}	
});

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);
}

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); });
	$$("#header .navBarTop div.wiibtn").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: 716, 
			height: 459			
		});
	});
	
	// set gus register link to proper sports URL
    if($('gus_register')) {
          var gusLink = $('gus_register').getElement('a');
          gusLink.href = gusLink.href + "&ref=EASports";
    }
    // set gus login link to proper sports URL
    if($('gus_login')) {
          var gusLogin = $('gus_login').getElement('a');
          gusLogin.href = gusLogin.href.replace('registrationSource','authenticationSource') + '&ref=EASports';
    }
	
});

// Pop Quiz Initialize
function showQuiz (){
	new Mindow('myQuizOverlay', {
		mdowClass: 'mindowQuizOverlay',
		width: 993, 
		height: 499			
	});
}

// Pop Quiz Setup
function setupQuiz (){
	var myElement = $$('.mindowQuizOverlay .quizContent');
	var mySecondElement = $$('.mindowQuizOverlay');
	var myThirdElement = $$('..mindowQuizOverlay .quizQuestions');
	
	//expand Mindow and hide landing page
	$$('.mindowQuizOverlay .quizLanding').setStyle('display', 'none');
	$$('.mindowQuizOverlay .quizQuestions').setStyle('display', 'block');
	$$('.mindowQuizOverlay .quizSubmit a').setStyle('display', 'block');
	
	//If IE6 - don't morph.
	if (!(Browser.Engine.trident && Browser.Engine.version <= 4)){ 
		var myQuizExpand = new Fx.Morph(myElement[0], {}); 
		myQuizExpand.start({
		    'height': 420,
		    'background': 'none',	    
		    'background-color': '#000'
		});
		var myMindowExpand = new Fx.Morph(mySecondElement[0], {});
		myMindowExpand.start({
		    'height': 527
		});
		var myQuestionsExpand = new Fx.Morph(myThirdElement[0], {});
		myQuestionsExpand.start({
		    'height': 420
		});
	}
	//If IE6 - blast background
	if (Browser.Engine.trident && Browser.Engine.version <= 4){
		myElement[0].setStyle('background', 'none');
		myElement[0].setStyle('background-color', '#000');
	}
}

//Pop Quiz Submit
function submitQuiz (){

	var myForm = $$('.mindowQuizOverlay').getElement('form');
	var ajaxContainer = $$('.mindowQuizOverlay .quizQuestionsBG');
	
	var myReq = new Request.HTML({
		method: 'post',
		url: 'quiz.action?quizSubmit=true',
		update: ajaxContainer[0],
		onComplete: function(){
			//ajaxContainer[0].scrollTo(0, 300);
		}
		}).post(myForm[0]);
	
	//hide Submit button after post.
	$$('.mindowQuizOverlay .quizSubmit a').setStyle('display', 'none');
	
	$$('.mindowQuizOverlay .quizQuestions').scrollTo();
	
}

//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' : '' );
}

// Custom scrollbar class
var scrollBar = new Class ({
	initialize: function(content,scrollbar,handle,horizontal,ignoreMouse) {
		this.content = $(content);
		this.scrollbar = $(scrollbar);
		this.handle = $(handle); 
		this.checkScroll(horizontal,ignoreMouse);
	},
	checkScroll: function(horizontal,ignoreMouse) {
		this.steps = (horizontal?(this.content.getScrollSize().x - this.content.getSize().x):(this.content.getScrollSize().y - this.content.getSize().y));
		if ((!horizontal) && (this.content.getScrollSize().y - this.content.getSize().y) <= 0) {
			this.scrollbar.setStyle('display', 'none');
			this.scrollbar.getParent().setStyle('display', 'none');
		} else {
			this.scrollbar.setStyle('display', '');
			this.scrollbar.getParent().setStyle('display', '');
			this.makeSlider(horizontal,ignoreMouse);
		}
	},
	makeSlider: function(horizontal,ignoreMouse) {
		this.slider = new Slider(this.scrollbar, this.handle, {	
			steps: this.steps,
			mode: (horizontal?'horizontal':'vertical'),
			onChange: function(step){
				var x = (horizontal?step:0);
				var y = (horizontal?0:step);
				this.content.scrollTo(x,y);
			}.bind(this)
		}).set(0);
		if( !(ignoreMouse) ){
			this.content.addEvent('mousewheel', function(e){
				e = new Event(e).stop();
				var step = this.slider.step - (e.wheel * 30);
				this.slider.set(step);					
			}.bind(this));
			this.scrollbar.addEvent('mousewheel', function(e){	
				e = new Event(e).stop();
				var step = this.slider.step - (e.wheel * 30);	
				this.slider.set(step);					
			}.bind(this));
		}
		this.killEvent();
	},
	killEvent: function() {
		$(document.body).addEvent('mouseleave',function(){this.slider.drag.stop()}.bind(this));
	}
});


//FILMSTRIP
var FilmStrip = new Class({
    initialize: function(containerId, myOptions){	
		this.myOptions = myOptions;
		this.container = $(containerId);
		
		// get elements and their size
		this.getElements();
		
		// init paging
		this.initPaging();
		
		// set film strips height or width
		if(this.myOptions.scrollDir == 'vertical'){
			this.filmStrip.setStyle("height", this.pages*this.viewPortHeight+"px");
		} else {
			this.filmStrip.setStyle('left', '0');
			this.filmStrip.setStyle("width", this.pages*this.viewPortWidth+"px");
		}
		
		//create effect
		($type(this.myOptions.transitionSpeed)) ? this.transitionSpeed = this.myOptions.transitionSpeed : this.transitionSpeed = 200;		
		($type(this.myOptions.transitionType)) ? this.transitionType = this.myOptions.transitionType : this.transitionType = Fx.Transitions.Sine.easeInOut;
		this.setupEffect();
		
		// show or hide the pagination controls
		this.setPaginationControls();

		// attach all the click handlers to the next and previous buttons
		this.nextButton.addEvent('click', function(e) { this.setPage(e,1); }.bind(this));
		this.prevButton.addEvent('click', function(e) { this.setPage(e,-1); }.bind(this));	
	},
	setupEffect: function() {
		(this.myOptions.scrollDir == 'vertical') ? this.styleType = 'top' : this.styleType = 'left';
		this.pageSlider = new Fx.Tween(this.filmStrip, this.styleType, {
			duration: this.transitionSpeed,
			transition: this.transitionType
		});		
	},
	getElements: function() {
		this.viewPort = this.container.getElement(this.myOptions.viewPort);	
    	this.filmStrip = this.viewPort.getElement(this.myOptions.filmStrip);
    	this.prevButton = this.container.getElement(this.myOptions.prevButton);
    	this.nextButton = this.container.getElement(this.myOptions.nextButton);
		if (this.myOptions.pagerControls)
			this.pagerControls = this.container.getElement(this.myOptions.pagerControls);
    	this.getElementSize();
	},
	getElementSize: function() {
		($type(this.myOptions.viewPortWidth)) ? this.viewPortWidth = this.myOptions.viewPortWidth : this.viewPortWidth = this.viewPort.getSize().x;
		($type(this.myOptions.viewPortHeight)) ? this.viewPortHeight = this.myOptions.viewPortHeight : this.viewPortHeight = this.viewPort.getSize().y;
		($type(this.myOptions.filmStripHeight)) ? this.filmStripHeight = this.myOptions.filmStripHeight : this.filmStripHeight = this.filmStrip.getSize().y;
	},
	initPaging: function() {
		this.curPage = 0;
		if(this.myOptions.scrollDir == 'vertical'){
			this.pages = Math.ceil(this.filmStripHeight/this.viewPortHeight);
		} else {
			if (this.pagerControls) {
				var pages = this.pagerControls.getElements(".pages span");
				if (pages.length) pages[0].addClass("active");
				for (var i = 0; i < pages.length; i++) {
					var that = this;
					pages[i].addEvent('click', (function(index) { 
						return (function(e) {
							this.setPage(e,null,index); 
						}).bind(that)
					})(i));
				}
			}
			this.itemPerPage = this.myOptions.itemPerPage;			
			this.numResults = +this.container.getElement(this.myOptions.numResults).value;
			this.pages = Math.ceil(this.numResults/this.itemPerPage);	
			if (this.pagerControls)
				this.pagerControls.getElement(".currentPageLength").innerHTML = (this.pages == this.curPage + 1) && (this.numResults % this.itemPerPage) ? this.numResults % this.itemPerPage : this.itemPerPage;
		}	
	},
	setPage: function(e, direction, index) {
		e = new Event(e);
		// Update curpage
		if (direction !== null) {
			(direction == 1) ? this.curPage++ :	this.curPage--;
		} else {
			this.curPage = index;
		}
		
		// determine the pages new left value
		var filmstripScrollPosition;
		if(this.myOptions.scrollDir == 'vertical'){
			 filmstripScrollPosition = this.viewPortHeight * -(this.curPage);
		} else {
			filmstripScrollPosition = this.viewPortWidth * -(this.curPage);
		}
		
		if (this.pagerControls) {
			this.pagerControls.getElements(".pages span").removeClass("active")[this.curPage].addClass("active");
			this.pagerControls.getElement(".currentPageLength").innerHTML = (this.pages == this.curPage + 1) && (this.numResults % this.itemPerPage) ? this.numResults % this.itemPerPage : this.itemPerPage;
		}
			
		
		this.pageSlider.start('left', filmstripScrollPosition+"px");
		
		// set the pagination controls
		this.setPaginationControls();
	
		e.stop();
	},
	setPaginationControls: function() {
		// decide whether to show or hide each pagination control
		(this.curPage == 0) ? this.prevButton.setStyle("visibility", "hidden") : this.prevButton.setStyle("visibility", "visible");
		(this.curPage == (this.pages-1) || this.numResults == 0) ? 	this.nextButton.setStyle("visibility", "hidden") : this.nextButton.setStyle("visibility", "visible");
		if($type(this.myOptions.pageCurrent)){
			this.container.getElement(this.myOptions.pageCurrent).innerHTML = this.curPage + 1;
		}
		if(this.myOptions.pageTotal) {
			this.container.getElement(this.myOptions.pageTotal).innerHTML = this.pages;	
		}
	}	
});


/*** Draft Picks poll ***/
var Polls = new Class({
    initialize: function(containerID,pollID){
    	this.pollURL 		= "polls.action";
    	this.pollID 		= pollID;
    	this.myContainer 	= $(containerID);
    	this.resultsBtn		= $('resultsBtn');
    	this.loadPoll();
    },
    loadPoll: function(params){
    	if (!params) params = "";
    	
    	//check cookie - if exists, load resulst pane
    	if(Cookie.read('EASportsMadden2010-poll-' + this.pollID)) params += "&result=true";
    	
		new Request.HTML({
    		url:this.pollURL + "?pollsName=" + this.pollID + params, 
    		onSuccess: function(responseTree, responseElements, responseHTML){
    			this.loadContent(responseHTML);
    			// sets graphical options for poll instead of input radio buttons
    			setPollAnswer(this.myContainer);
			}.bind(this),
			onRequest: function() {
				this.setStatus('Calculating poll data...');
			}.bind(this),
			onFailure: function() {
				this.setStatus('Polls cannot be loaded at this time.');
			}.bind(this)
		}).send();

    },
    loadContent: function(responseHTML){
		this.myContainer.set('html',responseHTML);
		
		if ($('pollSubmit')) {
			$('pollSubmit').addEvent('click', function(e) {	
				this.submitPoll();
				e.stop();
			}.bind(this));
		}

		this.myBars = this.myContainer.getElements('.bar');
		if (this.myBars) this.drawBars();

    },
    submitPoll: function(){
    	
    	//set cookie for later
    	var myCookie = Cookie.write('EASportsMadden2010-poll-' + this.pollID, true,{duration: 7});
    	   	
    	var myForm 		= this.myContainer.getElement('form');
    	var myVotes 	= myForm.getElements('ul li input');
    	var choiceID	= false;
    	   
    	//get raido button values
    	myVotes.each(function(item){
    		if (item.checked) choiceID = item.value;
    	});
	   	var params = "";
	    params += "&result=true";
		params += "&pollQuestionId=" + myForm.getElement('#pollID').value;
		if (choiceID) params += "&choiceId=" + choiceID;   	   	
		   	
	    this.loadPoll(params);
    
    },
    setStatus: function(msg){
		this.myContainer.innerHTML = "<p>" + msg + "</p>";
    },
    drawBars: function(){
		this.myBars.each(function(item){
			var percentage = item.getElement('.percentage');
			var offset = parseInt((273 - (percentage.innerHTML * 2.73 * 100)) * -1);
			var realPercentage = parseInt(percentage.innerHTML * 100) + "%";
			percentage.innerHTML = realPercentage;
			
			var myFx1 = new Fx.Tween(item,{duration:1000});
			
			if (Browser.Engine.trident) {
				myFx1.start('background-position-x',offset+'px');
			} else {
				myFx1.start('background-position',offset + 'px 0px');		
			}
			
		});
    } 
});

function setPollAnswer(pollname) {
	var poll = pollname;
	var answers = $(poll).getElements('a');
	answers.each(function(answer,index,array) {
		answer.addEvent("click", function(event) {
			array.removeClass('selected');	
			var pollAnswer = answer.id;
			answer.addClass('selected');
			event = new Event(event).stop();
		});
	});
}

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');
			});
		});
	}	
});

var Dropdown2 = new Class({
	initialize: function(container) {
		var trigger 	= container.getElement('.trigger');
		var answers		= container.getElements('.filter label');
		var caption 	= container.getElement('.caption a');
		
		container.addEvent('mouseleave', function(e) {
			container.removeClass('on');
		});
		
		trigger.addEvent('click', function(e) {
			container.addClass('on');
		});
				
		answers.each(function(item, index){
			item.addEvent('click', function(e) {
				caption.innerHTML = item.getElement("span").innerHTML;
				item.getElement('input').set('checked','checked');
				container.removeClass('on');
			});
		});
	}	
});

var submittedDropdowns = new Class({
	initialize: function(container) {
		var trigger 	= container.getElement('.trigger');
		var answers		= container.getElements('.filter label');
		var caption 	= container.getElement('.caption a');
		
		container.addEvent('mouseleave', function(e) {
			container.removeClass('on');
		});
		
		trigger.addEvent('click', function(e) {
			container.addClass('on');
		});
				
		answers.each(function(item, index){
			if(item.getElement('input').get('checked')){
				if(item.getElement('span').hasClass('correct')){
					caption.innerHTML = item.getElement('span').innerHTML;
					caption.setStyle('color', '#00CC00');
				}else if (item.getElement('span').hasClass('incorrect')){
					caption.innerHTML = item.getElement('span').innerHTML;
					caption.setStyle('color', '#ff0000');
				}else{
					caption.innerHTML = item.getElement('span').innerHTML;
				}
			}
		});
	}	
});





