var current_question = 0; var current_weights = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; var key_presses = []; var teams_sort = []; var speech = "In a nearby land, a lone fan wandered astray.\nSearching for a club, he walked for days.\nUntil Ref appeared to light the way....\nHi, I'm Ref.\nLet's find an MLS Club that matches you best.\nEach question you answer helps me guide you to your ideal fandom. Let the game begin!"; var smallspeech = "I usually give out red cards for things like this. How'd you know there was a cheat code? Well, well, my cheeky compadre... Congratulations. You've unlocked the newest MLS team, NYC FC!"; var ref_image = new Image(); ref_image.src = "img/ref_short.gif"; var finish_animation = false; var bubble_timeout; var arrow_press = false; var refer; function setCookie(c_name,value,exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; } function getCookie(c_name) { var c_value = document.cookie; var c_start = c_value.indexOf(" " + c_name + "="); if (c_start == -1) { c_start = c_value.indexOf(c_name + "="); } if (c_start == -1) { c_value = null; } else { c_start = c_value.indexOf("=", c_start) + 1; var c_end = c_value.indexOf(";", c_start); if (c_end == -1) { c_end = c_value.length; } c_value = unescape(c_value.substring(c_start,c_end)); } return c_value; } $(document).ready(function(){ if(document.referrer.indexOf('sb') == -1 && document.referrer.indexOf('espn') == -1 && document.referrer.indexOf('local') == -1){ refer = getCookie('referrer'); } else { setCookie('referrer',document.referrer,1); refer = document.referrer; } _gaq.push(['_trackPageview', '/home']); $(document).keydown(function(event){ key_presses.push(event.keyCode); if(key_presses.toString() == "38,38,40,40,37,39,37,39,66,65"){ $('#controls').css({backgroundImage: 'none', color: '#fff'}); $('#kickoff').css({color: '#f7d309', backgroundImage: 'url(http://mlssoccer.com.s3.amazonaws.com/12thMan/img/home_soccer_ball.gif)'}); $(document).unbind('keydown').keydown(function(event){ if(event.keyCode == 13){ //enter key show20thTeam(); } }); $('#kickoff').unbind('click').click(function(){ show20thTeam(); }); } else { if(event.keyCode == 39){ //left arrow $('#kickoff').css({backgroundImage: 'none', color: '#fff'}); $('#controls').css({color: '#f7d309', backgroundImage: 'url(http://mlssoccer.com.s3.amazonaws.com/12thMan/img/home_soccer_ball.png)'}); } else if(event.keyCode == 37){ //right arrow $('#controls').css({backgroundImage: 'none', color: '#fff'}); $('#kickoff').css({color: '#f7d309', backgroundImage: 'url(http://mlssoccer.com.s3.amazonaws.com/12thMan/img/home_soccer_ball.png)'}); } else if(event.keyCode == 13){ //enter key if($('#kickoff').css('color') == 'rgb(247, 211, 9)'){ showIntro(); } else { showControls(); } } else if(event.keyCode == 27){ //escape key closePopovers(); } } }); $('#kickoff').click(function(){ showIntro(); }); $('#controls').click(function(){ showControls(); }); }); function showControls(){ _gaq.push([ '_trackEvent', 'Entry', 'Controls', '' ]); $d = $('
').attr({id: 'dither'}); $o = $('
').attr({id: 'overlay'}).html('
close x
Controls

- Embark on your journey with dignity and answer each question honestly

- Discover the club that matches your fan personality best based on the decisions you make along the way

- Once you\'re all cozy with your new team, explore all MLS clubs you could have been matched with

- Make sure you listen to Ref and use your keyboard to navigate'); $('body').append($d).append($o); $('#dither').fadeTo(500,0.8,function(){ $('#overlay').fadeIn(500,function(){ $('#dither, #close').click(function(){ $('#overlay').fadeOut(500,function(){ $('#dither').fadeOut(500,function(){ $('#dither').remove(); $('#overlay').remove(); }); }); }); }); }); } function showNextQuestion(){ _gaq.push(['_trackPageview', '/Question ' + (current_question + 1)]); window.scrollTo(0, 0); if(window.top != window.self){ parent.postMessage('100','*'); } if($('#smallspeech').length == 0){ $('#content').html('
Ref:

'); $('#ref img').attr('src', ''); $('#ref img').attr('src', ref_image.src + '?' + Math.random()); } else { $('#body,#answers').remove(); $('#ref img').attr('src', ''); $('#ref img').attr('src', ref_image.src + '?' + Math.random()); $('#smallspeech').html('Ref:

'); } $(document).unbind('keydown').keydown(function(event){ if(event.keyCode == 13 || event.keyCode == 32){ //enter key_presses finish_animation = true; } else if(event.keyCode == 27){ //escape key closePopovers(); } }); questionChar(0); } function questionChar(position){ question = questions[current_question].question; if(position < question.length && !finish_animation){ $('#smallspeech').append(question[position]); setTimeout('questionChar(' + (position + 1) + ');', 40); } else { if(position < question.length){ finish_animation = false; app = question.substr(position); $('#smallspeech').append(app); } showAnswers(); } } function showAnswers(){ body_html = '
' + questions[current_question].body + '
'; answer_html = '
' for(x in questions[current_question].answers){ answer_html += '
13){ answer_html += ' style="top: -5px;"'; } answer_html += '>' + questions[current_question].answers[x] + '

'; } answer_html += '
'; $('#content').append(body_html + answer_html); $(document).unbind('keydown').keydown(function(event){ if(event.keyCode == 65){ recordAnswer(0); } else if(event.keyCode == 66){ recordAnswer(1); } else if(event.keyCode == 67){ recordAnswer(2); } else if(event.keyCode == 68){ recordAnswer(3); } else if(event.keyCode == 27){ //escape key closePopovers(); } }); $('.answer').unbind('click').click(function(){ recordAnswer($('.answer').index($(this))); }); } function recordAnswer(ans){ _gaq.push([ '_trackEvent', 'Questions', 'Question ' + (current_question + 1), questions[current_question].answers[ans] ]); $(document).unbind('keydown'); w = weights[current_question][ans]; for(i = 0; i < current_weights.length; i++){ current_weights[i] += w[i]; } if(current_question < 3){ current_question++; showNextQuestion(); } else { highest_weight = Math.max.apply(Math, current_weights); final_html = ''; for(i = 0; i < current_weights.length; i++){ percent = current_weights[i] / highest_weight; percent *= 100; percent = Math.round(percent); teams_sort[i] = []; teams_sort[i]['team_id'] = i; teams_sort[i]['percent'] = percent; } teams_sort.sort(function(a,b){ if(a['percent'] < b['percent']){ return 1; } else { return -1; } }); _gaq.push(['_trackPageview', '/results']); showResults(0); } } function showResults(index,direction){ window.scrollTo(0, 0); if(window.top != window.self){ parent.postMessage('100','*'); } if($('#result').length == 0){ _gaq.push([ '_trackEvent', 'Results', teams[teams_sort[index]['team_id']].name, 'Displayed as Perfect Match' ]); final_html = '
Club Found!
' + teams[teams_sort[index]['team_id']].name + '
Match Score:' + teams_sort[index]['percent'] + '%
'; final_html += '
'; for(x in teams_sort){ l = (x * 100) + '%'; final_html += '
'; } final_html += '
<Play Again
' + teams[teams_sort[index]['team_id']].character + '

' + teams[teams_sort[index]['team_id']].description + '
' final_html += ''; final_html += '
'; bubble_timeout = setTimeout('showBubble()',8000); $('#content').html(final_html); $('#desctext').css({marginTop: Math.round((210 - $('#desctext').height()) / 2) + 'px'}); $('#links #social a').each(function(){ if($(this).attr('href') == ''){ $(this).hide(); } else { $(this).show(); } }); } else { clearTimeout(bubble_timeout); $("#resultsbubble").remove(); $("#rightarrow").unbind('mouseenter mouseleave'); if(direction == 'left'){ //setTimeout('prependCharacter(' + index + ');',201); setTimeout("$('#result').fadeOut(200,function(){animateCharacters('left');})",1); setTimeout("$('#logo,#description,#links').fadeOut(200)", 1); //setTimeout("",250); } else { //setTimeout('appendCharacter(' + index + ');',201); setTimeout("$('#result').fadeOut(200,function(){animateCharacters('right');})",1); setTimeout("$('#logo,#description,#links').fadeOut(200)", 1); //setTimeout("$('.character').animate({left: '-=100%'},300)",250); } setTimeout('updateInfo(' + index + ')',600); _gaq.push([ '_trackEvent', 'CTA', teams[teams_sort[index]['team_id']].name, 'Was a Result for More Matches' ]); } //$('.character').width($('body').width()); $('#leftarrow').unbind('click').click(function(){ if(!arrow_press){ arrow_press = true; showResults(index - 1,'left'); } }); $('#rightarrow').unbind('click').click(function(){ if(!arrow_press){ arrow_press = true; showResults(index + 1,'right'); } }); $(document).unbind('keydown').keydown(function(event){ if(event.keyCode == 37 && index != 0){ //left arrow if(!arrow_press){ arrow_press = true; $(document).unbind('keydown') showResults(index - 1,'left'); } } else if(event.keyCode == 39 && index != teams_sort.length - 1){ //right arrow if(!arrow_press){ arrow_press = true; $(document).unbind('keydown') showResults(index + 1,'right'); } } else if(event.keyCode == 27){ //escape key closePopovers(); } }); $('#playagain').unbind('click').click(function(){ playAgain(); }); $('#sharetab').unbind('click').click(function(){ sharePop(index); }); if(index == 0){ $('#leftarrow').hide(); } else if(index == teams_sort.length - 1){ $('#rightarrow').hide(); } else { $('#leftarrow').show(); $('#rightarrow').show(); } } function animateCharacters(direction){ if(direction == 'left'){ $('.character').each(function(){ l = parseInt($(this).css('left')); l += $('#content').width(); $(this).animate({left: l + 'px'},300); }); } else { $('.character').each(function(){ l = parseInt($(this).css('left')); l -= $('#content').width(); $(this).animate({left: l + 'px'},300); }); } } function sharePop(index){ _gaq.push(['_trackPageview', '/share']); _gaq.push([ '_trackEvent', 'Results', teams[teams_sort[index]['team_id']].name, 'Initially clicked the share button' ]); $d = $('
').attr({id: 'dither'}); if(index == 0){ if(refer.indexOf('espn') == -1){ sharefile = teams[teams_sort[index]['team_id']].slug + '_s_1.html'; } else { sharefile = teams[teams_sort[index]['team_id']].slug + '_e_1.html'; } twtext = encodeURIComponent("I now support " + teams[teams_sort[index]['team_id']].handle + ". Find your #MLS Club now. " + teams[teams_sort[index]['team_id']].hashtag); } else { if(refer.indexOf('espn') == -1){ sharefile = teams[teams_sort[index]['team_id']].slug + '_s_2.html'; } else { sharefile = teams[teams_sort[index]['team_id']].slug + '_e_2.html'; } twtext = encodeURIComponent("Check out what it takes to be a " + teams[teams_sort[index]['team_id']].handle + " fan and find your #MLS Club! " + teams[teams_sort[index]['team_id']].hashtag); } $o = $('
').attr({id: 'shareoverlay'}).html('
close x
Share The Journey!

Now that you\'ve found a club to rep, help your friends find theirs.

    

Or Download your personal player card and then share it on Facebook or Twitter.'); $('body').append($d).append($o); $('#dither').fadeTo(500,0.8,function(){ $('#shareoverlay').fadeIn(500,function(){ $('#dither, #close').unbind('click').click(function(){ $('#shareoverlay').fadeOut(500,function(){ $('#dither').fadeOut(500,function(){ $('#dither').remove(); $('#shareoverlay').remove(); }); }); }); }); }); } function appendCharacter(index){ $('#content').append('
'); //$('.character').width($('body').width()); } function prependCharacter(index){ $('#content').append('
'); //$('.character').width($('body').width()); } function updateInfo(index){ if(index != 0 && teams_sort[index]['percent'] == 100){ $('#result').html('
' + teams[teams_sort[index]['team_id']].name + '
Match Score:98%'); } else if(teams_sort[index]['percent'] == 100){ $('#result').html('club Found!
' + teams[teams_sort[index]['team_id']].name + '
Match Score:' + teams_sort[index]['percent'] + '%'); } else { $('#result').html('
' + teams[teams_sort[index]['team_id']].name + '
Match Score:' + teams_sort[index]['percent'] + '%'); } $('#logo').attr({src: "img/logo_" + teams_sort[index]['team_id'] + ".png"}); $('#description').html('
<Play Again
' + teams[teams_sort[index]['team_id']].character + '

' + teams[teams_sort[index]['team_id']].description + '
'); $('#links').html('
View Team Site>
And Social Channels
'); setTimeout("$('#result,#logo,#description,#links').fadeIn(200)",1); setTimeout("$('#desctext').css({marginTop: Math.round((210 - $('#desctext').height()) / 2) + 'px'})",50); $('#links #social a').each(function(){ if($(this).attr('href') == ''){ $(this).hide(); } else { $(this).show(); } }); $('#playagain').unbind('click').click(function(){ playAgain(); }); $('#sharetab').unbind('click').click(function(){ sharePop(index); }); setTimeout('arrow_press = false;', 400); } function showBubble(){ $('#content').append(''); setTimeout('$("#resultsbubble").remove();',5000); $("#rightarrow").hover(function(){$('#content').append('');},function(){$("#resultsbubble").remove();}); } function showIntro(){ _gaq.push(['_trackPageview', '/instructions']); _gaq.push([ '_trackEvent', 'Entry', 'Kick-Off', '' ]); window.scrollTo(0, 0); if(window.top != window.self){ parent.postMessage('100','*'); } $('#content').html('
'); $(document).unbind('keydown').keydown(function(event){ if(event.keyCode == 13 || event.keyCode == 32){ //enter key_presses finish_animation = true; } }); speechChar(0); } function speechChar(position){ if(position < speech.length && !finish_animation){ if(speech[position] == "\n"){ $('#bigspeech').append('

'); } else { $('#bigspeech').append(speech[position]); } setTimeout('speechChar(' + (position + 1) + ');',40); } else { if(position < speech.length){ finish_animation = false; app = speech.substr(position).replace(/\n/gi,"

"); $('#bigspeech').append(app); } $('#bigspeech').append('
'); $('#continue').click(function(){ showNextQuestion(); }); $(document).unbind('keydown').keydown(function(event){ if(event.keyCode == 65){ showNextQuestion(); } }); } } function playAgain(){ _gaq.push([ '_trackEvent', 'Entry', 'Play Again Entry', '' ]); window.location.reload(); } function show20thTeam(){ _gaq.push([ '_trackEvent', 'Entry', 'Contra Code', '' ]); window.scrollTo(0, 0); if(window.top != window.self){ parent.postMessage('100','*'); } $('#content').html('
'); $(document).unbind('keydown').keydown(function(event){ if(event.keyCode == 13 || event.keyCode == 32){ //enter key_presses finish_animation = true; } }); cheatChar(0); } function cheatChar(position){ if(position < smallspeech.length && !finish_animation){ if(smallspeech[position] == "\n"){ $('#bigspeech').append('

'); } else { $('#bigspeech').append(smallspeech[position]); } setTimeout('cheatChar(' + (position + 1) + ');',40); } else { if(position < speech.length){ finish_animation = false; app = smallspeech.substr(position); $('#bigspeech').append(app); } $('#bigspeech').append('

'); $('#continue').click(function(){ showCheatTeam(); }); $(document).unbind('keydown').keydown(function(event){ if(event.keyCode == 65){ showCheatTeam(); } }); } } function showCheatTeam(){ final_html = '
Club Found!
NYC FC
'; final_html += '
'; final_html += '
<Play Again
Name: Unknown

A new army of supporters has risen. We stand together, a wall of fans, to usher in a new age of prosperity.

Expect us on your shores in 2015.

A new New York is coming.
'; final_html += ''; $('#content').html(final_html); $('#desctext').css({marginTop: Math.round((210 - $('#desctext').height()) / 2) + 'px'}); $('#playagain').unbind('click').click(function(){ playAgain(); }); $('#sharetab').unbind('click').click(function(){ $d = $('
').attr({id: 'dither'}); if(refer.indexOf('espn') == -1){ sharefile = '20_s_1.html'; } else { sharefile = '20_e_1.html'; } twtext = encodeURIComponent("I found the newest MLS team, NYC FC. Find out what MLS club you were born to support!"); $o = $('
').attr({id: 'shareoverlay'}).html('
close x
Share The Journey!

Now that you\'ve found a club to rep, help your friends find theirs.

    

Or Download your personal player cardand then share it on Facebook or Twitter.'); $('body').append($d).append($o); $('#dither').fadeTo(500,0.8,function(){ $('#shareoverlay').fadeIn(500,function(){ $('#dither, #close').unbind('click').click(function(){ $('#shareoverlay').fadeOut(500,function(){ $('#dither').fadeOut(500,function(){ $('#dither').remove(); $('#shareoverlay').remove(); }); }); }); }); }); }); } function closePopovers(){ if($('#dither').length > 0){ $('#overlay, #shareoverlay').fadeOut(500,function(){ $('#dither').fadeOut(500,function(){ $('#dither').remove(); $('#overlay').remove(); $('#shareoverlay').remove(); }); }); } }