/*  Copyright 2016, University of St Andrews QuVis Interactive Simulations
jQuery JavaScript Library v2.0.n Copyright 2005, 2013 jQuery Foundation, Inc. and other contributors http://jquery.com/ Released under the MIT license http://jquery.org/license
edge Adobe Edge Animate JavaScript Library v3.0 Copyright 2014 Adobe Systems Inc. and its licensors. Released under the CC BY-NC-SA license, creativecommons.org/licenses   
fastclick.js Version: 1.0.6 Copyright (c) 2014 The Financial Times Ltd. https://github.com/ftlabs/fastclick Released under the MIT license https://github.com/ftlabs/fastclick/blob/master/LICENSE
normalize.css v3 Copyright (c) Nicolas Gallagher and Jonathan Neal https://github.com/necolas/normalize.css Released under the MIT license https://github.com/necolas/normalize.css/blob/master/LICENSE.md
*/
(function($,Edge,compId){var Composition=Edge.Composition,Symbol=Edge.Symbol;function debug(value){$('#Stage_debug').text(value);}
var save={};save.values={};var row_count=0
var a_basis=['','','','','',''];var a_outcome=['','','','','',''];var b_basis=['','','','','',''];var b_outcome=['','','','','',''];var same_basis=['','','','','',''];var key=['','','','','',''];var e_basis=['','','','','',''];var e_outcome=['','','','','',''];var streaming=false;var a_keys=[];var b_keys=[];var numberOfErrors=0;var count_keys=0;var challenges=false;var multiple=false;var multiple2=false;var error=false;var outcome={};function show_boxes_event(e){var show_key=$('#Stage_show_key_checkbox').hasClass('selected');var show_errors=$('#Stage_show_errors_checkbox').hasClass('selected');var show_graph=$('#Stage_show_graph_checkbox').hasClass('selected');show_boxes(show_key,show_errors,show_graph);save.show_key=show_key;save.show_errors=show_errors;save.show_graph=show_graph;}
function show_boxes(show_key,show_errors,show_graph){show_key?sym_select($('#Stage_show_key_checkbox')):sym_deselect($('#Stage_show_key_checkbox'));show_errors?sym_select($('#Stage_show_errors_checkbox')):sym_deselect($('#Stage_show_errors_checkbox'));show_graph?sym_select($('#Stage_show_graph_checkbox')):sym_deselect($('#Stage_show_graph_checkbox'));show_key?$('#Stage_box_key').show():$('#Stage_box_key').hide();show_errors?$('#Stage_box_errors').show():$('#Stage_box_errors').hide();show_graph?$('#Stage_box_key_bits').show():$('#Stage_box_key_bits').hide();}
function glassesAnimation(){$('#Stage .introText').hide();$('#Stage .controls').hide();$('#Stage .optionalBoxes').hide();$('#Stage_goggles').css({'width':'45px','height':'20px','top':'202px','left':'819px','opacity':1.0})
$('#Stage_goggles').show();$('#Stage_goggles').animate({'width':'1802px','height':'800px','top':'0px','left':'-380px','opacity':0.1},1200,function(){$('#Stage .controls').fadeIn(800);$('#Stage .controls').fadeIn(800);(save.show_key)?$('#Stage_box_key').fadeIn(800):alpha=1;(save.show_errors)?$('#Stage_box_errors').fadeIn(800):alpha=1;(save.show_graph)?$('#Stage_box_key_bits').fadeIn(800):alpha=1;if(save.show_key)$('#Stage_box_key').fadeIn(800);$('#Stage_goggles').fadeOut();});}
function send_single_particle(e){add_single_count();}
var k=0;function send_multiple_particles(e){for(k=1;k<=94;k++){add_single_count();}}
var continuous_count=false;function send_continuous_particles(e){if(continuous_count){clearTimeout(z);clearTimeout(y);clearTimeout(zz);clearTimeout(yy);clearTimeout(w);clearTimeout(ww);clearTimeout(www);clearTimeout(wwww);clearTimeout(wwwww);clearTimeout(wwwwww);clearTimeout(u);clearTimeout(v);clearTimeout(x);$('#Stage_photon').hide();$('#Stage_photon_eve').hide();clearInterval(continuous_count);continuous_count=false;sym_enable($('#Stage_send_single_button'))
$('#Stage_send_continuous_button_label').text("Continuous");return;}
sym_disable($('#Stage_send_single_button'));$('#Stage_send_continuous_button_label').text("Stop");add_single_count();if($('#Stage_eavesdrop').css('display')=='block')continuous_count=setInterval(function(){add_single_count()},5500);else continuous_count=setInterval(function(){add_single_count()},4500);}
var z;var y;var zz;var yy;var w;var ww;var www;var wwww;var wwwww;var wwwwww;var u;var v;var x;var middle_up=0;function add_single_count(){rotate_sgas(save.left_angle,save.right_angle);var prefix=AdobeEdge.getComposition(compId).getStage();if(multiple==false)frozen_flashes();if($('#Stage_sga_angle_rand_radio').hasClass('selected')){rotate_sgas(Math.floor(Math.random()*2)+1,Math.floor(Math.random()*2)+1);}
var n_tot=$('#Stage_n_tot').text()*1+1;var left_plus=left_up>0.5;var right_plus=false;var left_90=$('#Stage_sga_left_angle2_radio').hasClass('selected')?true:false;var right_90=$('#Stage_sga_right_angle2_radio').hasClass('selected')?true:false;var eavesdrop_plus=false;var eavesdrop_90=right_90;var stage=AdobeEdge.getComposition(compId).getStage();clearTimeout(z);clearTimeout(y);clearTimeout(zz);clearTimeout(yy);clearTimeout(w);clearTimeout(ww);clearTimeout(www);clearTimeout(wwww);clearTimeout(wwwww);clearTimeout(wwwwww);clearTimeout(u);clearTimeout(v);clearTimeout(x);if($('#Stage_eavesdrop').css('display')=='block'){$('#Stage_eavesdrop_source').hide();$('#Stage_photon_eve').show();$('#Stage_photon').hide();middle_up=Math.floor(Math.random()*2);if(multiple2==false)stage.getSymbol('photon_eve').play(0);if($('#Stage_sga_angle_rand_radio').hasClass('selected')){var eavesdrop_random=Math.floor(Math.random()*2)+1;if(multiple==false){stage.getSymbol('polarizer_eve1').stop((eavesdrop_random-1)*2+middle_up+''),stage.getSymbol('polarizer_eve2').stop((eavesdrop_random-1)*2+middle_up+'')};eavesdrop_90=(eavesdrop_random==2);}
else{if(multiple==false){stage.getSymbol('polarizer_eve1').stop((((eavesdrop_90==true)?2:1)-1)*2+middle_up+''),stage.getSymbol('polarizer_eve2').stop((((eavesdrop_90==true)?2:1)-1)*2+middle_up+'')};}
if(left_90==eavesdrop_90){eavesdrop_plus=left_plus==true;if(multiple2==false){if(middle_up==left_plus)u=setTimeout(function(){stage.getSymbol('polarizer_eve2').stop((((eavesdrop_90==true)?2:1)-1)*2+middle_up+'')},2750);else u=setTimeout(function(){stage.getSymbol('polarizer_eve2').stop((((eavesdrop_90==true)?2:1)-1)*2+Math.abs(middle_up-1)+'')},2750);}}
else{eavesdrop_plus=Math.random()<0.5;if(multiple2==false){if(middle_up==eavesdrop_plus){u=setTimeout(function(){stage.getSymbol('polarizer_eve2').stop((((eavesdrop_90==true)?2:1)-1)*2+middle_up+'')},2750);}
else{u=setTimeout(function(){stage.getSymbol('polarizer_eve2').stop((((eavesdrop_90==true)?2:1)-1)*2+Math.abs(middle_up-1)+'')},2750);}}}
if(multiple2==false){if(middle_up==eavesdrop_plus){zz=setTimeout(function(){prefix.getSymbol('greenFlashGapEve').play(0),prefix.getSymbol('tickFlashEve').play(0)},2750);}
else{zz=setTimeout(function(){prefix.getSymbol('crossFlashEve').play(0)},2750);yy=setTimeout(function(){$('#Stage_photon_eve').fadeOut(100)},2000);x=setTimeout(function(){$('#Stage_photon_eve').show()},3000);}};if(eavesdrop_90==right_90){right_plus=eavesdrop_plus;if(multiple2==false){if(left_up==right_up){z=setTimeout(function(){prefix.getSymbol('greenFlashGap').play(0),prefix.getSymbol('tickFlash').play(0)},5000);}
else{z=setTimeout(function(){prefix.getSymbol('crossFlash').play(0)},5000);y=setTimeout(function(){$('#Stage_photon_eve').fadeOut(100)},4300);}}}
else{right_plus=Math.random()<0.5;if(multiple2==false){if(right_plus==right_up){z=setTimeout(function(){prefix.getSymbol('greenFlashGap').play(0),prefix.getSymbol('tickFlash').play(0)},5000);}
else{z=setTimeout(function(){prefix.getSymbol('crossFlash').play(0)},5000);y=setTimeout(function(){$('#Stage_photon_eve').fadeOut(100)},4300);}}}
$('#Stage_photon_eve').show();if(multiple2==false){var eavesdrop_source=1;if(eavesdrop_plus){eavesdrop_source=eavesdrop_90?3:1;}
else{eavesdrop_source=eavesdrop_90?4:2;}
v=setTimeout(function(){if(!challenges){if(eavesdrop_source==1)$('#Stage_eavesdrop_source').html('|V&#x232A;');if(eavesdrop_source==2)$('#Stage_eavesdrop_source').html('|H&#x232A;');if(eavesdrop_source==3)$('#Stage_eavesdrop_source').html('|&#8211;45°&#x232A;');if(eavesdrop_source==4)$('#Stage_eavesdrop_source').html('|+45°&#x232A;');$('#Stage_eavesdrop_source').fadeIn(200);}},3000);}
if(challenges){$('#Stage_eavesdrop_source').html('|?&#x232A;');$('#Stage_eavesdrop_source').show();}}
else{$('#Stage_photon_eve').hide();$('#Stage_photon').show();if(left_90==right_90){right_plus=left_plus==true;if(multiple2==false){if(left_up==right_up){z=setTimeout(function(){prefix.getSymbol('greenFlashGap').play(0),prefix.getSymbol('tickFlash').play(0)},4000);}
else{z=setTimeout(function(){prefix.getSymbol('crossFlash').play(0)},4000);y=setTimeout(function(){$('#Stage_photon').fadeOut(100)},3400);}}}
else{right_plus=Math.random()<0.5;if(multiple2==false){if(right_plus==right_up){z=setTimeout(function(){prefix.getSymbol('greenFlashGap').play(0),prefix.getSymbol('tickFlash').play(0)},4000);}
else{z=setTimeout(function(){prefix.getSymbol('crossFlash').play(0)},4000);y=setTimeout(function(){$('#Stage_photon').fadeOut(100)},3400);}}}
$('#Stage_photon_eve').hide();$('#Stage_photon').show();if(multiple2==false)prefix.getSymbol('photon').play(0);}
outcome={'left_plus':left_plus,'left_90':left_90,'eavesdrop_plus':eavesdrop_plus,'eavesdrop_90':eavesdrop_90,'right_plus':right_plus,'right_90':right_90};show_single_count(outcome);if(multiple==false){$('#Stage_alice_source').show();if(left_plus){if(left_90){prefix.getSymbol('#Stage_up_x').play(0);prefix.getSymbol('#Stage_up_z').stop(0);prefix.getSymbol('#Stage_down_z').stop(0);prefix.getSymbol('#Stage_down_x').stop(0);}
else{prefix.getSymbol('#Stage_up_x').stop(0);prefix.getSymbol('#Stage_up_z').play(0);prefix.getSymbol('#Stage_down_z').stop(0);prefix.getSymbol('#Stage_down_x').stop(0);}}
else{if(left_90){prefix.getSymbol('#Stage_up_x').stop(0);prefix.getSymbol('#Stage_up_z').stop(0);prefix.getSymbol('#Stage_down_z').stop(0);prefix.getSymbol('#Stage_down_x').play(0);}
else{prefix.getSymbol('#Stage_up_x').stop(0);prefix.getSymbol('#Stage_up_z').stop(0);prefix.getSymbol('#Stage_down_z').play(0);prefix.getSymbol('#Stage_down_x').stop(0);}}}}
var checked_errors=false;function show_single_count(outcome){if(checked_errors){var text_alice='';for(var i=0;i<a_keys.length;i++){text_alice=text_alice+' '+a_keys[i];}
$('#Stage_alice_keys').html(text_alice);var text_bob='';for(var i=0;i<b_keys.length;i++){text_bob=text_bob+' '+b_keys[i];}
$('#Stage_bob_keys').html(text_bob);}
checked_errors=false;$('#Stage_orangeContainer').hide();var n_tot=parseInt($('#Stage_n_tot').text())+1;var n_key_old=parseInt($('#Stage_n_key').text());var n_key=n_key_old;var n_err_old=parseInt($('#Stage_n_err').text());var n_err=n_err_old;if(outcome.left_90==outcome.right_90){n_key++;if(outcome.left_plus!=outcome.right_plus){n_err++;}}
if(multiple2==false){wwww=setTimeout(function(){$('#Stage_n_tot').text(n_tot);$('#Stage_n_key').text(n_key);$('#Stage_n_err').text(n_err);var p_err=0;if(n_key>0){p_err=n_err/n_key;var p_err_old=parseInt($('#Stage_p_err').text());$('#Stage_p_err').text(p_err.toFixed(3));}},($('#Stage_eavesdrop').css('display')=='block')?5000:4000);}
else{$('#Stage_n_tot').text(n_tot);$('#Stage_n_key').text(n_key);$('#Stage_n_err').text(n_err);var p_err=0;if(n_key>0){p_err=n_err/n_key;var p_err_old=parseInt($('#Stage_p_err').text());$('#Stage_p_err').text(p_err.toFixed(3));}}
row_count++;if(multiple==false){$('#Stage_eve_wrong_basis').hide();for(var i=1;i<=5;i++){if(a_basis[i-1]=='X')$('#Stage_a_basis'+(i+1)).html('+45/&#8211;45');else if(a_basis[i-1]=='Z')$('#Stage_a_basis'+(i+1)).html('H/V');else $('#Stage_a_basis'+(i+1)).html('');if(b_basis[i-1]=='X')$('#Stage_b_basis'+(i+1)).html('+45/&#8211;45');else if(b_basis[i-1]=='Z')$('#Stage_b_basis'+(i+1)).html('H/V');else $('#Stage_b_basis'+(i+1)).html('');if(e_basis[i-1]=='X')$('#Stage_e_basis'+(i+1)).html('+45/&#8211;45');else if(e_basis[i-1]=='Z')$('#Stage_e_basis'+(i+1)).html('H/V');else $('#Stage_e_basis'+(i+1)).html('');$('#Stage_a_outcome'+(i+1)).html(a_outcome[i-1]);$('#Stage_b_outcome'+(i+1)).html(b_outcome[i-1]);$('#Stage_e_outcome'+(i+1)).html(e_outcome[i-1]);$('#Stage_same_basis'+(i+1)).html(same_basis[i-1]);$('#Stage_key'+(i+1)).html(key[i-1]);if((same_basis[i-1]=='YES')&&(a_basis[i-1]!=e_basis[i-1])&&(e_basis[i-1]!='')){$('#Stage_red'+(i+1)).show();$('#Stage_eve_wrong_basis').show();}
else $('#Stage_red'+(i+1)).hide();}
$('#Stage_a_basis'+1).html('');$('#Stage_b_basis'+1).html('');$('#Stage_e_basis'+1).html('');$('#Stage_a_outcome'+1).html('');$('#Stage_b_outcome'+1).html('');$('#Stage_e_outcome'+1).html('');$('#Stage_same_basis'+1).html('');$('#Stage_key'+1).html('');}
if(multiple2==false){wwwww=setTimeout(function(){if(multiple==false){if(row_count>1){if(row_count<6){for(i=row_count-1;i>0;i--){a_basis[i]=a_basis[i-1];a_outcome[i]=a_outcome[i-1];b_basis[i]=b_basis[i-1];b_outcome[i]=b_outcome[i-1];same_basis[i]=same_basis[i-1];key[i]=key[i-1];e_basis[i]=e_basis[i-1];e_outcome[i]=e_outcome[i-1];}}
else{for(i=6;i>0;i--){a_basis[i]=a_basis[i-1];a_outcome[i]=a_outcome[i-1];b_basis[i]=b_basis[i-1];b_outcome[i]=b_outcome[i-1];same_basis[i]=same_basis[i-1];key[i]=key[i-1];e_basis[i]=e_basis[i-1];e_outcome[i]=e_outcome[i-1];}}}}
a_basis[0]=(outcome.left_90?'X':'Z');a_outcome[0]=(outcome.left_plus?'1':'0');b_basis[0]=(outcome.right_90?'X':'Z');b_outcome[0]=(outcome.right_plus?'1':'0');same_basis[0]=(n_key>n_key_old?'YES':'NO');key[0]='';if(n_key>n_key_old)key[0]=(outcome.left_plus?'1':'0');if(n_err>n_err_old){key[0]=('ERROR'.fontcolor('red'));error=true;}
else error=false;if($('#Stage_eavesdrop').css('display')=='block'){e_basis[0]=(outcome.eavesdrop_90?'X':'Z');e_outcome[0]=(outcome.eavesdrop_plus?'1':'0');}
else{e_basis[0]=('');e_outcome[0]=('');;}},($('#Stage_eavesdrop').css('display')=='block')?5000:4000)}
else{if(row_count>1){if(row_count<6){for(i=row_count-1;i>0;i--){a_basis[i]=a_basis[i-1];a_outcome[i]=a_outcome[i-1];b_basis[i]=b_basis[i-1];b_outcome[i]=b_outcome[i-1];same_basis[i]=same_basis[i-1];key[i]=key[i-1];e_basis[i]=e_basis[i-1];e_outcome[i]=e_outcome[i-1];}}
else{for(i=6;i>0;i--){a_basis[i]=a_basis[i-1];a_outcome[i]=a_outcome[i-1];b_basis[i]=b_basis[i-1];b_outcome[i]=b_outcome[i-1];same_basis[i]=same_basis[i-1];key[i]=key[i-1];e_basis[i]=e_basis[i-1];e_outcome[i]=e_outcome[i-1];}}}
a_basis[0]=(outcome.left_90?'X':'Z');a_outcome[0]=(outcome.left_plus?'1':'0');b_basis[0]=(outcome.right_90?'X':'Z');b_outcome[0]=(outcome.right_plus?'1':'0');same_basis[0]=(n_key>n_key_old?'YES':'NO');key[0]='';if(n_key>n_key_old)key[0]=(outcome.left_plus?'1':'0');if(n_err>n_err_old){key[0]=('ERROR'.fontcolor('red'));error=true;}
else error=false;if($('#Stage_eavesdrop').css('display')=='block'){e_basis[0]=(outcome.eavesdrop_90?'X':'Z');e_outcome[0]=(outcome.eavesdrop_plus?'1':'0');}
else{e_basis[0]=('');e_outcome[0]=('');;}}
if(multiple==false){w=setTimeout(function(){if(a_basis[0]=='X')$('#Stage_a_basis'+1).html('+45/&#8211;45');else if(a_basis[0]=='Z')$('#Stage_a_basis'+1).html('H/V');else $('#Stage_a_basis'+1).html('');if(b_basis[0]=='X')$('#Stage_b_basis'+1).html('+45/&#8211;45');else if(b_basis[0]=='Z')$('#Stage_b_basis'+1).html('H/V');else $('#Stage_b_basis'+0).html('');if(e_basis[0]=='X')$('#Stage_e_basis'+1).html('+45/&#8211;45');else if(e_basis[0]=='Z')$('#Stage_e_basis'+1).html('H/V');else $('#Stage_e_basis'+0).html('');$('#Stage_a_outcome'+1).html(a_outcome[0]);$('#Stage_b_outcome'+1).html(b_outcome[0]);$('#Stage_e_outcome'+1).html(e_outcome[0]);$('#Stage_same_basis'+1).html(same_basis[0]);$('#Stage_key'+1).html(key[0]);},(multiple2==false)?(($('#Stage_eavesdrop').css('display')=='block')?5000:4000):0)}
if(multiple2==false){ww=setTimeout(function(){if(same_basis[0]=='YES'){if(a_keys.length>=40){a_keys.pop();b_keys.pop();}
a_keys.unshift(a_outcome[0]);b_keys.unshift(b_outcome[0]);}
var text_alice='';for(var i=0;i<a_keys.length;i++){text_alice=text_alice+' '+a_keys[i];}
$('#Stage_alice_keys').html(text_alice);var text_bob='';for(var i=0;i<b_keys.length;i++){text_bob=text_bob+' '+b_keys[i];}
$('#Stage_bob_keys').html(text_bob);count_keys=0;for(var i=0;i<b_keys.length;i++){if(b_keys[i]=='0'||b_keys[i]=='1')count_keys++;}
if(count_keys<30){sym_disable($('#Stage_check_for_errors_button'));$('#Stage_feedback_text').html('More measurements needed for error checking');}
else{sym_enable($('#Stage_check_for_errors_button'));$('#Stage_feedback_text').html('');}},(multiple2==false)?(($('#Stage_eavesdrop').css('display')=='block')?5000:4000):0);}
else{if(same_basis[0]=='YES'){if(a_keys.length>=40){a_keys.pop();b_keys.pop();}
a_keys.unshift(a_outcome[0]);b_keys.unshift(b_outcome[0]);}
var text_alice='';for(var i=0;i<a_keys.length;i++){text_alice=text_alice+' '+a_keys[i];}
$('#Stage_alice_keys').html(text_alice);var text_bob='';for(var i=0;i<b_keys.length;i++){text_bob=text_bob+' '+b_keys[i];}
$('#Stage_bob_keys').html(text_bob);count_keys=0;for(var i=0;i<b_keys.length;i++){if(b_keys[i]=='0'||b_keys[i]=='1')count_keys++;}
if(count_keys<30){sym_disable($('#Stage_check_for_errors_button'));$('#Stage_feedback_text').html('More measurements needed for error checking');}
else{sym_enable($('#Stage_check_for_errors_button'));$('#Stage_feedback_text').html('');}}}
var text_a='';var text_b='';function check_for_errors(){checked_errors=true;text_a='';text_b='';var random_keys=[];for(var i=1;i<=20;i++){a=Math.floor(Math.random()*(a_keys.length));if((a_keys[a]=='0'||a_keys[a]=='1')&&$.inArray(a,random_keys)==-1){random_keys.unshift(a);}
else i--;}
var twenty=0;for(var k=0;k<a_keys.length;k++){if($.inArray(k,random_keys)!=-1){text_a=text_a+' '+((a_keys[k]==b_keys[k])?a_keys[k].fontcolor('green'):a_keys[k].fontcolor('red'));bKeys=b_keys[k]
text_b=text_b+' '+((a_keys[k]==b_keys[k])?bKeys.fontcolor('green'):bKeys.fontcolor('red'));$('#Stage_o'+twenty).css({'left':188+18*(k%10)+'px','top':374+17*((k-k%10)/10)+'px','background-color':(a_keys[k]!=b_keys[k])?'rgb(255,169,112)':'rgb(152,204,108)'});$('#Stage_o'+twenty+'Copy').css({'left':187+182+18*(k%10)+'px','top':374+17*((k-k%10)/10)+'px','background-color':(a_keys[k]!=b_keys[k])?'rgb(255,169,112)':'rgb(152,204,108)'});twenty++;if(a_keys[k]!=b_keys[k])numberOfErrors++;}
else{text_a=text_a+' '+a_keys[k];text_b=text_b+' '+b_keys[k];}}
$('#Stage_orangeContainer').show();$('#Stage_alice_keys').html(text_a);$('#Stage_bob_keys').html(text_b);var space='2'.fontcolor('#ffe89a');if(numberOfErrors==0){if($('#Stage_sga_angle_rand_radio').hasClass('selected')){$('#Stage_feedback_text').html('No errors! Non-shared key bits secure.'.fontcolor('green'));for(var j=0;j<20;j++){a_keys.splice(random_keys[j],1,space);b_keys.splice(random_keys[j],1,space);}}
else{$('#Stage_feedback_text').html('No errors, but fixed bases, so not secure!');a_keys=[];b_keys=[];}}
else{$('#Stage_feedback_text').html((numberOfErrors+' errors found -Eavesdropper! Discard the entire key.').fontcolor('red'));a_keys=[];b_keys=[];}
numberOfErrors=0;if(continuous_count)send_continuous_particles();}
function clear_measurements_event(e){save.values={};clear_measurements();}
function clear_measurements(){close_to_prediction=0;$('#Stage_eavesdrop_source').hide();$('#Stage_orangeContainer').hide();var n_key_th=0.5;var n_err_th=0;var p_err_th=0;if($('#Stage_sga_angle_fixd_radio').hasClass('selected')){if($('#Stage_sga_left_angle1_radio').hasClass('selected')==$('#Stage_sga_right_angle1_radio').hasClass('selected')){n_key_th='';var left_angle=$('#Stage_sga_left_angle1_radio').hasClass('selected')?1:2;var stage=AdobeEdge.getComposition(compId).getStage();}
else{n_key_th=0;n_err_th='';p_err_th='';}}
else if($('#Stage_eavesdrop').css('display')=='block'){n_err_th=0.25;p_err_th=0.25;}
$('#Stage_n_tot').text(0);$('#Stage_n_key').text(0);$('#Stage_n_err').text(0);$('#Stage_p_err').text('');$('#Stage_n_key_th').text(n_key_th);$('#Stage_n_err_th').text(n_err_th);$('#Stage_p_err_th').text(p_err_th);$('#Stage_n_tot_label2').hide();$('#Stage_n_key_label2').hide();n_key_th!==0?$('#Stage_n_tot_label2').show():$('#Stage_n_tot_label2').hide();n_err_th!==0&&n_key_th!==0?$('#Stage_n_key_label2').show():$('#Stage_key_label2').hide();$('#Stage_n_tot_label2').css('left',(n_key_th===''?192:202)+'px');$('#Stage_n_err_th').css('left',(n_err_th===0?165:162)+'px');row_count=0;a_basis=['','','','','',''];a_outcome=['','','','','',''];b_basis=['','','','','',''];b_outcome=['','','','','',''];same_basis=['','','','','',''];key=['','','','','',''];e_basis=['','','','','',''];e_outcome=['','','','','',''];for(var i=1;i<=6;i++){$('#Stage_a_basis'+i).html('');$('#Stage_a_outcome'+i).html('');$('#Stage_b_basis'+i).html('');$('#Stage_b_outcome'+i).html('');$('#Stage_e_basis'+i).html('');$('#Stage_e_outcome'+i).html('');$('#Stage_same_basis'+i).html('');$('#Stage_key'+i).html('');}
sym_disable($('#Stage_check_for_errors_button'));$('#Stage_feedback_text').html('More measurements needed for error checking');a_keys=[];b_keys=[];$('#Stage_alice_keys').text('');$('#Stage_bob_keys').text('');for(var i=2;i<=6;i++){$('#Stage_red'+i).hide();}
$('#Stage_eve_wrong_basis').hide();numberOfErrors=0;frozen_flashes();$('#Stage_alice_source').hide();AdobeEdge.getComposition(compId).getStage().$('polarizer_eve1').show();AdobeEdge.getComposition(compId).getStage().$('polarizer_eve2').show();AdobeEdge.getComposition(compId).getStage().$('greenFlashGapEve').show();clearTimeout(y);clearTimeout(z);clearTimeout(yy);clearTimeout(zz);clearTimeout(v);clearTimeout(w);clearTimeout(ww);clearTimeout(www);clearTimeout(wwww);clearTimeout(wwwww);clearTimeout(wwwwww);clearTimeout(u);AdobeEdge.getComposition(compId).getStage().getSymbol('photon').stop(0);AdobeEdge.getComposition(compId).getStage().getSymbol('photon_eve').stop(0);}
function frozen_flashes(){prefix=AdobeEdge.getComposition(compId).getStage();prefix.getSymbol('#Stage_greenFlashGap').stop(0);prefix.getSymbol('#Stage_crossFlash').stop(0);prefix.getSymbol('#Stage_tickFlash').stop(0);prefix.getSymbol('#Stage_greenFlashGapEve').stop(0);prefix.getSymbol('#Stage_crossFlashEve').stop(0);prefix.getSymbol('#Stage_tickFlashEve').stop(0);AdobeEdge.getComposition(compId).getStage().$('photon').hide();AdobeEdge.getComposition(compId).getStage().$('photon_eve').hide();$('#Stage_alice_source').hide();}
function rotate_sgas_event(e){var left_angle=$('#Stage_sga_left_angle1_radio').hasClass('selected')?1:2;var right_angle=$('#Stage_sga_right_angle1_radio').hasClass('selected')?1:2;if(multiple==false)rotate_sgas(left_angle,right_angle);save.left_angle=left_angle;save.right_angle=right_angle;clear_measurements();}
var left_up=0;var right_up=0;var middle_up=0;function rotate_sgas(left_angle,right_angle){left_up=Math.floor(Math.random()*2);right_up=Math.floor(Math.random()*2);if(left_angle=='random')return;sym_select($('#Stage_sga_left_angle'+left_angle+'_radio'));sym_select($('#Stage_sga_right_angle'+right_angle+'_radio'));if(multiple==false){var stage=AdobeEdge.getComposition(compId).getStage();stage.getSymbol('polarizer_alice').stop((left_angle-1)*2+left_up+'');stage.getSymbol('polarizer_bob').stop((right_angle-1)*2+right_up+'');}}
function rotate_sgas_random_event(e){var randomize_angles=$('#Stage_sga_angle_rand_radio').hasClass('selected');rotate_sgas_random(randomize_angles);save.randomize_angles=randomize_angles;if(randomize_angles){save.left_angle='random';save.right_angle='random';}
else{rotate_sgas_event(null);return;}
clear_measurements();}
function rotate_sgas_random(randomize_angles){if(randomize_angles){sym_select($('#Stage_sga_angle_rand_radio'));sym_disable($('#Stage_sga_left_angle1_radio'));sym_disable($('#Stage_sga_left_angle2_radio'));sym_disable($('#Stage_sga_right_angle1_radio'));sym_disable($('#Stage_sga_right_angle2_radio'));}else{sym_select($('#Stage_sga_angle_fixd_radio'));sym_enable($('#Stage_sga_left_angle1_radio'));sym_enable($('#Stage_sga_left_angle2_radio'));sym_enable($('#Stage_sga_right_angle1_radio'));sym_enable($('#Stage_sga_right_angle2_radio'));}}
function eavesdrop_enable_event(e){var eavesdrop=$('#Stage_eavesdrop_button_label').text()=="Eavesdrop!";eavesdrop_enable(eavesdrop);save.eavesdrop=eavesdrop;clear_measurements();}
function eavesdrop_enable(eavesdrop){eavesdrop?$('#Stage_eavesdrop').show():$('#Stage_eavesdrop').hide();$('#Stage_eavesdrop_button_label').text(eavesdrop?"Stop eavesdropping":"Eavesdrop!");}
function fireworks(){var number=6;var spread=75;var delay_const=500;var speed_const=700;var speed_const_offset=500;var x0=138,y0=493;var totalDelay=0;$('#Stage .star').hide();$('#Stage .star').css({'left':x0+'px','top':y0+'px','opacity':1});$('#Stage .star').fadeIn(500);for(var i=0;i<number;i++){var left=Math.round(Math.random()*spread);if(Math.random()<0.5)
left='-='+left+'px';else
left='+='+left+'px';var delay1=Math.round((Math.random()+.25)*delay_const);totalDelay+=delay1;var speed=Math.round((Math.random()+.5)*speed_const)+speed_const_offset;$('#Stage_stars'+i).delay(delay1).animate({'left':left,'top':'-=500px','opacity':0},speed);}
$('#Stage .star').delay(1000).fadeOut();}
function startScoreAnimation(a,b){var startValue=a;var endValue=b;var delayScore=150;var delayScoreCountdown=delayScore;if(b>a)
{function recursiveFunction(){clearInterval(scoreIncrementer);startValue++;$('#Stage_textScore').text(+startValue+'/100');if(startValue==endValue)
return;delayScoreCountdown=delayScoreCountdown-8;scoreIncrementer=setInterval(function(){recursiveFunction()},delayScoreCountdown);}
var scoreIncrementer=setInterval(function(){recursiveFunction()},delayScoreCountdown);$('#Stage_textScore').fadeOut(500);$('#Stage_textScore').fadeIn(500);}}
var totalScore=0;var feedbackProb=1;function addedFeedback(score){if(totalScore<100){startScoreAnimation(score,totalScore);if(totalScore>score&&Math.random()<feedbackProb){fireworks();feedbackProb=0.25;}else
feedbackProb=2*feedbackProb;}else
$('#Stage_textScore').text('100/100');if(totalScore==100){AdobeEdge.getComposition(compId).getStage().getSymbol('steps').getSymbol('fancyExcellent').play();totalScore=101;}}
function setup_mode(l,r,random){stage=AdobeEdge.getComposition(compId).getStage();if(l=='z')sym_select($('#Stage_sga_left_angle1_radio'));else sym_select($('#Stage_sga_left_angle2_radio'));if(r=='z')sym_select($('#Stage_sga_right_angle1_radio'));else sym_select($('#Stage_sga_right_angle2_radio'));if(random)sym_select($('#Stage_sga_angle_rand_radio'));else sym_select($('#Stage_sga_angle_fixd_radio'));rotate_sgas_random_event(null);if(challenges){$('#Stage .radio').each(function(){sym_disable($(this));});$('#Stage .button').each(function(){sym_disable($(this));});$('#Stage .noChallenge').hide();}
else{$('#Stage .radio').each(function(){sym_enable($(this));});$('#Stage .button').each(function(){sym_enable($(this));})
sym_select($('#Stage_sga_angle_rand_radio'));$('#Stage .noChallenge').show();rotate_sgas_random_event(null);}
clear_measurements();sym_enable(stage.getSymbol('#Stage_steps').$('submitButton'));}
function random_array(n){var container=[];var myArray=[];for(var i=1;i<=n;i++){container.push(i)}
for(var i=1;i<=n;i++){k=Math.floor(Math.random()*(container.length));myArray.push(container[k]);container.splice(k,1);}
return myArray;}
var answer=[];correct=false;function submit(){var stage=AdobeEdge.getComposition(compId).getStage().getSymbol('#Stage_steps');var feedback_text='';var score=0;var currentScore=totalScore;switch(current_challenge){case 1:answer=[];for(var i=1;i<=4;i++){if(stage.$('answer1_'+i+'_checkbox').hasClass('selected'))answer.push(i);}
var countFalse=0;for(var i=0;i<answer.length;i++){if($.inArray(answer[i],correct_answers)==-1){countFalse++;}}
if(countFalse==0&&number_selected==2){feedback_text='Correct, congratulations! Alice and Bob have the same values whenever they both measured in the same basis. Otherwise, their results are completely uncorrelated.';if(!$('#Stage_Tick1').hasClass('showing'))totalScore+=15;$('#Stage_Tick1').show();$('#Stage_Tick1').addClass('showing');}
else if(countFalse>0&&number_selected>countFalse&&number_selected<4){feedback_text='This is partially correct but not yet fully correct. Remember that Alice and Bob&apos;s values are perfectly correlated (if Alice sends 1, Bob measures 1; if Alice sends 0, Bob measures 0) only when they both happened to choose the same basis.';}
else if(countFalse==0&&number_selected==1){feedback_text='This is partially correct but not yet fully correct. Alice and Bob have the same values whenever they both measured in the same basis. Otherwise, their results are completely uncorrelated.';}
else{feedback_text='This is not yet correct. Remember that Alice and Bob&apos;s values are perfectly correlated (if Alice sends 1, Bob measures 1; if Alice sends 0, Bob measures 0) only when they both happened to choose the same basis.';}
if(countFalse>0||number_selected==1)correct=false;else correct=true;break;case 2:answer=[];for(var i=1;i<=6;i++){if(stage.$('answer2_'+i+'_radio').hasClass('selected'))answer.push(i);}
for(var i=0;i<answer.length;i++){if($.inArray(answer[i],correct_answers)==-1){correct=false;break;}
else correct=true;}
if(correct){if(count_keys>1)feedback_text='Correct, congratulations! Alice and Bob used the same bases for '+count_keys+' of the six measurements. Thus, there are '+count_keys+' bits in their shared key.';else feedback_text='Correct, congratulations! Alice and Bob used the same bases for '+count_keys+' of the six measurements. Thus, there is '+count_keys+' bit in their shared key.';if(!$('#Stage_Tick2').hasClass('showing'))totalScore+=15;$('#Stage_Tick2').show();$('#Stage_Tick2').addClass('showing');}
else{feedback_text='This is not yet correct. Remember that Alice and Bob keep only those values for which their bases were the same - this is the key.';}
break;case 3:answer=[];for(var i=1;i<=4;i++){if(stage.$('answer3_'+i+'_radio').hasClass('selected'))answer.push(i);}
for(var i=0;i<answer.length;i++){if($.inArray(answer[i],correct_answers)==-1){correct=false;break;}
else correct=true;}
if(correct){feedback_text='Correct, congratulations! The key consists of all values for which Alice and Bob chose the same basis. For these bits, Alice and Bob&apos;s values are perfectly correlated - they both have the same values.';if(!$('#Stage_Tick3').hasClass('showing'))totalScore+=15;$('#Stage_Tick3').show();$('#Stage_Tick3').addClass('showing');}
else if(stage.$('radio_label3_'+(answer[0])).text().length==12){feedback_text='This is not yet correct. Remember that Alice and Bob keep only those values for which their bases were the same - this is the key.';}
else{feedback_text='This is not yet correct. Remember that Alice and Bob&apos;s values are perfectly correlated (if Alice sends1, Bob measures 1; if Alice sends 0, Bob measures 0) when they both choose the same basis.';}
break;case 4:answer=[];for(var i=1;i<=3;i++){if(stage.$('answer4_'+i+'_radio').hasClass('selected'))answer.push(i);}
for(var i=0;i<answer.length;i++){if($.inArray(answer[i],correct_answers)==-1){correct=false;break;}
else correct=true;}
if(correct){feedback_text='Correct, congratulations! Eve intercepts the photon sent to Bob and measures its polarization component in the same way as Bob. She then sends a photon on to Bob with the polarization state she measured. If Eve guesses the wrong basis (a different basis to Alice and Bob), errors can occur. For example, if Alice sends |V&#x232A;, Eve measures 1 in the <span style="white-space: nowrap;">-45/+45</span> basis and passes on the state |-45&#x232A; to Bob, then Bob has a 50% probability of measuring |H&#x232A;, resulting in an error.';if(!$('#Stage_Tick4').hasClass('showing'))totalScore+=15;$('#Stage_Tick4').show();$('#Stage_Tick4').addClass('showing');}
else if(!correct&&answer[0]==1||answer[0]==2){feedback_text='This is not yet correct. Eve intercepts the photon sent to Bob and measures its polarization component in the same way as Bob. She then sends a photon on to Bob with the polarization state she measured. If Eve guessed the same basis as Alice, she passes on Alice&apos;s polarization state unchanged to Bob (e.g. if Alice sends |V&#x232A;, Eve measures 1 in the <span style="white-space: nowrap;">H/V</span> basis, and passes on the same state |V&#x232A; to Bob). Thus, errors do not occur when Eve guesses Alice&apos;s basis correctly.';}
else{feedback_text='This is not yet correct. Eve intercepts the photon and measures its polarization component in the same way as Bob. She then sends a photon on to Bob with the polarization state she measured. If Eve guessed the same basis as Alice, she passes on Alice&apos;s polarization state unchanged to Bob (e.g. if Alice sends |V&#x232A;, Eve measures 1 in the <span style="white-space: nowrap;">H/V</span> basis, and passes on the same state |V&#x232A; to Bob). What happens if Eve guesses the wrong basis?'}
break;case 5:answer=[];for(var i=1;i<=3;i++){if(stage.$('answer4_'+i+'_radio').hasClass('selected'))answer.push(i);}
for(var i=0;i<answer.length;i++){if($.inArray(answer[i],correct_answers)==-1){correct=false;break;}
else correct=true;}
if(correct){feedback_text='Correct, congratulations! Eve must have measured in the <span style="white-space: nowrap;">'+((e_basis[0]=='X')?'+45/-45':'H/V')+'</span> basis for an error to have occurred. Eve sends either the state '+((e_basis[0]=='X')?'<span style="white-space: nowrap;">|-45&#x232A; or |+45&#x232A;</span>':'<span style="white-space: nowrap;">|V&#x232A; or |H&#x232A;</span>')+' to Bob, but both of these states give completely random outcomes in the <span style="white-space: nowrap;">'+((e_basis[0]=='X')?'H/V':'-45/+45')+'</span> basis. Thus, while Alice sent '+((e_basis[0]=='X')?'|V&#x232A; (value 1 in the H/V basis)':'|-45&#x232A; (value 1 in the <span style="white-space: nowrap;">-45/+45</span> basis) ')+' Bob can measure 0 in the <span style="white-space: nowrap;">'+((e_basis[0]=='X')?'H/V':'-45/+45')+'</span> independent of whether Eve sent him a photon in state '+((e_basis[0]=='-45/+45')?'<span style="white-space: nowrap;">|-45&#x232A; or |+45&#x232A;</span>':'<span style="white-space: nowrap;">|V&#x232A; or |H&#x232A;</span>')+'. Thus, we cannot know Eve&apos;s outcome.';if(!$('#Stage_Tick5').hasClass('showing'))totalScore+=20;$('#Stage_Tick5').show();$('#Stage_Tick5').addClass('showing');}
else{feedback_text='This is not yet correct. Eve must have measured in the <span style="white-space: nowrap;">'+((e_basis[0]=='X')?'+45/-45':'H/V')+'</span> basis for an error to have occurred. Eve sends either the state '+((e_basis[0]=='X')?'<span style="white-space: nowrap;">|-45&#x232A; or |+45&#x232A;</span>':'<span style="white-space: nowrap;">|V&#x232A; or |H&#x232A;</span>')+' to Bob, but both of these states give completely random outcomes in the <span style="white-space: nowrap;">'+((e_basis[0]=='X')?'H/V':'-45/+45')+'</span> basis. Thus, while Alice sent '+((e_basis[0]=='X')?'|V&#x232A; (value 1 in the H/V basis)':'|-45&#x232A; (value 1 in the <span style="white-space: nowrap;">-45/+45</span> basis) ')+' Bob can measure 0 in the <span style="white-space: nowrap;">'+((e_basis[0]=='X')?'H/V':'-45/+45')+'</span> independent of whether Eve sent him a photon in state '+((e_basis[0]=='-45/+45')?'<span style="white-space: nowrap;">|-45&#x232A; or |+45&#x232A;</span>':'<span style="white-space: nowrap;">|V&#x232A; or |H&#x232A;</span>')+'. Thus, we cannot know Eve&apos;s outcome.';;}
break;case 6:answer=[];for(var i=1;i<=3;i++){if(stage.$('answer4_'+i+'_radio').hasClass('selected'))answer.push(i);}
for(var i=0;i<answer.length;i++){if($.inArray(answer[i],correct_answers)==-1){correct=false;break;}
else correct=true;}
if(correct){feedback_text='Correct, congratulations! Alice and Bob&apos;s values are both in the <span style="white-space: nowrap;">'+((a_basis[0]=='X')?'+45/-45':'H/V')+'</span> basis. If Eve used the same basis, there is no error. If Eve used the wrong basis <span style="white-space: nowrap;">('+((a_basis[0]=='X')?'H/V':'-45/+45')+')</span> then she sends either the state '+((a_basis[0]=='Z')?'<span style="white-space: nowrap;">|-45&#x232A; or |+45&#x232A;</span>':'<span style="white-space: nowrap;">|V&#x232A; or |H&#x232A;</span>')+' to Bob, but both of these states give completely random outcomes in the <span style="white-space: nowrap;">'+((a_basis[0]=='X')?'+45/-45':'H/V')+'</span> basis. Thus, Bob can measure 0 or 1 with equal probability when Eve uses the wrong basis. Thus, 50% of the time, Eve&apos;s presence will not introduce an error in Bob&apos;s outcome when she has used the wrong basis.';if(!$('#Stage_Tick6').hasClass('showing'))totalScore+=20;$('#Stage_Tick6').show();$('#Stage_Tick6').addClass('showing');}
else{feedback_text='This is not yet correct. Alice and Bob&apos;s values are both in the <span style="white-space: nowrap;">'+((a_basis[0]=='X')?'+45/-45':'H/V')+'</span> basis. If Eve used the same basis, there is no error. If Eve used the wrong basis <span style="white-space: nowrap;">('+((a_basis[0]=='X')?'H/V':'-45/+45')+')</span> then she sends either the state '+((a_basis[0]=='Z')?'<span style="white-space: nowrap;">|-45&#x232A; or |+45&#x232A;</span>':'<span style="white-space: nowrap;">|V&#x232A; or |H&#x232A;</span>')+' to Bob, but both of these states give completely random outcomes in the <span style="white-space: nowrap;">'+((a_basis[0]=='X')?'+45/-45':'H/V')+'</span> basis. Thus, Bob can measure 0 or 1 with equal probability when Eve uses the wrong basis. Thus, 50% of the time, Eve&apos;s presence will not introduce an error in Bob&apos;s outcome when she has used the wrong basis.';}
break;}
if(correct==false)
feedback_text='<div style="color:#960000">'+feedback_text+'</div>';else
feedback_text='<div style="color:#008f00">'+feedback_text+'</div>';if(stage.$('feedback').text()!=''){stage.$('feedback').fadeOut(250)};write=setTimeout(function(){stage.$('feedback').html("<span style='line-height: 1.3'>"+feedback_text+"</span>")},250);stage.$('feedback').fadeIn(250);addedFeedback(currentScore);}
var number_selected=0;function submit_button_hide(){var stage=AdobeEdge.getComposition(compId).getStage().getSymbol('#Stage_steps');number_selected=0;switch(current_challenge){case 1:for(var i=1;i<=4;i++){if(stage.$('answer1_'+i+'_checkbox').hasClass('selected'))number_selected++;}
break;case 2:for(var i=1;i<=6;i++){if(stage.$('answer2_'+i+'_radio').hasClass('selected'))number_selected++;}
break;case 3:for(var i=1;i<=4;i++){if(stage.$('answer3_'+i+'_radio').hasClass('selected'))number_selected++;}
break;case 4:for(var i=1;i<=3;i++){if(stage.$('answer4_'+i+'_radio').hasClass('selected'))number_selected++;}
break;case 5:for(var i=1;i<=3;i++){if(stage.$('answer4_'+i+'_radio').hasClass('selected'))number_selected++;}
break;case 6:for(var i=1;i<=3;i++){if(stage.$('answer4_'+i+'_radio').hasClass('selected'))number_selected++;}
break;}
if(number_selected==0)sym_disable(stage.getSymbol('#Stage_steps').$('submitButton'));else sym_enable(stage.getSymbol('#Stage_steps').$('submitButton'));}
var correct_answers=[];var current_challenge;function step_functions(step){clearTimeout(AdobeEdge.step_animation);current_challenge=step;var stage=AdobeEdge.getComposition(compId).getStage().getSymbol('#Stage_steps');stage.$('feedback').html('');switch(step){case 1:eavesdrop_enable(false);setup_mode('z','z',true);sym_disable(stage.getSymbol('#Stage_steps').$('submitButton'));for(var i=1;i<=4;i++)sym_deselect(stage.$('answer1_'+i+'_checkbox'));multiple2=true;for(var i=1;i<=6;i++)add_single_count();multiple2=false;if(count_keys==0||count_keys==6)return step_functions(1);frozen_flashes();setTimeout(function(){for(var i=1;i<=6;i++)$('#Stage_b_outcome'+i).html('?');},0);answer1='';answer2='';answer3='';answer4='';count=0;correct_answers=[];for(var i=1;i<=6;i++){if(same_basis[i-1]=='YES'){answer1=answer1+a_outcome[i-1]+' ';answer2=answer2+a_outcome[i-1]+' ';answer3=answer3+((a_outcome[i-1]=='0')?'1':'0')+' ';answer4=answer4+((a_outcome[i-1]=='0')?'1':'0')+' ';}
else{count++;answer1=answer1+(count%2)+' ';answer2=answer2+((count+1)%2)+' ';answer3=answer3+((count+1)%2)+' ';answer4=answer4+(count%2)+' ';}}
random_four=random_array(4);for(var i=0;i<=3;i++){stage.$('answer1_'+(i+1)).html(window['answer'+(random_four[i])]);if(random_four[i]==1||random_four[i]==2)correct_answers.push(i+1);}
break;case 2:eavesdrop_enable(false);setup_mode('z','z',true);sym_enable(stage.getSymbol('#Stage_steps').$('.group_answer2'));sym_deselect(stage.getSymbol('#Stage_steps').$('.group_answer2'));sym_disable(stage.getSymbol('#Stage_steps').$('submitButton'));multiple2=true;for(var i=1;i<=6;i++)add_single_count();multiple2=false;if(count_keys==0)return step_functions(2);frozen_flashes();setTimeout(function(){for(var i=1;i<=6;i++)$('#Stage_key'+i).html('?');},0);correct_answers=[count_keys];break;case 3:eavesdrop_enable(false);setup_mode('z','z',true);sym_enable(stage.getSymbol('#Stage_steps').$('.group_answer3'));sym_deselect(stage.getSymbol('#Stage_steps').$('.group_answer3'));sym_disable(stage.getSymbol('#Stage_steps').$('submitButton'));multiple2=true;for(var i=1;i<=6;i++)add_single_count();multiple2=false;if(count_keys==0||count_keys==6)return step_functions(3);frozen_flashes();setTimeout(function(){for(var i=1;i<=6;i++)$('#Stage_key'+i).html('?');},0);answer1='';answer2='';answer3='';answer4='';correct_answers=[];for(var i=1;i<=6;i++){if(same_basis[i-1]=='YES'){answer1=answer1+a_outcome[i-1]+'&nbsp;';answer2=answer2+((a_outcome[i-1]=='0')?'1':'0')+'&nbsp;';}
answer3=answer3+(a_outcome[i-1])+'&nbsp;';answer4=answer4+((a_outcome[i-1]=='0')?'1':'0')+'&nbsp;';}
random_four=random_array(4);for(var i=0;i<=3;i++){stage.$('radio_label3_'+(i+1)).html(window['answer'+(random_four[i])]);if(random_four[i]==1)correct_answers.push(i+1);}
break;case 4:eavesdrop_enable(true);setup_mode('z','z',true);multiple2=true;add_single_count();multiple2=false;frozen_flashes();if(error==false)return step_functions(4);stage.$('answer4_radio1_label').html('-45/+45');stage.$('answer4_radio2_label').html('H/V');AdobeEdge.getComposition(compId).getStage().$('polarizer_eve1').hide();AdobeEdge.getComposition(compId).getStage().$('polarizer_eve2').hide();AdobeEdge.getComposition(compId).getStage().$('greenFlashGapEve').hide();setTimeout(function(){$('#Stage_e_basis'+1).html('?');$('#Stage_e_outcome'+1).html('?');},0);sym_enable(stage.getSymbol('#Stage_steps').$('.group_answer4'));sym_deselect(stage.getSymbol('#Stage_steps').$('.group_answer4'));sym_disable(stage.getSymbol('#Stage_steps').$('submitButton'));correct_answers=[((e_basis[0]=='X')?1:2)];break;case 5:eavesdrop_enable(true);setup_mode('z','z',true);multiple2=true;add_single_count();multiple2=false;frozen_flashes();if(error==false||a_outcome[0]=='0')return step_functions(5);stage.$('answer4_radio1_label').html('0');stage.$('answer4_radio2_label').html('1');AdobeEdge.getComposition(compId).getStage().$('polarizer_eve1').hide();AdobeEdge.getComposition(compId).getStage().$('polarizer_eve2').hide();AdobeEdge.getComposition(compId).getStage().$('greenFlashGapEve').hide();setTimeout(function(){$('#Stage_e_basis'+1).html('?');$('#Stage_e_outcome'+1).html('?');},0);sym_enable(stage.getSymbol('#Stage_steps').$('.group_answer4'));sym_deselect(stage.getSymbol('#Stage_steps').$('.group_answer4'));sym_disable(stage.getSymbol('#Stage_steps').$('submitButton'));correct_answers=[3];break;case 6:eavesdrop_enable(true);setup_mode('z','z',true);multiple2=true;add_single_count();multiple2=false;frozen_flashes();if(error||same_basis[0]=='NO')return step_functions(6);stage.$('answer4_radio1_label').html('-45/+45');stage.$('answer4_radio2_label').html('H/V');AdobeEdge.getComposition(compId).getStage().$('polarizer_eve1').hide();AdobeEdge.getComposition(compId).getStage().$('polarizer_eve2').hide();AdobeEdge.getComposition(compId).getStage().$('greenFlashGapEve').hide();setTimeout(function(){$('#Stage_e_basis'+1).html('?');$('#Stage_e_outcome'+1).html('?');},0);sym_enable(stage.getSymbol('#Stage_steps').$('.group_answer4'));sym_deselect(stage.getSymbol('#Stage_steps').$('.group_answer4'));sym_disable(stage.getSymbol('#Stage_steps').$('submitButton'));correct_answers=[3];break;}}
function sym_features(){$('#Stage').css({'-webkit-user-select':'none','-moz-user-select':'none','-ms-user-select':'none','user-select':'none'});if(sym_ie()==9){makeUnselectable($('#Stage')[0]);function makeUnselectable(node){if(node.nodeType==1)node.setAttribute("unselectable","on");var child=node.firstChild;while(child){makeUnselectable(child);child=child.nextSibling;}}}
if(!$('#Stage').data('link_areas')){$('#Stage').data('link_areas',true);$('#Stage_links').children().each(function(){$(this).append('<div id="'+$(this).attr('id')+'_area"></div>');$('#'+$(this).attr('id')+'_area').css({'background':'black','opacity':'0','position':'absolute','width':'100%','height':'100%','left':'0px','top':'0px'});});}
$('#Stage').find('.button > div, .checkbox .tickbox, .radio .tickbox, .radio .tickbox div').css({'border-top-color':'#B5B8BA','border-right-color':'#898E91','border-bottom-color':'#5A6165','border-left-color':'#898E91'});$('#Stage .slider').not('.vertical').children().children().css({'width':'100%','border-top-color':'#575E62','border-right-color':'#8C9295','border-bottom-color':'#AEB2B4','border-left-color':'#8C9295'});$('#Stage .slider.vertical').children().children().css({'height':'100%','border-top-color':'#8C9295','border-right-color':'#575E62','border-bottom-color':'#8C9295','border-left-color':'#AEB2B4'});$(function(){FastClick.attach(document.body);});if(sym_ie()==9){$('#Stage').find('.button > div, .checkbox .tickbox, .radio .tickbox').css({'background':'url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZkZmRmZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNlYmViZWIiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+)'});$('#Stage .radio .tickbox div').css({'background':'url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPHJhZGlhbEdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgY3g9IjUwJSIgY3k9IjUwJSIgcj0iNzUlIj4KICAgIDxzdG9wIG9mZnNldD0iMCUiIHN0b3AtY29sb3I9IiMwMDJkMDAiIHN0b3Atb3BhY2l0eT0iMSIvPgogICAgPHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjYmZmZmJmIiBzdG9wLW9wYWNpdHk9IjEiLz4KICA8L3JhZGlhbEdyYWRpZW50PgogIDxyZWN0IHg9Ii01MCIgeT0iLTUwIiB3aWR0aD0iMTAxIiBoZWlnaHQ9IjEwMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+)'});}
$('#Stage').find('*').each(function(){if($(this).css('-webkit-transform')!=''&&$(this).css('-webkit-transform')!='none')
$(this).css('-webkit-transform',$(this).css('-webkit-transform'));});$('#Stage').find('.button, .checkbox, .radio, .slider').each(function(){if(!$(this).hasClass('disabled'))sym_enable(this)});$('#Stage .disabled').each(function(){sym_disable(this)});$('#Stage').find('.checkbox, .radio').each(function(){if(!$(this).hasClass('selected'))sym_deselect(this)});$('#Stage .selected').each(function(){sym_select(this)});$('#Stage .slider').each(function(){if(!$(this).attr('class').match(/min_(\d+)/))var min=0;else var min=$(this).attr('class').match(/min_(\d+)/)[1]*1;if(!$(this).attr('class').match(/max_\d+/))var max=100;else var max=$(this).attr('class').match(/max_(\d+)/)[1]*1;if(!$(this).attr('class').match(/snap_\d+/))var snap=1;else var snap=$(this).attr('class').match(/snap_(\d+)/)[1]*1;if(!$(this).attr('class').match(/val_\d+/))var val=min;else var val=$(this).attr('class').match(/val_(\d+)/)[1]*1;$(this).data('min',min);$(this).data('max',max);$(this).data('snap',snap);$(this).data('default',val);sym_val(this,$(this).data('val')===undefined?val:$(this).data('val'));});if(!$('#Stage').data('slider_events')){$('#Stage').data('slider_events',true);$(document).on('mousedown mousemove touchstart touchmove',function(e){var slider=$('#Stage .slider.active');if(slider.length){e.preventDefault();var min=slider.data('min');var max=slider.data('max');var snap=slider.data('snap');var range,pos;var scale=$('#Stage').attr('style').match(/scale *\(([0-9\.]+)\)/)[1]*1;if(slider.hasClass('vertical')){range=slider.children().height();pos=-slider.children().offset().top;if(e.type=='mousedown'||e.type=='mousemove')pos+=e.pageY;else pos+=e.originalEvent.touches[0].pageY;}else{range=slider.children().width();pos=-slider.children().offset().left;if(e.type=='mousedown'||e.type=='mousemove')pos+=e.pageX;else pos+=e.originalEvent.touches[0].pageX;}
pos=Math.min(Math.max(pos,0),range*scale)/scale;var snap_steps=(max-min)/snap;var snap_interval=range/snap_steps;pos=Math.round(pos/snap_interval)*snap_interval;slider.find('.handle').css(slider.hasClass('vertical')?'top':'left',pos+'px');var val=Math.round(min+pos/range*(max-min));slider.data('val',val);}});$(document).on('mouseup touchend',function(e){$('#Stage .slider.active').removeClass('active');});}
if(!$('#Stage').data('step_events')){$('#Stage').data('step_events',true);$('#Stage_steps').children().find('*').each(function(){if($(this).attr('id')&&$(this).attr('id').match(/_highlight_circle$/))
$(this).css({'outline':'transparent solid 1px'});});$('#Stage_steps_step_buttons').children().each(function(){$(this).append('<div id="'+$(this).attr('id')+'_area"></div>');$('#'+$(this).attr('id')+'_area').css({'background':'black','opacity':'0','position':'absolute','width':'100%','height':'100%','left':'0px','top':'0px'});});var i=1;while(i){if(!$('#Stage_steps_step'+i).length)break;$('#Stage_steps_step'+i).click(function(){sym_step(this.id.match(/\d+/)*1)});i++;}
$('#Stage').data('step_count',i-1);}}
function sym_enable(element){$(element).removeClass('disabled');$(element).css({'opacity':''});$('#'+$(element).attr('id')+'_mask').hide();if($(element).data('css_events'))return;$(element).data('css_events',true);$(element).append('<div id="'+$(element).attr('id')+'_area"></div>');$('#'+$(element).attr('id')+'_area').css({'background':'black','opacity':'0','position':'absolute','width':'100%','height':'100%','left':'0px','top':'0px'});if($(element).hasClass('button')){$(element).on('mouseover touchstart',function(){$(this).children().first().css({'border-top-color':'#009CFE','border-right-color':'#0089DF','border-bottom-color':'#0076C1','border-left-color':'#0089DF'});});$(element).on('mousedown touchstart',function(){$(this).children().first().attr('style',$(this).children().first().attr('style')
+'background:-moz-linear-gradient(top, #e1f3fe 0%, #9cd8fd 100%);'
+'background:-webkit-gradient(linear, left top, left bottom, color-stop(0%,#e1f3fe), color-stop(100%,#9cd8fd));'
+'background:-webkit-linear-gradient(top, #e1f3fe 0%,#9cd8fd 100%);'
+'background:-o-linear-gradient(top, #e1f3fe 0%,#9cd8fd 100%);'
+'background:-ms-linear-gradient(top, #e1f3fe 0%,#9cd8fd 100%);'
+'background:linear-gradient(to bottom, #e1f3fe 0%,#9cd8fd 100%);');if(sym_ie()==9)$(this).children().first().css({'background':'url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2UxZjNmZSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM5Y2Q4ZmQiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+)'});});$(element).on('mouseout touchend',function(){$(this).children().first().css({'border-top-color':'#B5B8BA','border-right-color':'#898E91','border-bottom-color':'#5A6165','border-left-color':'#898E91'});});$(element).on('mouseout mouseup touchend',function(){$(this).children().first().attr('style',$(this).children().first().attr('style')
+'background:-moz-linear-gradient(top, #fdfdfd 0%, #ebebeb 100%);'
+'background:-webkit-gradient(linear, left top, left bottom, color-stop(0%,#fdfdfd), color-stop(100%,#ebebeb));'
+'background:-webkit-linear-gradient(top, #fdfdfd 0%,#ebebeb 100%);'
+'background:-o-linear-gradient(top, #fdfdfd 0%,#ebebeb 100%);'
+'background:-ms-linear-gradient(top, #fdfdfd 0%,#ebebeb 100%);'
+'background:linear-gradient(to bottom, #fdfdfd 0%,#ebebeb 100%);');if(sym_ie()==9)$(this).children().first().css({'background':'url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZkZmRmZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNlYmViZWIiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+)'});});}
else if($(element).hasClass('checkbox')||$(element).hasClass('radio')){$('#'+$(element).attr('id')+'_area').on('click',function(){if($(this).parent().hasClass('selected')){if($(this).parent().hasClass('radio'))return;sym_deselect($(this).parent());}
else{sym_select($(this).parent());}});$(element).on('mouseover touchstart',function(){$(this).find('.tickbox').css({'border-top-color':'#009CFE','border-right-color':'#0089DF','border-bottom-color':'#0076C1','border-left-color':'#0089DF'});});$(element).on('mousedown touchstart',function(){$(this).find('.tickbox').attr('style',$(this).find('.tickbox').attr('style')
+'background:-moz-linear-gradient(top, #e1f3fe 0%, #9cd8fd 100%);'
+'background:-webkit-gradient(linear, left top, left bottom, color-stop(0%,#e1f3fe), color-stop(100%,#9cd8fd));'
+'background:-webkit-linear-gradient(top, #e1f3fe 0%,#9cd8fd 100%);'
+'background:-o-linear-gradient(top, #e1f3fe 0%,#9cd8fd 100%);'
+'background:-ms-linear-gradient(top, #e1f3fe 0%,#9cd8fd 100%);'
+'background:linear-gradient(to bottom, #e1f3fe 0%,#9cd8fd 100%);');if(sym_ie()==9)$(this).find('.tickbox').css({'background':'url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2UxZjNmZSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM5Y2Q4ZmQiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+)'});});$(element).on('mouseout touchend',function(){$(this).find('.tickbox').css({'border-top-color':'#B5B8BA','border-right-color':'#898E91','border-bottom-color':'#5A6165','border-left-color':'#898E91'});});$(element).on('mouseout mouseup touchend',function(){$(this).find('.tickbox').attr('style',$(this).find('.tickbox').attr('style')
+'background:-moz-linear-gradient(top, #fdfdfd 0%, #ebebeb 100%);'
+'background:-webkit-gradient(linear, left top, left bottom, color-stop(0%,#fdfdfd), color-stop(100%,#ebebeb));'
+'background:-webkit-linear-gradient(top, #fdfdfd 0%,#ebebeb 100%);'
+'background:-o-linear-gradient(top, #fdfdfd 0%,#ebebeb 100%);'
+'background:-ms-linear-gradient(top, #fdfdfd 0%,#ebebeb 100%);'
+'background:linear-gradient(to bottom, #fdfdfd 0%,#ebebeb 100%);');if(sym_ie()==9)$(this).find('.tickbox').css({'background':'url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZkZmRmZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNlYmViZWIiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+)'});});if($(element).hasClass('radio')){$(element).on('mouseover touchstart',function(){$(this).find('.tickbox div').css({'opacity':'0.8','border-top-color':'#009CFE','border-right-color':'#0089DF','border-bottom-color':'#0076C1','border-left-color':'#0089DF'});});$(element).on('mouseout touchend',function(){$(this).find('.tickbox div').css({'opacity':'','border-top-color':'#B5B8BA','border-right-color':'#898E91','border-bottom-color':'#5A6165','border-left-color':'#898E91'});});}}
else if($(element).hasClass('slider')){$(element).on('mouseover mouseup',function(){$(this).find('.handle').css({'background-position':'0% 50%'});});$(element).on('mousedown touchstart',function(){$(this).find('.handle').css({'background-position':'0% 100%'});$(this).addClass('active');});$(element).on('mouseout touchend',function(){$(this).find('.handle').css({'background-position':'0% 0%'});});}}
function sym_disable(element){$(element).addClass('disabled');$(element).css({'opacity':'0.4'});$('#'+$(element).attr('id')+'_mask').show();if(!$('#'+$(element).attr('id')+'_mask').length){$(element).after('<div id="'+$(element).attr('id')+'_mask"></div>');$('#'+$(element).attr('id')+'_mask').css({'background':'black','opacity':'0','position':$(element).css('position'),'width':$(element).css('width'),'height':$(element).css('height'),'left':$(element)[0].style.left,'top':$(element)[0].style.top,'right':$(element)[0].style.right,'bottom':$(element)[0].style.bottom});}}
function sym_select(element){$(element).addClass('selected');$(element).find('.tickbox div').show();if($(element).hasClass('radio')){$(element).data('selecting',true);var group=$(element).attr('class').match(/group_[^ ]+/)[0];$('#Stage .'+group).each(function(){if($(this).data('selecting'))$(this).data('selecting',false);else sym_deselect(this);});}}
function sym_deselect(element){$(element).removeClass('selected');$(element).find('.tickbox div').hide();}
function sym_val(element,val){var min=$(element).data('min');var max=$(element).data('max');var range=$(element).hasClass('vertical')?$(element).children().height():$(element).children().width();var pos=(val-min)/(max-min)*range;$(element).find('.handle').css($(element).hasClass('vertical')?'top':'left',pos+'px');$(element).data('val',val);}
function sym_step(step){step*=1;$('#Stage').data('step',step);var sym=AdobeEdge.getComposition(compId).getSymbols('steps')[0];sym.stop(step+'');sym.$('step_buttons').children().children().css({'border-color':'#999999'});sym.$('step'+step).children().css({'border-color':'#1F7258'});sym.$('step_buttons').children().children().children().css({'color':'#999999'});sym.$('step'+step).children().children().css({'color':'#1F7258'});step_functions(step);}
function sym_ie(){var version=false;if(navigator.appVersion.indexOf("MSIE")!=-1)
version=parseFloat(navigator.appVersion.split("MSIE")[1]);return version;}

//Edge symbol: 'stage'
(function(symbolName){Symbol.bindElementAction(compId,symbolName,"document","compositionReady",function(sym,e){sym_features();yepnope({load:"normalize.css"});show_boxes_event(e);rotate_sgas_event(e);rotate_sgas_random_event(e);eavesdrop_enable_event(e);clear_measurements_event(e);sym.$('n_key_label').html('N<sub>key</sub>');sym.$('n_key_label2').html('N<sub>key</sub>');sym.$('n_key_label3').html('N<sub>key</sub>');sym.$('n_err_label').html('N<sub>err</sub>');sym.$('n_err_label2').html('N<sub>err</sub>');sym.$('n_tot_label').html('N<sub>tot</sub>');sym.$('n_tot_label2').html('N<sub>tot</sub>');formula='<span style="white-space: nowrap;">|&#936;&#x232A;<sub>ab</sub> = 1/&radic;<span style="text-decoration: overline">2</span>(|&#8593;<sub>a</sub>&#x232A;|&#8595;<sub>b</sub>&#x232A; - |&#8595;<sub>a</sub>&#x232A;|&#8593;<sub>b</sub>&#x232A;).</span>';sym.$('Text4').html('Alice and Bob need to share a secret perfectly random sequence of zeros and ones (a so-called secure key), but cannot meet in person. Classically this is impossible, as they can never be certain that the key was not intercepted during transmission. Quantum mechanics makes secure key generation possible! <br><div style="line-height:50%;"><br></div>In this simulation, you can help Alice and Bob generate a secure key using polarized photons. Alice prepares each photon polarization in one of two bases, either H/V (horizontal/vertical) or +45/-45 (at ±45 degrees from the vertical), using a polarizer oriented along one of these four directions. The vertical and -45 degree orientations are assigned a value of 1, the horizontal and +45 degree orientations a value of 0.  In the simulation, the states |H&#x232A;, |V&#x232A;, |+45&#x232A;, |-45&#x232A; refer to photon states with horizontal, vertical, +45 and -45 degree polarization respectively.<br><div style="line-height:50%;"><br></div>Alice sends the polarized photon to Bob, who is equipped with a polarization analyzer and a single photon detector. Bob randomly chooses one of the two bases, and orients his analyzer along one of the directions in this basis. Alice informs Bob whenever she sends a photon.');sym.$('Text7').html('Bob either registers a photon in his detector or not, determining his bit value. For example, if Bob orients his analyzer horizontally but does not detect a photon, his bit value is 1 (vertical in the H/V basis). <div style="line-height:50%;"><br></div> Alice and Bob note independent of one another the basis (H/V or +45/-45) and bit value (0 or 1) for each particle. They know that their bit values are the same when they both happened to choose the same basis. After completing the measurements, Alice and Bob publicly share the bases used (but not the values!), and keep only those values for which their bases were the same – this is the key.  Alice and Bob then exchange a small number of their values (which they then discard) to check for errors.<br><div style="line-height:50%;"><br></div><b>Your goal is to help Alice and Bob decide whether or not they have generated a secure key. How can they tell that an eavesdropper Eve has infiltrated their experiment?  <br>Click on the virtual reality goggles that allow you to “see” the photons to start sending photons from Alice to Bob and to eavesdrop by intercepting and resending photons.</b>');sym.getSymbol('up_x').$('Text8').html('|&#8211;45°&#x232A;');sym.getSymbol('down_z').$('Text9').html('|H&#x232A;');sym.getSymbol('down_x').$('Text10').html('|+45°&#x232A;');sym.getSymbol('up_z').$('Text11').html('|V&#x232A;');sym.$('radio_labelCopy').html('+45/&#8211;45');sym.$('radio_labelCopy2').html('+45/&#8211;45');sym.$('Text5Copy4').html('&#8211;45');sym.getSymbol('#Stage_steps').$(".feedback").css({'position':'absolute','left':'50%','top':'50%','margin-left':-(sym.getSymbol('#Stage_steps').$(".feedback").outerWidth()/2),'margin-top':-(sym.getSymbol('#Stage_steps').$(".feedback").outerHeight()/2)});$('#Stage .star,.tick').hide();$('#Stage_show_controls_button').hide();$('#Stage_show_controls_button').fadeIn(1000,function(){$('#Stage_show_controls_button').animate({'top':'-=5px'},300);$('#Stage_show_controls_button').animate({'top':'+=10px'},300);$('#Stage_show_controls_button').animate({'top':'-=10px'},300);$('#Stage_show_controls_button').animate({'top':'+=10px'},300);$('#Stage_show_controls_button').animate({'top':'-=5px'},300);});});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_send_single_button}","click",function(sym,e){multiple=false;send_single_particle(e);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_send_continuous_button}","click",function(sym,e){multiple=false;send_continuous_particles(e);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_tab_simulation}","click",function(sym,e){sym.stop('simulation');sym_features();$('#Stage').data('step',false);clearTimeout(AdobeEdge.step_animation);challenges=false;setup_mode('z','z',true);show_boxes(save.show_key,save.show_errors,save.show_graph);rotate_sgas(save.left_angle,save.right_angle);rotate_sgas_random(save.randomize_angles);eavesdrop_enable(save.eavesdrop);clear_measurements();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_tab_challenges}","click",function(sym,e){if(continuous_count)send_continuous_particles(null);challenges=true;sym.stop('challenges');sym_features();sym_step(1);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_send_multiple_button}","click",function(sym,e){AdobeEdge.getComposition(compId).getStage().$('photon').hide();AdobeEdge.getComposition(compId).getStage().$('photon_eve').hide();clearTimeout(y);clearTimeout(z);clearTimeout(yy);clearTimeout(zz);clearTimeout(v);clearTimeout(w);clearTimeout(ww);clearTimeout(www);clearTimeout(wwww);clearTimeout(u);AdobeEdge.getComposition(compId).getStage().getSymbol('photon').stop(0);AdobeEdge.getComposition(compId).getStage().getSymbol('photon_eve').stop(0);if(continuous_count)k=setTimeout(function(){send_continuous_particles(e)},0);clearInterval(continuous_count);continuous_count=false;multiple=true;multiple2=true;send_multiple_particles(e);multiple=false;for(k=1;k<=6;k++){add_single_count();}
multiple2=false;AdobeEdge.getComposition(compId).getStage().$('photon').hide();AdobeEdge.getComposition(compId).getStage().$('photon_eve').hide();if($('#Stage_eavesdrop').css('display')=='block'){if(middle_up==outcome.eavesdrop_plus){sym.getSymbol('tickFlashEve').stop(250);sym.getSymbol('greenFlashGapEve').stop(250);}
else{sym.getSymbol('crossFlashEve').stop(250);}
if(outcome.left_90==outcome.eavesdrop_90){if(middle_up==outcome.left_plus)sym.getSymbol('polarizer_eve2').stop((((outcome.eavesdrop_90==true)?2:1)-1)*2+middle_up+'');else sym.getSymbol('polarizer_eve2').stop((((outcome.eavesdrop_90==true)?2:1)-1)*2+Math.abs(middle_up-1)+'')}
else{if(middle_up==outcome.eavesdrop_plus){sym.getSymbol('polarizer_eve2').stop((((outcome.eavesdrop_90==true)?2:1)-1)*2+middle_up+'');}
else{sym.getSymbol('polarizer_eve2').stop((((outcome.eavesdrop_90==true)?2:1)-1)*2+Math.abs(middle_up-1)+'')}}
var temp=1;if(outcome.eavesdrop_plus){temp=(outcome.eavesdrop_90)?3:1;}
else{temp=(outcome.eavesdrop_90)?4:2;}
if(temp==1)$('#Stage_eavesdrop_source').html('|V&#x232A;');if(temp==2)$('#Stage_eavesdrop_source').html('|H&#x232A;');if(temp==3)$('#Stage_eavesdrop_source').html('|&#8211;45°&#x232A;');if(temp==4)$('#Stage_eavesdrop_source').html('|+45°&#x232A;');$('#Stage_eavesdrop_source').fadeIn(200);if(outcome.eavesdrop_90==outcome.right_90){if(left_up==right_up){sym.getSymbol('greenFlashGap').stop(250);sym.getSymbol('tickFlash').stop(250)}
else{sym.getSymbol('crossFlash').stop(250);}}
else{if(outcome.right_plus==right_up){sym.getSymbol('greenFlashGap').stop(250);sym.getSymbol('tickFlash').stop(250);}
else{sym.getSymbol('crossFlash').stop(250);}}}
else{if(left_up==right_up){sym.getSymbol('greenFlashGap').stop(250);sym.getSymbol('tickFlash').stop(250)}
else{sym.getSymbol('crossFlash').stop(250);}}});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_show_introduction_button}","click",function(sym,e){sym.stop('introduction');sym_features();frozen_flashes();if(continuous_count)send_continuous_particles(null);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_show_controls_button}","click",function(sym,e){sym.stop('simulation');sym_features();glassesAnimation();sym.$('show_controls_button').fadeOut();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_show_key_checkbox}","click",function(sym,e){show_boxes_event(null);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_show_errors_checkbox}","click",function(sym,e){show_boxes_event(null);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_show_graph_checkbox}","click",function(sym,e){show_boxes_event(null);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_sga_right_angle1_radio}","click",function(sym,e){rotate_sgas_event(null);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_sga_right_angle2_radio}","click",function(sym,e){rotate_sgas_event(null);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_sga_angle_fixd_radio}","click",function(sym,e){rotate_sgas_random_event(null);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_sga_angle_rand_radio}","click",function(sym,e){rotate_sgas_random_event(null);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_eavesdrop_button}","click",function(sym,e){eavesdrop_enable_event(null);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_clear_measurements_button}","click",function(sym,e){clear_measurements_event(e);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_check_for_errors_button}","click",function(sym,e){check_for_errors();sym_disable($('#Stage_check_for_errors_button'));});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_link_st_andrews}","click",function(sym,e){window.open('http://www.st-andrews.ac.uk/physics/quvis','_blank');});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_sga_left_angle1_radio}","click",function(sym,e){rotate_sgas_event(null);});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_sga_left_angle2_radio}","click",function(sym,e){rotate_sgas_event(null);});
//Edge binding end
})("stage");
//Edge symbol end:'stage'

//=========================================================

//Edge symbol: 'checkbox_tickbox'
(function(symbolName){})("checkbox_tickbox");
//Edge symbol end:'checkbox_tickbox'

//=========================================================

//Edge symbol: 'radio_tickbox'
(function(symbolName){})("radio_tickbox");
//Edge symbol end:'radio_tickbox'

//=========================================================

//Edge symbol: 'highlight'
(function(symbolName){Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.play(0);});
//Edge binding end
})("highlight");
//Edge symbol end:'highlight'

//=========================================================

//Edge symbol: 'sga_left'
(function(symbolName){})("sga_left");
//Edge symbol end:'sga_left'

//=========================================================

//Edge symbol: 'sga_right'
(function(symbolName){})("sga_right");
//Edge symbol end:'sga_right'

//=========================================================

//Edge symbol: 'flash_detector_0'
(function(symbolName){})("flash_detector_0");
//Edge symbol end:'flash_detector_0'

//=========================================================

//Edge symbol: 'flash_detector_1'
(function(symbolName){})("flash_detector_1");
//Edge symbol end:'flash_detector_1'

//=========================================================

//Edge symbol: 'screen'
(function(symbolName){})("screen");
//Edge symbol end:'screen'

//=========================================================

//Edge symbol: 'key_row'
(function(symbolName){})("key_row");
//Edge symbol end:'key_row'

//=========================================================

//=========================================================

//Edge symbol: 'greenFlashGap'
(function(symbolName){Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.getComposition().getStage().continueStream();});
//Edge binding end
Symbol.bindTriggerAction(compId,symbolName,"Default Timeline",250,function(sym,e){sym.stop();});
//Edge binding end
})("greenFlashGap");
//Edge symbol end:'greenFlashGap'

//=========================================================

//Edge symbol: 'blueFlashGap'
(function(symbolName){Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.getComposition().getStage().continueStream();});
//Edge binding end
Symbol.bindTriggerAction(compId,symbolName,"Default Timeline",250,function(sym,e){if(!continuous_count){sym.stop();}});
//Edge binding end
})("blueFlashGap");
//Edge symbol end:'blueFlashGap'

//=========================================================

//Edge symbol: 'blueFlash'
(function(symbolName){Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.getComposition().getStage().continueStream();});
//Edge binding end
Symbol.bindTriggerAction(compId,symbolName,"Default Timeline",250,function(sym,e){if(!continuous_count){sym.stop();}});
//Edge binding end
})("blueFlash");
//Edge symbol end:'blueFlash'

//=========================================================

//Edge symbol: 'greenFlash'
(function(symbolName){Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.getComposition().getStage().continueStream();});
//Edge binding end
Symbol.bindTriggerAction(compId,symbolName,"Default Timeline",250,function(sym,e){sym.stop();});
//Edge binding end
})("greenFlash");
//Edge symbol end:'greenFlash'

//=========================================================

//=========================================================

//=========================================================

//Edge symbol: 'highlight'
(function(symbolName){Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.play(0);});
//Edge binding end
})("highlight_1");
//Edge symbol end:'highlight_1'

//=========================================================

//=========================================================

//=========================================================

//Edge symbol: 'highlight'
(function(symbolName){Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.play(0);});
//Edge binding end
})("highlight_1_1");
//Edge symbol end:'highlight_1_1'

//=========================================================

//=========================================================

//Edge symbol: 'highlight_rectangle'
(function(symbolName){Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.play(0);});
//Edge binding end
})("highlight_rectangle");
//Edge symbol end:'highlight_rectangle'

//=========================================================

//Edge symbol: 'up_z'
(function(symbolName){Symbol.bindTriggerAction(compId,symbolName,"Default Timeline",250,function(sym,e){sym.stop();});
//Edge binding end
Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.getComposition().getStage().continueStream();});
//Edge binding end
})("up_z");
//Edge symbol end:'up_z'

//=========================================================

//Edge symbol: 'up_z_2'
(function(symbolName){Symbol.bindTriggerAction(compId,symbolName,"Default Timeline",250,function(sym,e){sym.stop();});
//Edge binding end
})("down_z");
//Edge symbol end:'down_z'

//=========================================================

//Edge symbol: 'up_z_3'
(function(symbolName){Symbol.bindTriggerAction(compId,symbolName,"Default Timeline",250,function(sym,e){sym.stop();});
//Edge binding end
})("down_x");
//Edge symbol end:'down_x'

//=========================================================

//Edge symbol: 'up_z_1'
(function(symbolName){Symbol.bindTriggerAction(compId,symbolName,"Default Timeline",250,function(sym,e){sym.stop();});
//Edge binding end
})("up_x");
//Edge symbol end:'up_x'

//=========================================================

//Edge symbol: 'exploration'
(function(symbolName){Symbol.bindElementAction(compId,symbolName,"${_submitButton}","click",function(sym,e){submit();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer1_1_checkbox}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer1_2_checkbox}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer1_3_checkbox}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer1_4_checkbox}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer2_1_radio}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer2_2_radio}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer2_3_radio}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer2_4_radio}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer2_5_radio}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer2_6_radio}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer3_1_radio}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer3_2_radio}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer3_3_radio}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer3_4_radio}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer4_1_radio}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer4_2_radio}","click",function(sym,e){submit_button_hide();});
//Edge binding end
Symbol.bindElementAction(compId,symbolName,"${_answer4_3_radio}","click",function(sym,e){submit_button_hide();});
//Edge binding end
})("steps");
//Edge symbol end:'steps'

//=========================================================

//=========================================================

//=========================================================

//Edge symbol: 'highlight'
(function(symbolName){Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.play(0);});
//Edge binding end
})("highlight_1_2");
//Edge symbol end:'highlight_1_2'

//=========================================================

//=========================================================

//=========================================================

//Edge symbol: 'highlight'
(function(symbolName){Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.play(0);});
//Edge binding end
})("highlight_1_1_1");
//Edge symbol end:'highlight_1_1_1'

//=========================================================

//=========================================================

//Edge symbol: 'highlight_rectangle'
(function(symbolName){Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.play(0);});
//Edge binding end
})("highlight_rectangle_1");
//Edge symbol end:'highlight_rectangle_1'

//=========================================================

//Edge symbol: 'fancyExcellent'
(function(symbolName){Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.stop(0);});
//Edge binding end
})("fancyExcellent");
//Edge symbol end:'fancyExcellent'

//=========================================================

//Edge symbol: 'polarizer_alice'
(function(symbolName){})("polarizer_alice");
//Edge symbol end:'polarizer_alice'

//=========================================================

//Edge symbol: 'photon'
(function(symbolName){})("photon");
//Edge symbol end:'photon'

//=========================================================

//Edge symbol: 'greenFlashGap_1'
(function(symbolName){Symbol.bindTriggerAction(compId,symbolName,"Default Timeline",250,function(sym,e){sym.stop();});
//Edge binding end
Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.getComposition().getStage().continueStream();});
//Edge binding end
})("crossFlash");
//Edge symbol end:'crossFlash'

//=========================================================

//Edge symbol: 'crossFlash_1'
(function(symbolName){Symbol.bindTriggerAction(compId,symbolName,"Default Timeline",250,function(sym,e){sym.stop();});
//Edge binding end
Symbol.bindTimelineAction(compId,symbolName,"Default Timeline","complete",function(sym,e){sym.getComposition().getStage().continueStream();});
//Edge binding end
})("tickFlash");
//Edge symbol end:'tickFlash'

//=========================================================

//Edge symbol: 'photon_1'
(function(symbolName){})("photon_eve");
//Edge symbol end:'photon_eve'
})(jQuery,AdobeEdge,"EDGE-19890435");