jQuery(function($) {
	var body = $('div.ie').length > 0 ? $('div.ie') : $('body');
	var myESPNTimeout, closeMyEspnTimeout, myEspnButton = $('#myespn'), myEspnPopup = '#member-services', hellip = "&hellip;", cookieLanguage = getCookie('lang');
	$(document).bind('click', function(e){closeContent(e);});
	
	//check to see if myEspn needs to be reset because the language changed
	if(cookieLanguage != null && cookieLanguage != '' && myEspnText.language != cookieLanguage){
		$.myespn.reset();
		document.cookie = 'lang=' + myEspnText.language + '; ; path=/; domain=espn.go.com';
	}else if(cookieLanguage == null || cookieLanguage == ''){
		document.cookie = 'lang=' + myEspnText.language + '; ; path=/; domain=espn.go.com';
	}
	
	//bind the mouseover event to the myEspn button
	enableMouseover();
	myEspnButton.bind('mouseleave', function() {clearTimeout(myESPNTimeout);});
	myEspnButton.bind('click', function(evt){evt.preventDefault();});
	//bind moving the popup if the window is resized
	$(window).resize(setPopupStyles);
	
	function activateContent(){
		// if we're already displayed, we can safely leave
		if(myEspnButton.hasClass('hover')) { return false; } 
		// if staticLogin.js has not completed yet, don't show the popup
		if(serverProtocol != undefined) {
			myEspnButton.addClass('hover');
			var uri = '/v2_0/signIn'; 
			var showCached = false;
			// user-active means they passively or manually logged in
			if(myEspnButton.hasClass('user-active')) uri = '/v2_0/myEspn';
			if($(myEspnPopup + 'Hidden').length == 0) 
				displayLoadingGraphic();
			else{ 
				$(myEspnPopup + 'Hidden').attr('id', myEspnPopup.substr(1));
				showCached = true;
			}
			enableMouseout(myEspnButton);
			enableMouseout($(myEspnPopup));	
			$(myEspnPopup).bind('mouseenter', function() {
				clearTimeout(closeMyEspnTimeout);
			});
			myEspnButton.bind('mouseenter', function() {
				clearTimeout(closeMyEspnTimeout);
			});
			//don't enable clicking to close the dropdown right away for users that try to open the dropdown with a click
			setTimeout(
					function() {
						myEspnButton.click(function(e) {
							closeContent(e);
							myEspnButton.unbind('mouseenter');
							myEspnButton.click(activateContent);
							myEspnButton.one('mouseleave', enableMouseover);
							return false;
						});	
				},
				500
			);	
			if(showCached){
				myEspnButton.addClass('active');
				$(myEspnPopup).show();
			}
			else sendRequest(uri, 'GET', $('#form-memberarea').serialize());		
		}
	}
	
	function sendRequest(uri, type, data){
		//grab the cached version if it's available
		if((uri.match('/v2_0/myEspn') != null || uri.match('/v2_0/signIn') != null) && $(myEspnPopup + 'Hidden').length > 0){
			$(myEspnPopup).remove();
			$(myEspnPopup + 'Hidden').attr('id', myEspnPopup.substr(1));
			$(myEspnPopup).show();
			enableMouseout($(myEspnPopup));
		}else{
			var pattern = /v[0-9]/;
			var host = uri.substring(0, uri.search(pattern) - 1);
			uri = uri.substring(uri.search(pattern) - 1);
			$.ajax({
				url: host + '/personalization/cached' + uri,
				data: data + '&noFrame=true',
				cache: true,
				dataType: 'html',
				type:type,
				success: function(html,status){ drawPopup(html,uri); },
				error: function(request, status, error) {displayError();}
			});
			return false;
		}
	}
			
	function drawPopup(html,uri) {
		//send analytics beacon
		anLinkHover('hover:myespntab','hover:myespn');
		//if they moused out before the request completed, don't render popup
		if(!(myEspnButton.hasClass('hover'))) { return false; }
		if(html.match("<title>ESPN.com - Member Services - Global Registration Error</title>") != null || html.match("<title>ESPN Deportes: Servicios para Miembros - Global Registration Error</title>")){
			displayError(); 
			return false;
		}
		if(uri.match("myEspn") != null){
			populateMyEspnContent($(html));
		}else appendPopupContent($(html));
	}
				
	function populateMyEspnContent(html){
		personalizationPrefix = myEspnText.urlPrefix;
		if(myEspnText.isProd == "true") personalizationPrefix = 'http://espn.go.com';
		$.myespn.init({
			success: function(data){
				parseMyEspn(data, html);
			},
			error: function(errorThrown){
				$.myespn.reset({
					success: function(data) {parseMyEspn(data, html);},
					error: function(errorThrown) {showMyEspnParsingError(html);}
				});
			}
		});
	}
	
	function parseMyEspn(data, html){
		var spacer = '-';
		if(myEspnText.language == 'es') spacer = '_';
		cleanupJson(data);
		if(data.mySports == undefined || data.myTeams == undefined || data.myPlayers == undefined || data.myColumnists == undefined ||
			(data.mySports.length == 0 && data.myTeams.length == 0 && data.myPlayers.length == 0 && data.myColumnists.length == 0)){
			hideFavoriteWrappers(html);
			html.find('#myEspnError').hide();
			html.find('#no-prefs').show();
		}else if(html.find('#category').length == 0){
			html.find('#no-prefs').hide();
			html.find('#myEspnError').hide();
			writeInfo(html, data, 'mySports', html.find('#mySportsContainer'), spacer, 13);
			writeInfo(html, data, 'myTeams', html.find('#myTeamsContainer'), spacer, 20);
			writeInfo(html, data, 'myPlayers', html.find('#myPlayersContainer'), spacer, 13);
			writeInfo(html, data, 'myColumnists', html.find('#myColumnistsContainer'), spacer, 20);
			writeViewMoreLink(data.mySports.length, 'sports', 'mySports', html);
			writeViewMoreLink(data.myTeams.length, 'teams', 'myTeams', html);
			writeViewMoreLink(data.myPlayers.length, 'players', 'myPlayers', html);
			writeViewMoreLink(data.myColumnists.length, 'columnists', 'myColumnists', html);
		}else{
			var category = html.find('#category').val();
			var myText = 'my';
			if(myEspnText.language == 'es') myText = 'mis';
			var objList = data['my' + myEspnText[category + 'jsonkey']];
			$('<h6>' + myText + myEspnText[category + 'text'] + '</h6>').appendTo(html.find('#my-favs-all-links'));
			var index = 0;
			for(var column = 0; column < 3; column++){
				var ul = $('<ul/>');
				if(column == 2) ul.className = 'last';
				for(var n = 0; n < 9; n++){
					if(objList[index] != undefined){
						switch(category){
							case 'sports': writeSportInfo(objList[index], html, ul, 'li', spacer, 15);break;
							case 'teams' : writeTeamInfo(objList[index], html, ul, 'li', spacer, 30);break;
							case 'players' : writePlayerInfo(objList[index], html, ul, 'li', spacer, 15);break;
							case 'columnists' : writeColumnistInfo(objList[index], html, ul, 'li', spacer, 15);break;
						}
					}else{
						appendAnchor(null, '#', '&nbsp;', ul, 'li', null, null);
					}
					index++;
				}
				html.find('#my-favs-all-links').append(ul);
			}
		}
		writeUsernameInfo(html);
		if(!(myEspnButton.hasClass('hover'))) { return false; }
		appendPopupContent(html);
	}
	
	function appendPopupContent(html){
		//remove any content currently showing in the popup and cache if necessary
		if($(myEspnPopup).length > 0){
			if(($('#my-favs').length != 0 || $('div.form-signin').length != 0) && $(myEspnPopup + 'Hidden').length == 0){
				$(myEspnPopup).hide();
				$(myEspnPopup).attr('id', myEspnPopup.substr(1) + 'Hidden').unbind('mouseleave');
				$('#errorsUl').html('');
			}
			else $(myEspnPopup).remove();
		}
		setLoginStatus(html);
		bindPopupEvents(html);
		body.append(html);
		setPopupStyles();
	}
	
	function writeInfo(html, data, category, parent, spacer, maxLength){
		var length = data[category].length > 5 ? 5 : data[category].length;
		for(var i = 0; i < length; i++){
			switch(category){
				case 'mySports': writeSportInfo(data[category][i], html, parent, 'dd', spacer, maxLength);break;
				case 'myTeams' : writeTeamInfo(data[category][i], html, parent, 'dd', spacer, maxLength);break;
				case 'myPlayers' : writePlayerInfo(data[category][i], html, parent, 'dd', spacer, maxLength);break;
				case 'myColumnists' : writeColumnistInfo(data[category][i], html, parent, 'dd', spacer, maxLength);break;
			}
		}
	}
	
	function writeTeamInfo(team, html, parent, parentElementTag, spacer, maxLength){
		var teamText = team.text + getSportAbbrev(team.sport);
		if(teamText.length > maxLength) teamText = jQuery.trim(team.text.substring(0, (maxLength - 10))) + hellip + getSportAbbrev(team.sport);
		if(team.sport == 59){
			var link = getTeamsLink(myEspnText.language).replace('abbrev', getLowerCaseSportAbbrev(team.sport));
			link = link.replace('teamId', 'team');
			appendAnchor(null, link + team.abbrev, teamText, html.find('#myTeamsContainer'), parentElementTag, null, 'myteams');
		}else{
			var link = getTeamsLink(myEspnText.language).replace('abbrev', getLowerCaseSportAbbrev(team.sport));
			if(myEspnText.language == 'es') link = link + team.abbrev;
			else link = link + team.id;
			if(team.sport >= 600) link = getSoccerTeamsLink(myEspnText.language) + team.id;
			appendAnchor(null, link, teamText, parent, parentElementTag, null, 'myteams');
		}
	}
	
	function writePlayerInfo(player, html, parent, parentElementTag, spacer, maxLength){
		var playerText = player.text;
		if(playerText.length > maxLength) playerText = jQuery.trim(playerText.substring(0,maxLength)) + hellip;
		appendAnchor(null, getPlayersLink(myEspnText.language).replace('abbrev', getLowerCaseSportAbbrev(player.sport)) + player.id, playerText, parent, parentElementTag, null, 'myplayers');
	}
	
	function writeSportInfo(sport, html, parent, parentElementTag, spacer, maxLength){
		var sportText = sport.text;
		if(sport.id == 23 || sport.id == 41 || sport.id == 54) sportText = (getSportAbbrev(sport.id)).substring(1, getSportAbbrev(sport.id).length - 1);
		if(sportText != undefined && sportText.length > maxLength) sportText = jQuery.trim(sportText.substring(0,maxLength)) + hellip;
		appendAnchor(null, getSportsLink(myEspnText.language, sport.id), sportText, parent, parentElementTag, null, 'mysports');
	}
	
	function writeColumnistInfo(columnist, html, parent, parentElementTag, spacer, maxLength){
		var columnistName = '';
		var columnistId = '';
		if(columnist.id.indexOf('Deportes') == -1){
			var columnistIdText = columnist.id.split("_");
			columnistId = columnistIdText[columnistIdText.length - 1];
			for(var j = 0; j < columnistIdText.length - 1; j++){
				columnistId = columnistId + spacer + columnistIdText[j];
			}
			columnistName = getColumnistName(columnistId, spacer);
		}else{
			columnistId = columnist.text.replace(/ /g, spacer);
			columnistId = scrubSpecialCharacters(columnistId);
			columnistName = columnist.text;
		}
		if(columnistName.length > maxLength) columnistName = jQuery.trim(columnistName.substring(0,maxLength)) + hellip;
		appendAnchor(null, getColumnistsLink(myEspnText.language) + columnistId + '/', columnistName, parent, parentElementTag, null, 'mycolumnists');
	}
	
	function writeViewMoreLink(length, category, longCategory, html){
		var personalizationLink = personalizationPrefix + '/personalization/';
		if(myEspnText.language != "en") personalizationLink = personalizationLink + '?myEspnText.language=' + myEspnText.language;
		if(length > 5){
			appendAnchor('showall' + category, '/v2_0/myEspnShowAll?category=' + category, myEspnText.viewall, html.find('#' + longCategory + 'Container'), 'dd', 'more', null);
		}else{
			appendAnchor(null, personalizationLink, myEspnText.addlc + ' ' + myEspnText[category + 'text'], html.find('#' + longCategory + 'Container'), 'dd', 'more', 'add_' + category);
		}			
	}
	
	function writeUsernameInfo(d){
		var usernameVal = $('#username').html();
		if(usernameVal.length > 28) usernameVal = usernameVal.substring(0,25) + hellip;
		var firstnameVal = $('a.membername').html();
		if(usernameVal != null && usernameVal != ""  && usernameVal.indexOf('NRT_DUM') == -1){
			d.find('#myEspnUsername1').html(usernameVal);
		}else{
			d.find('#signInAs').html('&nbsp;');
		}
		d.find('#myEspnUsername2').html(firstnameVal);
	}
	
	function hideFavoriteWrappers(d){
		d.find('#mySportsContainer').hide();
		d.find('#myTeamsContainer').hide();
		d.find('#myPlayersContainer').hide();
		d.find('#myColumnistsContainer').hide();
	}
	
	function cleanupJson(data){
		parseBadJson(data, 'mySports');
		parseBadJson(data, 'myTeams');
		parseBadJson(data, 'myTeams');
		parseBadJson(data, 'myColumnists');
	}
	
	function showMyEspnParsingError(html){
		hideFavoriteWrappers(html);
		html.find('#no-prefs').hide()
		html.find('#myEspnError').show();
		writeUsernameInfo(html);
		if(!(myEspnButton.hasClass('hover'))) { return false; }
		appendPopupContent(html);
	}
	
	function setLoginStatus(html){
		var loginStatus = $('#loginStatus').html();
		var hasInsider = $('#hasInsider').html();
		if(loginStatus == '1' || loginStatus == '0') html.find('#loggedIn').show();
		else html.find('#notLoggedIn').show();
		if(hasInsider == true || hasInsider == 'true'){
			if(location.pathname.indexOf("/outdoors") > -1){
				html.find('#bassInsiderXml').show();
				html.find('#asabassinsider').show();					
			}else{
				html.find('#insiderXml').show();
				html.find('#asaninsider').show();
			}
		}else{
			if(location.pathname.indexOf("/outdoors") > -1){
				html.find('#bassinsiderbenefits').show();
				html.find('#morebassbenefits').show();					
			}else{
				html.find('#insiderbenefits').show();
				html.find('#morebenefits').show();
			}
		}
		if(location.pathname.indexOf("/outdoors") > -1){
			html.find('#myEspnInsiderLogo').hide();
			html.find('#myEspnBassInsiderLogo').show();
		}
		if(html.find('#myEspnUsernameWrapper #username').length > 0) html.find('#myEspnUsernameWrapper #username').val($('#hiddenUsername').val());
		if(html.find('#myEspnPasswordWrapper #password').length > 0) html.find('#myEspnPasswordWrapper #password').val($('#hiddenPassword').val());
	}
	
	function bindPopupEvents(html){
		//bind all popup anchor tag click events
		bindAnchors(html);
		//bind all popup form submit events
		bindInputs(html);
		enableMouseout(html);
		//if they re-enter the popup after mousing out, don't close
		html.bind('mouseenter', function() {
			clearTimeout(closeMyEspnTimeout);
		});
		html.one('keypress', function(){
			myEspnButton.unbind('mouseleave');
			html.unbind('mouseleave');
		});
	}
	
	function bindAnchors(html){
		html.find('a').each(function(i){
			$(this).click(function(){
				if(this.href.indexOf('/v2_0') == -1 && this.href.indexOf('/v3_1') == -1){
					window.location = this.href;
				}else if(this.href.indexOf('v3_1') != -1){
					jQuery('#loginRegisterLink').attr('href', jQuery('#loginRegisterLink').attr('href') + '&appRedirect=' + encodeURIComponent(window.location.href));
					jQuery('#loginRegisterLink').colorbox({iframe:true, height:jQuery('div.ie6').length > 0 || jQuery('div.ie7').length > 0 ? 550 : 528, width:830, scrolling:false, close:"", overlayClose:false});
				}else{
					sendRequest(this.href, 'GET', $('#form-memberarea').serialize());
					return false;
				}
			});
		});	
	}
	
	function bindInputs(html){
		html.find('input').each(function(i){
			if(this.type == 'image' || this.type == 'submit'){
				html.find('.' + this.className).bind('click', function() {setCookies(this.value, $(myEspnPopup).find('#myEspnForm').serializeArray()); return false;});
			}
		});	
	}
		
	function setCookies(uri, data){
		try {
			jQuery.each(data, function(i, field){
				if(serverProtocol.indexOf('https') == -1){
					document.cookie = field.name + '=' + encodeURIComponent(field.value) + '; path=/; domain=.go.com';
				}else{
					document.cookie = field.name + '=' + encodeURIComponent(field.value) + '; path=/; domain=.go.com; secure';
				}
			});
			var script = document.createElement('script'); 
			script.type = 'text/javascript'; 
			script.src = serverProtocol + uri + '?' + parseInt(Math.random() * 1000000000); 
			document.getElementById('member-services').appendChild(script);
		} catch(e) { displayError(); }
		return false;
	}
				
	function displayLoadingGraphic(){
		myEspnButton.addClass('active');
		var height = 324;
		if(myEspnButton.hasClass('user-active')) {
			height = 400;
		} 
		if($(myEspnPopup) != null)  $(myEspnPopup).remove();
		body.append('<div id="member-services" class="span-4 last gradient-background user-active" style="height:' + height + 'px"><img src="' + myEspnText.imgRef + '/assets/memberservices/ajax-loader.gif" style="padding-left:285px;padding-top:140px;"/></div>');
		setPopupStyles();
	}
	
	function displayError(){
		var loginStatus = $('#loginStatus').html();
		if(!(myEspnButton.hasClass('hover'))) { return false; }
		var height = 324;
		if(myEspnButton.hasClass('user-active')) {
			height = 400;
		} 
		if($(myEspnPopup) != null)  $(myEspnPopup).remove();
		var errorHtml = '<div id="member-services" class="span-4 last gradient-background user-active" style="height:' + height + 'px"><div style="padding-top:140px;padding-left:16px;">' + myEspnText.myespnerrortext1;
		if(loginStatus != '1' && loginStatus != '0'){ 
			errorHtml = errorHtml + ' ' + myEspnText.myespnerrortext2 + ' <a href="' + myEspnText.urlPrefix + '/members/login?appRedirect=' + encodeURIComponent(returnURL);
			if(myEspnText.language != "en" && myEspnText.language != "EN") errorHtml = errorHtml + '&myEspnText.language=' + myEspnText.language;
			errorHtml = errorHtml + '">' + myEspnText.myespnerrortext3 + '</a>.';
		}
		errorHtml = errorHtml + '<br/><br/>' + myEspnText.mserrortext2 + '</div></div>';
		body.append(errorHtml);
		setPopupStyles();
		bindPopupEvents();
	}
			
	function enableMouseover(){
		myEspnButton.unbind('click');
		myEspnButton.bind('click', function(evt){evt.preventDefault();});
		var eventName = 'mouseenter';
		if(navigator.userAgent.toLowerCase().indexOf('iphone') != -1) eventName = 'click';
		myEspnButton.bind(eventName, function() {
			myESPNTimeout = setTimeout(
				function() {
					activateContent();
				},
				250
			);	
		});
	}
	
	function enableMouseout(e){
		e.bind('mouseleave', function(evt){
			//stop the popup from closing on select dropdowns
			var overPopup = false;
			if(e.attr('id') == "member-services") overPopup = isOverPopup(evt);
			if(!overPopup){
				closeMyEspnTimeout = setTimeout(
					function(){
						closeContent(true);
					},750);
			}
		});	
	}
	
	function closeContent(e) {
		if(!e) { 
			return false; 
		} else if(((e.target && e.target.id != 'member-services' && $(e.target).parents(myEspnPopup).length == 0) || e === true) && $(myEspnPopup).length != 0) {
			anStopCount();
			//if the login form or myEspn states are showing, cache content
			if(($('#my-favs').length != 0 || $('div.form-signin').length != 0) && $(myEspnPopup + 'Hidden').length == 0){
				$(myEspnPopup).hide();
				$(myEspnPopup).attr('id', myEspnPopup.substr(1) + 'Hidden').unbind('mouseleave');
				$('#errorsUl').html('');
			}
			else $(myEspnPopup).remove();
			myEspnButton.removeClass('hover active').unbind('click');
			myEspnButton.unbind('mouseleave');
			//$(document).unbind('click');
			myEspnButton.bind('mouseleave', function() {clearTimeout(myESPNTimeout);});
			if((window.location.host.indexOf('proxydev.espn.go.com') != -1 && location.pathname.indexOf('/personalization') == -1) || window.location.host.indexOf('rqa.espn.go.com') != -1 || location.pathname.indexOf('/tcmen') != -1){
				$('#registerLink').unbind();
				$('#registerLink').colorbox({iframe:true, height:jQuery('div.ie6').length > 0 || jQuery('div.ie7').length > 0 ? 550 : 528, width:830, scrolling:false, close:"", overlayClose:false});
			}
		}
	}
						
	//Utility functions -------------------------------------------------------------------------	
	function parseBadJson(data, element){
		if(data[element] != undefined && typeof data[element] !== "object") {
		    data[element] = JSON.parse(data[element]);
		}
	}
	
	function appendAnchor(className, href, text, parent, parentElementTag, parentClass, analyticsId){
		$('<' + parentElementTag + ' class="' + parentClass + '"><a class="' + className + '" href="' + href + '" name="&lpos=myespn&lid=' + analyticsId + '">' + text + '</a></' + parentElementTag + '>').appendTo(parent);
	}
	
	var sportAbbrev = {
		23:"(NCAAF)",
		41:"(NCAAB)",
		54:"(NCAAW)"
	};
	
	function getSportAbbrev(sportId) {
	    return sportAbbrev[sportId] || '';
	}
	
	function trimString(str){
		result = str;
		if(str.length > 30){
			result = str.substr(0, 30) + hellip;
		}
		return result;
	}
	
	function setPopupStyles(){
		var id = myEspnPopup + ',' + myEspnPopup + 'Hidden';
		if($(id).length > 0){
			$(id).css({
				'position':'absolute',
				'z-index':999999,
				'top':myEspnButton.offset().top + myEspnButton.height() - 1,
				'left':myEspnButton.offset().left + myEspnButton.width() - $(id).width()
			});
			$(id).bgiframe();
			//take into account the offset of a scrollbar and fix 1 pixel offset when screen width is an even number of pixels
			var offsetLeft = $(id).offset().left + ((myEspnButton.offset().left - $(id).offset().left) - ($(id).width() - myEspnButton.width()));
			if(window.document.body.clientWidth % 2 == 0) offsetLeft++;
			$(id).css({
				'left': offsetLeft
			});
		}
	}
	
	function isOverPopup(evt){
		var mouseX = evt.clientX;
		var mouseY = evt.clientY;
		//IE7
		if(mouseX < 0 || mouseY < 0) return true;
		//FF2
		if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ 
			 var ffversion=new Number(RegExp.$1);
			 if (ffversion < 3){
				 if(mouseX < 200) return true;
			}
		}
		var buttonOffset = myEspnButton.offset();
		var popupOffset = $(myEspnPopup).offset();
		var buttonLeft = buttonOffset.left;
		var buttonRight = buttonLeft + myEspnButton.outerWidth();
		var buttonTop = buttonOffset.top;
		var buttonBottom = buttonTop + myEspnButton.outerHeight();
		var popupLeft = popupOffset.left;
		var popupRight = popupLeft + $(myEspnPopup).outerWidth();
		var popupTop = popupOffset.top;
		var popupBottom = popupTop + $(myEspnPopup).outerHeight();
		if(mouseY > popupBottom) return false;
		else if(mouseY < buttonTop) return false;
		else if(mouseX > popupRight) return false;
		else if(mouseX < popupLeft) return false;
		else if(mouseY < popupTop && mouseX < buttonLeft) return false;
		else return true;
	}
	
	var columnistFirstName = {
		'Ja':'J.A.',
		'Dj':'DJ',
		'Lz':'LZ',
		'Ej':'E.J.',
		'Amy':'Amy K.',
		'Leanne':'Le Anne',
		'Stephen':'Stephen A.'
	};
	
	var columnistLastName = {
		'D ford':'D. Ford',
		'Kiper jr':'Kiper Jr',
		'Lebrun':'LeBrun',
		'Mcshay':'McShay',
		'Mcneil':'McNeil',
		'Oneil':'O\'Neil'
	};
	
	function getColumnistName(columnistCode, spacer){
		var columnistArray = columnistCode.split(spacer);
		var firstName = columnistArray[0];
		var lastName = columnistArray[1];
		if(columnistArray[0] == 'd'){
			firstName = columnistArray[2];
			lastName = columnistArray[0] + ' ' + columnistArray[1];
		}else if(columnistArray.length > 2){
				lastName = lastName + ' ' + columnistArray[2];
		}
		
		firstName = firstName.substring(0, 1).toUpperCase() + firstName.substring(1);
		lastName = lastName.substring(0, 1).toUpperCase() + lastName.substring(1);
		
		if(columnistFirstName[firstName] != null){
			if(columnistFirstName[firstName] != 'Amy K.' || (columnistFirstName[firstName] == 'Amy K.' && lastName == 'Nelson')){
				if(columnistFirstName[firstName] != 'Stephen A.' || (columnistFirstName[firstName] == 'Stephen A.' && lastName == 'Smith'))
					firstName = columnistFirstName[firstName];
			}
		}
		if(columnistLastName[lastName] != null){
			lastName = columnistLastName[lastName];
		}
		return firstName + ' ' + lastName;
	}
	
	function scrubSpecialCharacters(str){
		str = str.replace(/í/g, "i");
		str = str.replace(/Í/g, "i");
		str = str.replace(/ñ/g, "n");
		str = str.replace(/Ñ/g, "n");
		str = str.replace(/ó/g, "o");
		str = str.replace(/Ó/g, "o");
		str = str.replace(/Ú/g, "u");
		str = str.replace(/ú/g, "u");
		str = str.replace(/ü/g, "u");
		str = str.replace(/é/g, "e");
		str = str.replace(/É/g, "e");
		str = str.replace(/á/g, "a");
		str = str.replace(/Á/g, "a");
		str = str.replace(/¿/g, "");
		str = str.replace(/!/g, "");
		str = str.replace(/'/g, "");
		return str;
	}
	//End utility functions -------------------------------------------------------------------------	
	
	//Hardcoded Data
	function getTeamsLink(language){
		var teamsLink = {
			'en' : 'http://sports.espn.go.com/abbrev/clubhouse?teamId=',
			'es' : 'http://espndeportes.espn.go.com/abbrev/deportes/clubhouse?team='
		}
		return teamsLink[language];
	}
	function getSoccerTeamsLink(language){
		var soccerTeamsLink = {
			'en' : 'http://soccernet.espn.go.com/team?id=',
			'es' : 'http://espndeportes.espn.go.com/futbol/team?id='
		}
		return soccerTeamsLink[language];
	}
	function getPlayersLink(language){
		var playersLink = {
			'en' : 'http://sports.espn.go.com/abbrev/players/profile?playerId=',
			'es' : 'http://espndeportes.espn.go.com/abbrev/deportes/players/profile?playerId='
		}
		return playersLink[language];
	}
	function getColumnistsLink(language){
		var columnistsLink = {
			'en' : 'http://search.espn.go.com/',
			'es' : 'http://buscar.espn.go.com/'
		}
		return columnistsLink[language];
	}
	function getSoccerLink(language){
		var soccerLink = {
			'en' : 'http://soccernet.espn.go.com/section?id=',
			'es' : 'http://espndeportes.espn.go.com/futbol/'
		}
		return soccerLink[language];
	}

	function getSportsLink(language, sportId){
		var soccerLink = getSoccerLink(language);
		var sportLinksMatrix = {
			'en' : {
				10 : 'http://sports.espn.go.com/mlb/index',
				28 : 'http://sports.espn.go.com/nfl/index',
				46 : 'http://sports.espn.go.com/nba/index',
				90 : 'http://sports.espn.go.com/nhl/index',
				23 : 'http://sports.espn.go.com/ncf/index',
				41 : 'http://sports.espn.go.com/ncb/index',
				54 : 'http://sports.espn.go.com/ncw/index',
				850 : 'http://sports.espn.go.com/sports/tennis/index',
				1106 : 'http://sports.espn.go.com/golf/index',
				2000 : 'http://sports.espn.go.com/rpm/racing/index',
				2020 : 'http://sports.espn.go.com/rpm/nascar/index',
				2030 : 'http://sports.espn.go.com/rpm/racing/index',
				2040 : 'http://sports.espn.go.com/rpm/racing/index',
				1000 : 'http://sports.espn.go.com/sports/boxing/index',
				3301 : 'http://sports.espn.go.com/extra/mma/index',
				3180 : 'http://espn.go.com/action/',
				3520 : 'http://sports.espn.go.com/espn/poker/index',
				606 : soccerLink + 'worldcup2010',
				610 : soccerLink + 'global',
				620 : soccerLink + 'global',
				630 : soccerLink + 'global',
				640 : soccerLink + 'global',
				650 : soccerLink + 'global',
				660 : soccerLink + 'global',
				670 : soccerLink + 'global',
				680 : soccerLink + 'global',
				690 : soccerLink + 'global',
				700 : soccerLink + 'england',
				710 : soccerLink + 'europe',
				715 : soccerLink + 'europe',
				720 : soccerLink + 'europe',
				725 : soccerLink + 'europe',
				730 : soccerLink + 'europe',
				735 : soccerLink + 'europe',
				740 : soccerLink + 'europe',
				745 : soccerLink + 'global',
				750 : soccerLink + 'global',
				760 : soccerLink + 'global',
				770 : soccerLink + 'us',
				775 : soccerLink + 'uefachampionsleague',
				776 : soccerLink + 'uefachampionsleague',
				780 : soccerLink + 'conmebol.america',
				781 : 'http://soccernet.espn.go.com/euro2008/index',
				783 : soccerLink + 'global',
				786 : soccerLink + 'worldcup2010',
				787 : soccerLink + 'worldcup2010',
				788 : soccerLink + 'worldcup2010',
				789 : soccerLink + 'worldcup2010',
				790 : soccerLink + 'worldcup2010',
				792 : soccerLink + 'worldcup2010',
				795 : soccerLink + 'wwc07',
				3901 : soccerLink + 'europe',
				3902 : soccerLink + 'global',
				3903 : soccerLink + 'global',
				3904 : soccerLink + 'global',
				3905 : soccerLink + 'global',
				3906 : soccerLink + 'aus.1',
				3907 : soccerLink + 'europe',
				3908 : soccerLink + 'caf.nations',
				3909 : soccerLink + 'global',
				3910 : soccerLink + 'global',
				3911 : soccerLink + 'global',
				3912 : soccerLink + 'global',
				3913 : soccerLink + 'europe',
				3914 : soccerLink + 'england',
				3915 : soccerLink + 'england',
				3916 : soccerLink + 'england',
				3917 : soccerLink + 'england',
				3918 : soccerLink + 'england',
				3919 : soccerLink + 'england',
				3920 : soccerLink + 'england',
				3921 : soccerLink + 'europe',
				3922 : soccerLink + 'global',
				3923 : soccerLink + 'global',
				3924 : soccerLink + 'fifa.olympics',
				3925 : soccerLink + 'global',
				3926 : soccerLink + 'europe',
				3927 : soccerLink + 'europe',
				3928 : soccerLink + 'global',
				3929 : soccerLink + 'global',
				3930 : soccerLink + 'europe',
				3931 : soccerLink + 'europe',
				3932 : soccerLink + 'global',
				3933 : soccerLink + 'global',
				3934 : soccerLink + 'global',
				3935 : soccerLink + 'global',
				3936 : soccerLink + 'global',
				3937 : soccerLink + 'global',
				3938 : soccerLink + 'global',
				3939 : soccerLink + 'europe',
				3940 : soccerLink + 'europe',
				3941 : soccerLink + 'europe',
				3942 : soccerLink + 'europe',
				3943 : soccerLink + 'global',
				3944 : soccerLink + 'europe',
				3945 : soccerLink + 'europe',
				3946 : soccerLink + 'europe',
				3947 : 'http://soccernet.espn.go.com/euro2008/index',
				3948 : soccerLink + 'global',
				3949 : soccerLink + 'global',
				3950 : soccerLink + 'global',
				3951 : soccerLink + 'europe',
				3952 : soccerLink + 'europe',
				3953 : soccerLink + 'europe',
				3954 : soccerLink + 'europe',
				3955 : soccerLink + 'europe',
				3956 : soccerLink + 'europe',
				3957 : soccerLink + 'europe',
				3958 : soccerLink + 'europe',
				3959 : soccerLink + 'europe'
			},
			'es' : {
				10 : 'http://espndeportes.espn.go.com/beisbol/',
				28 : 'http://espndeportes.espn.go.com/futbol-americano/',
				46 : 'http://espndeportes.espn.go.com/basquetbol/',
				850 : 'http://espndeportes.espn.go.com/tenis/',
				1106 : 'http://espndeportes.espn.go.com/golf/',
				2000 : 'http://espndeportes.espn.go.com/deporte-motor/',
				1000 : 'http://espndeportes.espn.go.com/boxeo/',
				3301 : 'http://espndeportes.espn.go.com/artes-marciales-mixtas/',
				3520 : 'http://espndeportes.espn.go.com/poker/',
				606 : soccerLink + 'mundial/',
				620 : soccerLink + 'bolivia/',
				630 : soccerLink + 'brasil/',
				640 : soccerLink + 'chile/',
				650 : soccerLink + 'colombia/',
				660 : soccerLink + 'ecuador/',
				670 : soccerLink + 'peru/',
				680 : soccerLink + 'uruguay/',
				700 : soccerLink + 'inglaterra/',
				710 : soccerLink + 'francia/',
				715 : soccerLink + 'resultados?pais=portugal',
				720 : soccerLink + 'alemania/',
				725 : soccerLink + 'resultados?pais=holanda',
				730 : soccerLink + 'italia/',
				735 : soccerLink + 'resultados?pais=escocia',
				740 : soccerLink + 'espana/',
				745 : soccerLink + 'argentina/',
				750 : soccerLink + 'resultados?pais=japón',
				760 : soccerLink + 'mexico/',
				770 : soccerLink + 'mls/',
				775 : soccerLink + 'champions-league/',
				776 : soccerLink + 'copa-uefa/',
				780 : soccerLink + 'resultados?liga=conmebol.america',
				781 : soccerLink + 'euro2008/resultados',
				783 : soccerLink + 'copa-libertadores/',
				786 : soccerLink + 'mundial/eliminatories-uefa/',
				787 : soccerLink + 'eliminatorias-conmebol/',
				788 : soccerLink + 'eliminatories-concacaf/',
				789 : soccerLink + 'resultados?liga=fifa.worldq.afc',
				790 : soccerLink + 'resultados?liga=fifa.worldq.caf',
				792 : soccerLink + 'resultados?liga=fifa.worldq.ofc',
				795 : soccerLink + 'futbol/resultados?liga=fifa.wwc',
				3901 : soccerLink + 'resultados?pais=bélgica',
				3902 : soccerLink + 'resultados?liga=afc.champions',
				3903 : soccerLink + 'argentina/',
				3904 : soccerLink + 'argentina/',
				3905 : soccerLink + 'argentina/',
				3906 : soccerLink + 'resultados?pais=australia',
				3907 : soccerLink + 'resultados?pais=australia',
				3908 : soccerLink + 'resultados?liga=caf.nations',
				3909 : soccerLink + 'resultados?pais=chile',
				3910 : soccerLink + 'colombia/',
				3911 : soccerLink + 'resultados?liga=concacaf.u23',
				3912 : soccerLink + 'resultados?liga=conmebol.sudamericano_sub20',
				3913 : soccerLink + 'resultados?pais=dinamarca',
				3914 : soccerLink + 'inglaterra/',
				3915 : soccerLink + 'inglaterra/',
				3916 : soccerLink + 'inglaterra/',
				3917 : soccerLink + 'inglaterra/',
				3918 : soccerLink + 'inglaterra/fa-cup/',
				3919 : soccerLink + 'resultados?pais=inglaterra',
				3920 : soccerLink + 'resultados?pais=inglaterra',
				3921 : soccerLink + 'resultados?pais=espana',
				3922 : soccerLink + 'resultados?liga=fifa.friendly',
				3923 : soccerLink + 'resultados?liga=fifa.friendly.w',
				3924 : soccerLink + 'resultados?liga=fifa.olympics',
				3925 : soccerLink + 'resultados?liga=fifa.w.olympics',
				3926 : soccerLink + 'francia/',
				3927 : soccerLink + 'alemania/',
				3928 : soccerLink + 'guatemala/',
				3929 : soccerLink + 'honduras/',
				3930 : soccerLink + 'resultados?pais=irlanda',
				3931 : soccerLink + 'italia/',
				3932 : soccerLink + 'mexico/',
				3933 : soccerLink + 'resultados?pais=holanda',
				3934 : soccerLink + 'paraguay/',
				3935 : soccerLink + 'paraguay/',
				3936 : soccerLink + 'peru/',
				3937 : soccerLink + 'resultados?pais=sudáfrica',
				3938 : soccerLink + 'resultados?pais=sudáfrica',
				3939 : soccerLink + 'resultados?pais=rusia',
				3940 : soccerLink + 'resultados?pais=escocia',
				3941 : soccerLink + 'resultados?pais=escocia',
				3942 : soccerLink + 'resultados?pais=escocia',
				3943 : soccerLink + 'el-salvador/',
				3944 : soccerLink + 'resultados?pais=suiza',
				3945 : soccerLink + 'resultados?pais=suecia',
				3946 : soccerLink + 'resultados?pais=turquía',
				3947 : soccerLink + 'resultados?liga=uefa.euroq',
				3948 : soccerLink + 'uruguay/',
				3949 : soccerLink + 'venezuela/',
				3950 : soccerLink + 'venezuela/',
				3951 : soccerLink + 'resultados?pais=espana',
				3952 : soccerLink + 'francia/',
				3953 : soccerLink + 'francia/',
				3954 : soccerLink + 'alemania/',
				3955 : soccerLink + 'resultados?pais=grecia',
				3956 : soccerLink + 'italia/copa-italia/',
				3957 : soccerLink + 'resultados?pais=holanda',
				3958 : soccerLink + 'resultados?pais=irlanda_del_norte',
				3959 : soccerLink + 'resultados?pais=escocia'
			}
		}
		return sportLinksMatrix[language][sportId];
	}

	function getLowerCaseSportAbbrev(sportId){
		var sportMatrix = {
			10 : 'mlb',
			28 : 'nfl',
			46 : 'nba',
			90 : 'nhl',
			23 : 'ncf',
			41 : 'ncb',
			54 : 'ncw',
			59 : 'wnba',
			850 : 'tennis',
			1106 : 'golf',
			2020 : 'nascar',
			700 : 'eng soccer',
			710 : 'fra soccer',
			715 : 'por soccer',
			720 : 'ger soccer',
			725 : 'ned soccer',
			730 : 'ita soccer',
			735 : 'sco soccer',
			740 : 'esp soccer',
			745 : 'arg soccer',
			760 : 'mex soccer',
			770 : 'usa soccer',
			775 : 'uefa champions league',
			776 : 'uefa cup',
			783 : 'copa libertadores',
			786 : 'uefa wcq',
			787 : 'conmebol wcq',
			788 : 'concacaf wcq',
			789 : 'afc wcq',
			790 : 'caf wcq',
			792 : 'qfc wcq'
		}
		return sportMatrix[sportId];
	}
});

