]> git.sesse.net Git - remoteglot/commitdiff
Handle streaming PGNs, like from Lichess (although this might break non-streaming... master
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 7 Feb 2024 16:47:21 +0000 (17:47 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 7 Feb 2024 16:47:46 +0000 (17:47 +0100)
24 files changed:
.gitignore
Position.pm
build.sh
clean-svg.pl [new file with mode: 0644]
config.pm
remoteglot.pl
server/hash-lookup.js
server/serve-analysis.js
www/analysis.pl [changed mode: 0755->0644]
www/css/chessboard-0.3.0.css
www/css/chessboard-0.3.0.min.css [deleted file]
www/css/remoteglot.css
www/favicon.ico
www/index.dev.html [moved from www/index.html with 71% similarity]
www/js/chess.js
www/js/chess.min.js [deleted file]
www/js/chessboard-0.3.0.js
www/js/chessboard-0.3.0.min.js [deleted file]
www/js/jquery-1.10.2.min.js [deleted file]
www/js/jquery-deprecated-sizzle.js [deleted file]
www/js/jquery.sparkline.js [deleted file]
www/js/json_delta.js
www/js/remoteglot.js
www/manual-override.pl [new file with mode: 0755]

index c6b42d32f1ddd3a59d6a496be37dcbfb3fedfc39..3134bf10d1989c4c25627c713d2780a6a6f06ad6 100644 (file)
@@ -2,9 +2,11 @@ config.local.pm
 junk/
 www/analysis.json
 www/js/remoteglot.min.js
+www/css/remoteglot.min.css
 tblog.txt
 ucilog.txt
 ficslog.txt
 openings.txt
 www/history/
 closure/
+index.html
index 3e39e46f0f09ed2d762b6e3f3eca002b800e974b..9e9fe29ac63af32ff5c31439c837ec3c4c7eeaae 100644 (file)
@@ -191,6 +191,8 @@ sub fen {
 sub to_json_hash {
        my $pos = shift;
        my $json = { %$pos, fen => $pos->fen() };
+       delete $json->{'toplay'};
+       delete $json->{'move_num'};
        delete $json->{'board'};
        delete $json->{'prettyprint_cache'};
        delete $json->{'tbprobe_cache'};
index 9f97e35fd8383ee36365f8fee6420d922d9ddf76..75141e4e10d0b096aba4c0e5994fdc96ba9693a7 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -1,21 +1,19 @@
 #! /bin/sh
 
-# Download http://dl.google.com/closure-compiler/compiler-latest.zip
-# and unzip it in closure/ before running this script.
+# Download the latest .jar from
+# https://mvnrepository.com/artifact/com.google.javascript/closure-compiler/v20231112
+# (adjust the URL for the version you want) before running this script.
 
-# The JQuery build comes from http://projects.jga.me/jquery-builder/,
-# more specifically
-#
-# https://raw.githubusercontent.com/jgallen23/jquery-builder/0.7.0/dist/2.1.1/jquery-deprecated-sizzle.js
+umask 022
 
-java -jar closure/compiler.jar \
-       --language_in ECMASCRIPT5 \
+java -jar closure-compiler-v20231112.jar \
        --compilation_level SIMPLE \
        --js_output_file=www/js/remoteglot.min.js \
-        www/js/jquery-deprecated-sizzle.js \
        www/js/chessboard-0.3.0.js \
        www/js/chess.js \
        www/js/json_delta.js \
-       www/js/jquery.sparkline.js \
        www/js/remoteglot.js
 
+cat www/css/chessboard-0.3.0.css www/css/remoteglot.css | sass --scss -t compressed > www/css/remoteglot.min.css
+perl replace.pl < www/index.dev.html > www/index.html
+
diff --git a/clean-svg.pl b/clean-svg.pl
new file mode 100644 (file)
index 0000000..e102edb
--- /dev/null
@@ -0,0 +1,26 @@
+#! /usr/bin/perl
+use strict;
+use warnings;
+use MIME::Base64;
+
+undef $/;
+my $x = <>;
+$x = MIME::Base64::decode_base64($x);
+$x =~ s/>\s*</></sg;  # Remove whitespace between tags.
+$x =~ s/\s+/ /sg;  # Compress whitespace.
+$x =~ s# />#/>#g;  # <foo /> -> <foo/>.
+$x =~ s/;\s+/;/sg; # Remove whitespace in CSS.
+$x =~ s/;"/"/g;   # Remove final semicolon in CSS.
+$x =~ s/\s+$//;  # Remove tailing whitespace.
+$x =~ s/><!DOCTYPE/>\n<!DOCTYPE/;  # Add back newline after XML header.
+$x =~ s/<svg/\n<svg/;   # Add back newline after DOCTYPE.
+
+print $x, "\n";
+print MIME::Base64::encode_base64($x, ""), "\n";
+
+my $z = $x;
+$z =~ s/%/%25/g;
+$z =~ s/\n/%0A/g;
+$z =~ s/"/%22/g;
+$z =~ s/#/%23/g;
+print $z, "\n";
index 44ed56b0b50555498e80fede05077e3981c85464..073ab92f6192f2ff10b2961ec1673e83634a0a82 100644 (file)
--- a/config.pm
+++ b/config.pm
@@ -4,10 +4,6 @@
 
 package remoteglotconf;
 
-our $server = "freechess.org";  # undef to not connect to FICS.
-our $nick = "SesseBOT";
-our $target = "GMCarlsen";  # FICS username or HTTP to a PGN file.
-
 # Set to non-undef to pick out one specific game from a PGN file with many games.
 # See example.
 our $pgn_filter = undef;
@@ -58,6 +54,7 @@ our %engine2_config = (
 our $engine2_grpc_backend = undef;  # Not used by us, but will be communicated to serve-analysis.js.
 
 our $update_max_interval = 1.0;
+our $update_force_after_move = 0.2;
 our @masters = (
        'Sesse',
 );
@@ -66,11 +63,6 @@ our @masters = (
 # including the --path= argument.
 our $fathom_cmdline = undef;
 
-# ChessOK serial key (of the form NNNNN-NNNNN-NNNNN-NNNNN-NNNNN-NNNNN)
-# for looking up 7-man tablebases; undef means no lookup. Note that
-# you probably need specific prior permission to use this.
-our $tb_serial_key = undef;
-
 # Credits to show in the footer.
 our $engine_url = "http://www.stockfishchess.org/";
 our $engine_details = undef;  # For hardware.
@@ -82,6 +74,12 @@ our $dbistr = "dbi:Pg:dbname=remoteglot";
 our $dbiuser = undef;
 our $dbipass = undef;
 
+# For manual moves made from the web interface.
+our $adminpass = undef;
+
+# How often to poll the target, in seconds.
+our $poll_frequency = 1.0;
+
 eval {
        my $config_filename = $ENV{'REMOTEGLOT_CONFIG'} // 'config.local.pm';
        require $config_filename;
index 9d611c0e6cfe2700cc0f8a5118f36b2e318b72fa..b5db356ca5dde24c1d2f7fb167448e07e4ae660c 100755 (executable)
@@ -1,9 +1,8 @@
 #! /usr/bin/perl
 
 #
-# remoteglot - Connects an abitrary UCI-speaking engine to ICS for easier post-game
-#              analysis, or for live analysis of relayed games. (Do not use for
-#              cheating! Cheating is bad for your karma, and your abuser flag.)
+# remoteglot - Connects an abitrary UCI-speaking engine to a (live) PGN,
+#              for live analysis of relayed games.
 #
 # Copyright 2007 Steinar H. Gunderson <steinar+remoteglot@gunderson.no>
 # Licensed under the GNU General Public License, version 2.
@@ -14,7 +13,6 @@ use AnyEvent::Handle;
 use AnyEvent::HTTP;
 use Chess::PGN::Parse;
 use EV;
-use Net::Telnet;
 use File::Slurp;
 use IPC::Open2;
 use Time::HiRes;
@@ -35,7 +33,6 @@ my $output_timer = undef;
 my $http_timer = undef;
 my $stop_pgn_fetch = 0;
 my $tb_retry_timer = undef;
-my %tb_cache = ();
 my $tb_lookup_running = 0;
 my $last_written_json = undef;
 
@@ -48,12 +45,6 @@ $dbh->{RaiseError} = 1;
 
 $| = 1;
 
-open(FICSLOG, ">ficslog.txt")
-       or die "ficslog.txt: $!";
-print FICSLOG "Log starting.\n";
-select(FICSLOG);
-$| = 1;
-
 open(UCILOG, ">ucilog.txt")
        or die "ucilog.txt: $!";
 print UCILOG "Log starting.\n";
@@ -76,6 +67,15 @@ my $last_move;
 my $last_text = '';
 my ($pos_calculating, $pos_calculating_second_engine);
 
+# If not undef, we've started calculating this position but haven't ever given out
+# any analysis for it, so we're on a forced timer to do so.
+my $pos_calculating_started = undef;
+
+# If not undef, we've output this position, but without a main PV, so we're on
+# _another_ forced timer to do so.
+my $pos_pv_started = undef;
+my $last_output_had_pv = 0;
+
 setoptions($engine, \%remoteglotconf::engine_config);
 uciprint($engine, "ucinewgame");
 
@@ -87,46 +87,14 @@ if (defined($engine2)) {
 
 print "Chess engine ready.\n";
 
-# now talk to FICS
-my ($t, $ev1);
-if (defined($remoteglotconf::server)) {
-       $t = Net::Telnet->new(Timeout => 10, Prompt => '/fics% /');
-       $t->input_log(\*FICSLOG);
-       $t->open($remoteglotconf::server);
-       $t->print($remoteglotconf::nick);
-       $t->waitfor('/Press return to enter the server/');
-       $t->cmd("");
-
-       # set some options
-       $t->cmd("set shout 0");
-       $t->cmd("set seek 0");
-       $t->cmd("set style 12");
-
-       $ev1 = AnyEvent->io(
-               fh => fileno($t),
-               poll => 'r',
-               cb => sub {    # what callback to execute
-                       while (1) {
-                               my $line = $t->getline(Timeout => 0, errmode => 'return');
-                               return if (!defined($line));
-
-                               chomp $line;
-                               $line =~ tr/\r//d;
-                               handle_fics($line);
-                       }
-               }
-       );
-}
 if (defined($remoteglotconf::target)) {
        if ($remoteglotconf::target =~ /^(?:\/|https?:)/) {
-               fetch_pgn($remoteglotconf::target);
-       } elsif (defined($t)) {
-               $t->cmd("observe $remoteglotconf::target");
+               my $target = $remoteglotconf::target;
+               # Convenience.
+               $target =~ s#https://lichess.org/broadcast/.*/([^/]+)?$#https://lichess.org/api/stream/broadcast/round/$1.pgn#;
+               fetch_pgn($target);
        }
 }
-if (defined($t)) {
-       print "FICS ready.\n";
-}
 
 # Engine events have already been set up by Engine.pm.
 EV::run;
@@ -143,7 +111,7 @@ sub handle_uci {
        return if ($engine->{'stopping'} && $line !~ /^bestmove/);
        $engine->{'stopping'} = 0;
 
-       if ($line =~ /^info/) {
+       if ($line =~ /^info/ && $line !~ / cluster /) {
                my (@infos) = split / /, $line;
                shift @infos;
 
@@ -163,82 +131,6 @@ my $pos_for_movelist = undef;
 my @uci_movelist = ();
 my @pretty_movelist = ();
 
-sub handle_fics {
-       my $line = shift;
-       if ($line =~ /^<12> /) {
-               handle_position(Position->new($line));
-               $t->cmd("moves");
-       }
-       if ($line =~ /^Movelist for game /) {
-               my $pos = $pos_calculating;
-               if (defined($pos)) {
-                       @uci_movelist = ();
-                       @pretty_movelist = ();
-                       $pos_for_movelist = Position->start_pos($pos->{'player_w'}, $pos->{'player_b'});
-                       $getting_movelist = 1;
-               }
-       }
-       if ($getting_movelist &&
-           $line =~ /^\s* \d+\. \s+                     # move number
-                       (\S+) \s+ \( [\d:.]+ \) \s*       # first move, then time
-                      (?: (\S+) \s+ \( [\d:.]+ \) )?    # second move, then time 
-                    /x) {
-               eval {
-                       my $uci_move;
-                       ($pos_for_movelist, $uci_move) = $pos_for_movelist->make_pretty_move($1);
-                       push @uci_movelist, $uci_move;
-                       push @pretty_movelist, $1;
-
-                       if (defined($2)) {
-                               ($pos_for_movelist, $uci_move) = $pos_for_movelist->make_pretty_move($2);
-                               push @uci_movelist, $uci_move;
-                               push @pretty_movelist, $2;
-                       }
-               };
-               if ($@) {
-                       warn "Error when getting FICS move history: $@";
-                       $getting_movelist = 0;
-               }
-       }
-       if ($getting_movelist &&
-           $line =~ /^\s+ \{.*\} \s+ (?: \* | 1\/2-1\/2 | 0-1 | 1-0 )/x) {
-               # End of movelist.
-               if (defined($pos_calculating)) {
-                       if ($pos_calculating->fen() eq $pos_for_movelist->fen()) {
-                               $pos_calculating->{'history'} = \@pretty_movelist;
-                       }
-               }
-               $getting_movelist = 0;
-       }
-       if ($line =~ /^([A-Za-z]+)(?:\([A-Z]+\))* tells you: (.*)$/) {
-               my ($who, $msg) = ($1, $2);
-
-               next if (grep { $_ eq $who } (@remoteglotconf::masters) == 0);
-
-               if ($msg =~ /^fics (.*?)$/) {
-                       $t->cmd("tell $who Executing '$1' on FICS.");
-                       $t->cmd($1);
-               } elsif ($msg =~ /^uci (.*?)$/) {
-                       $t->cmd("tell $who Sending '$1' to the engine.");
-                       print { $engine->{'write'} } "$1\n";
-               } elsif ($msg =~ /^pgn (.*?)$/) {
-                       my $url = $1;
-                       $t->cmd("tell $who Starting to poll '$url'.");
-                       fetch_pgn($url);
-               } elsif ($msg =~ /^stoppgn$/) {
-                       $t->cmd("tell $who Stopping poll.");
-                       $stop_pgn_fetch = 1;
-                       $http_timer = undef;
-               } elsif ($msg =~ /^quit$/) {
-                       $t->cmd("tell $who Bye bye.");
-                       exit;
-               } else {
-                       $t->cmd("tell $who Couldn't understand '$msg', sorry.");
-               }
-       }
-       #print "FICS: [$line]\n";
-}
-
 # Starts periodic fetching of PGNs from the given URL.
 sub fetch_pgn {
        my ($url) = @_;
@@ -253,14 +145,19 @@ sub fetch_pgn {
                };
                if ($@) {
                        warn "$url: $@";
-                       $http_timer = AnyEvent->timer(after => 1.0, cb => sub {
+                       $http_timer = AnyEvent->timer(after => $remoteglotconf::poll_frequency, cb => sub {
                                fetch_pgn($url);
                        });
                }
        } else {
-               AnyEvent::HTTP::http_get($url, sub {
-                       handle_pgn(@_, $url);
-               });
+               my $buffer = '';
+               AnyEvent::HTTP::http_get($url,
+                       on_body => sub {
+                               handle_partial_pgn(@_, \$buffer, $url);
+                       },
+                       sub {
+                               end_pgn(@_, \$buffer, $url);
+                       });
        }
 }
 
@@ -268,14 +165,32 @@ my ($last_pgn_white, $last_pgn_black);
 my @last_pgn_uci_moves = ();
 my $pgn_hysteresis_counter = 0;
 
-sub handle_pgn {
-       my ($body, $header, $url) = @_;
+sub handle_partial_pgn {
+       my ($body, $header, $buffer, $url) = @_;
 
        if ($stop_pgn_fetch) {
                $stop_pgn_fetch = 0;
                $http_timer = undef;
-               return;
+               return 0;
        }
+       $$buffer .= $body;
+       while ($$buffer =~ s/^\s*(.*)\n\n\n//s) {
+               handle_pgn($1, $url);
+       }
+       return 1;
+}
+
+sub end_pgn {
+       my ($body, $header, $buffer, $url) = @_;
+       handle_pgn($$buffer, $url);
+       $$buffer = "";
+       $http_timer = AnyEvent->timer(after => $remoteglotconf::poll_frequency, cb => sub {
+               fetch_pgn($url);
+       });
+}
+
+sub handle_pgn {
+       my ($body, $url) = @_;
 
        my $pgn = Chess::PGN::Parse->new(undef, $body);
        if (!defined($pgn)) {
@@ -330,9 +245,12 @@ sub handle_pgn {
                        if ($pgn->result eq '1-0' || $pgn->result eq '1/2-1/2' || $pgn->result eq '0-1') {
                                $pos->{'result'} = $pgn->result;
                        }
-                       $pos->{'history'} = \@repretty_moves;
 
+                       my @extra_moves = ();
+                       $pos = extend_from_manual_override($pos, \@repretty_moves, \@extra_moves);
                        extract_clock($pgn, $pos);
+                       $pos->{'history'} = \@repretty_moves;
+                       $pos->{'extra_moves'} = \@extra_moves;
 
                        # Sometimes, PGNs lose a move or two for a short while,
                        # or people push out new ones non-atomically. 
@@ -360,7 +278,7 @@ sub handle_pgn {
                }
        }
        
-       $http_timer = AnyEvent->timer(after => 1.0, cb => sub {
+       $http_timer = AnyEvent->timer(after => $remoteglotconf::poll_frequency, cb => sub {
                fetch_pgn($url);
        });
 }
@@ -376,6 +294,7 @@ sub handle_position {
                for my $key ('white_clock', 'black_clock', 'white_clock_target', 'black_clock_target') {
                        $pos_calculating->{$key} //= $pos->{$key};
                }
+               $pos_calculating->{'extra_moves'} = $pos->{'extra_moves'};
                return;
        }
 
@@ -388,12 +307,23 @@ sub handle_position {
                # the position.)
                #
                # Do not output anything new to the main analysis; that's
-               # going to be obsolete really soon.
+               # going to be obsolete really soon. (Exception: If we've never
+               # output anything for this move, ie., it didn't hit the 200ms
+               # limit, spit it out to the user anyway. It's probably a really
+               # fast blitz game or something, and it's good to show the moves
+               # as they come in even without great analysis.)
                $pos_calculating->{'white_clock'} = $pos->{'white_clock'};
                $pos_calculating->{'black_clock'} = $pos->{'black_clock'};
                delete $pos_calculating->{'white_clock_target'};
                delete $pos_calculating->{'black_clock_target'};
-               output_json(1);
+
+               if (defined($pos_calculating_started)) {
+                       output_json(0);
+               } else {
+                       output_json(1);
+               }
+               $pos_calculating_started = [Time::HiRes::gettimeofday];
+               $pos_pv_started = undef;
 
                # Ask the engine to stop; we will throw away its data until it
                # sends us "bestmove", signaling the end of it.
@@ -411,6 +341,8 @@ sub handle_position {
        uciprint($engine, "position fen " . $pos->fen());
        uciprint($engine, "go infinite");
        $pos_calculating = $pos;
+       $pos_calculating_started = [Time::HiRes::gettimeofday];
+       $pos_pv_started = undef;
 
        if (defined($engine2)) {
                if (defined($pos_calculating_second_engine)) {
@@ -429,19 +361,6 @@ sub handle_position {
 
        $engine->{'info'} = {};
        $last_move = time;
-
-       schedule_tb_lookup();
-
-       # 
-       # Output a command every move to note that we're
-       # still paying attention -- this is a good tradeoff,
-       # since if no move has happened in the last half
-       # hour, the analysis/relay has most likely stopped
-       # and we should stop hogging server resources.
-       #
-       if (defined($t)) {
-               $t->cmd("date");
-       }
 }
 
 sub parse_infos {
@@ -484,6 +403,7 @@ sub parse_infos {
 
                        delete $info->{'score_cp' . $mpv};
                        delete $info->{'score_mate' . $mpv};
+                       delete $info->{'splicepos' . $mpv};
 
                        while ($x[0] eq 'cp' || $x[0] eq 'mate') {
                                if ($x[0] eq 'cp') {
@@ -579,8 +499,11 @@ sub complete_using_tbprobe {
        my @pv = @{$info->{'pv' . $mpv}};
        my $key = $pos->fen() . " " . join('', @pv);
        my @moves = ();
+       my $splicepos;
        if (exists($tbprobe_cache{$key})) {
-               @moves = @{$tbprobe_cache{$key}};
+               my $c = $tbprobe_cache{$key};
+               @moves = @{$c->{'moves'}};
+               $splicepos = $c->{'splicepos'};
        } else {
                if ($mpv ne '') {
                        # Force doing at least one move of the PV.
@@ -598,13 +521,13 @@ sub complete_using_tbprobe {
                return if ($pos->num_pieces() > 7);
 
                my $fen = $pos->fen();
-               my $pgn_text = `fathom --path=/srv/syzygy "$fen"`;
+               my $pgn_text = `$remoteglotconf::fathom_cmdline "$fen"`;
                my $pgn = Chess::PGN::Parse->new(undef, $pgn_text);
                return if (!defined($pgn) || !$pgn->read_game() || ($pgn->result ne '0-1' && $pgn->result ne '1-0'));
                $pgn->quick_parse_game;
-               $info->{'pv' . $mpv} = \@moves;
 
                # Splice the PV from the tablebase onto what we have so far.
+               $splicepos = scalar @moves;
                for my $move (@{$pgn->moves}) {
                        last if $move eq '#';
                        last if $move eq '1-0';
@@ -615,7 +538,10 @@ sub complete_using_tbprobe {
                        push @moves, $uci_move;
                }
 
-               $tbprobe_cache{$key} = \@moves;
+               $tbprobe_cache{$key} = {
+                       moves => \@moves,
+                       splicepos => $splicepos
+               };
        }
 
        $info->{'pv' . $mpv} = \@moves;
@@ -626,6 +552,7 @@ sub complete_using_tbprobe {
        } else {
                $info->{'score_mate' . $mpv} = $matelen;
        }
+       $info->{'splicepos' . $mpv} = $splicepos;
 }
 
 sub output {
@@ -633,55 +560,32 @@ sub output {
 
        return if (!defined($pos_calculating));
 
-       # Don't update too often.
-       my $age = Time::HiRes::tv_interval($latest_update);
-       if ($age < $remoteglotconf::update_max_interval) {
-               my $wait = $remoteglotconf::update_max_interval + 0.01 - $age;
-               $output_timer = AnyEvent->timer(after => $wait, cb => \&output);
-               return;
-       }
-       
        my $info = $engine->{'info'};
 
-       #
-       # If we have tablebase data from a previous lookup, replace the
-       # engine data with the data from the tablebase.
-       #
-       my $fen = $pos_calculating->fen();
-       if (exists($tb_cache{$fen})) {
-               for my $key (qw(pv score_cp score_mate nodes nps depth seldepth tbhits)) {
-                       delete $info->{$key . '1'};
-                       delete $info->{$key};
-               }
-               $info->{'nodes'} = 0;
-               $info->{'nps'} = 0;
-               $info->{'depth'} = 0;
-               $info->{'seldepth'} = 0;
-               $info->{'tbhits'} = 0;
-
-               my $t = $tb_cache{$fen};
-               my $pv = $t->{'pv'};
-               my $matelen = int((1 + $t->{'score'}) / 2);
-               if ($t->{'result'} eq '1/2-1/2') {
-                       $info->{'score_cp'} = 0;
-               } elsif ($t->{'result'} eq '1-0') {
-                       if ($pos_calculating->{'toplay'} eq 'B') {
-                               $info->{'score_mate'} = -$matelen;
-                       } else {
-                               $info->{'score_mate'} = $matelen;
-                       }
-               } else {
-                       if ($pos_calculating->{'toplay'} eq 'B') {
-                               $info->{'score_mate'} = $matelen;
-                       } else {
-                               $info->{'score_mate'} = -$matelen;
-                       }
+       # Don't update too often.
+       my $wait = $remoteglotconf::update_max_interval - Time::HiRes::tv_interval($latest_update);
+       if (defined($pos_calculating_started)) {
+               my $new_pos_wait = $remoteglotconf::update_force_after_move - Time::HiRes::tv_interval($pos_calculating_started);
+               $wait = $new_pos_wait if ($new_pos_wait < $wait);
+       }
+       if (!$last_output_had_pv && has_pv($info)) {
+               if (!defined($pos_pv_started)) {
+                       $pos_pv_started = [Time::HiRes::gettimeofday];
                }
-               $info->{'pv'} = $pv;
-               $info->{'tablebase'} = 1;
-       } else {
-               $info->{'tablebase'} = 0;
+               # We just got initial PV, and we're in a hurry since we gave out a blank one earlier,
+               # so give us just 200ms more to increase the quality and then force a display.
+               my $new_pos_wait = $remoteglotconf::update_force_after_move - Time::HiRes::tv_interval($pos_pv_started);
+               $wait = $new_pos_wait if ($new_pos_wait < $wait);
+       }
+       if ($wait > 0.0) {
+               $output_timer = AnyEvent->timer(after => $wait + 0.01, cb => \&output);
+               return;
        }
+       $pos_pv_started = undef;
+       
+       # We're outputting something for this position now, so the special handling
+       # for new positions is off.
+       undef $pos_calculating_started;
        
        #
        # Some programs _always_ report MultiPV, even with only one PV.
@@ -689,7 +593,7 @@ sub output {
        # specified.
        #
        if (exists($info->{'pv1'}) && !exists($info->{'pv2'})) {
-               for my $key (qw(pv score_cp score_mate nodes nps depth seldepth tbhits)) {
+               for my $key (qw(pv score_cp score_mate nodes nps depth seldepth tbhits splicepos)) {
                        if (exists($info->{$key . '1'})) {
                                $info->{$key} = $info->{$key . '1'};
                        } else {
@@ -734,6 +638,14 @@ sub output {
        output_screen();
        output_json(0);
        $latest_update = [Time::HiRes::gettimeofday];
+       $last_output_had_pv = has_pv($info);
+}
+
+sub has_pv {
+       my $info = shift;
+       return 1 if (exists($info->{'pv'}) && (scalar(@{$info->{'pv'}}) > 0));
+       return 1 if (exists($info->{'pv1'}) && (scalar(@{$info->{'pv1'}}) > 0));
+       return 0;
 }
 
 sub output_screen {
@@ -759,6 +671,11 @@ sub output_screen {
        }
 
        return unless (exists($pos_calculating->{'board'}));
+
+       my $extra_moves = $pos_calculating->{'extra_moves'};
+       if (defined($extra_moves) && scalar @$extra_moves > 0) {
+               $text .= "  Manual move extensions: " . join(' ', @$extra_moves) . "\n";
+       }
                
        if (exists($info->{'pv1'}) && exists($info->{'pv2'})) {
                # multi-PV
@@ -811,8 +728,6 @@ sub output_screen {
                $text .= "\n\n";
        }
 
-       #$text .= book_info($pos_calculating->fen(), $pos_calculating->{'board'}, $pos_calculating->{'toplay'});
-
        my @refutation_lines = ();
        if (defined($engine2)) {
                for (my $mpv = 1; $mpv < 500; ++$mpv) {
@@ -881,7 +796,6 @@ sub output_json {
                $json->{'move_source_url'} = $remoteglotconf::move_source_url;
        }
        $json->{'score'} = score_digest($info, $pos_calculating, '');
-       $json->{'using_lomonosov'} = defined($remoteglotconf::tb_serial_key);
 
        $json->{'nodes'} = $info->{'nodes'};
        $json->{'nps'} = $info->{'nps'};
@@ -911,6 +825,9 @@ sub output_json {
                                        move => $pretty_move,
                                        pv => \@pretty_pv,
                                };
+                               if (exists($info->{'splicepos' . $mpv})) {
+                                       $refutation_lines{$pretty_move}->{'splicepos'} = $info->{'splicepos' . $mpv};
+                               }
                        };
                }
        }
@@ -1016,7 +933,7 @@ sub output_json {
        }
 
        if (exists($pos_calculating->{'history'}) &&
-           defined($remoteglotconf::json_history_dir)) {
+           defined($remoteglotconf::json_history_dir) && defined($json->{'engine'}{name})) {
                my $id = id_for_pos($pos_calculating);
                my $filename = $remoteglotconf::json_history_dir . "/" . $id . ".json";
 
@@ -1122,7 +1039,24 @@ sub score_digest {
                if ($pos->{'toplay'} eq 'B') {
                        $mate = -$mate;
                }
-               return ['m', $mate];
+               if (exists($info->{'splicepos' . $mpv})) {
+                       my $sp = $info->{'splicepos' . $mpv};
+                       if ($mate > 0) {
+                               return ['T', $sp];
+                       } else {
+                               return ['t', $sp];
+                       }
+               } else {
+                       if ($mate > 0) {
+                               return ['M', $mate];
+                       } elsif ($mate < 0) {
+                               return ['m', -$mate];
+                       } elsif ($pos->{'toplay'} eq 'B') {
+                               return ['M', 0];
+                       } else {
+                               return ['m', 0];
+                       }
+               }
        } else {
                if (exists($info->{'score_cp' . $mpv})) {
                        my $score = $info->{'score_cp' . $mpv};
@@ -1148,10 +1082,19 @@ sub long_score {
                if ($pos->{'toplay'} eq 'B') {
                        $mate = -$mate;
                }
-               if ($mate > 0) {
-                       return sprintf "White mates in %u", $mate;
+               if (exists($info->{'splicepos' . $mpv})) {
+                       my $sp = $info->{'splicepos' . $mpv};
+                       if ($mate > 0) {
+                               return sprintf "White wins in %u", int(($sp + 1) * 0.5);
+                       } else {
+                               return sprintf "Black wins in %u", int(($sp + 1) * 0.5);
+                       }
                } else {
-                       return sprintf "Black mates in %u", -$mate;
+                       if ($mate > 0) {
+                               return sprintf "White mates in %u", $mate;
+                       } else {
+                               return sprintf "Black mates in %u", -$mate;
+                       }
                }
        } else {
                if (exists($info->{'score_cp' . $mpv})) {
@@ -1203,56 +1146,32 @@ sub plot_score {
        return undef;
 }
 
-my %book_cache = ();
-sub book_info {
-       my ($fen, $board, $toplay) = @_;
-
-       if (exists($book_cache{$fen})) {
-               return $book_cache{$fen};
-       }
-
-       my $ret = `./booklook $fen`;
-       return "" if ($ret =~ /Not found/ || $ret eq '');
-
-       my @moves = ();
-
-       for my $m (split /\n/, $ret) {
-               my ($move, $annotation, $win, $draw, $lose, $rating, $rating_div) = split /,/, $m;
+sub extend_from_manual_override {
+       my ($pos, $moves, $extra_moves) = @_;
 
-               my $pmove;
-               if ($move eq '')  {
-                       $pmove = '(current)';
-               } else {
-                       ($pmove) = prettyprint_pv_no_cache($board, $move);
-                       $pmove .= $annotation;
+       my $q = $dbh->prepare('SELECT next_move FROM game_extensions WHERE fen=? AND history=? AND player_w=? AND player_b=? AND (CURRENT_TIMESTAMP - ts) < INTERVAL \'1 hour\'');
+       while (1) {
+               my $player_w = $pos->{'player_w'};
+               my $player_b = $pos->{'player_b'};
+               if ($player_w =~ /^base64:(.*)$/) {
+                       $player_w = MIME::Base64::decode_base64($1);
                }
-
-               my $score;
-               if ($toplay eq 'W') {
-                       $score = 1.0 * $win + 0.5 * $draw + 0.0 * $lose;
-               } else {
-                       $score = 0.0 * $win + 0.5 * $draw + 1.0 * $lose;
+               if ($player_b =~ /^base64:(.*)$/) {
+                       $player_b = MIME::Base64::decode_base64($1);
                }
-               my $n = $win + $draw + $lose;
-               
-               my $percent;
-               if ($n == 0) {
-                       $percent = "     ";
+               #use Data::Dumper; print Dumper([$pos->fen(), JSON::XS::encode_json($moves), $player_w, $player_b]);
+               $q->execute($pos->fen(), JSON::XS::encode_json($moves), $player_w, $player_b);
+               my $ref = $q->fetchrow_hashref;
+               if (defined($ref)) {
+                       my $move = $ref->{'next_move'};
+                       ($pos) = $pos->make_pretty_move($move);
+                       push @$moves, $move;
+                       push @$extra_moves, $move;
                } else {
-                       $percent = sprintf "%4u%%", int(100.0 * $score / $n + 0.5);
+                       last;
                }
-
-               push @moves, [ $pmove, $n, $percent, $rating ];
        }
-
-       @moves[1..$#moves] = sort { $b->[2] cmp $a->[2] } @moves[1..$#moves];
-       
-       my $text = "Book moves:\n\n              Perf.     N     Rating\n\n";
-       for my $m (@moves) {
-               $text .= sprintf "  %-10s %s   %6u    %4s\n", $m->[0], $m->[2], $m->[1], $m->[3]
-       }
-
-       return $text;
+       return $pos;
 }
 
 sub extract_clock {
@@ -1316,7 +1235,6 @@ sub find_clock_start {
                return;
        }
 
-       # TODO(sesse): Maybe we can get the number of moves somehow else for FICS games.
        # The history is needed for id_for_pos.
        if (!exists($pos->{'history'})) {
                return;
@@ -1373,84 +1291,6 @@ sub find_clock_start {
        $dbh->commit;
 }
 
-sub schedule_tb_lookup {
-       return if (!defined($remoteglotconf::tb_serial_key));
-       my $pos = $pos_calculating;
-       return if (exists($tb_cache{$pos->fen()}));
-
-       # If there's more than seven pieces, there's not going to be an answer,
-       # so don't bother.
-       return if ($pos->num_pieces() > 7);
-
-       # Max one at a time. If it's still relevant when it returns,
-       # schedule_tb_lookup() will be called again.
-       return if ($tb_lookup_running);
-
-       $tb_lookup_running = 1;
-       my $url = 'http://tb7-api.chessok.com:6904/tasks/addtask?auth.login=' .
-               $remoteglotconf::tb_serial_key .
-               '&auth.password=aquarium&type=0&fen=' . 
-               URI::Escape::uri_escape($pos->fen());
-       print TBLOG "Downloading $url...\n";
-       AnyEvent::HTTP::http_get($url, sub {
-               handle_tb_lookup_return(@_, $pos, $pos->fen());
-       });
-}
-
-sub handle_tb_lookup_return {
-       my ($body, $header, $pos, $fen) = @_;
-       print TBLOG "Response for [$fen]:\n";
-       print TBLOG $header . "\n\n";
-       print TBLOG $body . "\n\n";
-       eval {
-               my $response = JSON::XS::decode_json($body);
-               if ($response->{'ErrorCode'} != 0) {
-                       die "Unknown tablebase server error: " . $response->{'ErrorDesc'};
-               }
-               my $state = $response->{'Response'}{'StateString'};
-               if ($state eq 'COMPLETE') {
-                       my $pgn = Chess::PGN::Parse->new(undef, $response->{'Response'}{'Moves'});
-                       if (!defined($pgn) || !$pgn->read_game()) {
-                               warn "Error in parsing PGN\n";
-                       } else {
-                               $pgn->quick_parse_game;
-                               my $pvpos = $pos;
-                               my $moves = $pgn->moves;
-                               my @uci_moves = ();
-                               for my $move (@$moves) {
-                                       my $uci_move;
-                                       ($pvpos, $uci_move) = $pvpos->make_pretty_move($move);
-                                       push @uci_moves, $uci_move;
-                               }
-                               $tb_cache{$fen} = {
-                                       result => $pgn->result,
-                                       pv => \@uci_moves,
-                                       score => $response->{'Response'}{'Score'},
-                               };
-                               output();
-                       }
-               } elsif ($state =~ /QUEUED/ || $state =~ /PROCESSING/) {
-                       # Try again in a second. Note that if we have changed
-                       # position in the meantime, we might query a completely
-                       # different position! But that's fine.
-               } else {
-                       die "Unknown response state " . $state;
-               }
-
-               # Wait a second before we schedule another one.
-               $tb_retry_timer = AnyEvent->timer(after => 1.0, cb => sub {
-                       $tb_lookup_running = 0;
-                       schedule_tb_lookup();
-               });
-       };
-       if ($@) {
-               warn "Error in tablebase lookup: $@";
-
-               # Don't try this one again, but don't block new lookups either.
-               $tb_lookup_running = 0;
-       }
-}
-
 sub open_engine {
        my ($cmdline, $tag, $cb) = @_;
        return undef if (!defined($cmdline));
index 7d7daeb9099c6c36f2781cb4889f4fd573f86618..e84974c779a69631d85138a41b93d1d44c33dfc1 100644 (file)
-var grpc = require('grpc');
-var Chess = require('../www/js/chess.js').Chess;
+var grpc = require('@grpc/grpc-js');
 
 var PROTO_PATH = __dirname + '/hashprobe.proto';
-var hashprobe_proto = grpc.load(PROTO_PATH).hashprobe;
+var protoLoader = require('@grpc/proto-loader');
+var packageDefinition = protoLoader.loadSync(
+    PROTO_PATH,
+    {keepCase: true,
+     longs: String,
+     enums: String,
+     defaults: true,
+     oneofs: true
+    });
+var hashprobe_proto = grpc.loadPackageDefinition(packageDefinition).hashprobe;
 
-var board = new Chess();
+/*
+ * validate_fen() is taken from chess.js, which has this license:
+ *
+ * Copyright (c) 2017, Jeff Hlywa (jhlywa@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ *----------------------------------------------------------------------------*/
+function validate_fen(fen) {
+  var errors = {
+     0: 'No errors.',
+     1: 'FEN string must contain six space-delimited fields.',
+     2: '6th field (move number) must be a positive integer.',
+     3: '5th field (half move counter) must be a non-negative integer.',
+     4: '4th field (en-passant square) is invalid.',
+     5: '3rd field (castling availability) is invalid.',
+     6: '2nd field (side to move) is invalid.',
+     7: '1st field (piece positions) does not contain 8 \'/\'-delimited rows.',
+     8: '1st field (piece positions) is invalid [consecutive numbers].',
+     9: '1st field (piece positions) is invalid [invalid piece].',
+    10: '1st field (piece positions) is invalid [row too large].',
+    11: 'Illegal en-passant square',
+  };
+
+  /* 1st criterion: 6 space-seperated fields? */
+  var tokens = fen.split(/\s+/);
+  if (tokens.length !== 6) {
+    return {valid: false, error_number: 1, error: errors[1]};
+  }
+
+  /* 2nd criterion: move number field is a integer value > 0? */
+  if (isNaN(tokens[5]) || (parseInt(tokens[5], 10) <= 0)) {
+    return {valid: false, error_number: 2, error: errors[2]};
+  }
+
+  /* 3rd criterion: half move counter is an integer >= 0? */
+  if (isNaN(tokens[4]) || (parseInt(tokens[4], 10) < 0)) {
+    return {valid: false, error_number: 3, error: errors[3]};
+  }
+
+  /* 4th criterion: 4th field is a valid e.p.-string? */
+  if (!/^(-|[abcdefgh][36])$/.test(tokens[3])) {
+    return {valid: false, error_number: 4, error: errors[4]};
+  }
+
+  /* 5th criterion: 3th field is a valid castle-string? */
+  if( !/^[C-HK]?[A-FQ]?[c-hk]?[a-fq]?$/.test(tokens[2]) &&
+      tokens[2] !== '-') {
+    return {valid: false, error_number: 5, error: errors[5]};
+  }
+
+  /* 6th criterion: 2nd field is "w" (white) or "b" (black)? */
+  if (!/^(w|b)$/.test(tokens[1])) {
+    return {valid: false, error_number: 6, error: errors[6]};
+  }
+
+  /* 7th criterion: 1st field contains 8 rows? */
+  var rows = tokens[0].split('/');
+  if (rows.length !== 8) {
+    return {valid: false, error_number: 7, error: errors[7]};
+  }
+
+  /* 8th criterion: every row is valid? */
+  for (var i = 0; i < rows.length; i++) {
+    /* check for right sum of fields AND not two numbers in succession */
+    var sum_fields = 0;
+    var previous_was_number = false;
+
+    for (var k = 0; k < rows[i].length; k++) {
+      if (!isNaN(rows[i][k])) {
+        if (previous_was_number) {
+          return {valid: false, error_number: 8, error: errors[8]};
+        }
+        sum_fields += parseInt(rows[i][k], 10);
+        previous_was_number = true;
+      } else {
+        if (!/^[prnbqkPRNBQK]$/.test(rows[i][k])) {
+          return {valid: false, error_number: 9, error: errors[9]};
+        }
+        sum_fields += 1;
+        previous_was_number = false;
+      }
+    }
+    if (sum_fields !== 8) {
+      return {valid: false, error_number: 10, error: errors[10]};
+    }
+  }
+
+  if ((tokens[3][1] == '3' && tokens[1] == 'w') ||
+      (tokens[3][1] == '6' && tokens[1] == 'b')) {
+        return {valid: false, error_number: 11, error: errors[11]};
+  }
+
+  /* everything's okay! */
+  return {valid: true, error_number: 0, error: errors[0]};
+}
 
 var clients = [];
 var current_servers = [];
@@ -32,7 +155,7 @@ var init = function(servers) {
 exports.init = init;
 
 var handle_request = function(fen, response) {
-       if (fen === undefined || fen === null || fen === '' || !board.validate_fen(fen).valid) {
+       if (fen === undefined || fen === null || fen === '' || !validate_fen(fen).valid) {
                response.writeHead(400, {});
                response.end();
                return;
@@ -68,11 +191,11 @@ var handle_response = function(fen, response, probe_responses) {
        var probe_response = reconcile_responses(probe_responses);
        var lines = {};
 
-       var root = translate_line(board, fen, probe_response['root']);
+       var root = translate_line(fen, probe_response['root']);
        for (var i = 0; i < probe_response['line'].length; ++i) {
                var line = probe_response['line'][i];
                var pretty_move = line['move']['pretty'];
-               lines[pretty_move] = translate_line(board, fen, line);
+               lines[pretty_move] = translate_line(fen, line);
        }
 
        var text = JSON.stringify({
@@ -141,7 +264,7 @@ var reconcile_moves = function(a, b) {
        }
 }      
 
-var translate_line = function(board, fen, line) {
+var translate_line = function(fen, line) {
        var r = {};
 
        if (line['move'] && line['move']['pretty']) {
index 86f2d9083aa9c229451a42acfa9edfba62daa97b..8448cfad0c6a55f4d75d27436a4060846ccde3e0 100644 (file)
@@ -23,9 +23,11 @@ var json_filename = '/srv/analysis.sesse.net/www/analysis.json';
 if (process.argv.length >= 3) {
        json_filename = process.argv[2];
 }
+var html_filename = '/srv/analysis.sesse.net/www/index.html';
 
 // Expected destination filenames.
 var serve_url = '/analysis.pl';
+var html_serve_url = '/index-inline.html';
 var hash_serve_url = '/hash';
 if (process.argv.length >= 4) {
        serve_url = process.argv[3];
@@ -53,6 +55,7 @@ var json_lock = 0;
 
 // The current contents of the file to hand out, and its last modified time.
 var json = undefined;
+var html = undefined;
 
 // The last five timestamps, and diffs from them to the latest version.
 var historic_json = [];
@@ -134,6 +137,17 @@ var create_json_historic_diff = function(new_json, history_left, new_diff_json,
        var histobj = history_left.shift();
        var diff = delta.JSON_delta.diff(histobj.parsed, new_json.parsed);
        var diff_text = JSON.stringify(diff);
+
+       // Verify that the delta is correct
+       var base = JSON.parse(histobj.plain);
+       delta.JSON_delta.patch(base, diff);
+       var correct_pv = JSON.stringify(base['pv']);
+       var wrong_pv = JSON.stringify(new_json.parsed['pv']);
+       if (correct_pv !== wrong_pv) {
+               console.log("Patch went wrong:", histobj.plain, new_json.plain);
+               exit();
+       }
+
        zlib.gzip(diff_text, function(err, buffer) {
                if (err) throw err;
                new_diff_json[histobj.last_modified] = {
@@ -146,6 +160,23 @@ var create_json_historic_diff = function(new_json, history_left, new_diff_json,
        });
 }
 
+function read_entire_file(filename, callback) {
+       fs.open(filename, 'r', function(err, fd) {
+               if (err) throw err;
+               fs.fstat(fd, function(err, st) {
+                       if (err) throw err;
+                       var buffer = new Buffer(1048576);
+                       fs.read(fd, buffer, 0, 1048576, 0, function(err, bytesRead, buffer) {
+                               if (err) throw err;
+                               fs.close(fd, function() {
+                                       var contents = buffer.toString('utf8', 0, bytesRead);
+                                       callback(contents, st.mtime.getTime());
+                               });
+                       });
+               });
+       });
+}
+
 var reread_file = function(event, filename) {
        if (filename != path.basename(json_filename)) {
                return;
@@ -162,17 +193,34 @@ var reread_file = function(event, filename) {
        json_lock = 1;
 
        console.log("Rereading " + json_filename);
-       fs.open(json_filename, 'r', function(err, fd) {
-               if (err) throw err;
-               fs.fstat(fd, function(err, st) {
-                       if (err) throw err;
-                       var buffer = new Buffer(1048576);
-                       fs.read(fd, buffer, 0, 1048576, 0, function(err, bytesRead, buffer) {
+       read_entire_file(json_filename, function(new_json_contents, mtime) {
+               replace_json(new_json_contents, mtime);
+
+               // The HTML can go async, it's not too hopeless if it's out of date by a few milliseconds
+               read_entire_file(html_filename, function(new_html_contents, html_mtime) {
+                       var json_headers = {
+                               'X-RGLM': mtime,
+                               'X-RGNV': count_viewers(),  // May be slightly out of date.
+                               'Date': (new Date).toUTCString(),
+                       };
+                       if (MINIMUM_VERSION) {
+                               json_headers['X-RGMV'] = MINIMUM_VERSION;
+                       }
+                       let inline_json = {
+                               'data': JSON.parse(new_json_contents),
+                               'headers': json_headers,
+                       };
+                       delete inline_json['data']['internal'];
+
+                       new_html_contents = new_html_contents.replace(
+                               '/*REPLACE:inlinejson*/',
+                               'window.inline_json=' + JSON.stringify(inline_json) + ';');
+                       zlib.gzip(new_html_contents, function(err, buffer) {
                                if (err) throw err;
-                               fs.close(fd, function() {
-                                       var new_json_contents = buffer.toString('utf8', 0, bytesRead);
-                                       replace_json(new_json_contents, st.mtime.getTime());
-                               });
+                               html = {
+                                       plain: new_html_contents,
+                                       gzip: buffer,
+                               };
                        });
                });
        });
@@ -231,6 +279,24 @@ var send_json = function(response, ims, accept_gzip, num_viewers) {
        }
        response.end();
 }
+var send_html = function(response, accept_gzip, num_viewers) {
+       var headers = {
+               'Content-type': 'text/html; charset=utf-8',
+               'Vary': 'Accept-Encoding',
+       };
+
+       if (accept_gzip) {
+               headers['Content-Length'] = html.gzip.length;
+               headers['Content-Encoding'] = 'gzip';
+               response.writeHead(200, headers);
+               response.write(html.gzip);
+       } else {
+               headers['Content-Length'] = html.plain.length;
+               response.writeHead(200, headers);
+               response.write(html.plain);
+       }
+       response.end();
+}
 var mark_recently_seen = function(unique) {
        if (unique) {
                last_seen_clients[unique] = (new Date).getTime();
@@ -277,7 +343,7 @@ if (COUNT_FROM_VARNISH_LOG) {
        // Note: We abuse serve_url as a regex.
        var varnishncsa = child_process.spawn(
                'varnishncsa', ['-F', '%{%s}t %U %q tffb=%{Varnish:time_firstbyte}x',
-               '-q', 'ReqURL ~ "^' + serve_url + '"']);
+               '-q', 'ReqURL ~ "^(' + serve_url + '|' + html_serve_url + ')"']);
        var rl = readline.createInterface({
                input: varnishncsa.stdout,
                output: varnishncsa.stdin,
@@ -348,22 +414,22 @@ server.on('request', function(request, response) {
                hash_lookup.handle_request(fen, response);
                return;
        }
-       if (u.pathname !== serve_url) {
+       if (u.pathname !== serve_url && u.pathname !== html_serve_url) {
                // This is not the request you are looking for.
                send_404(response);
                return;
        }
 
-       mark_recently_seen(unique);
-
        var accept_encoding = request.headers['accept-encoding'];
-       var accept_gzip;
-       if (accept_encoding !== undefined && accept_encoding.match(/\bgzip\b/)) {
-               accept_gzip = true;
-       } else {
-               accept_gzip = false;
+       let accept_gzip = (accept_encoding !== undefined && accept_encoding.match(/\bgzip\b/));
+
+       if (u.pathname === html_serve_url) {
+               send_html(response, accept_gzip, count_viewers());
+               return;
        }
 
+       mark_recently_seen(unique);
+
        // If we already have something newer than what the user has,
        // just send it out and be done with it.
        if (json !== undefined && (!ims || json.last_modified > ims)) {
old mode 100755 (executable)
new mode 100644 (file)
index e987b528bc35610b5c69c1431bcd50abc8025af4..557f28349c3e407fd3dfb72fbbe0e8ec5257e193 100644 (file)
@@ -1,70 +1,67 @@
-/*!\r
- * chessboard.js v0.3.0\r
- *\r
- * Copyright 2013 Chris Oakman\r
- * Released under the MIT license\r
- * https://github.com/oakmac/chessboardjs/blob/master/LICENSE\r
- *\r
- * Date: 10 Aug 2013\r
- */\r
-\r
-/* clearfix */\r
-.clearfix-7da63 {\r
-  clear: both;\r
-}\r
-\r
-/* board */\r
-.board-b72b1 {\r
-  border: 2px solid #404040;\r
-  -moz-box-sizing: content-box;\r
-  box-sizing: content-box;\r
-}\r
-\r
-/* square */\r
-.square-55d63 {\r
-  float: left;\r
-  position: relative;\r
-\r
-  /* disable any native browser highlighting */\r
-  -webkit-touch-callout: none;\r
-    -webkit-user-select: none;\r
-     -khtml-user-select: none;\r
-       -moz-user-select: none;\r
-        -ms-user-select: none;\r
-            user-select: none;\r
-}\r
-\r
-/* white square */\r
-.white-1e1d7 {\r
-  background-color: #f0d9b5;\r
-  color: #b58863;\r
-}\r
-\r
-/* black square */\r
-.black-3c85d {\r
-  background-color: #b58863;\r
-  color: #f0d9b5;\r
-}\r
-\r
-/* highlighted square */\r
-.highlight1-32417, .highlight2-9c5d2 {\r
-  -webkit-box-shadow: inset 0 0 3px 3px yellow;\r
-  -moz-box-shadow: inset 0 0 3px 3px yellow;\r
-  box-shadow: inset 0 0 3px 3px yellow;\r
-}\r
-\r
-/* notation */\r
-.notation-322f9 {\r
-  cursor: default;\r
-  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;\r
-  font-size: 14px;\r
-  position: absolute;\r
-}\r
-.alpha-d2270 {\r
-  bottom: 1px;\r
-  right: 3px;\r
-}\r
-.numeric-fc462 {\r
-  top: 2px;\r
-  left: 2px;\r
-}
\ No newline at end of file
+/*
+ * chessboard.js v0.3.0+asn
+ *
+ * Copyright 2013 Chris Oakman
+ * Portions copyright 2022 Steinar H. Gunderson
+ * Released under the MIT license
+ * https://github.com/oakmac/chessboardjs/blob/master/LICENSE
+ *
+ * Date: 10 Aug 2013
+ */
+
+/* board */
+.board-b72b1 {
+  outline: 2px solid #404040;
+  display: grid;
+  grid-template-rows: repeat(8, 12.5%);
+  grid-template-columns: repeat(8, 12.5%);
+  grid-gap: 0px;
+  width: 100%;
+  aspect-ratio: 1;
+}
+
+/* square */
+.square-55d63 {
+  /* disable any native browser highlighting */
+  user-select: none;
+}
+
+/* white square */
+.white-1e1d7 {
+  background-color: #f0d9b5;
+  color: #b58863;
+}
+
+/* black square */
+.black-3c85d {
+  background-color: #b58863;
+  color: #f0d9b5;
+}
+
+/* highlighted square */
+.highlight1-32417, .highlight2-9c5d2 {
+  box-shadow: inset 0 0 3px 3px yellow;
+}
+
+/* notation */
+.alpha-d2270, .numeric-fc462 {
+  cursor: default;
+  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+  font-size: 14px;
+  position: absolute;
+}
+.alpha-d2270 {
+  bottom: 1px;
+  right: 3px;
+}
+.numeric-fc462 {
+  top: 2px;
+  left: 2px;
+}
+
+.piece-417db {
+  transform: translate(0,0);  /* Force a new stacking context for SVG pieces. */
+  position: absolute;
+  width: 12.5%;
+  height: 12.5%;
+}
diff --git a/www/css/chessboard-0.3.0.min.css b/www/css/chessboard-0.3.0.min.css
deleted file mode 100644 (file)
index 52781a9..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-/*! chessboard.js v0.3.0 | (c) 2013 Chris Oakman | MIT License chessboardjs.com/license */
-.clearfix-7da63{clear:both}.board-b72b1{border:2px solid #404040;-moz-box-sizing:content-box;box-sizing:content-box}.square-55d63{float:left;position:relative;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.white-1e1d7{background-color:#f0d9b5;color:#b58863}.black-3c85d{background-color:#b58863;color:#f0d9b5}.highlight1-32417,.highlight2-9c5d2{-webkit-box-shadow:inset 0 0 3px 3px yellow;-moz-box-shadow:inset 0 0 3px 3px yellow;box-shadow:inset 0 0 3px 3px yellow}.notation-322f9{cursor:default;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;position:absolute}.alpha-d2270{bottom:1px;right:3px}.numeric-fc462{top:2px;left:2px}
\ No newline at end of file
index 09b6b089cee4884d7bbcff3eab857d37c4efafd4..a2e221fd0847b5c5a0ba1694fe4c9a4bff49b11b 100644 (file)
@@ -1,5 +1,8 @@
-body {
+html {
+       color-scheme: light dark;
        font-family: sans-serif;
+       background: white;
+       color: black;
 }
 h1 {
        margin-top: 0em;
@@ -11,42 +14,41 @@ h3 {
 #scorecontainer {
        font-size: x-large;
        margin-top: 0;
+       display: grid;
+       grid-template-columns: max-content 1fr;
+       gap: 12px;
 }
 #score {
-       float: left;
+       grid-column: 1;
 }
 #scoresparkcontainer {
+       grid-column: 2;
        overflow: hidden;
+       height: 0.85em;
+       margin-top: 0.15em;
+       width: 100%;
 }
-#scorespark {
-       margin-left: 0.5em;
-       margin-right: 0.5em;
+#sparklinehover {
+       position: absolute;
+       display: none;
+       background-color: rgba(0, 0, 0, 0.6);
+       color: white;
+       font-size: 10px;
+       white-space: nowrap;
+       padding: 5px;
+       border: 1px solid white;
+       z-index: 10000;
 }
 #pvcontainer {
        clear: left;
        margin-top: 1em;
 }
-.window {
-       position: absolute;    
-       width: 0px;
-       height: 0px;
-       opacity: 0.0; 
-}
 .c1 {
        opacity: 0.75;
 }
-.l1arrow {
-       opacity: 1.0;
-}
 .hidden {
        display: none;
 }
-.vir path {
-       opacity: 0.0;
-}
-.vir path.l1arrow {
-       opacity: 1.0;
-}
 #news {
        font-size: smaller;
 }
@@ -96,13 +98,14 @@ p {
        display: block;
        width: 100%;
        padding: 0;
+       transform: translate(0,0);  /* Make it a containing block. */
 }
 #hiddenboard {
        display: none;
 }
 #bottompanel {
        display: block;
-       width: 100%;
+       width: calc(100% + 4px);
        font-size: smaller;
        margin-top: 0.5em;
        margin-bottom: 0;
@@ -178,9 +181,6 @@ a.move:hover {
 #linenav {
        display: none;
 }
-#lomonosov {
-       display: none;
-}
 
 #games {
        font-size: smaller;
@@ -195,3 +195,44 @@ a.move:hover {
 .game:last-of-type {
        border-right: none;
 }
+
+.pv, #pv, #history {  /* Mute move colors a bit. */
+       color: #555;
+}
+
+.imbalance-inverted-piece {
+       display: none;
+       filter: invert(1);
+}
+
+.imbalance-piece, .imbalance-inverted-piece {
+       width: 15px;
+       height: 15px;
+}
+
+@media (prefers-color-scheme: dark) {
+
+:root {
+       background: black;
+       color: #eee;
+}
+.pv, #pv, #history {  /* Mute move colors a bit. */
+       color: #bbb;
+}
+#numviewers {
+       color: #bbb;
+}
+a.move, a.move:link {
+       color: #eee;
+}
+a:link {
+       color: rgb(128,128,238);
+}
+.imbalance-piece {
+       display: none;
+}
+.imbalance-inverted-piece {
+       display: initial;
+}
+
+}
index e4e22ddfd3d20165e9c28b23769aee92587efdd3..01488407c40aa922d8155d19b2a6ce5669c7a39c 100644 (file)
Binary files a/www/favicon.ico and b/www/favicon.ico differ
similarity index 71%
rename from www/index.html
rename to www/index.dev.html
index b6d9e8ba408c18b9d959e25e7d6d378aef9af4fc..a44ec1321da768af2dc041b9934d0fe6cf4f95de 100644 (file)
@@ -2,14 +2,23 @@
 <html>
 <head>
   <meta charset="utf-8" />
-  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
   <title>analysis.sesse.net</title>
-
-  <link rel="stylesheet" href="css/chessboard-0.3.0.min.css" />
-  <link rel="stylesheet" href="css/remoteglot.css" />
   <meta name="viewport" content="width=device-width, initial-scale=1" />
+  <!-- replace <style>[chomp;css/remoteglot.min.css]</style> -->
+  <link rel="stylesheet" href="css/chessboard-0.3.0.css" />
+  <link rel="stylesheet" href="css/remoteglot.css" />
+  <!-- end replace -->
+  <!-- replace <link rel="shortcut icon" href="data:image/png;base64,[base64;favicon.ico]" type="image/png"> -->
+  <!-- end replace -->
+
+  <!-- replace <script>/*REPLACE:inlinejson*/[js/remoteglot.min.js]</script> -->
+  <script type="text/javascript" src="js/chessboard-0.3.0.js"></script>
+  <script type="text/javascript" src="js/chess.js"></script>
+  <script type="text/javascript" src="js/json_delta.js"></script>
+  <script type="text/javascript" src="js/remoteglot.js"></script>
+  <!-- end replace -->
 </head>
-<body>
+<body style="opacity: 0">  <!-- Avoid layout shift on initial load. -->
 <audio id="ding" preload="none">
   <source src="ding.opus" type="audio/ogg; codecs=opus" />
   <source src="ding.mp3" type="audio/mp3" />
@@ -28,9 +37,9 @@
 <div id="analysis">
   <div id="scorecontainer">
     <span id="score">Score:</span>
-    <div id="scoresparkcontainer">
-      <span id="scorespark"></span>
-    </div>
+    <svg xmlns="http://www.w3.org/2000/svg" id="scoresparkcontainer">
+    </svg>
+    <div id="sparklinehover"></div>
   </div>
   <p id="pvcontainer"><strong id="pvtitle">PV:</strong> <span id="pv"></span></p>
   <p id="searchstats"></p>
@@ -52,7 +61,9 @@
 </div>
 <h2 style="clear: both;">Symbol explanation</h2>
 <ul>
-  <li><strong>Score:</strong> 1.00 is the value of one pawn (in a balanced endgame). Positive values are better for white.</li>
+  <li><strong>Score:</strong> 1.00 is roughly one pawn
+   (<a href="https://github.com/official-stockfish/Stockfish/commit/ad2aa8c06f438de8b8bb7b7c8726430e3f2a5685">technically</a>,
+   50% win probability for a computer). Positive values are better for white.</li>
   <li><strong>PV:</strong> Principal Variation, the series of moves the engine thinks is the best.</li>
   <li><strong>Thick red line:</strong> Marks the best move (in the view of the engine). Multiple chained arrows
     means that the PV starts with multiple successive moves with the same piece, ie., the engine thinks
     is forced or nearly so.</li>
 </ul>
 <p id="credits"><a href="http://git.sesse.net/?p=remoteglot;a=summary">remoteglot</a>
-  &copy; 2007&ndash;2018 <a href="http://www.sesse.net/">Steinar H. Gunderson</a>.
+  &copy; 2007&ndash;2023 <a href="http://www.sesse.net/">Steinar H. Gunderson</a>.
   Chess analysis by <a href="http://stockfishchess.org/" id="engineid">Stockfish</a><span id="enginedetails"></span>.
   <span id="movesource"></span>
   Hosting and additional analysis hardware by <a href="http://www.samfundet.no/">Studentersamfundet i Trondhjem</a>
   and Berge Schwebs Bjørlo.
-  JavaScript chessboard powered by <a href="http://chessboardjs.com/">chessboard.js</a>
+  Chessboard powered by <a href="http://chessboardjs.com/">chessboard.js</a>
   and <a href="https://github.com/jhlywa/chess.js">chess.js</a>.
   Ding sound by <a href="https://www.freesound.org/people/Aiwha/sounds/196106/">Aiwha</a> (CC-BY-3.0).
-  <span id="lomonosov">7-man Lomonosov tablebase lookup by <a href="http://tb7.chessok.com/">ChessOK</a>.</span></p>
-
-<!-- For faster development -->
-<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
-<script type="text/javascript" src="js/chessboard-0.3.0.min.js"></script>
-<script type="text/javascript" src="js/chess.js"></script>
-<script type="text/javascript" src="js/json_delta.js"></script>
-<script type="text/javascript" src="js/jquery.sparkline.js"></script>
-<script type="text/javascript" src="js/remoteglot.js"></script>
-<!--
--->
-
-<!-- Minified version of the previous six, compiled together -->
-<!--
-<script type="text/javascript" src="js/remoteglot.min.js"></script>
--->
+  </p>
 </body>
 </html>
index f274628273e33c6d964f3274bf524046ed5e0e61..4598758205ed2173b1bf75fe59129ed2b572fed1 100644 (file)
@@ -68,44 +68,6 @@ var Chess = function(fen) {
     k: [-17, -16, -15,   1,  17, 16, 15,  -1]
   };
 
-  var ATTACKS = [
-    20, 0, 0, 0, 0, 0, 0, 24,  0, 0, 0, 0, 0, 0,20, 0,
-     0,20, 0, 0, 0, 0, 0, 24,  0, 0, 0, 0, 0,20, 0, 0,
-     0, 0,20, 0, 0, 0, 0, 24,  0, 0, 0, 0,20, 0, 0, 0,
-     0, 0, 0,20, 0, 0, 0, 24,  0, 0, 0,20, 0, 0, 0, 0,
-     0, 0, 0, 0,20, 0, 0, 24,  0, 0,20, 0, 0, 0, 0, 0,
-     0, 0, 0, 0, 0,20, 2, 24,  2,20, 0, 0, 0, 0, 0, 0,
-     0, 0, 0, 0, 0, 2,53, 56, 53, 2, 0, 0, 0, 0, 0, 0,
-    24,24,24,24,24,24,56,  0, 56,24,24,24,24,24,24, 0,
-     0, 0, 0, 0, 0, 2,53, 56, 53, 2, 0, 0, 0, 0, 0, 0,
-     0, 0, 0, 0, 0,20, 2, 24,  2,20, 0, 0, 0, 0, 0, 0,
-     0, 0, 0, 0,20, 0, 0, 24,  0, 0,20, 0, 0, 0, 0, 0,
-     0, 0, 0,20, 0, 0, 0, 24,  0, 0, 0,20, 0, 0, 0, 0,
-     0, 0,20, 0, 0, 0, 0, 24,  0, 0, 0, 0,20, 0, 0, 0,
-     0,20, 0, 0, 0, 0, 0, 24,  0, 0, 0, 0, 0,20, 0, 0,
-    20, 0, 0, 0, 0, 0, 0, 24,  0, 0, 0, 0, 0, 0,20
-  ];
-
-  var RAYS = [
-     17,  0,  0,  0,  0,  0,  0, 16,  0,  0,  0,  0,  0,  0, 15, 0,
-      0, 17,  0,  0,  0,  0,  0, 16,  0,  0,  0,  0,  0, 15,  0, 0,
-      0,  0, 17,  0,  0,  0,  0, 16,  0,  0,  0,  0, 15,  0,  0, 0,
-      0,  0,  0, 17,  0,  0,  0, 16,  0,  0,  0, 15,  0,  0,  0, 0,
-      0,  0,  0,  0, 17,  0,  0, 16,  0,  0, 15,  0,  0,  0,  0, 0,
-      0,  0,  0,  0,  0, 17,  0, 16,  0, 15,  0,  0,  0,  0,  0, 0,
-      0,  0,  0,  0,  0,  0, 17, 16, 15,  0,  0,  0,  0,  0,  0, 0,
-      1,  1,  1,  1,  1,  1,  1,  0, -1, -1,  -1,-1, -1, -1, -1, 0,
-      0,  0,  0,  0,  0,  0,-15,-16,-17,  0,  0,  0,  0,  0,  0, 0,
-      0,  0,  0,  0,  0,-15,  0,-16,  0,-17,  0,  0,  0,  0,  0, 0,
-      0,  0,  0,  0,-15,  0,  0,-16,  0,  0,-17,  0,  0,  0,  0, 0,
-      0,  0,  0,-15,  0,  0,  0,-16,  0,  0,  0,-17,  0,  0,  0, 0,
-      0,  0,-15,  0,  0,  0,  0,-16,  0,  0,  0,  0,-17,  0,  0, 0,
-      0,-15,  0,  0,  0,  0,  0,-16,  0,  0,  0,  0,  0,-17,  0, 0,
-    -15,  0,  0,  0,  0,  0,  0,-16,  0,  0,  0,  0,  0,  0,-17
-  ];
-
-  var SHIFTS = { p: 0, n: 1, b: 2, r: 3, q: 4, k: 5 };
-
   var FLAGS = {
     NORMAL: 'n',
     CAPTURE: 'c',
@@ -166,11 +128,7 @@ var Chess = function(fen) {
     load(fen);
   }
 
-  function clear(keep_headers) {
-    if (typeof keep_headers === 'undefined') {
-      keep_headers = false;
-    }
-
+  function clear() {
     board = new Array(128);
     kings = {w: EMPTY, b: EMPTY};
     turn = WHITE;
@@ -179,7 +137,7 @@ var Chess = function(fen) {
     half_moves = 0;
     move_number = 1;
     history = [];
-    if (!keep_headers) header = {};
+    header = {};
     update_setup(generate_fen());
   }
 
@@ -187,11 +145,7 @@ var Chess = function(fen) {
     load(DEFAULT_POSITION);
   }
 
-  function load(fen, keep_headers) {
-    if (typeof keep_headers === 'undefined') {
-      keep_headers = false;
-    }
-
+  function load(fen) {
     var tokens = fen.split(/\s+/);
     var position = tokens[0];
     var square = 0;
@@ -200,7 +154,7 @@ var Chess = function(fen) {
       return false;
     }
 
-    clear(keep_headers);
+    clear();
 
     for (var i = 0; i < position.length; i++) {
       var piece = position.charAt(i);
@@ -708,6 +662,10 @@ var Chess = function(fen) {
       }
     }
 
+    return possibly_filter_moves(moves, us, legal);
+  }
+
+  function possibly_filter_moves(moves, us, legal) {
     /* return all pseudo-legal moves (this includes moves that allow the king
      * to be captured)
      */
@@ -820,40 +778,71 @@ var Chess = function(fen) {
   }
 
   function attacked(color, square) {
-    for (var i = SQUARES.a8; i <= SQUARES.h1; i++) {
-      /* did we run off the end of the board */
-      if (i & 0x88) { i += 7; continue; }
+    // Check for attacks by the king.
+    if (Math.abs(rank(kings[color]) - rank(square)) <= 1 &&
+        Math.abs(file(kings[color]) - file(square)) <= 1) {
+      return true;
+    }
 
-      /* if empty square or wrong color */
-      if (board[i] == null || board[i].color !== color) continue;
+    // Check for attacks by knights.
+    for (const offset of PIECE_OFFSETS[KNIGHT]) {
+      let knight_sq = square + offset;
+      if (knight_sq & 0x88) continue;
 
-      var piece = board[i];
-      var difference = i - square;
-      var index = difference + 119;
+      if (board[knight_sq] != null &&
+          board[knight_sq].type === KNIGHT &&
+          board[knight_sq].color === color) {
+        return true;
+      }
+    }
 
-      if (ATTACKS[index] & (1 << SHIFTS[piece.type])) {
-        if (piece.type === PAWN) {
-          if (difference > 0) {
-            if (piece.color === WHITE) return true;
-          } else {
-            if (piece.color === BLACK) return true;
+    // Check for attacks by pawns.
+    const p1sq = square - PAWN_OFFSETS[color][2];
+    const p2sq = square - PAWN_OFFSETS[color][3];
+    if (!(p1sq & 0x88) &&
+        board[p1sq] != null &&
+        board[p1sq].type === PAWN &&
+        board[p1sq].color === color) {
+      return true;
+    }
+    if (!(p2sq & 0x88) &&
+        board[p2sq] != null &&
+        board[p2sq].type === PAWN &&
+        board[p2sq].color === color) {
+      return true;
+    }
+
+    // Check for attacks by rooks (where queens count as rooks).
+    for (const offset of PIECE_OFFSETS[ROOK]) {
+      let rook_sq = square;
+      while (true) {
+        rook_sq += offset;
+        if (rook_sq & 0x88) break;
+
+        if (board[rook_sq] != null) {
+          if ((board[rook_sq].type === ROOK || board[rook_sq].type === QUEEN) &&
+              board[rook_sq].color === color) {
+            return true;
           }
-          continue;
+          break;
         }
+      }
+    }
 
-        /* if the piece is a knight or a king */
-        if (piece.type === 'n' || piece.type === 'k') return true;
-
-        var offset = RAYS[index];
-        var j = i + offset;
+    // And similarly for attacks by bishops (where queens count as bishops).
+    for (const offset of PIECE_OFFSETS[BISHOP]) {
+      let bishop_sq = square;
+      while (true) {
+        bishop_sq += offset;
+        if (bishop_sq & 0x88) break;
 
-        var blocked = false;
-        while (j !== square) {
-          if (board[j] != null) { blocked = true; break; }
-          j += offset;
+        if (board[bishop_sq] != null) {
+          if ((board[bishop_sq].type === BISHOP || board[bishop_sq].type === QUEEN) &&
+              board[bishop_sq].color === color) {
+            return true;
+          }
+          break;
         }
-
-        if (!blocked) return true;
       }
     }
 
@@ -1114,12 +1103,24 @@ var Chess = function(fen) {
 
   /* this function is used to uniquely identify ambiguous moves */
   function get_disambiguator(move, sloppy) {
-    var moves = generate_moves({legal: !sloppy});
-
     var from = move.from;
     var to = move.to;
     var piece = move.piece;
 
+    if (piece === 'p' || piece === 'k') {
+       // Pawn or king moves are never ambiguous.
+       return '';
+    }
+
+    let moves = find_attacking_moves(move.to, piece, move.color);
+    if (moves.length <= 1) {
+       // There can be no ambiguity, so don't bother checking legality
+       // (we assume the move has already been found legal).
+       return '';
+    }
+
+    moves = possibly_filter_moves(moves, move.color, !sloppy);
+
     var ambiguities = 0;
     var same_rank = 0;
     var same_file = 0;
@@ -1167,6 +1168,42 @@ var Chess = function(fen) {
     return '';
   }
 
+  // Find all pseudolegal moves featuring the given piece moving to
+  // the given square (using symmetry of all non-pawn-or-castle moves,
+  // we simply generate moves backwards). Does not support pawns.
+  // Assumes there's not already a piece of our own color
+  // on the destination square.
+  function find_attacking_moves(to, piece, us) {
+    let moves = [];
+
+    function add_move(board, moves, from, to, flags, rook_sq) {
+      moves.push(build_move(board, from, to, flags, undefined, rook_sq));
+    }
+    for (let offset of PIECE_OFFSETS[piece]) {
+      var square = to;
+
+      while (true) {
+        square += offset;
+        if (square & 0x88) break;
+
+        if (board[square] != null) {
+          if (board[square].color !== us || board[square].type !== piece) break;
+          if (board[to] == null) {
+            add_move(board, moves, square, to, BITS.NORMAL);
+          } else {
+            add_move(board, moves, square, to, BITS.CAPTURE);
+          }
+          break;
+        }
+
+        /* break if knight or king */
+        if (piece === 'n' || piece === 'k') break;
+      }
+    }
+
+    return moves;
+  }
+
   function ascii() {
     var s = '   +------------------------+\n';
     for (var i = SQUARES.a8; i <= SQUARES.h1; i++) {
@@ -1214,7 +1251,23 @@ var Chess = function(fen) {
       }
     }
 
-    var moves = generate_moves();
+    let moves;
+    let piece_matches = clean_move.match(/^([NBRQK])x?([a-h][1-8])$/);
+    if (piece_matches) {
+      // Only look for moves by the given piece to the given square.
+      let to = SQUARES[piece_matches[2]];
+      if (board[to] != null && board[to].color === turn) {
+        // Cannot capture our own piece.
+        return null;
+      }
+      moves = find_attacking_moves(to, piece_matches[1].toLowerCase(), turn);
+      // Legal moves only.
+      moves = possibly_filter_moves(moves, turn, true);
+    } else {
+      // Fallback (also used for pawns): Any (legal) moves.
+      moves = generate_moves();
+    }
+
     for (var i = 0, len = moves.length; i < len; i++) {
       // try the strict parser first, then the sloppy parser if requested
       // by the user
@@ -1356,9 +1409,9 @@ var Chess = function(fen) {
       return load(fen);
     },
 
-    reset: function() {
-      return reset();
-    },
+    // reset: function() {
+    //   return reset();
+    // },
 
     moves: function(options) {
       /* The internal representation of a chess move is in 0x88 format, and
@@ -1386,32 +1439,32 @@ var Chess = function(fen) {
       return moves;
     },
 
-    in_check: function() {
-      return in_check();
-    },
+    // in_check: function() {
+    //   return in_check();
+    // },
 
-    in_checkmate: function() {
-      return in_checkmate();
-    },
+    // in_checkmate: function() {
+    //   return in_checkmate();
+    // },
 
-    in_stalemate: function() {
-      return in_stalemate();
-    },
+    // in_stalemate: function() {
+    //   return in_stalemate();
+    // },
 
-    in_draw: function() {
-      return half_moves >= 100 ||
-             in_stalemate() ||
-             insufficient_material() ||
-             in_threefold_repetition();
-    },
+    // in_draw: function() {
+    //   return half_moves >= 100 ||
+    //          in_stalemate() ||
+    //          insufficient_material() ||
+    //          in_threefold_repetition();
+    // },
 
-    insufficient_material: function() {
-      return insufficient_material();
-    },
+    // insufficient_material: function() {
+    //   return insufficient_material();
+    // },
 
-    in_threefold_repetition: function() {
-      return in_threefold_repetition();
-    },
+    // in_threefold_repetition: function() {
+    //   return in_threefold_repetition();
+    // },
 
     game_over: function() {
       return half_moves >= 100 ||
@@ -1421,263 +1474,263 @@ var Chess = function(fen) {
              in_threefold_repetition();
     },
 
-    validate_fen: function(fen) {
-      return validate_fen(fen);
-    },
+    // validate_fen: function(fen) {
+    //   return validate_fen(fen);
+    // },
 
     fen: function() {
       return generate_fen();
     },
 
-    board: function() {
-      var output = [],
-          row    = [];
-
-      for (var i = SQUARES.a8; i <= SQUARES.h1; i++) {
-        if (board[i] == null) {
-          row.push(null)
-        } else {
-          row.push({type: board[i].type, color: board[i].color})
-        }
-        if ((i + 1) & 0x88) {
-          output.push(row);
-          row = []
-          i += 8;
-        }
-      }
-
-      return output;
-    },
-
-    pgn: function(options) {
-      /* using the specification from http://www.chessclub.com/help/PGN-spec
-       * example for html usage: .pgn({ max_width: 72, newline_char: "<br />" })
-       */
-      var newline = (typeof options === 'object' &&
-                     typeof options.newline_char === 'string') ?
-                     options.newline_char : '\n';
-      var max_width = (typeof options === 'object' &&
-                       typeof options.max_width === 'number') ?
-                       options.max_width : 0;
-      var result = [];
-      var header_exists = false;
-
-      /* add the PGN header headerrmation */
-      for (var i in header) {
-        /* TODO: order of enumerated properties in header object is not
-         * guaranteed, see ECMA-262 spec (section 12.6.4)
-         */
-        result.push('[' + i + ' \"' + header[i] + '\"]' + newline);
-        header_exists = true;
-      }
-
-      if (header_exists && history.length) {
-        result.push(newline);
-      }
-
-      /* pop all of history onto reversed_history */
-      var reversed_history = [];
-      while (history.length > 0) {
-        reversed_history.push(undo_move());
-      }
-
-      var moves = [];
-      var move_string = '';
-
-      /* build the list of moves.  a move_string looks like: "3. e3 e6" */
-      while (reversed_history.length > 0) {
-        var move = reversed_history.pop();
-
-        /* if the position started with black to move, start PGN with 1. ... */
-        if (!history.length && move.color === 'b') {
-          move_string = move_number + '. ...';
-        } else if (move.color === 'w') {
-          /* store the previous generated move_string if we have one */
-          if (move_string.length) {
-            moves.push(move_string);
-          }
-          move_string = move_number + '.';
-        }
-
-        move_string = move_string + ' ' + move_to_san(move, false);
-        make_move(move);
-      }
-
-      /* are there any other leftover moves? */
-      if (move_string.length) {
-        moves.push(move_string);
-      }
-
-      /* is there a result? */
-      if (typeof header.Result !== 'undefined') {
-        moves.push(header.Result);
-      }
-
-      /* history should be back to what is was before we started generating PGN,
-       * so join together moves
-       */
-      if (max_width === 0) {
-        return result.join('') + moves.join(' ');
-      }
-
-      /* wrap the PGN output at max_width */
-      var current_width = 0;
-      for (var i = 0; i < moves.length; i++) {
-        /* if the current move will push past max_width */
-        if (current_width + moves[i].length > max_width && i !== 0) {
-
-          /* don't end the line with whitespace */
-          if (result[result.length - 1] === ' ') {
-            result.pop();
-          }
-
-          result.push(newline);
-          current_width = 0;
-        } else if (i !== 0) {
-          result.push(' ');
-          current_width++;
-        }
-        result.push(moves[i]);
-        current_width += moves[i].length;
-      }
-
-      return result.join('');
-    },
-
-    load_pgn: function(pgn, options) {
-      // allow the user to specify the sloppy move parser to work around over
-      // disambiguation bugs in Fritz and Chessbase
-      var sloppy = (typeof options !== 'undefined' && 'sloppy' in options) ?
-                    options.sloppy : false;
-
-      function mask(str) {
-        return str.replace(/\\/g, '\\');
-      }
-
-      function has_keys(object) {
-        for (var key in object) {
-          return true;
-        }
-        return false;
-      }
-
-      function parse_pgn_header(header, options) {
-        var newline_char = (typeof options === 'object' &&
-                            typeof options.newline_char === 'string') ?
-                            options.newline_char : '\r?\n';
-        var header_obj = {};
-        var headers = header.split(new RegExp(mask(newline_char)));
-        var key = '';
-        var value = '';
-
-        for (var i = 0; i < headers.length; i++) {
-          key = headers[i].replace(/^\[([A-Z][A-Za-z]*)\s.*\]$/, '$1');
-          value = headers[i].replace(/^\[[A-Za-z]+\s"(.*)"\]$/, '$1');
-          if (trim(key).length > 0) {
-            header_obj[key] = value;
-          }
-        }
-
-        return header_obj;
-      }
-
-      var newline_char = (typeof options === 'object' &&
-                          typeof options.newline_char === 'string') ?
-                          options.newline_char : '\r?\n';
-      var regex = new RegExp('^(\\[(.|' + mask(newline_char) + ')*\\])' +
-                             '(' + mask(newline_char) + ')*' +
-                             '1.(' + mask(newline_char) + '|.)*$', 'g');
-
-      /* get header part of the PGN file */
-      var header_string = pgn.replace(regex, '$1');
-
-      /* no info part given, begins with moves */
-      if (header_string[0] !== '[') {
-        header_string = '';
-      }
-
-      reset();
-
-      /* parse PGN header */
-      var headers = parse_pgn_header(header_string, options);
-      for (var key in headers) {
-        set_header([key, headers[key]]);
-      }
-
-      /* load the starting position indicated by [Setup '1'] and
-      * [FEN position] */
-      if (headers['SetUp'] === '1') {
-          if (!(('FEN' in headers) && load(headers['FEN'], true ))) { // second argument to load: don't clear the headers
-            return false;
-          }
-      }
-
-      /* delete header to get the moves */
-      var ms = pgn.replace(header_string, '').replace(new RegExp(mask(newline_char), 'g'), ' ');
-
-      /* delete comments */
-      ms = ms.replace(/(\{[^}]+\})+?/g, '');
-
-      /* delete recursive annotation variations */
-      var rav_regex = /(\([^\(\)]+\))+?/g
-      while (rav_regex.test(ms)) {
-        ms = ms.replace(rav_regex, '');
-      }
-
-      /* delete move numbers */
-      ms = ms.replace(/\d+\.(\.\.)?/g, '');
-
-      /* delete ... indicating black to move */
-      ms = ms.replace(/\.\.\./g, '');
-
-      /* delete numeric annotation glyphs */
-      ms = ms.replace(/\$\d+/g, '');
-
-      /* trim and get array of moves */
-      var moves = trim(ms).split(new RegExp(/\s+/));
-
-      /* delete empty entries */
-      moves = moves.join(',').replace(/,,+/g, ',').split(',');
-      var move = '';
-
-      for (var half_move = 0; half_move < moves.length - 1; half_move++) {
-        move = move_from_san(moves[half_move], sloppy);
-
-        /* move not possible! (don't clear the board to examine to show the
-         * latest valid position)
-         */
-        if (move == null) {
-          return false;
-        } else {
-          make_move(move);
-        }
-      }
-
-      /* examine last move */
-      move = moves[moves.length - 1];
-      if (POSSIBLE_RESULTS.indexOf(move) > -1) {
-        if (has_keys(header) && typeof header.Result === 'undefined') {
-          set_header(['Result', move]);
-        }
-      }
-      else {
-        move = move_from_san(move, sloppy);
-        if (move == null) {
-          return false;
-        } else {
-          make_move(move);
-        }
-      }
-      return true;
-    },
-
-    header: function() {
-      return set_header(arguments);
-    },
-
-    ascii: function() {
-      return ascii();
-    },
+    // board: function() {
+    //   var output = [],
+    //       row    = [];
+
+    //   for (var i = SQUARES.a8; i <= SQUARES.h1; i++) {
+    //     if (board[i] == null) {
+    //       row.push(null)
+    //     } else {
+    //       row.push({type: board[i].type, color: board[i].color})
+    //     }
+    //     if ((i + 1) & 0x88) {
+    //       output.push(row);
+    //       row = []
+    //       i += 8;
+    //     }
+    //   }
+
+    //   return output;
+    // },
+
+    // pgn: function(options) {
+    //   /* using the specification from http://www.chessclub.com/help/PGN-spec
+    //    * example for html usage: .pgn({ max_width: 72, newline_char: "<br />" })
+    //    */
+    //   var newline = (typeof options === 'object' &&
+    //                  typeof options.newline_char === 'string') ?
+    //                  options.newline_char : '\n';
+    //   var max_width = (typeof options === 'object' &&
+    //                    typeof options.max_width === 'number') ?
+    //                    options.max_width : 0;
+    //   var result = [];
+    //   var header_exists = false;
+
+    //   /* add the PGN header headerrmation */
+    //   for (var i in header) {
+    //     /* TODO: order of enumerated properties in header object is not
+    //      * guaranteed, see ECMA-262 spec (section 12.6.4)
+    //      */
+    //     result.push('[' + i + ' \"' + header[i] + '\"]' + newline);
+    //     header_exists = true;
+    //   }
+
+    //   if (header_exists && history.length) {
+    //     result.push(newline);
+    //   }
+
+    //   /* pop all of history onto reversed_history */
+    //   var reversed_history = [];
+    //   while (history.length > 0) {
+    //     reversed_history.push(undo_move());
+    //   }
+
+    //   var moves = [];
+    //   var move_string = '';
+
+    //   /* build the list of moves.  a move_string looks like: "3. e3 e6" */
+    //   while (reversed_history.length > 0) {
+    //     var move = reversed_history.pop();
+
+    //     /* if the position started with black to move, start PGN with 1. ... */
+    //     if (!history.length && move.color === 'b') {
+    //       move_string = move_number + '. ...';
+    //     } else if (move.color === 'w') {
+    //       /* store the previous generated move_string if we have one */
+    //       if (move_string.length) {
+    //         moves.push(move_string);
+    //       }
+    //       move_string = move_number + '.';
+    //     }
+
+    //     move_string = move_string + ' ' + move_to_san(move, false);
+    //     make_move(move);
+    //   }
+
+    //   /* are there any other leftover moves? */
+    //   if (move_string.length) {
+    //     moves.push(move_string);
+    //   }
+
+    //   /* is there a result? */
+    //   if (typeof header.Result !== 'undefined') {
+    //     moves.push(header.Result);
+    //   }
+
+    //   /* history should be back to what is was before we started generating PGN,
+    //    * so join together moves
+    //    */
+    //   if (max_width === 0) {
+    //     return result.join('') + moves.join(' ');
+    //   }
+
+    //   /* wrap the PGN output at max_width */
+    //   var current_width = 0;
+    //   for (var i = 0; i < moves.length; i++) {
+    //     /* if the current move will push past max_width */
+    //     if (current_width + moves[i].length > max_width && i !== 0) {
+
+    //       /* don't end the line with whitespace */
+    //       if (result[result.length - 1] === ' ') {
+    //         result.pop();
+    //       }
+
+    //       result.push(newline);
+    //       current_width = 0;
+    //     } else if (i !== 0) {
+    //       result.push(' ');
+    //       current_width++;
+    //     }
+    //     result.push(moves[i]);
+    //     current_width += moves[i].length;
+    //   }
+
+    //   return result.join('');
+    // },
+
+    // load_pgn: function(pgn, options) {
+    //   // allow the user to specify the sloppy move parser to work around over
+    //   // disambiguation bugs in Fritz and Chessbase
+    //   var sloppy = (typeof options !== 'undefined' && 'sloppy' in options) ?
+    //                 options.sloppy : false;
+
+    //   function mask(str) {
+    //     return str.replace(/\\/g, '\\');
+    //   }
+
+    //   function has_keys(object) {
+    //     for (var key in object) {
+    //       return true;
+    //     }
+    //     return false;
+    //   }
+
+    //   function parse_pgn_header(header, options) {
+    //     var newline_char = (typeof options === 'object' &&
+    //                         typeof options.newline_char === 'string') ?
+    //                         options.newline_char : '\r?\n';
+    //     var header_obj = {};
+    //     var headers = header.split(new RegExp(mask(newline_char)));
+    //     var key = '';
+    //     var value = '';
+
+    //     for (var i = 0; i < headers.length; i++) {
+    //       key = headers[i].replace(/^\[([A-Z][A-Za-z]*)\s.*\]$/, '$1');
+    //       value = headers[i].replace(/^\[[A-Za-z]+\s"(.*)"\]$/, '$1');
+    //       if (trim(key).length > 0) {
+    //         header_obj[key] = value;
+    //       }
+    //     }
+
+    //     return header_obj;
+    //   }
+
+    //   var newline_char = (typeof options === 'object' &&
+    //                       typeof options.newline_char === 'string') ?
+    //                       options.newline_char : '\r?\n';
+    //   var regex = new RegExp('^(\\[(.|' + mask(newline_char) + ')*\\])' +
+    //                          '(' + mask(newline_char) + ')*' +
+    //                          '1.(' + mask(newline_char) + '|.)*$', 'g');
+
+    //   /* get header part of the PGN file */
+    //   var header_string = pgn.replace(regex, '$1');
+
+    //   /* no info part given, begins with moves */
+    //   if (header_string[0] !== '[') {
+    //     header_string = '';
+    //   }
+
+    //   reset();
+
+    //   /* parse PGN header */
+    //   var headers = parse_pgn_header(header_string, options);
+    //   for (var key in headers) {
+    //     set_header([key, headers[key]]);
+    //   }
+
+    //   /* load the starting position indicated by [Setup '1'] and
+    //   * [FEN position] */
+    //   if (headers['SetUp'] === '1') {
+    //       if (!(('FEN' in headers) && load(headers['FEN'], true ))) { // second argument to load: don't clear the headers
+    //         return false;
+    //       }
+    //   }
+
+    //   /* delete header to get the moves */
+    //   var ms = pgn.replace(header_string, '').replace(new RegExp(mask(newline_char), 'g'), ' ');
+
+    //   /* delete comments */
+    //   ms = ms.replace(/(\{[^}]+\})+?/g, '');
+
+    //   /* delete recursive annotation variations */
+    //   var rav_regex = /(\([^\(\)]+\))+?/g
+    //   while (rav_regex.test(ms)) {
+    //     ms = ms.replace(rav_regex, '');
+    //   }
+
+    //   /* delete move numbers */
+    //   ms = ms.replace(/\d+\.(\.\.)?/g, '');
+
+    //   /* delete ... indicating black to move */
+    //   ms = ms.replace(/\.\.\./g, '');
+
+    //   /* delete numeric annotation glyphs */
+    //   ms = ms.replace(/\$\d+/g, '');
+
+    //   /* trim and get array of moves */
+    //   var moves = trim(ms).split(new RegExp(/\s+/));
+
+    //   /* delete empty entries */
+    //   moves = moves.join(',').replace(/,,+/g, ',').split(',');
+    //   var move = '';
+
+    //   for (var half_move = 0; half_move < moves.length - 1; half_move++) {
+    //     move = move_from_san(moves[half_move], sloppy);
+
+    //     /* move not possible! (don't clear the board to examine to show the
+    //      * latest valid position)
+    //      */
+    //     if (move == null) {
+    //       return false;
+    //     } else {
+    //       make_move(move);
+    //     }
+    //   }
+
+    //   /* examine last move */
+    //   move = moves[moves.length - 1];
+    //   if (POSSIBLE_RESULTS.indexOf(move) > -1) {
+    //     if (has_keys(header) && typeof header.Result === 'undefined') {
+    //       set_header(['Result', move]);
+    //     }
+    //   }
+    //   else {
+    //     move = move_from_san(move, sloppy);
+    //     if (move == null) {
+    //       return false;
+    //     } else {
+    //       make_move(move);
+    //     }
+    //   }
+    //   return true;
+    // },
+
+    // header: function() {
+    //   return set_header(arguments);
+    // },
+
+    // ascii: function() {
+    //   return ascii();
+    // },
 
     turn: function() {
       return turn;
@@ -1742,30 +1795,30 @@ var Chess = function(fen) {
       return clear();
     },
 
-    put: function(piece, square) {
-      return put(piece, square);
-    },
+    // put: function(piece, square) {
+    //   return put(piece, square);
+    // },
 
-    get: function(square) {
-      return get(square);
-    },
+    // get: function(square) {
+    //   return get(square);
+    // },
 
-    remove: function(square) {
-      return remove(square);
-    },
+    // remove: function(square) {
+    //   return remove(square);
+    // },
 
-    perft: function(depth) {
-      return perft(depth);
-    },
+    // perft: function(depth) {
+    //   return perft(depth);
+    // },
 
-    square_color: function(square) {
-      if (square in SQUARES) {
-        var sq_0x88 = SQUARES[square];
-        return ((rank(sq_0x88) + file(sq_0x88)) % 2 === 0) ? 'light' : 'dark';
-      }
+    // square_color: function(square) {
+    //   if (square in SQUARES) {
+    //     var sq_0x88 = SQUARES[square];
+    //     return ((rank(sq_0x88) + file(sq_0x88)) % 2 === 0) ? 'light' : 'dark';
+    //   }
 
-      return null;
-    },
+    //   return null;
+    // },
 
     history: function(options) {
       var reversed_history = [];
diff --git a/www/js/chess.min.js b/www/js/chess.min.js
deleted file mode 100644 (file)
index 095468d..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-"use strict";/* @license
- * Copyright (c) 2015, Jeff Hlywa (jhlywa@gmail.com)
- * Released under the BSD license
- * https://github.com/jhlywa/chess.js/blob/master/LICENSE
- */
-var Chess=function(r){function e(){fr=new Array(128),ar={w:Q,b:Q},ur=K,lr={w:0,b:0},sr=Q,pr=0,cr=1,vr=[],gr={},a(i())}function n(){t(F)}function t(r){var n=r.split(/\s+/),t=n[0],f=0;if(!o(r).valid)return!1;e();for(var u=0;u<t.length;u++){var s=t.charAt(u);if("/"===s)f+=8;else if(R(s))f+=parseInt(s,10);else{var p="a">s?K:q;l({type:s.toLowerCase(),color:p},w(f)),f++}}return ur=n[1],n[2].indexOf("K")>-1&&(lr.w|=Y.KSIDE_CASTLE),n[2].indexOf("Q")>-1&&(lr.w|=Y.QSIDE_CASTLE),n[2].indexOf("k")>-1&&(lr.b|=Y.KSIDE_CASTLE),n[2].indexOf("q")>-1&&(lr.b|=Y.QSIDE_CASTLE),sr="-"===n[3]?Q:or[n[3]],pr=parseInt(n[4],10),cr=parseInt(n[5],10),a(i()),!0}function o(r){var e={0:"No errors.",1:"FEN string must contain six space-delimited fields.",2:"6th field (move number) must be a positive integer.",3:"5th field (half move counter) must be a non-negative integer.",4:"4th field (en-passant square) is invalid.",5:"3rd field (castling availability) is invalid.",6:"2nd field (side to move) is invalid.",7:"1st field (piece positions) does not contain 8 '/'-delimited rows.",8:"1st field (piece positions) is invalid [consecutive numbers].",9:"1st field (piece positions) is invalid [invalid piece].",10:"1st field (piece positions) is invalid [row too large]."},n=r.split(/\s+/);if(6!==n.length)return{valid:!1,error_number:1,error:e[1]};if(isNaN(n[5])||parseInt(n[5],10)<=0)return{valid:!1,error_number:2,error:e[2]};if(isNaN(n[4])||parseInt(n[4],10)<0)return{valid:!1,error_number:3,error:e[3]};if(!/^(-|[abcdefgh][36])$/.test(n[3]))return{valid:!1,error_number:4,error:e[4]};if(!/^(KQ?k?q?|Qk?q?|kq?|q|-)$/.test(n[2]))return{valid:!1,error_number:5,error:e[5]};if(!/^(w|b)$/.test(n[1]))return{valid:!1,error_number:6,error:e[6]};var t=n[0].split("/");if(8!==t.length)return{valid:!1,error_number:7,error:e[7]};for(var o=0;o<t.length;o++){for(var i=0,f=!1,a=0;a<t[o].length;a++)if(isNaN(t[o][a])){if(!/^[prnbqkPRNBQK]$/.test(t[o][a]))return{valid:!1,error_number:9,error:e[9]};i+=1,f=!1}else{if(f)return{valid:!1,error_number:8,error:e[8]};i+=parseInt(t[o][a],10),f=!0}if(8!==i)return{valid:!1,error_number:10,error:e[10]}}return{valid:!0,error_number:0,error:e[0]}}function i(){for(var r=0,e="",n=or.a8;n<=or.h1;n++){if(null==fr[n])r++;else{r>0&&(e+=r,r=0);var t=fr[n].color,o=fr[n].type;e+=t===K?o.toUpperCase():o.toLowerCase()}n+1&136&&(r>0&&(e+=r),n!==or.h1&&(e+="/"),r=0,n+=8)}var i="";lr[K]&Y.KSIDE_CASTLE&&(i+="K"),lr[K]&Y.QSIDE_CASTLE&&(i+="Q"),lr[q]&Y.KSIDE_CASTLE&&(i+="k"),lr[q]&Y.QSIDE_CASTLE&&(i+="q"),i=i||"-";var f=sr===Q?"-":w(sr);return[e,ur,i,f,pr,cr].join(" ")}function f(r){for(var e=0;e<r.length;e+=2)"string"==typeof r[e]&&"string"==typeof r[e+1]&&(gr[r[e]]=r[e+1]);return gr}function a(r){vr.length>0||(r!==F?(gr.SetUp="1",gr.FEN=r):(delete gr.SetUp,delete gr.FEN))}function u(r){var e=fr[or[r]];return e?{type:e.type,color:e.color}:null}function l(r,e){if(!("type"in r&&"color"in r))return!1;if(-1===G.indexOf(r.type.toLowerCase()))return!1;if(!(e in or))return!1;var n=or[e];return r.type==M&&ar[r.color]!=Q&&ar[r.color]!=n?!1:(fr[n]={type:r.type,color:r.color},r.type===M&&(ar[r.color]=n),a(i()),!0)}function s(r){var e=u(r);return fr[or[r]]=null,e&&e.type===M&&(ar[e.color]=Q),a(i()),e}function p(r,e,n,t,o){var i={color:ur,from:e,to:n,flags:t,piece:r[e].type};return o&&(i.flags|=Y.PROMOTION,i.promotion=o),r[n]?i.captured=r[n].type:t&Y.EP_CAPTURE&&(i.captured=U),i}function c(r){function e(r,e,n,t,o){if(r[n].type!==U||I(t)!==tr&&I(t)!==rr)e.push(p(r,n,t,o));else for(var i=[B,j,$,x],f=0,a=i.length;a>f;f++)e.push(p(r,n,t,o,i[f]))}var n=[],t=ur,o=L(t),i={b:nr,w:er},f=or.a8,a=or.h1,u=!1,l="undefined"!=typeof r&&"legal"in r?r.legal:!0;if("undefined"!=typeof r&&"square"in r){if(!(r.square in or))return[];f=a=or[r.square],u=!0}for(var s=f;a>=s;s++)if(136&s)s+=7;else{var c=fr[s];if(null!=c&&c.color===t)if(c.type===U){var v=s+H[t][0];if(null==fr[v]){e(fr,n,s,v,Y.NORMAL);var v=s+H[t][1];i[t]===I(s)&&null==fr[v]&&e(fr,n,s,v,Y.BIG_PAWN)}for(E=2;4>E;E++){var v=s+H[t][E];136&v||(null!=fr[v]&&fr[v].color===o?e(fr,n,s,v,Y.CAPTURE):v===sr&&e(fr,n,s,sr,Y.EP_CAPTURE))}}else for(var E=0,d=Z[c.type].length;d>E;E++)for(var b=Z[c.type][E],v=s;;){if(v+=b,136&v)break;if(null!=fr[v]){if(fr[v].color===t)break;e(fr,n,s,v,Y.CAPTURE);break}if(e(fr,n,s,v,Y.NORMAL),"n"===c.type||"k"===c.type)break}}if(!u||a===ar[t]){if(lr[t]&Y.KSIDE_CASTLE){var _=ar[t],A=_+2;null!=fr[_+1]||null!=fr[A]||g(o,ar[t])||g(o,_+1)||g(o,A)||e(fr,n,ar[t],A,Y.KSIDE_CASTLE)}if(lr[t]&Y.QSIDE_CASTLE){var _=ar[t],A=_-2;null!=fr[_-1]||null!=fr[_-2]||null!=fr[_-3]||g(o,ar[t])||g(o,_-1)||g(o,A)||e(fr,n,ar[t],A,Y.QSIDE_CASTLE)}}if(!l)return n;for(var S=[],s=0,d=n.length;d>s;s++)y(n[s]),h(t)||S.push(n[s]),m();return S}function v(r){var e="";if(r.flags&Y.KSIDE_CASTLE)e="O-O";else if(r.flags&Y.QSIDE_CASTLE)e="O-O-O";else{var n=C(r);r.piece!==U&&(e+=r.piece.toUpperCase()+n),r.flags&(Y.CAPTURE|Y.EP_CAPTURE)&&(r.piece===U&&(e+=w(r.from)[0]),e+="x"),e+=w(r.to),r.flags&Y.PROMOTION&&(e+="="+r.promotion.toUpperCase())}return y(r),E()&&(e+=d()?"#":"+"),m(),e}function g(r,e){for(var n=or.a8;n<=or.h1;n++)if(136&n)n+=7;else if(null!=fr[n]&&fr[n].color===r){var t=fr[n],o=n-e,i=o+119;if(z[i]&1<<V[t.type]){if(t.type===U){if(o>0){if(t.color===K)return!0}else if(t.color===q)return!0;continue}if("n"===t.type||"k"===t.type)return!0;for(var f=J[i],a=n+f,u=!1;a!==e;){if(null!=fr[a]){u=!0;break}a+=f}if(!u)return!0}}return!1}function h(r){return g(L(r),ar[r])}function E(){return h(ur)}function d(){return E()&&0===c().length}function b(){return!E()&&0===c().length}function _(){for(var r={},e=[],n=0,t=0,o=or.a8;o<=or.h1;o++)if(t=(t+1)%2,136&o)o+=7;else{var i=fr[o];i&&(r[i.type]=i.type in r?r[i.type]+1:1,i.type===$&&e.push(t),n++)}if(2===n)return!0;if(3===n&&(1===r[$]||1===r[x]))return!0;if(n===r[$]+2){for(var f=0,a=e.length,o=0;a>o;o++)f+=e[o];if(0===f||f===a)return!0}return!1}function A(){for(var r=[],e={},n=!1;;){var t=m();if(!t)break;r.push(t)}for(;;){var o=i().split(" ").slice(0,4).join(" ");if(e[o]=o in e?e[o]+1:1,e[o]>=3&&(n=!0),!r.length)break;y(r.pop())}return n}function S(r){vr.push({move:r,kings:{b:ar.b,w:ar.w},turn:ur,castling:{b:lr.b,w:lr.w},ep_square:sr,half_moves:pr,move_number:cr})}function y(r){var e=ur,n=L(e);if(S(r),fr[r.to]=fr[r.from],fr[r.from]=null,r.flags&Y.EP_CAPTURE&&(ur===q?fr[r.to-16]=null:fr[r.to+16]=null),r.flags&Y.PROMOTION&&(fr[r.to]={type:r.promotion,color:e}),fr[r.to].type===M){if(ar[fr[r.to].color]=r.to,r.flags&Y.KSIDE_CASTLE){var t=r.to-1,o=r.to+1;fr[t]=fr[o],fr[o]=null}else if(r.flags&Y.QSIDE_CASTLE){var t=r.to+1,o=r.to-2;fr[t]=fr[o],fr[o]=null}lr[e]=""}if(lr[e])for(var i=0,f=ir[e].length;f>i;i++)if(r.from===ir[e][i].square&&lr[e]&ir[e][i].flag){lr[e]^=ir[e][i].flag;break}if(lr[n])for(var i=0,f=ir[n].length;f>i;i++)if(r.to===ir[n][i].square&&lr[n]&ir[n][i].flag){lr[n]^=ir[n][i].flag;break}sr=r.flags&Y.BIG_PAWN?"b"===ur?r.to-16:r.to+16:Q,r.piece===U?pr=0:r.flags&(Y.CAPTURE|Y.EP_CAPTURE)?pr=0:pr++,ur===q&&cr++,ur=L(ur)}function m(){var r=vr.pop();if(null==r)return null;var e=r.move;ar=r.kings,ur=r.turn,lr=r.castling,sr=r.ep_square,pr=r.half_moves,cr=r.move_number;var n=ur,t=L(ur);if(fr[e.from]=fr[e.to],fr[e.from].type=e.piece,fr[e.to]=null,e.flags&Y.CAPTURE)fr[e.to]={type:e.captured,color:t};else if(e.flags&Y.EP_CAPTURE){var o;o=n===q?e.to-16:e.to+16,fr[o]={type:U,color:t}}if(e.flags&(Y.KSIDE_CASTLE|Y.QSIDE_CASTLE)){var i,f;e.flags&Y.KSIDE_CASTLE?(i=e.to+1,f=e.to-1):e.flags&Y.QSIDE_CASTLE&&(i=e.to-2,f=e.to+1),fr[i]=fr[f],fr[f]=null}return e}function C(r){for(var e=c(),n=r.from,t=r.to,o=r.piece,i=0,f=0,a=0,u=0,l=e.length;l>u;u++){var s=e[u].from,p=e[u].to,v=e[u].piece;o===v&&n!==s&&t===p&&(i++,I(n)===I(s)&&f++,P(n)===P(s)&&a++)}return i>0?f>0&&a>0?w(n):w(n).charAt(a>0?1:0):""}function T(){for(var r="   +------------------------+\n",e=or.a8;e<=or.h1;e++){if(0===P(e)&&(r+=" "+"87654321"[I(e)]+" |"),null==fr[e])r+=" . ";else{var n=fr[e].type,t=fr[e].color,o=t===K?n.toUpperCase():n.toLowerCase();r+=" "+o+" "}e+1&136&&(r+="|\n",e+=8)}return r+="   +------------------------+\n",r+="     a  b  c  d  e  f  g  h\n"}function I(r){return r>>4}function P(r){return 15&r}function w(r){var e=P(r),n=I(r);return"abcdefgh".substring(e,e+1)+"87654321".substring(n,n+1)}function L(r){return r===K?q:K}function R(r){return-1!=="0123456789".indexOf(r)}function O(r){var e=N(r);e.san=v(e),e.to=w(e.to),e.from=w(e.from);var n="";for(var t in Y)Y[t]&e.flags&&(n+=X[t]);return e.flags=n,e}function N(r){var e=r instanceof Array?[]:{};for(var n in r)"object"==typeof n?e[n]=N(r[n]):e[n]=r[n];return e}function k(r){return r.replace(/^\s+|\s+$/g,"")}function D(r){for(var e=c({legal:!1}),n=0,t=ur,o=0,i=e.length;i>o;o++){if(y(e[o]),!h(t))if(r-1>0){var f=D(r-1);n+=f}else n++;m()}return n}var q="b",K="w",Q=-1,U="p",x="n",$="b",j="r",B="q",M="k",G="pnbrqkPNBRQK",F="rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",W=["1-0","0-1","1/2-1/2","*"],H={b:[16,32,17,15],w:[-16,-32,-17,-15]},Z={n:[-18,-33,-31,-14,18,33,31,14],b:[-17,-15,17,15],r:[-16,1,16,-1],q:[-17,-16,-15,1,17,16,15,-1],k:[-17,-16,-15,1,17,16,15,-1]},z=[20,0,0,0,0,0,0,24,0,0,0,0,0,0,20,0,0,20,0,0,0,0,0,24,0,0,0,0,0,20,0,0,0,0,20,0,0,0,0,24,0,0,0,0,20,0,0,0,0,0,0,20,0,0,0,24,0,0,0,20,0,0,0,0,0,0,0,0,20,0,0,24,0,0,20,0,0,0,0,0,0,0,0,0,0,20,2,24,2,20,0,0,0,0,0,0,0,0,0,0,0,2,53,56,53,2,0,0,0,0,0,0,24,24,24,24,24,24,56,0,56,24,24,24,24,24,24,0,0,0,0,0,0,2,53,56,53,2,0,0,0,0,0,0,0,0,0,0,0,20,2,24,2,20,0,0,0,0,0,0,0,0,0,0,20,0,0,24,0,0,20,0,0,0,0,0,0,0,0,20,0,0,0,24,0,0,0,20,0,0,0,0,0,0,20,0,0,0,0,24,0,0,0,0,20,0,0,0,0,20,0,0,0,0,0,24,0,0,0,0,0,20,0,0,20,0,0,0,0,0,0,24,0,0,0,0,0,0,20],J=[17,0,0,0,0,0,0,16,0,0,0,0,0,0,15,0,0,17,0,0,0,0,0,16,0,0,0,0,0,15,0,0,0,0,17,0,0,0,0,16,0,0,0,0,15,0,0,0,0,0,0,17,0,0,0,16,0,0,0,15,0,0,0,0,0,0,0,0,17,0,0,16,0,0,15,0,0,0,0,0,0,0,0,0,0,17,0,16,0,15,0,0,0,0,0,0,0,0,0,0,0,0,17,16,15,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,-15,-16,-17,0,0,0,0,0,0,0,0,0,0,0,0,-15,0,-16,0,-17,0,0,0,0,0,0,0,0,0,0,-15,0,0,-16,0,0,-17,0,0,0,0,0,0,0,0,-15,0,0,0,-16,0,0,0,-17,0,0,0,0,0,0,-15,0,0,0,0,-16,0,0,0,0,-17,0,0,0,0,-15,0,0,0,0,0,-16,0,0,0,0,0,-17,0,0,-15,0,0,0,0,0,0,-16,0,0,0,0,0,0,-17],V={p:0,n:1,b:2,r:3,q:4,k:5},X={NORMAL:"n",CAPTURE:"c",BIG_PAWN:"b",EP_CAPTURE:"e",PROMOTION:"p",KSIDE_CASTLE:"k",QSIDE_CASTLE:"q"},Y={NORMAL:1,CAPTURE:2,BIG_PAWN:4,EP_CAPTURE:8,PROMOTION:16,KSIDE_CASTLE:32,QSIDE_CASTLE:64},rr=7,er=6,nr=1,tr=0,or={a8:0,b8:1,c8:2,d8:3,e8:4,f8:5,g8:6,h8:7,a7:16,b7:17,c7:18,d7:19,e7:20,f7:21,g7:22,h7:23,a6:32,b6:33,c6:34,d6:35,e6:36,f6:37,g6:38,h6:39,a5:48,b5:49,c5:50,d5:51,e5:52,f5:53,g5:54,h5:55,a4:64,b4:65,c4:66,d4:67,e4:68,f4:69,g4:70,h4:71,a3:80,b3:81,c3:82,d3:83,e3:84,f3:85,g3:86,h3:87,a2:96,b2:97,c2:98,d2:99,e2:100,f2:101,g2:102,h2:103,a1:112,b1:113,c1:114,d1:115,e1:116,f1:117,g1:118,h1:119},ir={w:[{square:or.a1,flag:Y.QSIDE_CASTLE},{square:or.h1,flag:Y.KSIDE_CASTLE}],b:[{square:or.a8,flag:Y.QSIDE_CASTLE},{square:or.h8,flag:Y.KSIDE_CASTLE}]},fr=new Array(128),ar={w:Q,b:Q},ur=K,lr={w:0,b:0},sr=Q,pr=0,cr=1,vr=[],gr={};return t("undefined"==typeof r?F:r),{WHITE:K,BLACK:q,PAWN:U,KNIGHT:x,BISHOP:$,ROOK:j,QUEEN:B,KING:M,SQUARES:function(){for(var r=[],e=or.a8;e<=or.h1;e++)136&e?e+=7:r.push(w(e));return r}(),FLAGS:X,load:function(r){return t(r)},reset:function(){return n()},moves:function(r){for(var e=c(r),n=[],t=0,o=e.length;o>t;t++)n.push("undefined"!=typeof r&&"verbose"in r&&r.verbose?O(e[t]):v(e[t]));return n},in_check:function(){return E()},in_checkmate:function(){return d()},in_stalemate:function(){return b()},in_draw:function(){return pr>=100||b()||_()||A()},insufficient_material:function(){return _()},in_threefold_repetition:function(){return A()},game_over:function(){return pr>=100||d()||b()||_()||A()},validate_fen:function(r){return o(r)},fen:function(){return i()},pgn:function(r){var e="object"==typeof r&&"string"==typeof r.newline_char?r.newline_char:"\n",n="object"==typeof r&&"number"==typeof r.max_width?r.max_width:0,t=[],o=!1;for(var i in gr)t.push("["+i+' "'+gr[i]+'"]'+e),o=!0;o&&vr.length&&t.push(e);for(var f=[];vr.length>0;)f.push(m());for(var a=[],u="",l=1;f.length>0;){var s=f.pop();1===l&&"b"===s.color?(u="1. ...",l++):"w"===s.color&&(u.length&&a.push(u),u=l+".",l++),u=u+" "+v(s),y(s)}if(u.length&&a.push(u),"undefined"!=typeof gr.Result&&a.push(gr.Result),0===n)return t.join("")+a.join(" ");for(var p=0,i=0;i<a.length;i++)p+a[i].length>n&&0!==i?(" "===t[t.length-1]&&t.pop(),t.push(e),p=0):0!==i&&(t.push(" "),p++),t.push(a[i]),p+=a[i].length;return t.join("")},load_pgn:function(r,e){function o(r){return r.replace(/\\/g,"\\")}function i(r){for(var e=r.replace(/=/,"").replace(/[+#]?[?!]*$/,""),n=c(),t=0,o=n.length;o>t;t++)if(e===v(n[t]).replace(/=/,"").replace(/[+#]?[?!]*$/,""))return n[t];return null}function a(r){return i(k(r))}function u(r){var e=!1;for(var n in r)e=!0;return e}function l(r,e){for(var n="object"==typeof e&&"string"==typeof e.newline_char?e.newline_char:"\r?\n",t={},i=r.split(new RegExp(o(n))),f="",a="",u=0;u<i.length;u++)f=i[u].replace(/^\[([A-Z][A-Za-z]*)\s.*\]$/,"$1"),a=i[u].replace(/^\[[A-Za-z]+\s"(.*)"\]$/,"$1"),k(f).length>0&&(t[f]=a);return t}var s="object"==typeof e&&"string"==typeof e.newline_char?e.newline_char:"\r?\n",p=new RegExp("^(\\[(.|"+o(s)+")*\\])("+o(s)+")*1.("+o(s)+"|.)*$","g"),g=r.replace(p,"$1");"["!==g[0]&&(g=""),n();var h=l(g,e);for(var E in h)f([E,h[E]]);if("1"===h.SetUp&&!("FEN"in h&&t(h.FEN)))return!1;var d=r.replace(g,"").replace(new RegExp(o(s),"g")," ");d=d.replace(/(\{[^}]+\})+?/g,"");for(var b=/(\([^\(\)]+\))+?/g;b.test(d);)d=d.replace(b,"");d=d.replace(/\d+\./g,""),d=d.replace(/\.\.\./g,"");var _=k(d).split(new RegExp(/\s+/));_=_.join(",").replace(/,,+/g,",").split(",");for(var A="",S=0;S<_.length-1;S++){if(A=a(_[S]),null==A)return!1;y(A)}if(A=_[_.length-1],W.indexOf(A)>-1)u(gr)&&"undefined"==typeof gr.Result&&f(["Result",A]);else{if(A=a(A),null==A)return!1;y(A)}return!0},header:function(){return f(arguments)},ascii:function(){return T()},turn:function(){return ur},move:function(r){var e=null,n=c();if("string"==typeof r){for(var t=r.replace(/=/,"").replace(/[+#]?[?!]*$/,""),o=0,i=n.length;i>o;o++)if(t===v(n[o]).replace(/=/,"").replace(/[+#]?[?!]*$/,"")){e=n[o];break}}else if("object"==typeof r)for(var o=0,i=n.length;i>o;o++)if(!(r.from!==w(n[o].from)||r.to!==w(n[o].to)||"promotion"in n[o]&&r.promotion!==n[o].promotion)){e=n[o];break}if(!e)return null;var f=O(e);return y(e),f},undo:function(){var r=m();return r?O(r):null},clear:function(){return e()},put:function(r,e){return l(r,e)},get:function(r){return u(r)},remove:function(r){return s(r)},perft:function(r){return D(r)},square_color:function(r){if(r in or){var e=or[r];return(I(e)+P(e))%2===0?"light":"dark"}return null},history:function(r){for(var e=[],n=[],t=("undefined"!=typeof r&&"verbose"in r&&r.verbose);vr.length>0;)e.push(m());for(;e.length>0;){var o=e.pop();n.push(t?O(o):v(o)),y(o)}return n}}};"undefined"!=typeof exports&&(exports.Chess=Chess),"undefined"!=typeof define&&define(function(){return Chess});
index 4b24ec04d5fe3a29845da396f9a1e8c10bb79d57..24aa3da618d25cf3a9d27456aa3f09d53e2c825a 100644 (file)
@@ -1,7 +1,8 @@
 /*!
- * chessboard.js v0.3.0
+ * chessboard.js v0.3.0+asn
  *
  * Copyright 2013 Chris Oakman
+ * Portions copyright 2022 Steinar H. Gunderson
  * Released under the MIT license
  * http://chessboardjs.com/license
  *
@@ -25,7 +26,7 @@ function validMove(move) {
   var tmp = move.split('-');
   if (tmp.length !== 2) return false;
 
-  return (validSquare(tmp[0]) === true && validSquare(tmp[1]) === true);
+  return validSquare(tmp[0]) && validSquare(tmp[1]);
 }
 
 function validSquare(square) {
@@ -66,9 +67,9 @@ function validPositionObject(pos) {
   if (typeof pos !== 'object') return false;
 
   for (var i in pos) {
-    if (pos.hasOwnProperty(i) !== true) continue;
+    if (!pos.hasOwnProperty(i)) continue;
 
-    if (validSquare(i) !== true || validPieceCode(pos[i]) !== true) {
+    if (!validSquare(i) || !validPieceCode(pos[i])) {
       return false;
     }
   }
@@ -103,7 +104,7 @@ function pieceCodeToFen(piece) {
 // convert FEN string to position object
 // returns false if the FEN string is invalid
 function fenToObj(fen) {
-  if (validFen(fen) !== true) {
+  if (!validFen(fen)) {
     return false;
   }
 
@@ -143,11 +144,12 @@ function fenToObj(fen) {
 // position object to FEN string
 // returns false if the obj is not a valid position object
 function objToFen(obj) {
-  if (validPositionObject(obj) !== true) {
+  if (!validPositionObject(obj)) {
     return false;
   }
 
   var fen = '';
+  let num_empty = 0;
 
   var currentRow = 8;
   for (var i = 0; i < 8; i++) {
@@ -155,33 +157,31 @@ function objToFen(obj) {
       var square = COLUMNS[j] + currentRow;
 
       // piece exists
-      if (obj.hasOwnProperty(square) === true) {
+      if (obj.hasOwnProperty(square)) {
+        if (num_empty > 0) {
+          fen += num_empty;
+          num_empty = 0;
+        }
         fen += pieceCodeToFen(obj[square]);
       }
 
       // empty space
       else {
-        fen += '1';
+        ++num_empty;
       }
     }
 
     if (i !== 7) {
+      if (num_empty > 0) {
+        fen += num_empty;
+        num_empty = 0;
+      }
       fen += '/';
     }
 
     currentRow--;
   }
 
-  // squeeze the numbers together
-  // haha, I love this solution...
-  fen = fen.replace(/11111111/g, '8');
-  fen = fen.replace(/1111111/g, '7');
-  fen = fen.replace(/111111/g, '6');
-  fen = fen.replace(/11111/g, '5');
-  fen = fen.replace(/1111/g, '4');
-  fen = fen.replace(/111/g, '3');
-  fen = fen.replace(/11/g, '2');
-
   return fen;
 }
 
@@ -198,8 +198,7 @@ cfg = cfg || {};
 // Constants
 //------------------------------------------------------------------------------
 
-var MINIMUM_JQUERY_VERSION = '1.7.0',
-  START_FEN = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR',
+var START_FEN = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR',
   START_POSITION = fenToObj(START_FEN);
 
 // use unique class names to prevent clashing with anything else on the page
@@ -208,16 +207,11 @@ var CSS = {
   alpha: 'alpha-d2270',
   board: 'board-b72b1',
   chessboard: 'chessboard-63f37',
-  clearfix: 'clearfix-7da63',
   highlight1: 'highlight1-32417',
   highlight2: 'highlight2-9c5d2',
   notation: 'notation-322f9',
   numeric: 'numeric-fc462',
   piece: 'piece-417db',
-  row: 'row-5277c',
-  sparePieces: 'spare-pieces-7492f',
-  sparePiecesBottom: 'spare-pieces-bottom-ae20f',
-  sparePiecesTop: 'spare-pieces-top-4028b',
   square: 'square-55d63'
 };
 var CSSColor = {};
@@ -231,9 +225,7 @@ CSSColor['black'] = 'black-3c85d';
 // DOM elements
 var containerEl,
   boardEl,
-  draggedPieceEl,
-  sparePiecesTopEl,
-  sparePiecesBottomEl;
+  draggedPieceEl;
 
 // constructor return object
 var widget = {};
@@ -242,57 +234,27 @@ var widget = {};
 // Stateful
 //------------------------------------------------------------------------------
 
-var ANIMATION_HAPPENING = false,
-  BOARD_BORDER_SIZE = 2,
-  CURRENT_ORIENTATION = 'white',
+var CURRENT_ORIENTATION = 'white',
   CURRENT_POSITION = {},
-  SQUARE_SIZE,
   DRAGGED_PIECE,
   DRAGGED_PIECE_LOCATION,
   DRAGGED_PIECE_SOURCE,
   DRAGGING_A_PIECE = false,
-  SPARE_PIECE_ELS_IDS = {},
-  SQUARE_ELS_IDS = {},
-  SQUARE_ELS_OFFSETS;
+  PIECE_ON_SQUARE = {};
 
 //------------------------------------------------------------------------------
 // JS Util Functions
 //------------------------------------------------------------------------------
 
-// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
+let id_counter = 0;
 function createId() {
-  return 'xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx'.replace(/x/g, function(c) {
-    var r = Math.random() * 16 | 0;
-    return r.toString(16);
-  });
+  return 'chesspiece-id-' + (id_counter++);
 }
 
 function deepCopy(thing) {
   return JSON.parse(JSON.stringify(thing));
 }
 
-function parseSemVer(version) {
-  var tmp = version.split('.');
-  return {
-    major: parseInt(tmp[0], 10),
-    minor: parseInt(tmp[1], 10),
-    patch: parseInt(tmp[2], 10)
-  };
-}
-
-// returns true if version is >= minimum
-function compareSemVer(version, minimum) {
-  version = parseSemVer(version);
-  minimum = parseSemVer(minimum);
-
-  var versionNum = (version.major * 10000 * 10000) +
-    (version.minor * 10000) + version.patch;
-  var minimumNum = (minimum.major * 10000 * 10000) +
-    (minimum.minor * 10000) + minimum.patch;
-
-  return (versionNum >= minimumNum);
-}
-
 //------------------------------------------------------------------------------
 // Validation / Errors
 //------------------------------------------------------------------------------
@@ -304,7 +266,7 @@ function compareSemVer(version, minimum) {
  */
 function error(code, msg, obj) {
   // do nothing if showErrors is not set
-  if (cfg.hasOwnProperty('showErrors') !== true ||
+  if (!cfg.hasOwnProperty('showErrors') ||
       cfg.showErrors === false) {
     return;
   }
@@ -359,39 +321,12 @@ function checkDeps() {
     }
 
     // set the containerEl
-    containerEl = $(el);
+    containerEl = el;
   }
 
-  // else it must be something that becomes a jQuery collection
-  // with size 1
-  // ie: a single DOM node or jQuery object
+  // else it must be a DOM node
   else {
-    containerEl = $(containerElOrId);
-
-    if (containerEl.length !== 1) {
-      window.alert('ChessBoard Error 1003: The first argument to ' +
-        'ChessBoard() must be an ID or a single DOM node.' +
-        '\n\nExiting...');
-      return false;
-    }
-  }
-
-  // JSON must exist
-  if (! window.JSON ||
-      typeof JSON.stringify !== 'function' ||
-      typeof JSON.parse !== 'function') {
-    window.alert('ChessBoard Error 1004: JSON does not exist. ' +
-      'Please include a JSON polyfill.\n\nExiting...');
-    return false;
-  }
-
-  // check for a compatible version of jQuery
-  if (! (typeof window.$ && $.fn && $.fn.jquery &&
-      compareSemVer($.fn.jquery, MINIMUM_JQUERY_VERSION) === true)) {
-    window.alert('ChessBoard Error 1005: Unable to find a valid version ' +
-      'of jQuery. Please include jQuery ' + MINIMUM_JQUERY_VERSION + ' or ' +
-      'higher on the page.\n\nExiting...');
-    return false;
+    containerEl = containerElOrId;
   }
 
   return true;
@@ -411,7 +346,7 @@ function validAnimationSpeed(speed) {
 
 // validate config / set default options
 function expandConfig() {
-  if (typeof cfg === 'string' || validPositionObject(cfg) === true) {
+  if (typeof cfg === 'string' || validPositionObject(cfg)) {
     cfg = {
       position: cfg
     };
@@ -433,61 +368,46 @@ function expandConfig() {
     cfg.draggable = false;
   }
 
-  // default for dropOffBoard is 'snapback'
-  if (cfg.dropOffBoard !== 'trash') {
-    cfg.dropOffBoard = 'snapback';
-  }
-
-  // default for sparePieces is false
-  if (cfg.sparePieces !== true) {
-    cfg.sparePieces = false;
-  }
-
-  // draggable must be true if sparePieces is enabled
-  if (cfg.sparePieces === true) {
-    cfg.draggable = true;
-  }
-
   // default piece theme is wikipedia
-  if (cfg.hasOwnProperty('pieceTheme') !== true ||
+  if (!cfg.hasOwnProperty('pieceTheme') ||
       (typeof cfg.pieceTheme !== 'string' &&
        typeof cfg.pieceTheme !== 'function')) {
     cfg.pieceTheme = 'img/chesspieces/wikipedia/{piece}.png';
   }
 
   // animation speeds
-  if (cfg.hasOwnProperty('appearSpeed') !== true ||
-      validAnimationSpeed(cfg.appearSpeed) !== true) {
+  if (!cfg.hasOwnProperty('appearSpeed') ||
+      !validAnimationSpeed(cfg.appearSpeed)) {
     cfg.appearSpeed = 200;
   }
-  if (cfg.hasOwnProperty('moveSpeed') !== true ||
-      validAnimationSpeed(cfg.moveSpeed) !== true) {
+  if (!cfg.hasOwnProperty('moveSpeed') ||
+      !validAnimationSpeed(cfg.moveSpeed)) {
     cfg.moveSpeed = 200;
   }
-  if (cfg.hasOwnProperty('snapbackSpeed') !== true ||
-      validAnimationSpeed(cfg.snapbackSpeed) !== true) {
+  if (!cfg.hasOwnProperty('snapbackSpeed') ||
+      !validAnimationSpeed(cfg.snapbackSpeed)) {
     cfg.snapbackSpeed = 50;
   }
-  if (cfg.hasOwnProperty('snapSpeed') !== true ||
-      validAnimationSpeed(cfg.snapSpeed) !== true) {
+  if (!cfg.hasOwnProperty('snapSpeed') ||
+      !validAnimationSpeed(cfg.snapSpeed)) {
     cfg.snapSpeed = 25;
   }
-  if (cfg.hasOwnProperty('trashSpeed') !== true ||
-      validAnimationSpeed(cfg.trashSpeed) !== true) {
+  if (!cfg.hasOwnProperty('trashSpeed') ||
+      !validAnimationSpeed(cfg.trashSpeed)) {
     cfg.trashSpeed = 100;
   }
 
   // make sure position is valid
-  if (cfg.hasOwnProperty('position') === true) {
+  if (cfg.hasOwnProperty('position')) {
     if (cfg.position === 'start') {
       CURRENT_POSITION = deepCopy(START_POSITION);
     }
 
-    else if (validFen(cfg.position) === true) {
+    else if (validFen(cfg.position)) {
       CURRENT_POSITION = fenToObj(cfg.position);
     }
 
-    else if (validPositionObject(cfg.position) === true) {
+    else if (validPositionObject(cfg.position)) {
       CURRENT_POSITION = deepCopy(cfg.position);
     }
 
@@ -499,53 +419,6 @@ function expandConfig() {
   return true;
 }
 
-//------------------------------------------------------------------------------
-// DOM Misc
-//------------------------------------------------------------------------------
-
-// calculates square size based on the width of the container
-// got a little CSS black magic here, so let me explain:
-// get the width of the container element (could be anything), reduce by 1 for
-// fudge factor, and then keep reducing until we find an exact mod 8 for
-// our square size
-function calculateSquareSize() {
-  var containerWidth = parseInt(containerEl.css('width'), 10);
-
-  // defensive, prevent infinite loop
-  if (! containerWidth || containerWidth <= 0) {
-    return 0;
-  }
-
-  // pad one pixel
-  var boardWidth = containerWidth - 1;
-
-  while (boardWidth % 8 !== 0 && boardWidth > 0) {
-    boardWidth--;
-  }
-
-  return (boardWidth / 8);
-}
-
-// create random IDs for elements
-function createElIds() {
-  // squares on the board
-  for (var i = 0; i < COLUMNS.length; i++) {
-    for (var j = 1; j <= 8; j++) {
-      var square = COLUMNS[i] + j;
-      SQUARE_ELS_IDS[square] = square + '-' + createId();
-    }
-  }
-
-  // spare pieces
-  var pieces = 'KQRBNP'.split('');
-  for (var i = 0; i < pieces.length; i++) {
-    var whitePiece = 'w' + pieces[i];
-    var blackPiece = 'b' + pieces[i];
-    SPARE_PIECE_ELS_IDS[whitePiece] = whitePiece + '-' + createId();
-    SPARE_PIECE_ELS_IDS[blackPiece] = blackPiece + '-' + createId();
-  }
-}
-
 //------------------------------------------------------------------------------
 // Markup Building
 //------------------------------------------------------------------------------
@@ -553,39 +426,13 @@ function createElIds() {
 function buildBoardContainer() {
   var html = '<div class="' + CSS.chessboard + '">';
 
-  if (cfg.sparePieces === true) {
-    html += '<div class="' + CSS.sparePieces + ' ' +
-      CSS.sparePiecesTop + '"></div>';
-  }
-
   html += '<div class="' + CSS.board + '"></div>';
 
-  if (cfg.sparePieces === true) {
-    html += '<div class="' + CSS.sparePieces + ' ' +
-      CSS.sparePiecesBottom + '"></div>';
-  }
-
   html += '</div>';
 
   return html;
 }
 
-/*
-var buildSquare = function(color, size, id) {
-  var html = '<div class="' + CSS.square + ' ' + CSSColor[color] + '" ' +
-  'style="width: ' + size + 'px; height: ' + size + 'px" ' +
-  'id="' + id + '">';
-
-  if (cfg.showNotation === true) {
-
-  }
-
-  html += '</div>';
-
-  return html;
-};
-*/
-
 function buildBoard(orientation) {
   if (orientation !== 'black') {
     orientation = 'white';
@@ -603,27 +450,29 @@ function buildBoard(orientation) {
 
   var squareColor = 'white';
   for (var i = 0; i < 8; i++) {
-    html += '<div class="' + CSS.row + '">';
     for (var j = 0; j < 8; j++) {
       var square = alpha[j] + row;
 
       html += '<div class="' + CSS.square + ' ' + CSSColor[squareColor] + ' ' +
         'square-' + square + '" ' +
-        'style="width: ' + SQUARE_SIZE + 'px; height: ' + SQUARE_SIZE + 'px" ' +
-        'id="' + SQUARE_ELS_IDS[square] + '" ' +
+        'style="grid-row: ' + (i+1) + '; grid-column: ' + (j+1) + ';" ' +
         'data-square="' + square + '">';
 
-      if (cfg.showNotation === true) {
+      if (cfg.showNotation) {
         // alpha notation
         if ((orientation === 'white' && row === 1) ||
             (orientation === 'black' && row === 8)) {
-          html += '<div class="' + CSS.notation + ' ' + CSS.alpha + '">' +
+          let bottom = 'calc(' + (12.5 * (7-i)) + '% + 1px)';
+          let right = 'calc(' + (12.5 * (7-j)) + '% + 3px)';
+          html += '<div class="' + CSS.alpha + '" style="right: ' + right + '; bottom: ' + bottom + ';">' +
             alpha[j] + '</div>';
         }
 
         // numeric notation
         if (j === 0) {
-          html += '<div class="' + CSS.notation + ' ' + CSS.numeric + '">' +
+          let top = 'calc(' + (12.5 * i) + '% + 2px)';
+          let left = 'calc(' + (12.5 * j) + '% + 2px)';
+          html += '<div class="' + CSS.numeric + '" style="top: ' + top + '; left: ' + left + ';">' +
             row + '</div>';
         }
       }
@@ -632,7 +481,6 @@ function buildBoard(orientation) {
 
       squareColor = (squareColor === 'white' ? 'black' : 'white');
     }
-    html += '<div class="' + CSS.clearfix + '"></div></div>';
 
     squareColor = (squareColor === 'white' ? 'black' : 'white');
 
@@ -664,174 +512,148 @@ function buildPieceImgSrc(piece) {
 /**
  * @param {!string} piece
  * @param {boolean=} hidden
- * @param {!string=} id
  */
-function buildPiece(piece, hidden, id) {
-  var html = '<img src="' + buildPieceImgSrc(piece) + '" ';
-  if (id && typeof id === 'string') {
-    html += 'id="' + id + '" ';
-  }
-  html += 'alt="" ' +
-  'class="' + CSS.piece + '" ' +
-  'data-piece="' + piece + '" ' +
-  'style="width: ' + SQUARE_SIZE + 'px;' +
-  'height: ' + SQUARE_SIZE + 'px;';
+function buildPiece(piece, hidden) {
+  let img = document.createElement('img');
+  img.src = buildPieceImgSrc(piece);
+  img.setAttribute('alt', '');
+  img.classList.add(CSS.piece);
   if (hidden === true) {
-    html += 'display:none;';
+    img.style.display = 'none';
   }
-  html += '" />';
-
-  return html;
-}
-
-function buildSparePieces(color) {
-  var pieces = ['wK', 'wQ', 'wR', 'wB', 'wN', 'wP'];
-  if (color === 'black') {
-    pieces = ['bK', 'bQ', 'bR', 'bB', 'bN', 'bP'];
-  }
-
-  var html = '';
-  for (var i = 0; i < pieces.length; i++) {
-    html += buildPiece(pieces[i], false, SPARE_PIECE_ELS_IDS[pieces[i]]);
-  }
-
-  return html;
+  return img;
 }
 
 //------------------------------------------------------------------------------
 // Animations
 //------------------------------------------------------------------------------
 
-function animateSquareToSquare(src, dest, piece, completeFn) {
-  // get information about the source and destination squares
-  var srcSquareEl = $('#' + SQUARE_ELS_IDS[src]);
-  var srcSquarePosition = srcSquareEl.offset();
-  var destSquareEl = $('#' + SQUARE_ELS_IDS[dest]);
-  var destSquarePosition = destSquareEl.offset();
-
-  // create the animated piece and absolutely position it
-  // over the source square
-  var animatedPieceId = createId();
-  $('body').append(buildPiece(piece, true, animatedPieceId));
-  var animatedPieceEl = $('#' + animatedPieceId);
-  animatedPieceEl.css({
-    display: '',
-    position: 'absolute',
-    top: srcSquarePosition.top,
-    left: srcSquarePosition.left
-  });
-
-  // remove original piece from source square
-  srcSquareEl.find('.' + CSS.piece).remove();
-
-  // on complete
-  var complete = function() {
-    // add the "real" piece to the destination square
-    destSquareEl.append(buildPiece(piece));
-
-    // remove the animated piece
-    animatedPieceEl.remove();
-
-    // run complete function
-    if (typeof completeFn === 'function') {
-      completeFn();
-    }
-  };
-
-  // animate the piece to the destination square
-  var opts = {
-    duration: cfg.moveSpeed,
-    complete: complete
+function offset(el) {  // From https://youmightnotneedjquery.com/.
+  let box = el.getBoundingClientRect();
+  let docElem = document.documentElement;
+  return {
+    top: box.top + window.pageYOffset - docElem.clientTop,
+    left: box.left + window.pageXOffset - docElem.clientLeft
   };
-  animatedPieceEl.animate(destSquarePosition, opts);
 }
 
-function animateSparePieceToSquare(piece, dest, completeFn) {
-  var srcOffset = $('#' + SPARE_PIECE_ELS_IDS[piece]).offset();
-  var destSquareEl = $('#' + SQUARE_ELS_IDS[dest]);
-  var destOffset = destSquareEl.offset();
-
-  // create the animate piece
-  var pieceId = createId();
-  $('body').append(buildPiece(piece, true, pieceId));
-  var animatedPieceEl = $('#' + pieceId);
-  animatedPieceEl.css({
-    display: '',
-    position: 'absolute',
-    left: srcOffset.left,
-    top: srcOffset.top
-  });
-
-  // on complete
-  var complete = function() {
-    // add the "real" piece to the destination square
-    destSquareEl.find('.' + CSS.piece).remove();
-    destSquareEl.append(buildPiece(piece));
-
-    // remove the animated piece
-    animatedPieceEl.remove();
-
-    // run complete function
-    if (typeof completeFn === 'function') {
-      completeFn();
-    }
-  };
-
-  // animate the piece to the destination square
-  var opts = {
-    duration: cfg.moveSpeed,
-    complete: complete
+function findSquarePosition(square) {
+  let s1 = square.split('');
+  var s1x = COLUMNS.indexOf(s1[0]);
+  var s1y = parseInt(s1[1], 10) - 1;
+  if (CURRENT_ORIENTATION === 'white') {
+    s1y = 7 - s1y;
+  }
+  return {
+    top: (s1y * 12.5) + '%',
+    left: (s1x * 12.5) + '%',
   };
-  animatedPieceEl.animate(destOffset, opts);
 }
 
 // execute an array of animations
 function doAnimations(a, oldPos, newPos) {
-  ANIMATION_HAPPENING = true;
-
-  var numFinished = 0;
-  function onFinish() {
-    numFinished++;
-
-    // exit if all the animations aren't finished
-    if (numFinished !== a.length) return;
-
-    drawPositionInstant();
-    ANIMATION_HAPPENING = false;
-
-    // run their onMoveEnd function
-    if (cfg.hasOwnProperty('onMoveEnd') === true &&
-      typeof cfg.onMoveEnd === 'function') {
-      cfg.onMoveEnd(deepCopy(oldPos), deepCopy(newPos));
-    }
-  }
+  let fadeout_pieces = [];
+  let fadein_pieces = [];
+  let move_pieces = [];
+  let squares_to_clear = [];
+  let squares_to_fill = {};
+  let removed_pieces = [];
 
   for (var i = 0; i < a.length; i++) {
     // clear a piece
     if (a[i].type === 'clear') {
-      $('#' + SQUARE_ELS_IDS[a[i].square] + ' .' + CSS.piece)
-        .fadeOut(cfg.trashSpeed, onFinish);
-    }
-
-    // add a piece (no spare pieces)
-    if (a[i].type === 'add' && cfg.sparePieces !== true) {
-      $('#' + SQUARE_ELS_IDS[a[i].square])
-        .append(buildPiece(a[i].piece, true))
-        .find('.' + CSS.piece)
-        .fadeIn(cfg.appearSpeed, onFinish);
+      let square = a[i].square;
+      let piece = PIECE_ON_SQUARE[square];
+      if (piece) {
+        fadeout_pieces.push(piece);
+        squares_to_clear.push(square);
+        removed_pieces.push(piece);
+      }
     }
 
-    // add a piece from a spare piece
-    if (a[i].type === 'add' && cfg.sparePieces === true) {
-      animateSparePieceToSquare(a[i].piece, a[i].square, onFinish);
+    // add a piece
+    if (a[i].type === 'add') {
+      let square = a[i].square;
+      let pos = findSquarePosition(square);
+      let piece = buildPiece(a[i].piece, true);
+      piece.style.left = pos.left;
+      piece.style.top = pos.top;
+      boardEl.append(piece);
+      squares_to_fill[square] = piece;
+      fadein_pieces.push(piece);
     }
 
     // move a piece
     if (a[i].type === 'move') {
-      animateSquareToSquare(a[i].source, a[i].destination, a[i].piece,
-        onFinish);
+      let piece = PIECE_ON_SQUARE[a[i].source];
+      move_pieces.push([piece, a[i].destination]);
+      squares_to_clear.push(a[i].source);
+      squares_to_fill[a[i].destination] = piece;
+
+      // This is O(n²), but OK.
+      let replaced_piece = PIECE_ON_SQUARE[a[i].destination];
+      if (replaced_piece && !a.some(e => e.type === 'move' && e.source === a[i].destination)) {
+        removed_pieces.push(replaced_piece);
+      }
     }
   }
+
+  for (const square of squares_to_clear) {
+    delete PIECE_ON_SQUARE[square];
+  }
+  for (const [square, piece] of Object.entries(squares_to_fill)) {
+    PIECE_ON_SQUARE[square] = piece;
+    piece.setAttribute('data-square', square);
+  }
+
+  var numFinished = 0;
+  function onFinish(e, opt_force) {
+    if (++numFinished === a.length) {
+      for (let piece of removed_pieces) {
+        piece.remove();
+      }
+
+      // run their onMoveEnd function
+      if (cfg.hasOwnProperty('onMoveEnd') &&
+        typeof cfg.onMoveEnd === 'function') {
+        cfg.onMoveEnd(deepCopy(oldPos), deepCopy(newPos));
+      }
+    }
+  }
+
+  fadein_pieces.forEach((piece) => {
+    piece.style.display = null;
+    piece.style.opacity = 1;
+    piece.animate(
+      [ { opacity: 0 }, { opacity: 1 } ],
+      { duration: cfg.appearSpeed }
+    ).addEventListener('finish', onFinish);
+  });
+  fadeout_pieces.forEach((piece) => {
+    piece.style.display = null;
+    piece.style.opacity = 0;
+    piece.animate(
+      [ { opacity: 1 }, { opacity: 0 } ],
+      { duration: cfg.trashSpeed }
+    ).addEventListener('finish', onFinish);
+  });
+  for (const [piece, destination] of move_pieces) {
+    // Move it to the end of the stack, which changes the implicit z-index
+    // so that it will go on top of any pieces it's replacing.
+    piece.remove();
+    boardEl.appendChild(piece);
+
+    let destSquarePosition = findSquarePosition(destination);
+    piece.animate(
+      [
+        { top: piece.style.top, left: piece.style.left },
+        { top: destSquarePosition.top, left: destSquarePosition.left }
+      ],
+      { duration: cfg.moveSpeed }
+    ).addEventListener('finish', onFinish);
+    piece.style.top = destSquarePosition.top;
+    piece.style.left = destSquarePosition.left;
+  }
 }
 
 // returns the distance between two squares
@@ -851,55 +673,26 @@ function squareDistance(s1, s2) {
   return yDelta;
 }
 
-// returns an array of closest squares from square
-function createRadius(square) {
-  var squares = [];
-
-  // calculate distance of all squares
-  for (var i = 0; i < 8; i++) {
-    for (var j = 0; j < 8; j++) {
-      var s = COLUMNS[i] + (j + 1);
-
-      // skip the square we're starting from
-      if (square === s) continue;
-
-      squares.push({
-        square: s,
-        distance: squareDistance(square, s)
-      });
-    }
-  }
-
-  // sort by distance
-  squares.sort(function(a, b) {
-    return a.distance - b.distance;
-  });
-
-  // just return the square code
-  var squares2 = [];
-  for (var i = 0; i < squares.length; i++) {
-    squares2.push(squares[i].square);
-  }
-
-  return squares2;
-}
-
 // returns the square of the closest instance of piece
 // returns false if no instance of piece is found in position
 function findClosestPiece(position, piece, square) {
-  // create array of closest squares from square
-  var closestSquares = createRadius(square);
-
-  // search through the position in order of distance for the piece
-  for (var i = 0; i < closestSquares.length; i++) {
-    var s = closestSquares[i];
+  let best_square = false;
+  let best_dist = 1e9;
+  for (var i = 0; i < COLUMNS.length; i++) {
+    for (var j = 1; j <= 8; j++) {
+      let other_square = COLUMNS[i] + j;
 
-    if (position.hasOwnProperty(s) === true && position[s] === piece) {
-      return s;
+      if (position[other_square] === piece && square != other_square) {
+        let dist = squareDistance(square, other_square);
+        if (dist < best_dist) {
+          best_square = other_square;
+          best_dist = dist;
+        }
+      }
     }
   }
 
-  return false;
+  return best_square;
 }
 
 // calculate an array of animations that need to happen in order to get
@@ -914,9 +707,9 @@ function calculateAnimations(pos1, pos2) {
 
   // remove pieces that are the same in both positions
   for (var i in pos2) {
-    if (pos2.hasOwnProperty(i) !== true) continue;
+    if (!pos2.hasOwnProperty(i)) continue;
 
-    if (pos1.hasOwnProperty(i) === true && pos1[i] === pos2[i]) {
+    if (pos1.hasOwnProperty(i) && pos1[i] === pos2[i]) {
       delete pos1[i];
       delete pos2[i];
     }
@@ -924,7 +717,7 @@ function calculateAnimations(pos1, pos2) {
 
   // find all the "move" animations
   for (var i in pos2) {
-    if (pos2.hasOwnProperty(i) !== true) continue;
+    if (!pos2.hasOwnProperty(i)) continue;
 
     var closestPiece = findClosestPiece(pos1, pos2[i], i);
     if (closestPiece !== false) {
@@ -943,7 +736,7 @@ function calculateAnimations(pos1, pos2) {
 
   // add pieces to pos2
   for (var i in pos2) {
-    if (pos2.hasOwnProperty(i) !== true) continue;
+    if (!pos2.hasOwnProperty(i)) continue;
 
     animations.push({
       type: 'add',
@@ -956,11 +749,11 @@ function calculateAnimations(pos1, pos2) {
 
   // clear pieces from pos1
   for (var i in pos1) {
-    if (pos1.hasOwnProperty(i) !== true) continue;
+    if (!pos1.hasOwnProperty(i)) continue;
 
     // do not clear a piece if it is on a square that is the result
     // of a "move", ie: a piece capture
-    if (squaresMovedTo.hasOwnProperty(i) === true) continue;
+    if (squaresMovedTo.hasOwnProperty(i)) continue;
 
     animations.push({
       type: 'clear',
@@ -980,30 +773,23 @@ function calculateAnimations(pos1, pos2) {
 
 function drawPositionInstant() {
   // clear the board
-  boardEl.find('.' + CSS.piece).remove();
+  boardEl.querySelectorAll('.' + CSS.piece).forEach((piece) => piece.remove());
 
   // add the pieces
-  for (var i in CURRENT_POSITION) {
-    if (CURRENT_POSITION.hasOwnProperty(i) !== true) continue;
-
-    $('#' + SQUARE_ELS_IDS[i]).append(buildPiece(CURRENT_POSITION[i]));
+  for (const [square, piece] of Object.entries(CURRENT_POSITION)) {
+    let pos = findSquarePosition(square);
+    let pieceEl = buildPiece(piece);
+    pieceEl.style.left = pos.left;
+    pieceEl.style.top = pos.top;
+    pieceEl.setAttribute('data-square', square);
+    boardEl.append(pieceEl);
+    PIECE_ON_SQUARE[square] = pieceEl;
   }
 }
 
 function drawBoard() {
-  boardEl.html(buildBoard(CURRENT_ORIENTATION));
+  boardEl.innerHTML = buildBoard(CURRENT_ORIENTATION);
   drawPositionInstant();
-
-  if (cfg.sparePieces === true) {
-    if (CURRENT_ORIENTATION === 'white') {
-      sparePiecesTopEl.html(buildSparePieces('black'));
-      sparePiecesBottomEl.html(buildSparePieces('white'));
-    }
-    else {
-      sparePiecesTopEl.html(buildSparePieces('white'));
-      sparePiecesBottomEl.html(buildSparePieces('black'));
-    }
-  }
 }
 
 // given a position and a set of moves, return a new position
@@ -1012,10 +798,10 @@ function calculatePositionFromMoves(position, moves) {
   position = deepCopy(position);
 
   for (var i in moves) {
-    if (moves.hasOwnProperty(i) !== true) continue;
+    if (!moves.hasOwnProperty(i)) continue;
 
     // skip the move if the position doesn't have a piece on the source square
-    if (position.hasOwnProperty(i) !== true) continue;
+    if (!position.hasOwnProperty(i)) continue;
 
     var piece = position[i];
     delete position[i];
@@ -1035,7 +821,7 @@ function setCurrentPosition(position) {
   if (oldFen === newFen) return;
 
   // run their onChange function
-  if (cfg.hasOwnProperty('onChange') === true &&
+  if (cfg.hasOwnProperty('onChange') &&
     typeof cfg.onChange === 'function') {
     cfg.onChange(oldPos, newPos);
   }
@@ -1044,52 +830,22 @@ function setCurrentPosition(position) {
   CURRENT_POSITION = position;
 }
 
-function isXYOnSquare(x, y) {
-  for (var i in SQUARE_ELS_OFFSETS) {
-    if (SQUARE_ELS_OFFSETS.hasOwnProperty(i) !== true) continue;
-
-    var s = SQUARE_ELS_OFFSETS[i];
-    if (x >= s.left && x < s.left + SQUARE_SIZE &&
-        y >= s.top && y < s.top + SQUARE_SIZE) {
-      return i;
-    }
-  }
-
-  return 'offboard';
-}
-
-// records the XY coords of every square into memory
-function captureSquareOffsets() {
-  SQUARE_ELS_OFFSETS = {};
-
-  for (var i in SQUARE_ELS_IDS) {
-    if (SQUARE_ELS_IDS.hasOwnProperty(i) !== true) continue;
-
-    SQUARE_ELS_OFFSETS[i] = $('#' + SQUARE_ELS_IDS[i]).offset();
-  }
-}
-
 function removeSquareHighlights() {
-  boardEl.find('.' + CSS.square)
-    .removeClass(CSS.highlight1 + ' ' + CSS.highlight2);
+  boardEl.querySelectorAll('.' + CSS.square).forEach((piece) => {
+    piece.classList.remove(CSS.highlight1);
+    piece.classList.remove(CSS.highlight2);
+  });
 }
 
 function snapbackDraggedPiece() {
-  // there is no "snapback" for spare pieces
-  if (DRAGGED_PIECE_SOURCE === 'spare') {
-    trashDraggedPiece();
-    return;
-  }
-
   removeSquareHighlights();
 
   // animation complete
   function complete() {
     drawPositionInstant();
-    draggedPieceEl.css('display', 'none');
 
     // run their onSnapbackEnd function
-    if (cfg.hasOwnProperty('onSnapbackEnd') === true &&
+    if (cfg.hasOwnProperty('onSnapbackEnd') &&
       typeof cfg.onSnapbackEnd === 'function') {
       cfg.onSnapbackEnd(DRAGGED_PIECE, DRAGGED_PIECE_SOURCE,
         deepCopy(CURRENT_POSITION), CURRENT_ORIENTATION);
@@ -1097,71 +853,71 @@ function snapbackDraggedPiece() {
   }
 
   // get source square position
-  var sourceSquarePosition =
-    $('#' + SQUARE_ELS_IDS[DRAGGED_PIECE_SOURCE]).offset();
+  var sourceSquarePosition = findSquarePosition(DRAGGED_PIECE_SOURCE);
 
   // animate the piece to the target square
-  var opts = {
-    duration: cfg.snapbackSpeed,
-    complete: complete
-  };
-  draggedPieceEl.animate(sourceSquarePosition, opts);
+  DRAGGED_PIECE.animate(
+    [
+      { top: DRAGGED_PIECE.style.top, left: DRAGGED_PIECE.style.left },
+      { top: sourceSquarePosition.top, left: sourceSquarePosition.left }
+    ],
+    { duration: cfg.snapbackSpeed }
+  ).addEventListener('finish', complete);
+  DRAGGED_PIECE.style.top = sourceSquarePosition.top;
+  DRAGGED_PIECE.style.left = sourceSquarePosition.left;
 
   // set state
   DRAGGING_A_PIECE = false;
 }
 
-function trashDraggedPiece() {
+function dropDraggedPieceOnSquare(square) {
   removeSquareHighlights();
-
-  // remove the source piece
-  var newPosition = deepCopy(CURRENT_POSITION);
-  delete newPosition[DRAGGED_PIECE_SOURCE];
-  setCurrentPosition(newPosition);
-
-  // redraw the position
-  drawPositionInstant();
-
-  // hide the dragged piece
-  draggedPieceEl.fadeOut(cfg.trashSpeed);
-
-  // set state
   DRAGGING_A_PIECE = false;
-}
 
-function dropDraggedPieceOnSquare(square) {
-  removeSquareHighlights();
+  if (DRAGGED_PIECE_SOURCE === square) {
+    // Nothing to do, but call onSnapEnd anyway
+    if (cfg.hasOwnProperty('onSnapEnd') && typeof cfg.onSnapEnd === 'function') {
+      cfg.onSnapEnd(DRAGGED_PIECE_SOURCE, square, DRAGGED_PIECE);
+    }
+    return;
+  }
 
   // update position
   var newPosition = deepCopy(CURRENT_POSITION);
+  newPosition[square] = newPosition[DRAGGED_PIECE_SOURCE];
   delete newPosition[DRAGGED_PIECE_SOURCE];
-  newPosition[square] = DRAGGED_PIECE;
   setCurrentPosition(newPosition);
 
+  delete PIECE_ON_SQUARE[DRAGGED_PIECE_SOURCE];
+  PIECE_ON_SQUARE[square] = DRAGGED_PIECE;
+  DRAGGED_PIECE.setAttribute('data-square', square);
+
   // get target square information
-  var targetSquarePosition = $('#' + SQUARE_ELS_IDS[square]).offset();
+  var targetSquarePosition = findSquarePosition(square);
 
   // animation complete
   var complete = function() {
     drawPositionInstant();
-    draggedPieceEl.css('display', 'none');
 
     // execute their onSnapEnd function
-    if (cfg.hasOwnProperty('onSnapEnd') === true &&
+    if (cfg.hasOwnProperty('onSnapEnd') &&
       typeof cfg.onSnapEnd === 'function') {
-      cfg.onSnapEnd(DRAGGED_PIECE_SOURCE, square, DRAGGED_PIECE);
+      requestAnimationFrame(() => {  // HACK: so that we don't add event handlers from the callback...
+        cfg.onSnapEnd(DRAGGED_PIECE_SOURCE, square, DRAGGED_PIECE);
+      });
     }
   };
 
   // snap the piece to the target square
-  var opts = {
-    duration: cfg.snapSpeed,
-    complete: complete
-  };
-  draggedPieceEl.animate(targetSquarePosition, opts);
-
-  // set state
-  DRAGGING_A_PIECE = false;
+  DRAGGED_PIECE.animate(
+    [
+      { top: DRAGGED_PIECE.style.top, left: DRAGGED_PIECE.style.left },
+      { top: targetSquarePosition.top, left: targetSquarePosition.left }
+    ],
+    { duration: cfg.snapSpeed }
+  ).addEventListener('finish', complete);
+  DRAGGED_PIECE.style.top = targetSquarePosition.top;
+  DRAGGED_PIECE.style.left = targetSquarePosition.left;
 }
 
 function beginDraggingPiece(source, piece, x, y) {
@@ -1175,58 +931,60 @@ function beginDraggingPiece(source, piece, x, y) {
 
   // set state
   DRAGGING_A_PIECE = true;
-  DRAGGED_PIECE = piece;
+  DRAGGED_PIECE = PIECE_ON_SQUARE[source];
   DRAGGED_PIECE_SOURCE = source;
+  DRAGGED_PIECE_LOCATION = source;
 
-  // if the piece came from spare pieces, location is offboard
-  if (source === 'spare') {
-    DRAGGED_PIECE_LOCATION = 'offboard';
-  }
-  else {
-    DRAGGED_PIECE_LOCATION = source;
-  }
+  // Move it to the end of the stack, which changes the implicit z-index
+  // so that it will go on top of any pieces it's replacing.
+  DRAGGED_PIECE.remove();
+  boardEl.appendChild(DRAGGED_PIECE);
 
-  // capture the x, y coords of all squares in memory
-  captureSquareOffsets();
+  // highlight the source square
+  let square = document.querySelector('.' + CSS.square + '[data-square="' + source + '"]');
+  square.classList.add(CSS.highlight1);
+}
 
-  // create the dragged piece
-  draggedPieceEl.attr('src', buildPieceImgSrc(piece))
-    .css({
-      display: '',
-      position: 'absolute',
-      left: x - (SQUARE_SIZE / 2),
-      top: y - (SQUARE_SIZE / 2)
-    });
+function findSquareFromEvent(pageX, pageY) {
+  let o = offset(boardEl);
+  let x = pageX - o.left;
+  let y = pageY - o.top;
 
-  if (source !== 'spare') {
-    // highlight the source square and hide the piece
-    $('#' + SQUARE_ELS_IDS[source]).addClass(CSS.highlight1)
-      .find('.' + CSS.piece).css('display', 'none');
+  let position = {
+    x: x,
+    y: y,
+    left: Math.floor(x * 8 / boardEl.getBoundingClientRect().width),
+    top: Math.floor(y * 8 / boardEl.getBoundingClientRect().width)
+  };
+  if (CURRENT_ORIENTATION === 'white') {
+    position.top = 7 - position.top;
   }
+  if (position.left >= 0 && position.left < 8 && position.top >= 0 && position.top < 8) {
+    position.square = COLUMNS[position.left] + (position.top + 1);
+  } else {
+    position.square = 'offboard';
+  }
+  return position;
 }
 
-function updateDraggedPiece(x, y) {
+function updateDraggedPiece(position) {
   // put the dragged piece over the mouse cursor
-  draggedPieceEl.css({
-    left: x - (SQUARE_SIZE / 2),
-    top: y - (SQUARE_SIZE / 2)
-  });
-
-  // get location
-  var location = isXYOnSquare(x, y);
+  DRAGGED_PIECE.style.left = 'calc(' + position.x + 'px - 6.25%)';
+  DRAGGED_PIECE.style.top = 'calc(' + position.y + 'px - 6.25%)';
 
   // do nothing if the location has not changed
-  if (location === DRAGGED_PIECE_LOCATION) return;
+  if (position === DRAGGED_PIECE_LOCATION) return;
 
   // remove highlight from previous square
-  if (validSquare(DRAGGED_PIECE_LOCATION) === true) {
-    $('#' + SQUARE_ELS_IDS[DRAGGED_PIECE_LOCATION])
-      .removeClass(CSS.highlight2);
+  if (validSquare(DRAGGED_PIECE_LOCATION)) {
+    document.querySelector('.' + CSS.square + '[data-square="' + DRAGGED_PIECE_LOCATION + '"]')
+      .classList.remove(CSS.highlight2);
   }
 
   // add highlight to new square
-  if (validSquare(location) === true) {
-    $('#' + SQUARE_ELS_IDS[location]).addClass(CSS.highlight2);
+  if (validSquare(position.square)) {
+    document.querySelector('.' + CSS.square + '[data-square="' + position.square + '"]')
+      .classList.add(CSS.highlight2);
   }
 
   // run onDragMove
@@ -1237,53 +995,39 @@ function updateDraggedPiece(x, y) {
   }
 
   // update state
-  DRAGGED_PIECE_LOCATION = location;
+  DRAGGED_PIECE_LOCATION = position.square;
 }
 
 function stopDraggedPiece(location) {
   // determine what the action should be
   var action = 'drop';
-  if (location === 'offboard' && cfg.dropOffBoard === 'snapback') {
+  if (location.square === 'offboard' && cfg.dropOffBoard === 'snapback') {
     action = 'snapback';
   }
-  if (location === 'offboard' && cfg.dropOffBoard === 'trash') {
-    action = 'trash';
-  }
 
   // run their onDrop function, which can potentially change the drop action
-  if (cfg.hasOwnProperty('onDrop') === true &&
+  if (cfg.hasOwnProperty('onDrop') &&
     typeof cfg.onDrop === 'function') {
     var newPosition = deepCopy(CURRENT_POSITION);
 
-    // source piece is a spare piece and position is off the board
-    //if (DRAGGED_PIECE_SOURCE === 'spare' && location === 'offboard') {...}
-    // position has not changed; do nothing
-
-    // source piece is a spare piece and position is on the board
-    if (DRAGGED_PIECE_SOURCE === 'spare' && validSquare(location) === true) {
-      // add the piece to the board
-      newPosition[location] = DRAGGED_PIECE;
-    }
-
-    // source piece was on the board and position is off the board
-    if (validSquare(DRAGGED_PIECE_SOURCE) === true && location === 'offboard') {
-      // remove the piece from the board
-      delete newPosition[DRAGGED_PIECE_SOURCE];
-    }
-
     // source piece was on the board and position is on the board
-    if (validSquare(DRAGGED_PIECE_SOURCE) === true &&
-      validSquare(location) === true) {
+    if (validSquare(DRAGGED_PIECE_SOURCE) &&
+      validSquare(location.square)) {
       // move the piece
       delete newPosition[DRAGGED_PIECE_SOURCE];
-      newPosition[location] = DRAGGED_PIECE;
+      newPosition[location.square] = DRAGGED_PIECE;
+      if (location.square !== DRAGGED_PIECE_SOURCE) {
+        PIECE_ON_SQUARE[location.square] = PIECE_ON_SQUARE[DRAGGED_PIECE_SOURCE];
+        DRAGGED_PIECE.setAttribute('data-square', location.square);
+        delete PIECE_ON_SQUARE[DRAGGED_PIECE_SOURCE];
+      }
     }
 
     var oldPosition = deepCopy(CURRENT_POSITION);
 
-    var result = cfg.onDrop(DRAGGED_PIECE_SOURCE, location, DRAGGED_PIECE,
+    var result = cfg.onDrop(DRAGGED_PIECE_SOURCE, location.square, DRAGGED_PIECE,
       newPosition, oldPosition, CURRENT_ORIENTATION);
-    if (result === 'snapback' || result === 'trash') {
+    if (result === 'snapback') {
       action = result;
     }
   }
@@ -1292,11 +1036,8 @@ function stopDraggedPiece(location) {
   if (action === 'snapback') {
     snapbackDraggedPiece();
   }
-  else if (action === 'trash') {
-    trashDraggedPiece();
-  }
   else if (action === 'drop') {
-    dropDraggedPieceOnSquare(location);
+    dropDraggedPieceOnSquare(location.square);
   }
 }
 
@@ -1323,11 +1064,8 @@ widget.config = function(arg1, arg2) {
 // remove the widget from the page
 widget.destroy = function() {
   // remove markup
-  containerEl.html('');
+  containerEl.innerHTML = '';
   draggedPieceEl.remove();
-
-  // remove event handlers
-  containerEl.unbind();
 };
 
 // shorthand method to get the current FEN
@@ -1364,7 +1102,7 @@ widget.move = function() {
     }
 
     // skip invalid arguments
-    if (validMove(arguments[i]) !== true) {
+    if (!validMove(arguments[i])) {
       error(2826, 'Invalid move passed to the move method.', arguments[i]);
       continue;
     }
@@ -1432,17 +1170,17 @@ widget.position = function(position, useAnimation) {
   }
 
   // convert FEN to position object
-  if (validFen(position) === true) {
+  if (validFen(position)) {
     position = fenToObj(position);
   }
 
   // validate position object
-  if (validPositionObject(position) !== true) {
+  if (!validPositionObject(position)) {
     error(6482, 'Invalid value passed to the position method.', position);
     return;
   }
 
-  if (useAnimation === true) {
+  if (useAnimation) {
     // start the animations
     doAnimations(calculateAnimations(CURRENT_POSITION, position),
       CURRENT_POSITION, position);
@@ -1458,24 +1196,6 @@ widget.position = function(position, useAnimation) {
 };
 
 widget.resize = function() {
-  // calulate the new square size
-  SQUARE_SIZE = calculateSquareSize();
-
-  // set board width
-  boardEl.css('width', (SQUARE_SIZE * 8) + 'px');
-
-  // set drag piece size
-  draggedPieceEl.css({
-    height: SQUARE_SIZE,
-    width: SQUARE_SIZE
-  });
-
-  // spare pieces
-  if (cfg.sparePieces === true) {
-    containerEl.find('.' + CSS.sparePieces)
-      .css('paddingLeft', (SQUARE_SIZE + BOARD_BORDER_SIZE) + 'px');
-  }
-
   // redraw the board
   drawBoard();
 };
@@ -1493,124 +1213,97 @@ function isTouchDevice() {
   return ('ontouchstart' in document.documentElement);
 }
 
-// reference: http://www.quirksmode.org/js/detect.html
-function isMSIE() {
-  return (navigator && navigator.userAgent &&
-      navigator.userAgent.search(/MSIE/) !== -1);
-}
-
-function stopDefault(e) {
-  e.preventDefault();
-}
-
 function mousedownSquare(e) {
-  // do nothing if we're not draggable
-  if (cfg.draggable !== true) return;
-
-  var square = $(this).attr('data-square');
+  let square = e.target.getAttribute('data-square');
 
   // no piece on this square
-  if (validSquare(square) !== true ||
-      CURRENT_POSITION.hasOwnProperty(square) !== true) {
+  if (!validSquare(square) ||
+      !CURRENT_POSITION.hasOwnProperty(square)) {
     return;
   }
 
+  // do nothing if we're not draggable
+  if (!cfg.draggable) return;
+
   beginDraggingPiece(square, CURRENT_POSITION[square], e.pageX, e.pageY);
 }
 
 function touchstartSquare(e) {
+  let target = e.target.closest('.' + CSS.square);
+  if (!target) {
+    return;
+  }
+
   // do nothing if we're not draggable
-  if (cfg.draggable !== true) return;
+  if (!cfg.draggable) return;
 
-  var square = $(this).attr('data-square');
+  var square = target.getAttribute('data-square');
 
   // no piece on this square
-  if (validSquare(square) !== true ||
-      CURRENT_POSITION.hasOwnProperty(square) !== true) {
+  if (!validSquare(square) ||
+      !CURRENT_POSITION.hasOwnProperty(square)) {
     return;
   }
 
-  e = e.originalEvent;
   beginDraggingPiece(square, CURRENT_POSITION[square],
     e.changedTouches[0].pageX, e.changedTouches[0].pageY);
 }
 
-function mousedownSparePiece(e) {
-  // do nothing if sparePieces is not enabled
-  if (cfg.sparePieces !== true) return;
-
-  var piece = $(this).attr('data-piece');
-
-  beginDraggingPiece('spare', piece, e.pageX, e.pageY);
-}
-
-function touchstartSparePiece(e) {
-  // do nothing if sparePieces is not enabled
-  if (cfg.sparePieces !== true) return;
-
-  var piece = $(this).attr('data-piece');
-
-  e = e.originalEvent;
-  beginDraggingPiece('spare', piece,
-    e.changedTouches[0].pageX, e.changedTouches[0].pageY);
-}
-
 function mousemoveWindow(e) {
   // do nothing if we are not dragging a piece
-  if (DRAGGING_A_PIECE !== true) return;
+  if (!DRAGGING_A_PIECE) return;
 
-  updateDraggedPiece(e.pageX, e.pageY);
+  updateDraggedPiece(findSquareFromEvent(e.pageX, e.pageY));
 }
 
 function touchmoveWindow(e) {
   // do nothing if we are not dragging a piece
-  if (DRAGGING_A_PIECE !== true) return;
+  if (!DRAGGING_A_PIECE) return;
 
   // prevent screen from scrolling
   e.preventDefault();
 
-  updateDraggedPiece(e.originalEvent.changedTouches[0].pageX,
-    e.originalEvent.changedTouches[0].pageY);
+  updateDraggedPiece(findSquareFromEvent(e.changedTouches[0].pageX,
+    e.changedTouches[0].pageY));
 }
 
 function mouseupWindow(e) {
   // do nothing if we are not dragging a piece
-  if (DRAGGING_A_PIECE !== true) return;
+  if (!DRAGGING_A_PIECE) return;
 
-  // get the location
-  var location = isXYOnSquare(e.pageX, e.pageY);
-
-  stopDraggedPiece(location);
+  stopDraggedPiece(findSquareFromEvent(e.pageX, e.pageY));
 }
 
 function touchendWindow(e) {
   // do nothing if we are not dragging a piece
-  if (DRAGGING_A_PIECE !== true) return;
-
-  // get the location
-  var location = isXYOnSquare(e.originalEvent.changedTouches[0].pageX,
-    e.originalEvent.changedTouches[0].pageY);
+  if (!DRAGGING_A_PIECE) return;
 
-  stopDraggedPiece(location);
+  stopDraggedPiece(findSquareFromEvent(e.changedTouches[0].pageX,
+    e.changedTouches[0].pageY));
 }
 
 function mouseenterSquare(e) {
+  let target = e.target.closest('.' + CSS.square);
+  if (!target) {
+    return;
+  }
+
   // do not fire this event if we are dragging a piece
   // NOTE: this should never happen, but it's a safeguard
   if (DRAGGING_A_PIECE !== false) return;
 
-  if (cfg.hasOwnProperty('onMouseoverSquare') !== true ||
+  if (!cfg.hasOwnProperty('onMouseoverSquare') ||
     typeof cfg.onMouseoverSquare !== 'function') return;
 
   // get the square
-  var square = $(e.currentTarget).attr('data-square');
+  var square = target.getAttribute('data-square');
 
   // NOTE: this should never happen; defensive
-  if (validSquare(square) !== true) return;
+  if (!validSquare(square)) return;
 
   // get the piece on this square
   var piece = false;
-  if (CURRENT_POSITION.hasOwnProperty(square) === true) {
+  if (CURRENT_POSITION.hasOwnProperty(square)) {
     piece = CURRENT_POSITION[square];
   }
 
@@ -1620,22 +1313,27 @@ function mouseenterSquare(e) {
 }
 
 function mouseleaveSquare(e) {
+  let target = e.target.closest('.' + CSS.square);
+  if (!target) {
+    return;
+  }
+
   // do not fire this event if we are dragging a piece
   // NOTE: this should never happen, but it's a safeguard
   if (DRAGGING_A_PIECE !== false) return;
 
-  if (cfg.hasOwnProperty('onMouseoutSquare') !== true ||
+  if (!cfg.hasOwnProperty('onMouseoutSquare') ||
     typeof cfg.onMouseoutSquare !== 'function') return;
 
   // get the square
-  var square = $(e.currentTarget).attr('data-square');
+  var square = target.getAttribute('data-square');
 
   // NOTE: this should never happen; defensive
-  if (validSquare(square) !== true) return;
+  if (!validSquare(square)) return;
 
   // get the piece on this square
   var piece = false;
-  if (CURRENT_POSITION.hasOwnProperty(square) === true) {
+  if (CURRENT_POSITION.hasOwnProperty(square)) {
     piece = CURRENT_POSITION[square];
   }
 
@@ -1650,69 +1348,43 @@ function mouseleaveSquare(e) {
 
 function addEvents() {
   // prevent browser "image drag"
-  $('body').on('mousedown mousemove', '.' + CSS.piece, stopDefault);
+  let stopDefault = (e) => {
+    if (e.target.matches('.' + CSS.piece)) {
+      e.preventDefault();
+    }
+  };
+  document.body.addEventListener('mousedown', stopDefault);
+  document.body.addEventListener('mousemove', stopDefault);
 
   // mouse drag pieces
-  boardEl.on('mousedown', '.' + CSS.square, mousedownSquare);
-  containerEl.on('mousedown', '.' + CSS.sparePieces + ' .' + CSS.piece,
-    mousedownSparePiece);
+  boardEl.addEventListener('mousedown', mousedownSquare);
 
   // mouse enter / leave square
-  boardEl.on('mouseenter', '.' + CSS.square, mouseenterSquare);
-  boardEl.on('mouseleave', '.' + CSS.square, mouseleaveSquare);
+  boardEl.addEventListener('mouseenter', mouseenterSquare);
+  boardEl.addEventListener('mouseleave', mouseleaveSquare);
 
-  // IE doesn't like the events on the window object, but other browsers
-  // perform better that way
-  if (isMSIE() === true) {
-    // IE-specific prevent browser "image drag"
-    document.ondragstart = function() { return false; };
-
-    $('body').on('mousemove', mousemoveWindow);
-    $('body').on('mouseup', mouseupWindow);
-  }
-  else {
-    $(window).on('mousemove', mousemoveWindow);
-    $(window).on('mouseup', mouseupWindow);
-  }
+  window.addEventListener('mousemove', mousemoveWindow);
+  window.addEventListener('mouseup', mouseupWindow);
 
   // touch drag pieces
-  if (isTouchDevice() === true) {
-    boardEl.on('touchstart', '.' + CSS.square, touchstartSquare);
-    containerEl.on('touchstart', '.' + CSS.sparePieces + ' .' + CSS.piece,
-      touchstartSparePiece);
-    $(window).on('touchmove', touchmoveWindow);
-    $(window).on('touchend', touchendWindow);
+  if (isTouchDevice()) {
+    boardEl.addEventListener('touchstart', touchstartSquare);
+    window.addEventListener('touchmove', touchmoveWindow);
+    window.addEventListener('touchend', touchendWindow);
   }
 }
 
 function initDom() {
   // build board and save it in memory
-  containerEl.html(buildBoardContainer());
-  boardEl = containerEl.find('.' + CSS.board);
-
-  if (cfg.sparePieces === true) {
-    sparePiecesTopEl = containerEl.find('.' + CSS.sparePiecesTop);
-    sparePiecesBottomEl = containerEl.find('.' + CSS.sparePiecesBottom);
-  }
-
-  // create the drag piece
-  var draggedPieceId = createId();
-  $('body').append(buildPiece('wP', true, draggedPieceId));
-  draggedPieceEl = $('#' + draggedPieceId);
-
-  // get the border size
-  BOARD_BORDER_SIZE = parseInt(boardEl.css('borderLeftWidth'), 10);
+  containerEl.innerHTML = buildBoardContainer();
+  boardEl = containerEl.querySelector('.' + CSS.board);
 
   // set the size and draw the board
   widget.resize();
 }
 
 function init() {
-  if (checkDeps() !== true ||
-      expandConfig() !== true) return;
-
-  // create unique IDs for all the elements we will create
-  createElIds();
+  if (!checkDeps() || !expandConfig()) return;
 
   initDom();
   addEvents();
diff --git a/www/js/chessboard-0.3.0.min.js b/www/js/chessboard-0.3.0.min.js
deleted file mode 100644 (file)
index 81a29a1..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*! chessboard.js v0.3.0 | (c) 2013 Chris Oakman | MIT License chessboardjs.com/license */
-(function(){function l(f){return"string"!==typeof f?!1:-1!==f.search(/^[a-h][1-8]$/)}function Q(f){if("string"!==typeof f)return!1;f=f.replace(/ .+$/,"");f=f.split("/");if(8!==f.length)return!1;for(var b=0;8>b;b++)if(""===f[b]||8<f[b].length||-1!==f[b].search(/[^kqrbnpKQRNBP1-8]/))return!1;return!0}function F(f){if("object"!==typeof f)return!1;for(var b in f)if(!0===f.hasOwnProperty(b)){var n;(n=!0!==l(b))||(n=f[b],n="string"!==typeof n?!1:-1!==n.search(/^[bw][KQRNBP]$/),n=!0!==n);if(n)return!1}return!0}
-function K(f){if(!0!==Q(f))return!1;f=f.replace(/ .+$/,"");f=f.split("/");for(var b={},n=8,m=0;8>m;m++){for(var l=f[m].split(""),r=0,w=0;w<l.length;w++)if(-1!==l[w].search(/[1-8]/))var I=parseInt(l[w],10),r=r+I;else{var I=b,F=B[r]+n,A;A=l[w];A=A.toLowerCase()===A?"b"+A.toUpperCase():"w"+A.toUpperCase();I[F]=A;r++}n--}return b}function L(f){if(!0!==F(f))return!1;for(var b="",n=8,m=0;8>m;m++){for(var l=0;8>l;l++){var r=B[l]+n;!0===f.hasOwnProperty(r)?(r=f[r].split(""),r="w"===r[0]?r[1].toUpperCase():
-r[1].toLowerCase(),b+=r):b+="1"}7!==m&&(b+="/");n--}b=b.replace(/11111111/g,"8");b=b.replace(/1111111/g,"7");b=b.replace(/111111/g,"6");b=b.replace(/11111/g,"5");b=b.replace(/1111/g,"4");b=b.replace(/111/g,"3");return b=b.replace(/11/g,"2")}var B="abcdefgh".split("");window.ChessBoard=window.ChessBoard||function(f,b){function n(){return"xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxx".replace(/x/g,function(a){return(16*Math.random()|0).toString(16)})}function m(a){return JSON.parse(JSON.stringify(a))}function X(a){a=
-a.split(".");return{major:parseInt(a[0],10),minor:parseInt(a[1],10),patch:parseInt(a[2],10)}}function r(a,e,c){if(!0===b.hasOwnProperty("showErrors")&&!1!==b.showErrors){var d="ChessBoard Error "+a+": "+e;"console"===b.showErrors&&"object"===typeof console&&"function"===typeof console.log?(console.log(d),2<=arguments.length&&console.log(c)):"alert"===b.showErrors?(c&&(d+="\n\n"+JSON.stringify(c)),window.alert(d)):"function"===typeof b.showErrors&&b.showErrors(a,e,c)}}function w(a){return"fast"===
-a||"slow"===a?!0:parseInt(a,10)+""!==a+""?!1:0<=a}function I(){for(var a=0;a<B.length;a++)for(var b=1;8>=b;b++){var c=B[a]+b;s[c]=c+"-"+n()}b="KQRBNP".split("");for(a=0;a<b.length;a++){var c="w"+b[a],d="b"+b[a];M[c]=c+"-"+n();M[d]=d+"-"+n()}}function ga(){var a='<div class="'+h.chessboard+'">';!0===b.sparePieces&&(a+='<div class="'+h.sparePieces+" "+h.sparePiecesTop+'"></div>');a+='<div class="'+h.board+'"></div>';!0===b.sparePieces&&(a+='<div class="'+h.sparePieces+" "+h.sparePiecesBottom+'"></div>');
-return a+"</div>"}function A(a){"black"!==a&&(a="white");var e="",c=m(B),d=8;"black"===a&&(c.reverse(),d=1);for(var C="white",f=0;8>f;f++){for(var e=e+('<div class="'+h.row+'">'),k=0;8>k;k++){var g=c[k]+d,e=e+('<div class="'+h.square+" "+h[C]+" square-"+g+'" style="width: '+p+"px; height: "+p+'px" id="'+s[g]+'" data-square="'+g+'">');if(!0===b.showNotation){if("white"===a&&1===d||"black"===a&&8===d)e+='<div class="'+h.notation+" "+h.alpha+'">'+c[k]+"</div>";0===k&&(e+='<div class="'+h.notation+" "+
-h.numeric+'">'+d+"</div>")}e+="</div>";C="white"===C?"black":"white"}e+='<div class="'+h.clearfix+'"></div></div>';C="white"===C?"black":"white";"white"===a?d--:d++}return e}function Y(a){if("function"===typeof b.pieceTheme)return b.pieceTheme(a);if("string"===typeof b.pieceTheme)return b.pieceTheme.replace(/{piece}/g,a);r(8272,"Unable to build image source for cfg.pieceTheme.");return""}function D(a,b,c){var d='<img src="'+Y(a)+'" ';c&&"string"===typeof c&&(d+='id="'+c+'" ');d+='alt="" class="'+
-h.piece+'" data-piece="'+a+'" style="width: '+p+"px;height: "+p+"px;";!0===b&&(d+="display:none;");return d+'" />'}function N(a){var b="wK wQ wR wB wN wP".split(" ");"black"===a&&(b="bK bQ bR bB bN bP".split(" "));a="";for(var c=0;c<b.length;c++)a+=D(b[c],!1,M[b[c]]);return a}function ha(a,e,c,d){a=$("#"+s[a]);var C=a.offset(),f=$("#"+s[e]);e=f.offset();var k=n();$("body").append(D(c,!0,k));var g=$("#"+k);g.css({display:"",position:"absolute",top:C.top,left:C.left});a.find("."+h.piece).remove();g.animate(e,
-{duration:b.moveSpeed,complete:function(){f.append(D(c));g.remove();"function"===typeof d&&d()}})}function ia(a,e,c){var d=$("#"+M[a]).offset(),f=$("#"+s[e]);e=f.offset();var g=n();$("body").append(D(a,!0,g));var k=$("#"+g);k.css({display:"",position:"absolute",left:d.left,top:d.top});k.animate(e,{duration:b.moveSpeed,complete:function(){f.find("."+h.piece).remove();f.append(D(a));k.remove();"function"===typeof c&&c()}})}function ja(a,e,c){function d(){f++;if(f===a.length&&(G(),!0===b.hasOwnProperty("onMoveEnd")&&
-"function"===typeof b.onMoveEnd))b.onMoveEnd(m(e),m(c))}for(var f=0,g=0;g<a.length;g++)"clear"===a[g].type&&$("#"+s[a[g].square]+" ."+h.piece).fadeOut(b.trashSpeed,d),"add"===a[g].type&&!0!==b.sparePieces&&$("#"+s[a[g].square]).append(D(a[g].piece,!0)).find("."+h.piece).fadeIn(b.appearSpeed,d),"add"===a[g].type&&!0===b.sparePieces&&ia(a[g].piece,a[g].square,d),"move"===a[g].type&&ha(a[g].source,a[g].destination,a[g].piece,d)}function ka(a,b){a=a.split("");var c=B.indexOf(a[0])+1,d=parseInt(a[1],10);
-b=b.split("");var g=B.indexOf(b[0])+1,f=parseInt(b[1],10),c=Math.abs(c-g),d=Math.abs(d-f);return c>=d?c:d}function la(a){for(var b=[],c=0;8>c;c++)for(var d=0;8>d;d++){var g=B[c]+(d+1);a!==g&&b.push({square:g,distance:ka(a,g)})}b.sort(function(a,b){return a.distance-b.distance});a=[];for(c=0;c<b.length;c++)a.push(b[c].square);return a}function G(){x.find("."+h.piece).remove();for(var a in g)!0===g.hasOwnProperty(a)&&$("#"+s[a]).append(D(g[a]))}function R(){x.html(A(u));G();!0===b.sparePieces&&("white"===
-u?(S.html(N("black")),T.html(N("white"))):(S.html(N("white")),T.html(N("black"))))}function O(a){var e=m(g),c=m(a),d=L(e),f=L(c);if(d!==f){if(!0===b.hasOwnProperty("onChange")&&"function"===typeof b.onChange)b.onChange(e,c);g=a}}function U(a,b){for(var c in J)if(!0===J.hasOwnProperty(c)){var d=J[c];if(a>=d.left&&a<d.left+p&&b>=d.top&&b<d.top+p)return c}return"offboard"}function V(){x.find("."+h.square).removeClass(h.highlight1+" "+h.highlight2)}function ma(){function a(){G();y.css("display","none");
-if(!0===b.hasOwnProperty("onSnapbackEnd")&&"function"===typeof b.onSnapbackEnd)b.onSnapbackEnd(E,t,m(g),u)}if("spare"===t)Z();else{V();var e=$("#"+s[t]).offset();y.animate(e,{duration:b.snapbackSpeed,complete:a});z=!1}}function Z(){V();var a=m(g);delete a[t];O(a);G();y.fadeOut(b.trashSpeed);z=!1}function na(a){V();var e=m(g);delete e[t];e[a]=E;O(e);e=$("#"+s[a]).offset();y.animate(e,{duration:b.snapSpeed,complete:function(){G();y.css("display","none");if(!0===b.hasOwnProperty("onSnapEnd")&&"function"===
-typeof b.onSnapEnd)b.onSnapEnd(t,a,E)}});z=!1}function P(a,e,c,d){if("function"!==typeof b.onDragStart||!1!==b.onDragStart(a,e,m(g),u)){z=!0;E=e;t=a;H="spare"===a?"offboard":a;J={};for(var f in s)!0===s.hasOwnProperty(f)&&(J[f]=$("#"+s[f]).offset());y.attr("src",Y(e)).css({display:"",position:"absolute",left:c-p/2,top:d-p/2});"spare"!==a&&$("#"+s[a]).addClass(h.highlight1).find("."+h.piece).css("display","none")}}function aa(a,e){y.css({left:a-p/2,top:e-p/2});var c=U(a,e);if(c!==H){!0===l(H)&&$("#"+
-s[H]).removeClass(h.highlight2);!0===l(c)&&$("#"+s[c]).addClass(h.highlight2);if("function"===typeof b.onDragMove)b.onDragMove(c,H,t,E,m(g),u);H=c}}function ba(a){var e="drop";"offboard"===a&&"snapback"===b.dropOffBoard&&(e="snapback");"offboard"===a&&"trash"===b.dropOffBoard&&(e="trash");if(!0===b.hasOwnProperty("onDrop")&&"function"===typeof b.onDrop){var c=m(g);"spare"===t&&!0===l(a)&&(c[a]=E);!0===l(t)&&"offboard"===a&&delete c[t];!0===l(t)&&!0===l(a)&&(delete c[t],c[a]=E);var d=m(g),c=b.onDrop(t,
-a,E,c,d,u);if("snapback"===c||"trash"===c)e=c}"snapback"===e?ma():"trash"===e?Z():"drop"===e&&na(a)}function oa(a){a.preventDefault()}function pa(a){if(!0===b.draggable){var e=$(this).attr("data-square");!0===l(e)&&!0===g.hasOwnProperty(e)&&P(e,g[e],a.pageX,a.pageY)}}function qa(a){if(!0===b.draggable){var e=$(this).attr("data-square");!0===l(e)&&!0===g.hasOwnProperty(e)&&(a=a.originalEvent,P(e,g[e],a.changedTouches[0].pageX,a.changedTouches[0].pageY))}}function ra(a){if(!0===b.sparePieces){var e=
-$(this).attr("data-piece");P("spare",e,a.pageX,a.pageY)}}function sa(a){if(!0===b.sparePieces){var e=$(this).attr("data-piece");a=a.originalEvent;P("spare",e,a.changedTouches[0].pageX,a.changedTouches[0].pageY)}}function ca(a){!0===z&&aa(a.pageX,a.pageY)}function ta(a){!0===z&&(a.preventDefault(),aa(a.originalEvent.changedTouches[0].pageX,a.originalEvent.changedTouches[0].pageY))}function da(a){!0===z&&(a=U(a.pageX,a.pageY),ba(a))}function ua(a){!0===z&&(a=U(a.originalEvent.changedTouches[0].pageX,
-a.originalEvent.changedTouches[0].pageY),ba(a))}function va(a){if(!1===z&&(!0===b.hasOwnProperty("onMouseoverSquare")&&"function"===typeof b.onMouseoverSquare)&&(a=$(a.currentTarget).attr("data-square"),!0===l(a))){var e=!1;!0===g.hasOwnProperty(a)&&(e=g[a]);b.onMouseoverSquare(a,e,m(g),u)}}function wa(a){if(!1===z&&(!0===b.hasOwnProperty("onMouseoutSquare")&&"function"===typeof b.onMouseoutSquare)&&(a=$(a.currentTarget).attr("data-square"),!0===l(a))){var e=!1;!0===g.hasOwnProperty(a)&&(e=g[a]);
-b.onMouseoutSquare(a,e,m(g),u)}}function xa(){$("body").on("mousedown mousemove","."+h.piece,oa);x.on("mousedown","."+h.square,pa);v.on("mousedown","."+h.sparePieces+" ."+h.piece,ra);x.on("mouseenter","."+h.square,va);x.on("mouseleave","."+h.square,wa);!0===(navigator&&navigator.userAgent&&-1!==navigator.userAgent.search(/MSIE/))?(document.ondragstart=function(){return!1},$("body").on("mousemove",ca),$("body").on("mouseup",da)):($(window).on("mousemove",ca),$(window).on("mouseup",da));!0==="ontouchstart"in
-document.documentElement&&(x.on("touchstart","."+h.square,qa),v.on("touchstart","."+h.sparePieces+" ."+h.piece,sa),$(window).on("touchmove",ta),$(window).on("touchend",ua))}function ya(){v.html(ga());x=v.find("."+h.board);!0===b.sparePieces&&(S=v.find("."+h.sparePiecesTop),T=v.find("."+h.sparePiecesBottom));var a=n();$("body").append(D("wP",!0,a));y=$("#"+a);ea=parseInt(x.css("borderLeftWidth"),10);q.resize()}b=b||{};var fa=K("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"),h={alpha:"alpha-d2270",black:"black-3c85d",
-board:"board-b72b1",chessboard:"chessboard-63f37",clearfix:"clearfix-7da63",highlight1:"highlight1-32417",highlight2:"highlight2-9c5d2",notation:"notation-322f9",numeric:"numeric-fc462",piece:"piece-417db",row:"row-5277c",sparePieces:"spare-pieces-7492f",sparePiecesBottom:"spare-pieces-bottom-ae20f",sparePiecesTop:"spare-pieces-top-4028b",square:"square-55d63",white:"white-1e1d7"},v,x,y,S,T,q={},ea=2,u="white",g={},p,E,H,t,z=!1,M={},s={},J;q.clear=function(a){q.position({},a)};q.destroy=function(){v.html("");
-y.remove();v.unbind()};q.fen=function(){return q.position("fen")};q.flip=function(){q.orientation("flip")};q.move=function(){if(0!==arguments.length){for(var a=!0,b={},c=0;c<arguments.length;c++)if(!1===arguments[c])a=!1;else{var d;d=arguments[c];"string"!==typeof d?d=!1:(d=d.split("-"),d=2!==d.length?!1:!0===l(d[0])&&!0===l(d[1]));!0!==d?r(2826,"Invalid move passed to the move method.",arguments[c]):(d=arguments[c].split("-"),b[d[0]]=d[1])}var c=g,c=m(c),f;for(f in b)!0===b.hasOwnProperty(f)&&!0===
-c.hasOwnProperty(f)&&(d=c[f],delete c[f],c[b[f]]=d);b=c;q.position(b,a);return b}};q.orientation=function(a){if(0===arguments.length)return u;"white"===a||"black"===a?(u=a,R()):"flip"===a?(u="white"===u?"black":"white",R()):r(5482,"Invalid value passed to the orientation method.",a)};q.position=function(a,b){if(0===arguments.length)return m(g);if("string"===typeof a&&"fen"===a.toLowerCase())return L(g);!1!==b&&(b=!0);"string"===typeof a&&"start"===a.toLowerCase()&&(a=m(fa));!0===Q(a)&&(a=K(a));if(!0!==
-F(a))r(6482,"Invalid value passed to the position method.",a);else if(!0===b){var c=g,d=a,c=m(c),d=m(d),f=[],h={},k;for(k in d)!0===d.hasOwnProperty(k)&&(!0===c.hasOwnProperty(k)&&c[k]===d[k])&&(delete c[k],delete d[k]);for(k in d)if(!0===d.hasOwnProperty(k)){var l;a:{l=c;for(var n=d[k],s=la(k),p=0;p<s.length;p++){var q=s[p];if(!0===l.hasOwnProperty(q)&&l[q]===n){l=q;break a}}l=!1}!1!==l&&(f.push({type:"move",source:l,destination:k,piece:d[k]}),delete c[l],delete d[k],h[k]=!0)}for(k in d)!0===d.hasOwnProperty(k)&&
-(f.push({type:"add",square:k,piece:d[k]}),delete d[k]);for(k in c)!0===c.hasOwnProperty(k)&&!0!==h.hasOwnProperty(k)&&(f.push({type:"clear",square:k,piece:c[k]}),delete c[k]);ja(f,g,a);O(a)}else O(a),G()};q.resize=function(){var a=parseInt(v.css("width"),10);if(!a||0>=a)p=0;else{for(a-=1;0!==a%8&&0<a;)a--;p=a/8}x.css("width",8*p+"px");y.css({height:p,width:p});!0===b.sparePieces&&v.find("."+h.sparePieces).css("paddingLeft",p+ea+"px");R()};q.start=function(a){q.position("start",a)};var W;if(W=!0===
-function(){if("string"===typeof f){if(""===f)return window.alert("ChessBoard Error 1001: The first argument to ChessBoard() cannot be an empty string.\n\nExiting..."),!1;var a=document.getElementById(f);if(!a)return window.alert('ChessBoard Error 1002: Element with id "'+f+'" does not exist in the DOM.\n\nExiting...'),!1;v=$(a)}else if(v=$(f),1!==v.length)return window.alert("ChessBoard Error 1003: The first argument to ChessBoard() must be an ID or a single DOM node.\n\nExiting..."),!1;if(!window.JSON||
-"function"!==typeof JSON.stringify||"function"!==typeof JSON.parse)return window.alert("ChessBoard Error 1004: JSON does not exist. Please include a JSON polyfill.\n\nExiting..."),!1;if(a=typeof window.$)if(a=$.fn)if(a=$.fn.jquery)var a=$.fn.jquery,b="1.7.0",a=X(a),b=X(b),a=!0===1E8*a.major+1E4*a.minor+a.patch>=1E8*b.major+1E4*b.minor+b.patch;return a?!0:(window.alert("ChessBoard Error 1005: Unable to find a valid version of jQuery. Please include jQuery 1.7.0 or higher on the page.\n\nExiting..."),
-!1)}()){if("string"===typeof b||!0===F(b))b={position:b};"black"!==b.orientation&&(b.orientation="white");u=b.orientation;!1!==b.showNotation&&(b.showNotation=!0);!0!==b.draggable&&(b.draggable=!1);"trash"!==b.dropOffBoard&&(b.dropOffBoard="snapback");!0!==b.sparePieces&&(b.sparePieces=!1);!0===b.sparePieces&&(b.draggable=!0);if(!0!==b.hasOwnProperty("pieceTheme")||"string"!==typeof b.pieceTheme&&"function"!==typeof b.pieceTheme)b.pieceTheme="img/chesspieces/wikipedia/{piece}.png";if(!0!==b.hasOwnProperty("appearSpeed")||
-!0!==w(b.appearSpeed))b.appearSpeed=200;if(!0!==b.hasOwnProperty("moveSpeed")||!0!==w(b.moveSpeed))b.moveSpeed=200;if(!0!==b.hasOwnProperty("snapbackSpeed")||!0!==w(b.snapbackSpeed))b.snapbackSpeed=50;if(!0!==b.hasOwnProperty("snapSpeed")||!0!==w(b.snapSpeed))b.snapSpeed=25;if(!0!==b.hasOwnProperty("trashSpeed")||!0!==w(b.trashSpeed))b.trashSpeed=100;!0===b.hasOwnProperty("position")&&("start"===b.position?g=m(fa):!0===Q(b.position)?g=K(b.position):!0===F(b.position)?g=m(b.position):r(7263,"Invalid value passed to config.position.",
-b.position));W=!0}W&&(I(),ya(),xa());return q};window.ChessBoard.fenToObj=K;window.ChessBoard.objToFen=L})();
\ No newline at end of file
diff --git a/www/js/jquery-1.10.2.min.js b/www/js/jquery-1.10.2.min.js
deleted file mode 100644 (file)
index da41706..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-/*! jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
-//@ sourceMappingURL=jquery-1.10.2.min.map
-*/
-(function(e,t){var n,r,i=typeof t,o=e.location,a=e.document,s=a.documentElement,l=e.jQuery,u=e.$,c={},p=[],f="1.10.2",d=p.concat,h=p.push,g=p.slice,m=p.indexOf,y=c.toString,v=c.hasOwnProperty,b=f.trim,x=function(e,t){return new x.fn.init(e,t,r)},w=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,T=/\S+/g,C=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,N=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,k=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,E=/^[\],:{}\s]*$/,S=/(?:^|:|,)(?:\s*\[)+/g,A=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,j=/"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g,D=/^-ms-/,L=/-([\da-z])/gi,H=function(e,t){return t.toUpperCase()},q=function(e){(a.addEventListener||"load"===e.type||"complete"===a.readyState)&&(_(),x.ready())},_=function(){a.addEventListener?(a.removeEventListener("DOMContentLoaded",q,!1),e.removeEventListener("load",q,!1)):(a.detachEvent("onreadystatechange",q),e.detachEvent("onload",q))};x.fn=x.prototype={jquery:f,constructor:x,init:function(e,n,r){var i,o;if(!e)return this;if("string"==typeof e){if(i="<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3?[null,e,null]:N.exec(e),!i||!i[1]&&n)return!n||n.jquery?(n||r).find(e):this.constructor(n).find(e);if(i[1]){if(n=n instanceof x?n[0]:n,x.merge(this,x.parseHTML(i[1],n&&n.nodeType?n.ownerDocument||n:a,!0)),k.test(i[1])&&x.isPlainObject(n))for(i in n)x.isFunction(this[i])?this[i](n[i]):this.attr(i,n[i]);return this}if(o=a.getElementById(i[2]),o&&o.parentNode){if(o.id!==i[2])return r.find(e);this.length=1,this[0]=o}return this.context=a,this.selector=e,this}return e.nodeType?(this.context=this[0]=e,this.length=1,this):x.isFunction(e)?r.ready(e):(e.selector!==t&&(this.selector=e.selector,this.context=e.context),x.makeArray(e,this))},selector:"",length:0,toArray:function(){return g.call(this)},get:function(e){return null==e?this.toArray():0>e?this[this.length+e]:this[e]},pushStack:function(e){var t=x.merge(this.constructor(),e);return t.prevObject=this,t.context=this.context,t},each:function(e,t){return x.each(this,e,t)},ready:function(e){return x.ready.promise().done(e),this},slice:function(){return this.pushStack(g.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(0>e?t:0);return this.pushStack(n>=0&&t>n?[this[n]]:[])},map:function(e){return this.pushStack(x.map(this,function(t,n){return e.call(t,n,t)}))},end:function(){return this.prevObject||this.constructor(null)},push:h,sort:[].sort,splice:[].splice},x.fn.init.prototype=x.fn,x.extend=x.fn.extend=function(){var e,n,r,i,o,a,s=arguments[0]||{},l=1,u=arguments.length,c=!1;for("boolean"==typeof s&&(c=s,s=arguments[1]||{},l=2),"object"==typeof s||x.isFunction(s)||(s={}),u===l&&(s=this,--l);u>l;l++)if(null!=(o=arguments[l]))for(i in o)e=s[i],r=o[i],s!==r&&(c&&r&&(x.isPlainObject(r)||(n=x.isArray(r)))?(n?(n=!1,a=e&&x.isArray(e)?e:[]):a=e&&x.isPlainObject(e)?e:{},s[i]=x.extend(c,a,r)):r!==t&&(s[i]=r));return s},x.extend({expando:"jQuery"+(f+Math.random()).replace(/\D/g,""),noConflict:function(t){return e.$===x&&(e.$=u),t&&e.jQuery===x&&(e.jQuery=l),x},isReady:!1,readyWait:1,holdReady:function(e){e?x.readyWait++:x.ready(!0)},ready:function(e){if(e===!0?!--x.readyWait:!x.isReady){if(!a.body)return setTimeout(x.ready);x.isReady=!0,e!==!0&&--x.readyWait>0||(n.resolveWith(a,[x]),x.fn.trigger&&x(a).trigger("ready").off("ready"))}},isFunction:function(e){return"function"===x.type(e)},isArray:Array.isArray||function(e){return"array"===x.type(e)},isWindow:function(e){return null!=e&&e==e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?c[y.call(e)]||"object":typeof e},isPlainObject:function(e){var n;if(!e||"object"!==x.type(e)||e.nodeType||x.isWindow(e))return!1;try{if(e.constructor&&!v.call(e,"constructor")&&!v.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(r){return!1}if(x.support.ownLast)for(n in e)return v.call(e,n);for(n in e);return n===t||v.call(e,n)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},error:function(e){throw Error(e)},parseHTML:function(e,t,n){if(!e||"string"!=typeof e)return null;"boolean"==typeof t&&(n=t,t=!1),t=t||a;var r=k.exec(e),i=!n&&[];return r?[t.createElement(r[1])]:(r=x.buildFragment([e],t,i),i&&x(i).remove(),x.merge([],r.childNodes))},parseJSON:function(n){return e.JSON&&e.JSON.parse?e.JSON.parse(n):null===n?n:"string"==typeof n&&(n=x.trim(n),n&&E.test(n.replace(A,"@").replace(j,"]").replace(S,"")))?Function("return "+n)():(x.error("Invalid JSON: "+n),t)},parseXML:function(n){var r,i;if(!n||"string"!=typeof n)return null;try{e.DOMParser?(i=new DOMParser,r=i.parseFromString(n,"text/xml")):(r=new ActiveXObject("Microsoft.XMLDOM"),r.async="false",r.loadXML(n))}catch(o){r=t}return r&&r.documentElement&&!r.getElementsByTagName("parsererror").length||x.error("Invalid XML: "+n),r},noop:function(){},globalEval:function(t){t&&x.trim(t)&&(e.execScript||function(t){e.eval.call(e,t)})(t)},camelCase:function(e){return e.replace(D,"ms-").replace(L,H)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,t,n){var r,i=0,o=e.length,a=M(e);if(n){if(a){for(;o>i;i++)if(r=t.apply(e[i],n),r===!1)break}else for(i in e)if(r=t.apply(e[i],n),r===!1)break}else if(a){for(;o>i;i++)if(r=t.call(e[i],i,e[i]),r===!1)break}else for(i in e)if(r=t.call(e[i],i,e[i]),r===!1)break;return e},trim:b&&!b.call("\ufeff\u00a0")?function(e){return null==e?"":b.call(e)}:function(e){return null==e?"":(e+"").replace(C,"")},makeArray:function(e,t){var n=t||[];return null!=e&&(M(Object(e))?x.merge(n,"string"==typeof e?[e]:e):h.call(n,e)),n},inArray:function(e,t,n){var r;if(t){if(m)return m.call(t,e,n);for(r=t.length,n=n?0>n?Math.max(0,r+n):n:0;r>n;n++)if(n in t&&t[n]===e)return n}return-1},merge:function(e,n){var r=n.length,i=e.length,o=0;if("number"==typeof r)for(;r>o;o++)e[i++]=n[o];else while(n[o]!==t)e[i++]=n[o++];return e.length=i,e},grep:function(e,t,n){var r,i=[],o=0,a=e.length;for(n=!!n;a>o;o++)r=!!t(e[o],o),n!==r&&i.push(e[o]);return i},map:function(e,t,n){var r,i=0,o=e.length,a=M(e),s=[];if(a)for(;o>i;i++)r=t(e[i],i,n),null!=r&&(s[s.length]=r);else for(i in e)r=t(e[i],i,n),null!=r&&(s[s.length]=r);return d.apply([],s)},guid:1,proxy:function(e,n){var r,i,o;return"string"==typeof n&&(o=e[n],n=e,e=o),x.isFunction(e)?(r=g.call(arguments,2),i=function(){return e.apply(n||this,r.concat(g.call(arguments)))},i.guid=e.guid=e.guid||x.guid++,i):t},access:function(e,n,r,i,o,a,s){var l=0,u=e.length,c=null==r;if("object"===x.type(r)){o=!0;for(l in r)x.access(e,n,l,r[l],!0,a,s)}else if(i!==t&&(o=!0,x.isFunction(i)||(s=!0),c&&(s?(n.call(e,i),n=null):(c=n,n=function(e,t,n){return c.call(x(e),n)})),n))for(;u>l;l++)n(e[l],r,s?i:i.call(e[l],l,n(e[l],r)));return o?e:c?n.call(e):u?n(e[0],r):a},now:function(){return(new Date).getTime()},swap:function(e,t,n,r){var i,o,a={};for(o in t)a[o]=e.style[o],e.style[o]=t[o];i=n.apply(e,r||[]);for(o in t)e.style[o]=a[o];return i}}),x.ready.promise=function(t){if(!n)if(n=x.Deferred(),"complete"===a.readyState)setTimeout(x.ready);else if(a.addEventListener)a.addEventListener("DOMContentLoaded",q,!1),e.addEventListener("load",q,!1);else{a.attachEvent("onreadystatechange",q),e.attachEvent("onload",q);var r=!1;try{r=null==e.frameElement&&a.documentElement}catch(i){}r&&r.doScroll&&function o(){if(!x.isReady){try{r.doScroll("left")}catch(e){return setTimeout(o,50)}_(),x.ready()}}()}return n.promise(t)},x.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(e,t){c["[object "+t+"]"]=t.toLowerCase()});function M(e){var t=e.length,n=x.type(e);return x.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}r=x(a),function(e,t){var n,r,i,o,a,s,l,u,c,p,f,d,h,g,m,y,v,b="sizzle"+-new Date,w=e.document,T=0,C=0,N=st(),k=st(),E=st(),S=!1,A=function(e,t){return e===t?(S=!0,0):0},j=typeof t,D=1<<31,L={}.hasOwnProperty,H=[],q=H.pop,_=H.push,M=H.push,O=H.slice,F=H.indexOf||function(e){var t=0,n=this.length;for(;n>t;t++)if(this[t]===e)return t;return-1},B="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",P="[\\x20\\t\\r\\n\\f]",R="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",W=R.replace("w","w#"),$="\\["+P+"*("+R+")"+P+"*(?:([*^$|!~]?=)"+P+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+W+")|)|)"+P+"*\\]",I=":("+R+")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|"+$.replace(3,8)+")*)|.*)\\)|)",z=RegExp("^"+P+"+|((?:^|[^\\\\])(?:\\\\.)*)"+P+"+$","g"),X=RegExp("^"+P+"*,"+P+"*"),U=RegExp("^"+P+"*([>+~]|"+P+")"+P+"*"),V=RegExp(P+"*[+~]"),Y=RegExp("="+P+"*([^\\]'\"]*)"+P+"*\\]","g"),J=RegExp(I),G=RegExp("^"+W+"$"),Q={ID:RegExp("^#("+R+")"),CLASS:RegExp("^\\.("+R+")"),TAG:RegExp("^("+R.replace("w","w*")+")"),ATTR:RegExp("^"+$),PSEUDO:RegExp("^"+I),CHILD:RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+P+"*(even|odd|(([+-]|)(\\d*)n|)"+P+"*(?:([+-]|)"+P+"*(\\d+)|))"+P+"*\\)|)","i"),bool:RegExp("^(?:"+B+")$","i"),needsContext:RegExp("^"+P+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+P+"*((?:-\\d)?\\d*)"+P+"*\\)|)(?=[^-]|$)","i")},K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,et=/^(?:input|select|textarea|button)$/i,tt=/^h\d$/i,nt=/'|\\/g,rt=RegExp("\\\\([\\da-f]{1,6}"+P+"?|("+P+")|.)","ig"),it=function(e,t,n){var r="0x"+t-65536;return r!==r||n?t:0>r?String.fromCharCode(r+65536):String.fromCharCode(55296|r>>10,56320|1023&r)};try{M.apply(H=O.call(w.childNodes),w.childNodes),H[w.childNodes.length].nodeType}catch(ot){M={apply:H.length?function(e,t){_.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function at(e,t,n,i){var o,a,s,l,u,c,d,m,y,x;if((t?t.ownerDocument||t:w)!==f&&p(t),t=t||f,n=n||[],!e||"string"!=typeof e)return n;if(1!==(l=t.nodeType)&&9!==l)return[];if(h&&!i){if(o=Z.exec(e))if(s=o[1]){if(9===l){if(a=t.getElementById(s),!a||!a.parentNode)return n;if(a.id===s)return n.push(a),n}else if(t.ownerDocument&&(a=t.ownerDocument.getElementById(s))&&v(t,a)&&a.id===s)return n.push(a),n}else{if(o[2])return M.apply(n,t.getElementsByTagName(e)),n;if((s=o[3])&&r.getElementsByClassName&&t.getElementsByClassName)return M.apply(n,t.getElementsByClassName(s)),n}if(r.qsa&&(!g||!g.test(e))){if(m=d=b,y=t,x=9===l&&e,1===l&&"object"!==t.nodeName.toLowerCase()){c=mt(e),(d=t.getAttribute("id"))?m=d.replace(nt,"\\$&"):t.setAttribute("id",m),m="[id='"+m+"'] ",u=c.length;while(u--)c[u]=m+yt(c[u]);y=V.test(e)&&t.parentNode||t,x=c.join(",")}if(x)try{return M.apply(n,y.querySelectorAll(x)),n}catch(T){}finally{d||t.removeAttribute("id")}}}return kt(e.replace(z,"$1"),t,n,i)}function st(){var e=[];function t(n,r){return e.push(n+=" ")>o.cacheLength&&delete t[e.shift()],t[n]=r}return t}function lt(e){return e[b]=!0,e}function ut(e){var t=f.createElement("div");try{return!!e(t)}catch(n){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function ct(e,t){var n=e.split("|"),r=e.length;while(r--)o.attrHandle[n[r]]=t}function pt(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&(~t.sourceIndex||D)-(~e.sourceIndex||D);if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function ft(e){return function(t){var n=t.nodeName.toLowerCase();return"input"===n&&t.type===e}}function dt(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function ht(e){return lt(function(t){return t=+t,lt(function(n,r){var i,o=e([],n.length,t),a=o.length;while(a--)n[i=o[a]]&&(n[i]=!(r[i]=n[i]))})})}s=at.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?"HTML"!==t.nodeName:!1},r=at.support={},p=at.setDocument=function(e){var n=e?e.ownerDocument||e:w,i=n.defaultView;return n!==f&&9===n.nodeType&&n.documentElement?(f=n,d=n.documentElement,h=!s(n),i&&i.attachEvent&&i!==i.top&&i.attachEvent("onbeforeunload",function(){p()}),r.attributes=ut(function(e){return e.className="i",!e.getAttribute("className")}),r.getElementsByTagName=ut(function(e){return e.appendChild(n.createComment("")),!e.getElementsByTagName("*").length}),r.getElementsByClassName=ut(function(e){return e.innerHTML="<div class='a'></div><div class='a i'></div>",e.firstChild.className="i",2===e.getElementsByClassName("i").length}),r.getById=ut(function(e){return d.appendChild(e).id=b,!n.getElementsByName||!n.getElementsByName(b).length}),r.getById?(o.find.ID=function(e,t){if(typeof t.getElementById!==j&&h){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},o.filter.ID=function(e){var t=e.replace(rt,it);return function(e){return e.getAttribute("id")===t}}):(delete o.find.ID,o.filter.ID=function(e){var t=e.replace(rt,it);return function(e){var n=typeof e.getAttributeNode!==j&&e.getAttributeNode("id");return n&&n.value===t}}),o.find.TAG=r.getElementsByTagName?function(e,n){return typeof n.getElementsByTagName!==j?n.getElementsByTagName(e):t}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},o.find.CLASS=r.getElementsByClassName&&function(e,n){return typeof n.getElementsByClassName!==j&&h?n.getElementsByClassName(e):t},m=[],g=[],(r.qsa=K.test(n.querySelectorAll))&&(ut(function(e){e.innerHTML="<select><option selected=''></option></select>",e.querySelectorAll("[selected]").length||g.push("\\["+P+"*(?:value|"+B+")"),e.querySelectorAll(":checked").length||g.push(":checked")}),ut(function(e){var t=n.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("t",""),e.querySelectorAll("[t^='']").length&&g.push("[*^$]="+P+"*(?:''|\"\")"),e.querySelectorAll(":enabled").length||g.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),g.push(",.*:")})),(r.matchesSelector=K.test(y=d.webkitMatchesSelector||d.mozMatchesSelector||d.oMatchesSelector||d.msMatchesSelector))&&ut(function(e){r.disconnectedMatch=y.call(e,"div"),y.call(e,"[s!='']:x"),m.push("!=",I)}),g=g.length&&RegExp(g.join("|")),m=m.length&&RegExp(m.join("|")),v=K.test(d.contains)||d.compareDocumentPosition?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},A=d.compareDocumentPosition?function(e,t){if(e===t)return S=!0,0;var i=t.compareDocumentPosition&&e.compareDocumentPosition&&e.compareDocumentPosition(t);return i?1&i||!r.sortDetached&&t.compareDocumentPosition(e)===i?e===n||v(w,e)?-1:t===n||v(w,t)?1:c?F.call(c,e)-F.call(c,t):0:4&i?-1:1:e.compareDocumentPosition?-1:1}:function(e,t){var r,i=0,o=e.parentNode,a=t.parentNode,s=[e],l=[t];if(e===t)return S=!0,0;if(!o||!a)return e===n?-1:t===n?1:o?-1:a?1:c?F.call(c,e)-F.call(c,t):0;if(o===a)return pt(e,t);r=e;while(r=r.parentNode)s.unshift(r);r=t;while(r=r.parentNode)l.unshift(r);while(s[i]===l[i])i++;return i?pt(s[i],l[i]):s[i]===w?-1:l[i]===w?1:0},n):f},at.matches=function(e,t){return at(e,null,null,t)},at.matchesSelector=function(e,t){if((e.ownerDocument||e)!==f&&p(e),t=t.replace(Y,"='$1']"),!(!r.matchesSelector||!h||m&&m.test(t)||g&&g.test(t)))try{var n=y.call(e,t);if(n||r.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(i){}return at(t,f,null,[e]).length>0},at.contains=function(e,t){return(e.ownerDocument||e)!==f&&p(e),v(e,t)},at.attr=function(e,n){(e.ownerDocument||e)!==f&&p(e);var i=o.attrHandle[n.toLowerCase()],a=i&&L.call(o.attrHandle,n.toLowerCase())?i(e,n,!h):t;return a===t?r.attributes||!h?e.getAttribute(n):(a=e.getAttributeNode(n))&&a.specified?a.value:null:a},at.error=function(e){throw Error("Syntax error, unrecognized expression: "+e)},at.uniqueSort=function(e){var t,n=[],i=0,o=0;if(S=!r.detectDuplicates,c=!r.sortStable&&e.slice(0),e.sort(A),S){while(t=e[o++])t===e[o]&&(i=n.push(o));while(i--)e.splice(n[i],1)}return e},a=at.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=a(e)}else if(3===i||4===i)return e.nodeValue}else for(;t=e[r];r++)n+=a(t);return n},o=at.selectors={cacheLength:50,createPseudo:lt,match:Q,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(rt,it),e[3]=(e[4]||e[5]||"").replace(rt,it),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||at.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&at.error(e[0]),e},PSEUDO:function(e){var n,r=!e[5]&&e[2];return Q.CHILD.test(e[0])?null:(e[3]&&e[4]!==t?e[2]=e[4]:r&&J.test(r)&&(n=mt(r,!0))&&(n=r.indexOf(")",r.length-n)-r.length)&&(e[0]=e[0].slice(0,n),e[2]=r.slice(0,n)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(rt,it).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=N[e+" "];return t||(t=RegExp("(^|"+P+")"+e+"("+P+"|$)"))&&N(e,function(e){return t.test("string"==typeof e.className&&e.className||typeof e.getAttribute!==j&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=at.attr(r,e);return null==i?"!="===t:t?(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i+" ").indexOf(n)>-1:"|="===t?i===n||i.slice(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),a="last"!==e.slice(-4),s="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,l){var u,c,p,f,d,h,g=o!==a?"nextSibling":"previousSibling",m=t.parentNode,y=s&&t.nodeName.toLowerCase(),v=!l&&!s;if(m){if(o){while(g){p=t;while(p=p[g])if(s?p.nodeName.toLowerCase()===y:1===p.nodeType)return!1;h=g="only"===e&&!h&&"nextSibling"}return!0}if(h=[a?m.firstChild:m.lastChild],a&&v){c=m[b]||(m[b]={}),u=c[e]||[],d=u[0]===T&&u[1],f=u[0]===T&&u[2],p=d&&m.childNodes[d];while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if(1===p.nodeType&&++f&&p===t){c[e]=[T,d,f];break}}else if(v&&(u=(t[b]||(t[b]={}))[e])&&u[0]===T)f=u[1];else while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if((s?p.nodeName.toLowerCase()===y:1===p.nodeType)&&++f&&(v&&((p[b]||(p[b]={}))[e]=[T,f]),p===t))break;return f-=i,f===r||0===f%r&&f/r>=0}}},PSEUDO:function(e,t){var n,r=o.pseudos[e]||o.setFilters[e.toLowerCase()]||at.error("unsupported pseudo: "+e);return r[b]?r(t):r.length>1?(n=[e,e,"",t],o.setFilters.hasOwnProperty(e.toLowerCase())?lt(function(e,n){var i,o=r(e,t),a=o.length;while(a--)i=F.call(e,o[a]),e[i]=!(n[i]=o[a])}):function(e){return r(e,0,n)}):r}},pseudos:{not:lt(function(e){var t=[],n=[],r=l(e.replace(z,"$1"));return r[b]?lt(function(e,t,n,i){var o,a=r(e,null,i,[]),s=e.length;while(s--)(o=a[s])&&(e[s]=!(t[s]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),!n.pop()}}),has:lt(function(e){return function(t){return at(e,t).length>0}}),contains:lt(function(e){return function(t){return(t.textContent||t.innerText||a(t)).indexOf(e)>-1}}),lang:lt(function(e){return G.test(e||"")||at.error("unsupported lang: "+e),e=e.replace(rt,it).toLowerCase(),function(t){var n;do if(n=h?t.lang:t.getAttribute("xml:lang")||t.getAttribute("lang"))return n=n.toLowerCase(),n===e||0===n.indexOf(e+"-");while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===d},focus:function(e){return e===f.activeElement&&(!f.hasFocus||f.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeName>"@"||3===e.nodeType||4===e.nodeType)return!1;return!0},parent:function(e){return!o.pseudos.empty(e)},header:function(e){return tt.test(e.nodeName)},input:function(e){return et.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||t.toLowerCase()===e.type)},first:ht(function(){return[0]}),last:ht(function(e,t){return[t-1]}),eq:ht(function(e,t,n){return[0>n?n+t:n]}),even:ht(function(e,t){var n=0;for(;t>n;n+=2)e.push(n);return e}),odd:ht(function(e,t){var n=1;for(;t>n;n+=2)e.push(n);return e}),lt:ht(function(e,t,n){var r=0>n?n+t:n;for(;--r>=0;)e.push(r);return e}),gt:ht(function(e,t,n){var r=0>n?n+t:n;for(;t>++r;)e.push(r);return e})}},o.pseudos.nth=o.pseudos.eq;for(n in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})o.pseudos[n]=ft(n);for(n in{submit:!0,reset:!0})o.pseudos[n]=dt(n);function gt(){}gt.prototype=o.filters=o.pseudos,o.setFilters=new gt;function mt(e,t){var n,r,i,a,s,l,u,c=k[e+" "];if(c)return t?0:c.slice(0);s=e,l=[],u=o.preFilter;while(s){(!n||(r=X.exec(s)))&&(r&&(s=s.slice(r[0].length)||s),l.push(i=[])),n=!1,(r=U.exec(s))&&(n=r.shift(),i.push({value:n,type:r[0].replace(z," ")}),s=s.slice(n.length));for(a in o.filter)!(r=Q[a].exec(s))||u[a]&&!(r=u[a](r))||(n=r.shift(),i.push({value:n,type:a,matches:r}),s=s.slice(n.length));if(!n)break}return t?s.length:s?at.error(e):k(e,l).slice(0)}function yt(e){var t=0,n=e.length,r="";for(;n>t;t++)r+=e[t].value;return r}function vt(e,t,n){var r=t.dir,o=n&&"parentNode"===r,a=C++;return t.first?function(t,n,i){while(t=t[r])if(1===t.nodeType||o)return e(t,n,i)}:function(t,n,s){var l,u,c,p=T+" "+a;if(s){while(t=t[r])if((1===t.nodeType||o)&&e(t,n,s))return!0}else while(t=t[r])if(1===t.nodeType||o)if(c=t[b]||(t[b]={}),(u=c[r])&&u[0]===p){if((l=u[1])===!0||l===i)return l===!0}else if(u=c[r]=[p],u[1]=e(t,n,s)||i,u[1]===!0)return!0}}function bt(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function xt(e,t,n,r,i){var o,a=[],s=0,l=e.length,u=null!=t;for(;l>s;s++)(o=e[s])&&(!n||n(o,r,i))&&(a.push(o),u&&t.push(s));return a}function wt(e,t,n,r,i,o){return r&&!r[b]&&(r=wt(r)),i&&!i[b]&&(i=wt(i,o)),lt(function(o,a,s,l){var u,c,p,f=[],d=[],h=a.length,g=o||Nt(t||"*",s.nodeType?[s]:s,[]),m=!e||!o&&t?g:xt(g,f,e,s,l),y=n?i||(o?e:h||r)?[]:a:m;if(n&&n(m,y,s,l),r){u=xt(y,d),r(u,[],s,l),c=u.length;while(c--)(p=u[c])&&(y[d[c]]=!(m[d[c]]=p))}if(o){if(i||e){if(i){u=[],c=y.length;while(c--)(p=y[c])&&u.push(m[c]=p);i(null,y=[],u,l)}c=y.length;while(c--)(p=y[c])&&(u=i?F.call(o,p):f[c])>-1&&(o[u]=!(a[u]=p))}}else y=xt(y===a?y.splice(h,y.length):y),i?i(null,a,y,l):M.apply(a,y)})}function Tt(e){var t,n,r,i=e.length,a=o.relative[e[0].type],s=a||o.relative[" "],l=a?1:0,c=vt(function(e){return e===t},s,!0),p=vt(function(e){return F.call(t,e)>-1},s,!0),f=[function(e,n,r){return!a&&(r||n!==u)||((t=n).nodeType?c(e,n,r):p(e,n,r))}];for(;i>l;l++)if(n=o.relative[e[l].type])f=[vt(bt(f),n)];else{if(n=o.filter[e[l].type].apply(null,e[l].matches),n[b]){for(r=++l;i>r;r++)if(o.relative[e[r].type])break;return wt(l>1&&bt(f),l>1&&yt(e.slice(0,l-1).concat({value:" "===e[l-2].type?"*":""})).replace(z,"$1"),n,r>l&&Tt(e.slice(l,r)),i>r&&Tt(e=e.slice(r)),i>r&&yt(e))}f.push(n)}return bt(f)}function Ct(e,t){var n=0,r=t.length>0,a=e.length>0,s=function(s,l,c,p,d){var h,g,m,y=[],v=0,b="0",x=s&&[],w=null!=d,C=u,N=s||a&&o.find.TAG("*",d&&l.parentNode||l),k=T+=null==C?1:Math.random()||.1;for(w&&(u=l!==f&&l,i=n);null!=(h=N[b]);b++){if(a&&h){g=0;while(m=e[g++])if(m(h,l,c)){p.push(h);break}w&&(T=k,i=++n)}r&&((h=!m&&h)&&v--,s&&x.push(h))}if(v+=b,r&&b!==v){g=0;while(m=t[g++])m(x,y,l,c);if(s){if(v>0)while(b--)x[b]||y[b]||(y[b]=q.call(p));y=xt(y)}M.apply(p,y),w&&!s&&y.length>0&&v+t.length>1&&at.uniqueSort(p)}return w&&(T=k,u=C),x};return r?lt(s):s}l=at.compile=function(e,t){var n,r=[],i=[],o=E[e+" "];if(!o){t||(t=mt(e)),n=t.length;while(n--)o=Tt(t[n]),o[b]?r.push(o):i.push(o);o=E(e,Ct(i,r))}return o};function Nt(e,t,n){var r=0,i=t.length;for(;i>r;r++)at(e,t[r],n);return n}function kt(e,t,n,i){var a,s,u,c,p,f=mt(e);if(!i&&1===f.length){if(s=f[0]=f[0].slice(0),s.length>2&&"ID"===(u=s[0]).type&&r.getById&&9===t.nodeType&&h&&o.relative[s[1].type]){if(t=(o.find.ID(u.matches[0].replace(rt,it),t)||[])[0],!t)return n;e=e.slice(s.shift().value.length)}a=Q.needsContext.test(e)?0:s.length;while(a--){if(u=s[a],o.relative[c=u.type])break;if((p=o.find[c])&&(i=p(u.matches[0].replace(rt,it),V.test(s[0].type)&&t.parentNode||t))){if(s.splice(a,1),e=i.length&&yt(s),!e)return M.apply(n,i),n;break}}}return l(e,f)(i,t,!h,n,V.test(e)),n}r.sortStable=b.split("").sort(A).join("")===b,r.detectDuplicates=S,p(),r.sortDetached=ut(function(e){return 1&e.compareDocumentPosition(f.createElement("div"))}),ut(function(e){return e.innerHTML="<a href='#'></a>","#"===e.firstChild.getAttribute("href")})||ct("type|href|height|width",function(e,n,r){return r?t:e.getAttribute(n,"type"===n.toLowerCase()?1:2)}),r.attributes&&ut(function(e){return e.innerHTML="<input/>",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||ct("value",function(e,n,r){return r||"input"!==e.nodeName.toLowerCase()?t:e.defaultValue}),ut(function(e){return null==e.getAttribute("disabled")})||ct(B,function(e,n,r){var i;return r?t:(i=e.getAttributeNode(n))&&i.specified?i.value:e[n]===!0?n.toLowerCase():null}),x.find=at,x.expr=at.selectors,x.expr[":"]=x.expr.pseudos,x.unique=at.uniqueSort,x.text=at.getText,x.isXMLDoc=at.isXML,x.contains=at.contains}(e);var O={};function F(e){var t=O[e]={};return x.each(e.match(T)||[],function(e,n){t[n]=!0}),t}x.Callbacks=function(e){e="string"==typeof e?O[e]||F(e):x.extend({},e);var n,r,i,o,a,s,l=[],u=!e.once&&[],c=function(t){for(r=e.memory&&t,i=!0,a=s||0,s=0,o=l.length,n=!0;l&&o>a;a++)if(l[a].apply(t[0],t[1])===!1&&e.stopOnFalse){r=!1;break}n=!1,l&&(u?u.length&&c(u.shift()):r?l=[]:p.disable())},p={add:function(){if(l){var t=l.length;(function i(t){x.each(t,function(t,n){var r=x.type(n);"function"===r?e.unique&&p.has(n)||l.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=l.length:r&&(s=t,c(r))}return this},remove:function(){return l&&x.each(arguments,function(e,t){var r;while((r=x.inArray(t,l,r))>-1)l.splice(r,1),n&&(o>=r&&o--,a>=r&&a--)}),this},has:function(e){return e?x.inArray(e,l)>-1:!(!l||!l.length)},empty:function(){return l=[],o=0,this},disable:function(){return l=u=r=t,this},disabled:function(){return!l},lock:function(){return u=t,r||p.disable(),this},locked:function(){return!u},fireWith:function(e,t){return!l||i&&!u||(t=t||[],t=[e,t.slice?t.slice():t],n?u.push(t):c(t)),this},fire:function(){return p.fireWith(this,arguments),this},fired:function(){return!!i}};return p},x.extend({Deferred:function(e){var t=[["resolve","done",x.Callbacks("once memory"),"resolved"],["reject","fail",x.Callbacks("once memory"),"rejected"],["notify","progress",x.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return x.Deferred(function(n){x.each(t,function(t,o){var a=o[0],s=x.isFunction(e[t])&&e[t];i[o[1]](function(){var e=s&&s.apply(this,arguments);e&&x.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[a+"With"](this===r?n.promise():this,s?[e]:arguments)})}),e=null}).promise()},promise:function(e){return null!=e?x.extend(e,r):r}},i={};return r.pipe=r.then,x.each(t,function(e,o){var a=o[2],s=o[3];r[o[1]]=a.add,s&&a.add(function(){n=s},t[1^e][2].disable,t[2][2].lock),i[o[0]]=function(){return i[o[0]+"With"](this===i?r:this,arguments),this},i[o[0]+"With"]=a.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t=0,n=g.call(arguments),r=n.length,i=1!==r||e&&x.isFunction(e.promise)?r:0,o=1===i?e:x.Deferred(),a=function(e,t,n){return function(r){t[e]=this,n[e]=arguments.length>1?g.call(arguments):r,n===s?o.notifyWith(t,n):--i||o.resolveWith(t,n)}},s,l,u;if(r>1)for(s=Array(r),l=Array(r),u=Array(r);r>t;t++)n[t]&&x.isFunction(n[t].promise)?n[t].promise().done(a(t,u,n)).fail(o.reject).progress(a(t,l,s)):--i;return i||o.resolveWith(u,n),o.promise()}}),x.support=function(t){var n,r,o,s,l,u,c,p,f,d=a.createElement("div");if(d.setAttribute("className","t"),d.innerHTML="  <link/><table></table><a href='/a'>a</a><input type='checkbox'/>",n=d.getElementsByTagName("*")||[],r=d.getElementsByTagName("a")[0],!r||!r.style||!n.length)return t;s=a.createElement("select"),u=s.appendChild(a.createElement("option")),o=d.getElementsByTagName("input")[0],r.style.cssText="top:1px;float:left;opacity:.5",t.getSetAttribute="t"!==d.className,t.leadingWhitespace=3===d.firstChild.nodeType,t.tbody=!d.getElementsByTagName("tbody").length,t.htmlSerialize=!!d.getElementsByTagName("link").length,t.style=/top/.test(r.getAttribute("style")),t.hrefNormalized="/a"===r.getAttribute("href"),t.opacity=/^0.5/.test(r.style.opacity),t.cssFloat=!!r.style.cssFloat,t.checkOn=!!o.value,t.optSelected=u.selected,t.enctype=!!a.createElement("form").enctype,t.html5Clone="<:nav></:nav>"!==a.createElement("nav").cloneNode(!0).outerHTML,t.inlineBlockNeedsLayout=!1,t.shrinkWrapBlocks=!1,t.pixelPosition=!1,t.deleteExpando=!0,t.noCloneEvent=!0,t.reliableMarginRight=!0,t.boxSizingReliable=!0,o.checked=!0,t.noCloneChecked=o.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!u.disabled;try{delete d.test}catch(h){t.deleteExpando=!1}o=a.createElement("input"),o.setAttribute("value",""),t.input=""===o.getAttribute("value"),o.value="t",o.setAttribute("type","radio"),t.radioValue="t"===o.value,o.setAttribute("checked","t"),o.setAttribute("name","t"),l=a.createDocumentFragment(),l.appendChild(o),t.appendChecked=o.checked,t.checkClone=l.cloneNode(!0).cloneNode(!0).lastChild.checked,d.attachEvent&&(d.attachEvent("onclick",function(){t.noCloneEvent=!1}),d.cloneNode(!0).click());for(f in{submit:!0,change:!0,focusin:!0})d.setAttribute(c="on"+f,"t"),t[f+"Bubbles"]=c in e||d.attributes[c].expando===!1;d.style.backgroundClip="content-box",d.cloneNode(!0).style.backgroundClip="",t.clearCloneStyle="content-box"===d.style.backgroundClip;for(f in x(t))break;return t.ownLast="0"!==f,x(function(){var n,r,o,s="padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;",l=a.getElementsByTagName("body")[0];l&&(n=a.createElement("div"),n.style.cssText="border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px",l.appendChild(n).appendChild(d),d.innerHTML="<table><tr><td></td><td>t</td></tr></table>",o=d.getElementsByTagName("td"),o[0].style.cssText="padding:0;margin:0;border:0;display:none",p=0===o[0].offsetHeight,o[0].style.display="",o[1].style.display="none",t.reliableHiddenOffsets=p&&0===o[0].offsetHeight,d.innerHTML="",d.style.cssText="box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;",x.swap(l,null!=l.style.zoom?{zoom:1}:{},function(){t.boxSizing=4===d.offsetWidth}),e.getComputedStyle&&(t.pixelPosition="1%"!==(e.getComputedStyle(d,null)||{}).top,t.boxSizingReliable="4px"===(e.getComputedStyle(d,null)||{width:"4px"}).width,r=d.appendChild(a.createElement("div")),r.style.cssText=d.style.cssText=s,r.style.marginRight=r.style.width="0",d.style.width="1px",t.reliableMarginRight=!parseFloat((e.getComputedStyle(r,null)||{}).marginRight)),typeof d.style.zoom!==i&&(d.innerHTML="",d.style.cssText=s+"width:1px;padding:1px;display:inline;zoom:1",t.inlineBlockNeedsLayout=3===d.offsetWidth,d.style.display="block",d.innerHTML="<div></div>",d.firstChild.style.width="5px",t.shrinkWrapBlocks=3!==d.offsetWidth,t.inlineBlockNeedsLayout&&(l.style.zoom=1)),l.removeChild(n),n=d=o=r=null)}),n=s=l=u=r=o=null,t
-}({});var B=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,P=/([A-Z])/g;function R(e,n,r,i){if(x.acceptData(e)){var o,a,s=x.expando,l=e.nodeType,u=l?x.cache:e,c=l?e[s]:e[s]&&s;if(c&&u[c]&&(i||u[c].data)||r!==t||"string"!=typeof n)return c||(c=l?e[s]=p.pop()||x.guid++:s),u[c]||(u[c]=l?{}:{toJSON:x.noop}),("object"==typeof n||"function"==typeof n)&&(i?u[c]=x.extend(u[c],n):u[c].data=x.extend(u[c].data,n)),a=u[c],i||(a.data||(a.data={}),a=a.data),r!==t&&(a[x.camelCase(n)]=r),"string"==typeof n?(o=a[n],null==o&&(o=a[x.camelCase(n)])):o=a,o}}function W(e,t,n){if(x.acceptData(e)){var r,i,o=e.nodeType,a=o?x.cache:e,s=o?e[x.expando]:x.expando;if(a[s]){if(t&&(r=n?a[s]:a[s].data)){x.isArray(t)?t=t.concat(x.map(t,x.camelCase)):t in r?t=[t]:(t=x.camelCase(t),t=t in r?[t]:t.split(" ")),i=t.length;while(i--)delete r[t[i]];if(n?!I(r):!x.isEmptyObject(r))return}(n||(delete a[s].data,I(a[s])))&&(o?x.cleanData([e],!0):x.support.deleteExpando||a!=a.window?delete a[s]:a[s]=null)}}}x.extend({cache:{},noData:{applet:!0,embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"},hasData:function(e){return e=e.nodeType?x.cache[e[x.expando]]:e[x.expando],!!e&&!I(e)},data:function(e,t,n){return R(e,t,n)},removeData:function(e,t){return W(e,t)},_data:function(e,t,n){return R(e,t,n,!0)},_removeData:function(e,t){return W(e,t,!0)},acceptData:function(e){if(e.nodeType&&1!==e.nodeType&&9!==e.nodeType)return!1;var t=e.nodeName&&x.noData[e.nodeName.toLowerCase()];return!t||t!==!0&&e.getAttribute("classid")===t}}),x.fn.extend({data:function(e,n){var r,i,o=null,a=0,s=this[0];if(e===t){if(this.length&&(o=x.data(s),1===s.nodeType&&!x._data(s,"parsedAttrs"))){for(r=s.attributes;r.length>a;a++)i=r[a].name,0===i.indexOf("data-")&&(i=x.camelCase(i.slice(5)),$(s,i,o[i]));x._data(s,"parsedAttrs",!0)}return o}return"object"==typeof e?this.each(function(){x.data(this,e)}):arguments.length>1?this.each(function(){x.data(this,e,n)}):s?$(s,e,x.data(s,e)):null},removeData:function(e){return this.each(function(){x.removeData(this,e)})}});function $(e,n,r){if(r===t&&1===e.nodeType){var i="data-"+n.replace(P,"-$1").toLowerCase();if(r=e.getAttribute(i),"string"==typeof r){try{r="true"===r?!0:"false"===r?!1:"null"===r?null:+r+""===r?+r:B.test(r)?x.parseJSON(r):r}catch(o){}x.data(e,n,r)}else r=t}return r}function I(e){var t;for(t in e)if(("data"!==t||!x.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}x.extend({queue:function(e,n,r){var i;return e?(n=(n||"fx")+"queue",i=x._data(e,n),r&&(!i||x.isArray(r)?i=x._data(e,n,x.makeArray(r)):i.push(r)),i||[]):t},dequeue:function(e,t){t=t||"fx";var n=x.queue(e,t),r=n.length,i=n.shift(),o=x._queueHooks(e,t),a=function(){x.dequeue(e,t)};"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,a,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return x._data(e,n)||x._data(e,n,{empty:x.Callbacks("once memory").add(function(){x._removeData(e,t+"queue"),x._removeData(e,n)})})}}),x.fn.extend({queue:function(e,n){var r=2;return"string"!=typeof e&&(n=e,e="fx",r--),r>arguments.length?x.queue(this[0],e):n===t?this:this.each(function(){var t=x.queue(this,e,n);x._queueHooks(this,e),"fx"===e&&"inprogress"!==t[0]&&x.dequeue(this,e)})},dequeue:function(e){return this.each(function(){x.dequeue(this,e)})},delay:function(e,t){return e=x.fx?x.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,n){var r,i=1,o=x.Deferred(),a=this,s=this.length,l=function(){--i||o.resolveWith(a,[a])};"string"!=typeof e&&(n=e,e=t),e=e||"fx";while(s--)r=x._data(a[s],e+"queueHooks"),r&&r.empty&&(i++,r.empty.add(l));return l(),o.promise(n)}});var z,X,U=/[\t\r\n\f]/g,V=/\r/g,Y=/^(?:input|select|textarea|button|object)$/i,J=/^(?:a|area)$/i,G=/^(?:checked|selected)$/i,Q=x.support.getSetAttribute,K=x.support.input;x.fn.extend({attr:function(e,t){return x.access(this,x.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){x.removeAttr(this,e)})},prop:function(e,t){return x.access(this,x.prop,e,t,arguments.length>1)},removeProp:function(e){return e=x.propFix[e]||e,this.each(function(){try{this[e]=t,delete this[e]}catch(n){}})},addClass:function(e){var t,n,r,i,o,a=0,s=this.length,l="string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).addClass(e.call(this,t,this.className))});if(l)for(t=(e||"").match(T)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(U," "):" ")){o=0;while(i=t[o++])0>r.indexOf(" "+i+" ")&&(r+=i+" ");n.className=x.trim(r)}return this},removeClass:function(e){var t,n,r,i,o,a=0,s=this.length,l=0===arguments.length||"string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).removeClass(e.call(this,t,this.className))});if(l)for(t=(e||"").match(T)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(U," "):"")){o=0;while(i=t[o++])while(r.indexOf(" "+i+" ")>=0)r=r.replace(" "+i+" "," ");n.className=e?x.trim(r):""}return this},toggleClass:function(e,t){var n=typeof e;return"boolean"==typeof t&&"string"===n?t?this.addClass(e):this.removeClass(e):x.isFunction(e)?this.each(function(n){x(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if("string"===n){var t,r=0,o=x(this),a=e.match(T)||[];while(t=a[r++])o.hasClass(t)?o.removeClass(t):o.addClass(t)}else(n===i||"boolean"===n)&&(this.className&&x._data(this,"__className__",this.className),this.className=this.className||e===!1?"":x._data(this,"__className__")||"")})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;r>n;n++)if(1===this[n].nodeType&&(" "+this[n].className+" ").replace(U," ").indexOf(t)>=0)return!0;return!1},val:function(e){var n,r,i,o=this[0];{if(arguments.length)return i=x.isFunction(e),this.each(function(n){var o;1===this.nodeType&&(o=i?e.call(this,n,x(this).val()):e,null==o?o="":"number"==typeof o?o+="":x.isArray(o)&&(o=x.map(o,function(e){return null==e?"":e+""})),r=x.valHooks[this.type]||x.valHooks[this.nodeName.toLowerCase()],r&&"set"in r&&r.set(this,o,"value")!==t||(this.value=o))});if(o)return r=x.valHooks[o.type]||x.valHooks[o.nodeName.toLowerCase()],r&&"get"in r&&(n=r.get(o,"value"))!==t?n:(n=o.value,"string"==typeof n?n.replace(V,""):null==n?"":n)}}}),x.extend({valHooks:{option:{get:function(e){var t=x.find.attr(e,"value");return null!=t?t:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,o="select-one"===e.type||0>i,a=o?null:[],s=o?i+1:r.length,l=0>i?s:o?i:0;for(;s>l;l++)if(n=r[l],!(!n.selected&&l!==i||(x.support.optDisabled?n.disabled:null!==n.getAttribute("disabled"))||n.parentNode.disabled&&x.nodeName(n.parentNode,"optgroup"))){if(t=x(n).val(),o)return t;a.push(t)}return a},set:function(e,t){var n,r,i=e.options,o=x.makeArray(t),a=i.length;while(a--)r=i[a],(r.selected=x.inArray(x(r).val(),o)>=0)&&(n=!0);return n||(e.selectedIndex=-1),o}}},attr:function(e,n,r){var o,a,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return typeof e.getAttribute===i?x.prop(e,n,r):(1===s&&x.isXMLDoc(e)||(n=n.toLowerCase(),o=x.attrHooks[n]||(x.expr.match.bool.test(n)?X:z)),r===t?o&&"get"in o&&null!==(a=o.get(e,n))?a:(a=x.find.attr(e,n),null==a?t:a):null!==r?o&&"set"in o&&(a=o.set(e,r,n))!==t?a:(e.setAttribute(n,r+""),r):(x.removeAttr(e,n),t))},removeAttr:function(e,t){var n,r,i=0,o=t&&t.match(T);if(o&&1===e.nodeType)while(n=o[i++])r=x.propFix[n]||n,x.expr.match.bool.test(n)?K&&Q||!G.test(n)?e[r]=!1:e[x.camelCase("default-"+n)]=e[r]=!1:x.attr(e,n,""),e.removeAttribute(Q?n:r)},attrHooks:{type:{set:function(e,t){if(!x.support.radioValue&&"radio"===t&&x.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},propFix:{"for":"htmlFor","class":"className"},prop:function(e,n,r){var i,o,a,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return a=1!==s||!x.isXMLDoc(e),a&&(n=x.propFix[n]||n,o=x.propHooks[n]),r!==t?o&&"set"in o&&(i=o.set(e,r,n))!==t?i:e[n]=r:o&&"get"in o&&null!==(i=o.get(e,n))?i:e[n]},propHooks:{tabIndex:{get:function(e){var t=x.find.attr(e,"tabindex");return t?parseInt(t,10):Y.test(e.nodeName)||J.test(e.nodeName)&&e.href?0:-1}}}}),X={set:function(e,t,n){return t===!1?x.removeAttr(e,n):K&&Q||!G.test(n)?e.setAttribute(!Q&&x.propFix[n]||n,n):e[x.camelCase("default-"+n)]=e[n]=!0,n}},x.each(x.expr.match.bool.source.match(/\w+/g),function(e,n){var r=x.expr.attrHandle[n]||x.find.attr;x.expr.attrHandle[n]=K&&Q||!G.test(n)?function(e,n,i){var o=x.expr.attrHandle[n],a=i?t:(x.expr.attrHandle[n]=t)!=r(e,n,i)?n.toLowerCase():null;return x.expr.attrHandle[n]=o,a}:function(e,n,r){return r?t:e[x.camelCase("default-"+n)]?n.toLowerCase():null}}),K&&Q||(x.attrHooks.value={set:function(e,n,r){return x.nodeName(e,"input")?(e.defaultValue=n,t):z&&z.set(e,n,r)}}),Q||(z={set:function(e,n,r){var i=e.getAttributeNode(r);return i||e.setAttributeNode(i=e.ownerDocument.createAttribute(r)),i.value=n+="","value"===r||n===e.getAttribute(r)?n:t}},x.expr.attrHandle.id=x.expr.attrHandle.name=x.expr.attrHandle.coords=function(e,n,r){var i;return r?t:(i=e.getAttributeNode(n))&&""!==i.value?i.value:null},x.valHooks.button={get:function(e,n){var r=e.getAttributeNode(n);return r&&r.specified?r.value:t},set:z.set},x.attrHooks.contenteditable={set:function(e,t,n){z.set(e,""===t?!1:t,n)}},x.each(["width","height"],function(e,n){x.attrHooks[n]={set:function(e,r){return""===r?(e.setAttribute(n,"auto"),r):t}}})),x.support.hrefNormalized||x.each(["href","src"],function(e,t){x.propHooks[t]={get:function(e){return e.getAttribute(t,4)}}}),x.support.style||(x.attrHooks.style={get:function(e){return e.style.cssText||t},set:function(e,t){return e.style.cssText=t+""}}),x.support.optSelected||(x.propHooks.selected={get:function(e){var t=e.parentNode;return t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex),null}}),x.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){x.propFix[this.toLowerCase()]=this}),x.support.enctype||(x.propFix.enctype="encoding"),x.each(["radio","checkbox"],function(){x.valHooks[this]={set:function(e,n){return x.isArray(n)?e.checked=x.inArray(x(e).val(),n)>=0:t}},x.support.checkOn||(x.valHooks[this].get=function(e){return null===e.getAttribute("value")?"on":e.value})});var Z=/^(?:input|select|textarea)$/i,et=/^key/,tt=/^(?:mouse|contextmenu)|click/,nt=/^(?:focusinfocus|focusoutblur)$/,rt=/^([^.]*)(?:\.(.+)|)$/;function it(){return!0}function ot(){return!1}function at(){try{return a.activeElement}catch(e){}}x.event={global:{},add:function(e,n,r,o,a){var s,l,u,c,p,f,d,h,g,m,y,v=x._data(e);if(v){r.handler&&(c=r,r=c.handler,a=c.selector),r.guid||(r.guid=x.guid++),(l=v.events)||(l=v.events={}),(f=v.handle)||(f=v.handle=function(e){return typeof x===i||e&&x.event.triggered===e.type?t:x.event.dispatch.apply(f.elem,arguments)},f.elem=e),n=(n||"").match(T)||[""],u=n.length;while(u--)s=rt.exec(n[u])||[],g=y=s[1],m=(s[2]||"").split(".").sort(),g&&(p=x.event.special[g]||{},g=(a?p.delegateType:p.bindType)||g,p=x.event.special[g]||{},d=x.extend({type:g,origType:y,data:o,handler:r,guid:r.guid,selector:a,needsContext:a&&x.expr.match.needsContext.test(a),namespace:m.join(".")},c),(h=l[g])||(h=l[g]=[],h.delegateCount=0,p.setup&&p.setup.call(e,o,m,f)!==!1||(e.addEventListener?e.addEventListener(g,f,!1):e.attachEvent&&e.attachEvent("on"+g,f))),p.add&&(p.add.call(e,d),d.handler.guid||(d.handler.guid=r.guid)),a?h.splice(h.delegateCount++,0,d):h.push(d),x.event.global[g]=!0);e=null}},remove:function(e,t,n,r,i){var o,a,s,l,u,c,p,f,d,h,g,m=x.hasData(e)&&x._data(e);if(m&&(c=m.events)){t=(t||"").match(T)||[""],u=t.length;while(u--)if(s=rt.exec(t[u])||[],d=g=s[1],h=(s[2]||"").split(".").sort(),d){p=x.event.special[d]||{},d=(r?p.delegateType:p.bindType)||d,f=c[d]||[],s=s[2]&&RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),l=o=f.length;while(o--)a=f[o],!i&&g!==a.origType||n&&n.guid!==a.guid||s&&!s.test(a.namespace)||r&&r!==a.selector&&("**"!==r||!a.selector)||(f.splice(o,1),a.selector&&f.delegateCount--,p.remove&&p.remove.call(e,a));l&&!f.length&&(p.teardown&&p.teardown.call(e,h,m.handle)!==!1||x.removeEvent(e,d,m.handle),delete c[d])}else for(d in c)x.event.remove(e,d+t[u],n,r,!0);x.isEmptyObject(c)&&(delete m.handle,x._removeData(e,"events"))}},trigger:function(n,r,i,o){var s,l,u,c,p,f,d,h=[i||a],g=v.call(n,"type")?n.type:n,m=v.call(n,"namespace")?n.namespace.split("."):[];if(u=f=i=i||a,3!==i.nodeType&&8!==i.nodeType&&!nt.test(g+x.event.triggered)&&(g.indexOf(".")>=0&&(m=g.split("."),g=m.shift(),m.sort()),l=0>g.indexOf(":")&&"on"+g,n=n[x.expando]?n:new x.Event(g,"object"==typeof n&&n),n.isTrigger=o?2:3,n.namespace=m.join("."),n.namespace_re=n.namespace?RegExp("(^|\\.)"+m.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,n.result=t,n.target||(n.target=i),r=null==r?[n]:x.makeArray(r,[n]),p=x.event.special[g]||{},o||!p.trigger||p.trigger.apply(i,r)!==!1)){if(!o&&!p.noBubble&&!x.isWindow(i)){for(c=p.delegateType||g,nt.test(c+g)||(u=u.parentNode);u;u=u.parentNode)h.push(u),f=u;f===(i.ownerDocument||a)&&h.push(f.defaultView||f.parentWindow||e)}d=0;while((u=h[d++])&&!n.isPropagationStopped())n.type=d>1?c:p.bindType||g,s=(x._data(u,"events")||{})[n.type]&&x._data(u,"handle"),s&&s.apply(u,r),s=l&&u[l],s&&x.acceptData(u)&&s.apply&&s.apply(u,r)===!1&&n.preventDefault();if(n.type=g,!o&&!n.isDefaultPrevented()&&(!p._default||p._default.apply(h.pop(),r)===!1)&&x.acceptData(i)&&l&&i[g]&&!x.isWindow(i)){f=i[l],f&&(i[l]=null),x.event.triggered=g;try{i[g]()}catch(y){}x.event.triggered=t,f&&(i[l]=f)}return n.result}},dispatch:function(e){e=x.event.fix(e);var n,r,i,o,a,s=[],l=g.call(arguments),u=(x._data(this,"events")||{})[e.type]||[],c=x.event.special[e.type]||{};if(l[0]=e,e.delegateTarget=this,!c.preDispatch||c.preDispatch.call(this,e)!==!1){s=x.event.handlers.call(this,e,u),n=0;while((o=s[n++])&&!e.isPropagationStopped()){e.currentTarget=o.elem,a=0;while((i=o.handlers[a++])&&!e.isImmediatePropagationStopped())(!e.namespace_re||e.namespace_re.test(i.namespace))&&(e.handleObj=i,e.data=i.data,r=((x.event.special[i.origType]||{}).handle||i.handler).apply(o.elem,l),r!==t&&(e.result=r)===!1&&(e.preventDefault(),e.stopPropagation()))}return c.postDispatch&&c.postDispatch.call(this,e),e.result}},handlers:function(e,n){var r,i,o,a,s=[],l=n.delegateCount,u=e.target;if(l&&u.nodeType&&(!e.button||"click"!==e.type))for(;u!=this;u=u.parentNode||this)if(1===u.nodeType&&(u.disabled!==!0||"click"!==e.type)){for(o=[],a=0;l>a;a++)i=n[a],r=i.selector+" ",o[r]===t&&(o[r]=i.needsContext?x(r,this).index(u)>=0:x.find(r,this,null,[u]).length),o[r]&&o.push(i);o.length&&s.push({elem:u,handlers:o})}return n.length>l&&s.push({elem:this,handlers:n.slice(l)}),s},fix:function(e){if(e[x.expando])return e;var t,n,r,i=e.type,o=e,s=this.fixHooks[i];s||(this.fixHooks[i]=s=tt.test(i)?this.mouseHooks:et.test(i)?this.keyHooks:{}),r=s.props?this.props.concat(s.props):this.props,e=new x.Event(o),t=r.length;while(t--)n=r[t],e[n]=o[n];return e.target||(e.target=o.srcElement||a),3===e.target.nodeType&&(e.target=e.target.parentNode),e.metaKey=!!e.metaKey,s.filter?s.filter(e,o):e},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return null==e.which&&(e.which=null!=t.charCode?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,n){var r,i,o,s=n.button,l=n.fromElement;return null==e.pageX&&null!=n.clientX&&(i=e.target.ownerDocument||a,o=i.documentElement,r=i.body,e.pageX=n.clientX+(o&&o.scrollLeft||r&&r.scrollLeft||0)-(o&&o.clientLeft||r&&r.clientLeft||0),e.pageY=n.clientY+(o&&o.scrollTop||r&&r.scrollTop||0)-(o&&o.clientTop||r&&r.clientTop||0)),!e.relatedTarget&&l&&(e.relatedTarget=l===e.target?n.toElement:l),e.which||s===t||(e.which=1&s?1:2&s?3:4&s?2:0),e}},special:{load:{noBubble:!0},focus:{trigger:function(){if(this!==at()&&this.focus)try{return this.focus(),!1}catch(e){}},delegateType:"focusin"},blur:{trigger:function(){return this===at()&&this.blur?(this.blur(),!1):t},delegateType:"focusout"},click:{trigger:function(){return x.nodeName(this,"input")&&"checkbox"===this.type&&this.click?(this.click(),!1):t},_default:function(e){return x.nodeName(e.target,"a")}},beforeunload:{postDispatch:function(e){e.result!==t&&(e.originalEvent.returnValue=e.result)}}},simulate:function(e,t,n,r){var i=x.extend(new x.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?x.event.trigger(i,null,t):x.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},x.removeEvent=a.removeEventListener?function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)}:function(e,t,n){var r="on"+t;e.detachEvent&&(typeof e[r]===i&&(e[r]=null),e.detachEvent(r,n))},x.Event=function(e,n){return this instanceof x.Event?(e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.returnValue===!1||e.getPreventDefault&&e.getPreventDefault()?it:ot):this.type=e,n&&x.extend(this,n),this.timeStamp=e&&e.timeStamp||x.now(),this[x.expando]=!0,t):new x.Event(e,n)},x.Event.prototype={isDefaultPrevented:ot,isPropagationStopped:ot,isImmediatePropagationStopped:ot,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=it,e&&(e.preventDefault?e.preventDefault():e.returnValue=!1)},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=it,e&&(e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=it,this.stopPropagation()}},x.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){x.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,o=e.handleObj;return(!i||i!==r&&!x.contains(r,i))&&(e.type=o.origType,n=o.handler.apply(this,arguments),e.type=t),n}}}),x.support.submitBubbles||(x.event.special.submit={setup:function(){return x.nodeName(this,"form")?!1:(x.event.add(this,"click._submit keypress._submit",function(e){var n=e.target,r=x.nodeName(n,"input")||x.nodeName(n,"button")?n.form:t;r&&!x._data(r,"submitBubbles")&&(x.event.add(r,"submit._submit",function(e){e._submit_bubble=!0}),x._data(r,"submitBubbles",!0))}),t)},postDispatch:function(e){e._submit_bubble&&(delete e._submit_bubble,this.parentNode&&!e.isTrigger&&x.event.simulate("submit",this.parentNode,e,!0))},teardown:function(){return x.nodeName(this,"form")?!1:(x.event.remove(this,"._submit"),t)}}),x.support.changeBubbles||(x.event.special.change={setup:function(){return Z.test(this.nodeName)?(("checkbox"===this.type||"radio"===this.type)&&(x.event.add(this,"propertychange._change",function(e){"checked"===e.originalEvent.propertyName&&(this._just_changed=!0)}),x.event.add(this,"click._change",function(e){this._just_changed&&!e.isTrigger&&(this._just_changed=!1),x.event.simulate("change",this,e,!0)})),!1):(x.event.add(this,"beforeactivate._change",function(e){var t=e.target;Z.test(t.nodeName)&&!x._data(t,"changeBubbles")&&(x.event.add(t,"change._change",function(e){!this.parentNode||e.isSimulated||e.isTrigger||x.event.simulate("change",this.parentNode,e,!0)}),x._data(t,"changeBubbles",!0))}),t)},handle:function(e){var n=e.target;return this!==n||e.isSimulated||e.isTrigger||"radio"!==n.type&&"checkbox"!==n.type?e.handleObj.handler.apply(this,arguments):t},teardown:function(){return x.event.remove(this,"._change"),!Z.test(this.nodeName)}}),x.support.focusinBubbles||x.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){x.event.simulate(t,e.target,x.event.fix(e),!0)};x.event.special[t]={setup:function(){0===n++&&a.addEventListener(e,r,!0)},teardown:function(){0===--n&&a.removeEventListener(e,r,!0)}}}),x.fn.extend({on:function(e,n,r,i,o){var a,s;if("object"==typeof e){"string"!=typeof n&&(r=r||n,n=t);for(a in e)this.on(a,n,r,e[a],o);return this}if(null==r&&null==i?(i=n,r=n=t):null==i&&("string"==typeof n?(i=r,r=t):(i=r,r=n,n=t)),i===!1)i=ot;else if(!i)return this;return 1===o&&(s=i,i=function(e){return x().off(e),s.apply(this,arguments)},i.guid=s.guid||(s.guid=x.guid++)),this.each(function(){x.event.add(this,e,i,r,n)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,n,r){var i,o;if(e&&e.preventDefault&&e.handleObj)return i=e.handleObj,x(e.delegateTarget).off(i.namespace?i.origType+"."+i.namespace:i.origType,i.selector,i.handler),this;if("object"==typeof e){for(o in e)this.off(o,n,e[o]);return this}return(n===!1||"function"==typeof n)&&(r=n,n=t),r===!1&&(r=ot),this.each(function(){x.event.remove(this,e,r,n)})},trigger:function(e,t){return this.each(function(){x.event.trigger(e,t,this)})},triggerHandler:function(e,n){var r=this[0];return r?x.event.trigger(e,n,r,!0):t}});var st=/^.[^:#\[\.,]*$/,lt=/^(?:parents|prev(?:Until|All))/,ut=x.expr.match.needsContext,ct={children:!0,contents:!0,next:!0,prev:!0};x.fn.extend({find:function(e){var t,n=[],r=this,i=r.length;if("string"!=typeof e)return this.pushStack(x(e).filter(function(){for(t=0;i>t;t++)if(x.contains(r[t],this))return!0}));for(t=0;i>t;t++)x.find(e,r[t],n);return n=this.pushStack(i>1?x.unique(n):n),n.selector=this.selector?this.selector+" "+e:e,n},has:function(e){var t,n=x(e,this),r=n.length;return this.filter(function(){for(t=0;r>t;t++)if(x.contains(this,n[t]))return!0})},not:function(e){return this.pushStack(ft(this,e||[],!0))},filter:function(e){return this.pushStack(ft(this,e||[],!1))},is:function(e){return!!ft(this,"string"==typeof e&&ut.test(e)?x(e):e||[],!1).length},closest:function(e,t){var n,r=0,i=this.length,o=[],a=ut.test(e)||"string"!=typeof e?x(e,t||this.context):0;for(;i>r;r++)for(n=this[r];n&&n!==t;n=n.parentNode)if(11>n.nodeType&&(a?a.index(n)>-1:1===n.nodeType&&x.find.matchesSelector(n,e))){n=o.push(n);break}return this.pushStack(o.length>1?x.unique(o):o)},index:function(e){return e?"string"==typeof e?x.inArray(this[0],x(e)):x.inArray(e.jquery?e[0]:e,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){var n="string"==typeof e?x(e,t):x.makeArray(e&&e.nodeType?[e]:e),r=x.merge(this.get(),n);return this.pushStack(x.unique(r))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}});function pt(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}x.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return x.dir(e,"parentNode")},parentsUntil:function(e,t,n){return x.dir(e,"parentNode",n)},next:function(e){return pt(e,"nextSibling")},prev:function(e){return pt(e,"previousSibling")},nextAll:function(e){return x.dir(e,"nextSibling")},prevAll:function(e){return x.dir(e,"previousSibling")},nextUntil:function(e,t,n){return x.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return x.dir(e,"previousSibling",n)},siblings:function(e){return x.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return x.sibling(e.firstChild)},contents:function(e){return x.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:x.merge([],e.childNodes)}},function(e,t){x.fn[e]=function(n,r){var i=x.map(this,t,n);return"Until"!==e.slice(-5)&&(r=n),r&&"string"==typeof r&&(i=x.filter(r,i)),this.length>1&&(ct[e]||(i=x.unique(i)),lt.test(e)&&(i=i.reverse())),this.pushStack(i)}}),x.extend({filter:function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?x.find.matchesSelector(r,e)?[r]:[]:x.find.matches(e,x.grep(t,function(e){return 1===e.nodeType}))},dir:function(e,n,r){var i=[],o=e[n];while(o&&9!==o.nodeType&&(r===t||1!==o.nodeType||!x(o).is(r)))1===o.nodeType&&i.push(o),o=o[n];return i},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}});function ft(e,t,n){if(x.isFunction(t))return x.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return x.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(st.test(t))return x.filter(t,e,n);t=x.filter(t,e)}return x.grep(e,function(e){return x.inArray(e,t)>=0!==n})}function dt(e){var t=ht.split("|"),n=e.createDocumentFragment();if(n.createElement)while(t.length)n.createElement(t.pop());return n}var ht="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",gt=/ jQuery\d+="(?:null|\d+)"/g,mt=RegExp("<(?:"+ht+")[\\s/>]","i"),yt=/^\s+/,vt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,bt=/<([\w:]+)/,xt=/<tbody/i,wt=/<|&#?\w+;/,Tt=/<(?:script|style|link)/i,Ct=/^(?:checkbox|radio)$/i,Nt=/checked\s*(?:[^=]|=\s*.checked.)/i,kt=/^$|\/(?:java|ecma)script/i,Et=/^true\/(.*)/,St=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,At={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],area:[1,"<map>","</map>"],param:[1,"<object>","</object>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:x.support.htmlSerialize?[0,"",""]:[1,"X<div>","</div>"]},jt=dt(a),Dt=jt.appendChild(a.createElement("div"));At.optgroup=At.option,At.tbody=At.tfoot=At.colgroup=At.caption=At.thead,At.th=At.td,x.fn.extend({text:function(e){return x.access(this,function(e){return e===t?x.text(this):this.empty().append((this[0]&&this[0].ownerDocument||a).createTextNode(e))},null,e,arguments.length)},append:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=Lt(this,e);t.appendChild(e)}})},prepend:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=Lt(this,e);t.insertBefore(e,t.firstChild)}})},before:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},remove:function(e,t){var n,r=e?x.filter(e,this):this,i=0;for(;null!=(n=r[i]);i++)t||1!==n.nodeType||x.cleanData(Ft(n)),n.parentNode&&(t&&x.contains(n.ownerDocument,n)&&_t(Ft(n,"script")),n.parentNode.removeChild(n));return this},empty:function(){var e,t=0;for(;null!=(e=this[t]);t++){1===e.nodeType&&x.cleanData(Ft(e,!1));while(e.firstChild)e.removeChild(e.firstChild);e.options&&x.nodeName(e,"select")&&(e.options.length=0)}return this},clone:function(e,t){return e=null==e?!1:e,t=null==t?e:t,this.map(function(){return x.clone(this,e,t)})},html:function(e){return x.access(this,function(e){var n=this[0]||{},r=0,i=this.length;if(e===t)return 1===n.nodeType?n.innerHTML.replace(gt,""):t;if(!("string"!=typeof e||Tt.test(e)||!x.support.htmlSerialize&&mt.test(e)||!x.support.leadingWhitespace&&yt.test(e)||At[(bt.exec(e)||["",""])[1].toLowerCase()])){e=e.replace(vt,"<$1></$2>");try{for(;i>r;r++)n=this[r]||{},1===n.nodeType&&(x.cleanData(Ft(n,!1)),n.innerHTML=e);n=0}catch(o){}}n&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(){var e=x.map(this,function(e){return[e.nextSibling,e.parentNode]}),t=0;return this.domManip(arguments,function(n){var r=e[t++],i=e[t++];i&&(r&&r.parentNode!==i&&(r=this.nextSibling),x(this).remove(),i.insertBefore(n,r))},!0),t?this:this.remove()},detach:function(e){return this.remove(e,!0)},domManip:function(e,t,n){e=d.apply([],e);var r,i,o,a,s,l,u=0,c=this.length,p=this,f=c-1,h=e[0],g=x.isFunction(h);if(g||!(1>=c||"string"!=typeof h||x.support.checkClone)&&Nt.test(h))return this.each(function(r){var i=p.eq(r);g&&(e[0]=h.call(this,r,i.html())),i.domManip(e,t,n)});if(c&&(l=x.buildFragment(e,this[0].ownerDocument,!1,!n&&this),r=l.firstChild,1===l.childNodes.length&&(l=r),r)){for(a=x.map(Ft(l,"script"),Ht),o=a.length;c>u;u++)i=l,u!==f&&(i=x.clone(i,!0,!0),o&&x.merge(a,Ft(i,"script"))),t.call(this[u],i,u);if(o)for(s=a[a.length-1].ownerDocument,x.map(a,qt),u=0;o>u;u++)i=a[u],kt.test(i.type||"")&&!x._data(i,"globalEval")&&x.contains(s,i)&&(i.src?x._evalUrl(i.src):x.globalEval((i.text||i.textContent||i.innerHTML||"").replace(St,"")));l=r=null}return this}});function Lt(e,t){return x.nodeName(e,"table")&&x.nodeName(1===t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function Ht(e){return e.type=(null!==x.find.attr(e,"type"))+"/"+e.type,e}function qt(e){var t=Et.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function _t(e,t){var n,r=0;for(;null!=(n=e[r]);r++)x._data(n,"globalEval",!t||x._data(t[r],"globalEval"))}function Mt(e,t){if(1===t.nodeType&&x.hasData(e)){var n,r,i,o=x._data(e),a=x._data(t,o),s=o.events;if(s){delete a.handle,a.events={};for(n in s)for(r=0,i=s[n].length;i>r;r++)x.event.add(t,n,s[n][r])}a.data&&(a.data=x.extend({},a.data))}}function Ot(e,t){var n,r,i;if(1===t.nodeType){if(n=t.nodeName.toLowerCase(),!x.support.noCloneEvent&&t[x.expando]){i=x._data(t);for(r in i.events)x.removeEvent(t,r,i.handle);t.removeAttribute(x.expando)}"script"===n&&t.text!==e.text?(Ht(t).text=e.text,qt(t)):"object"===n?(t.parentNode&&(t.outerHTML=e.outerHTML),x.support.html5Clone&&e.innerHTML&&!x.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):"input"===n&&Ct.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):"option"===n?t.defaultSelected=t.selected=e.defaultSelected:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}}x.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){x.fn[e]=function(e){var n,r=0,i=[],o=x(e),a=o.length-1;for(;a>=r;r++)n=r===a?this:this.clone(!0),x(o[r])[t](n),h.apply(i,n.get());return this.pushStack(i)}});function Ft(e,n){var r,o,a=0,s=typeof e.getElementsByTagName!==i?e.getElementsByTagName(n||"*"):typeof e.querySelectorAll!==i?e.querySelectorAll(n||"*"):t;if(!s)for(s=[],r=e.childNodes||e;null!=(o=r[a]);a++)!n||x.nodeName(o,n)?s.push(o):x.merge(s,Ft(o,n));return n===t||n&&x.nodeName(e,n)?x.merge([e],s):s}function Bt(e){Ct.test(e.type)&&(e.defaultChecked=e.checked)}x.extend({clone:function(e,t,n){var r,i,o,a,s,l=x.contains(e.ownerDocument,e);if(x.support.html5Clone||x.isXMLDoc(e)||!mt.test("<"+e.nodeName+">")?o=e.cloneNode(!0):(Dt.innerHTML=e.outerHTML,Dt.removeChild(o=Dt.firstChild)),!(x.support.noCloneEvent&&x.support.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||x.isXMLDoc(e)))for(r=Ft(o),s=Ft(e),a=0;null!=(i=s[a]);++a)r[a]&&Ot(i,r[a]);if(t)if(n)for(s=s||Ft(e),r=r||Ft(o),a=0;null!=(i=s[a]);a++)Mt(i,r[a]);else Mt(e,o);return r=Ft(o,"script"),r.length>0&&_t(r,!l&&Ft(e,"script")),r=s=i=null,o},buildFragment:function(e,t,n,r){var i,o,a,s,l,u,c,p=e.length,f=dt(t),d=[],h=0;for(;p>h;h++)if(o=e[h],o||0===o)if("object"===x.type(o))x.merge(d,o.nodeType?[o]:o);else if(wt.test(o)){s=s||f.appendChild(t.createElement("div")),l=(bt.exec(o)||["",""])[1].toLowerCase(),c=At[l]||At._default,s.innerHTML=c[1]+o.replace(vt,"<$1></$2>")+c[2],i=c[0];while(i--)s=s.lastChild;if(!x.support.leadingWhitespace&&yt.test(o)&&d.push(t.createTextNode(yt.exec(o)[0])),!x.support.tbody){o="table"!==l||xt.test(o)?"<table>"!==c[1]||xt.test(o)?0:s:s.firstChild,i=o&&o.childNodes.length;while(i--)x.nodeName(u=o.childNodes[i],"tbody")&&!u.childNodes.length&&o.removeChild(u)}x.merge(d,s.childNodes),s.textContent="";while(s.firstChild)s.removeChild(s.firstChild);s=f.lastChild}else d.push(t.createTextNode(o));s&&f.removeChild(s),x.support.appendChecked||x.grep(Ft(d,"input"),Bt),h=0;while(o=d[h++])if((!r||-1===x.inArray(o,r))&&(a=x.contains(o.ownerDocument,o),s=Ft(f.appendChild(o),"script"),a&&_t(s),n)){i=0;while(o=s[i++])kt.test(o.type||"")&&n.push(o)}return s=null,f},cleanData:function(e,t){var n,r,o,a,s=0,l=x.expando,u=x.cache,c=x.support.deleteExpando,f=x.event.special;for(;null!=(n=e[s]);s++)if((t||x.acceptData(n))&&(o=n[l],a=o&&u[o])){if(a.events)for(r in a.events)f[r]?x.event.remove(n,r):x.removeEvent(n,r,a.handle);
-u[o]&&(delete u[o],c?delete n[l]:typeof n.removeAttribute!==i?n.removeAttribute(l):n[l]=null,p.push(o))}},_evalUrl:function(e){return x.ajax({url:e,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})}}),x.fn.extend({wrapAll:function(e){if(x.isFunction(e))return this.each(function(t){x(this).wrapAll(e.call(this,t))});if(this[0]){var t=x(e,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstChild&&1===e.firstChild.nodeType)e=e.firstChild;return e}).append(this)}return this},wrapInner:function(e){return x.isFunction(e)?this.each(function(t){x(this).wrapInner(e.call(this,t))}):this.each(function(){var t=x(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=x.isFunction(e);return this.each(function(n){x(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){x.nodeName(this,"body")||x(this).replaceWith(this.childNodes)}).end()}});var Pt,Rt,Wt,$t=/alpha\([^)]*\)/i,It=/opacity\s*=\s*([^)]*)/,zt=/^(top|right|bottom|left)$/,Xt=/^(none|table(?!-c[ea]).+)/,Ut=/^margin/,Vt=RegExp("^("+w+")(.*)$","i"),Yt=RegExp("^("+w+")(?!px)[a-z%]+$","i"),Jt=RegExp("^([+-])=("+w+")","i"),Gt={BODY:"block"},Qt={position:"absolute",visibility:"hidden",display:"block"},Kt={letterSpacing:0,fontWeight:400},Zt=["Top","Right","Bottom","Left"],en=["Webkit","O","Moz","ms"];function tn(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=en.length;while(i--)if(t=en[i]+n,t in e)return t;return r}function nn(e,t){return e=t||e,"none"===x.css(e,"display")||!x.contains(e.ownerDocument,e)}function rn(e,t){var n,r,i,o=[],a=0,s=e.length;for(;s>a;a++)r=e[a],r.style&&(o[a]=x._data(r,"olddisplay"),n=r.style.display,t?(o[a]||"none"!==n||(r.style.display=""),""===r.style.display&&nn(r)&&(o[a]=x._data(r,"olddisplay",ln(r.nodeName)))):o[a]||(i=nn(r),(n&&"none"!==n||!i)&&x._data(r,"olddisplay",i?n:x.css(r,"display"))));for(a=0;s>a;a++)r=e[a],r.style&&(t&&"none"!==r.style.display&&""!==r.style.display||(r.style.display=t?o[a]||"":"none"));return e}x.fn.extend({css:function(e,n){return x.access(this,function(e,n,r){var i,o,a={},s=0;if(x.isArray(n)){for(o=Rt(e),i=n.length;i>s;s++)a[n[s]]=x.css(e,n[s],!1,o);return a}return r!==t?x.style(e,n,r):x.css(e,n)},e,n,arguments.length>1)},show:function(){return rn(this,!0)},hide:function(){return rn(this)},toggle:function(e){return"boolean"==typeof e?e?this.show():this.hide():this.each(function(){nn(this)?x(this).show():x(this).hide()})}}),x.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=Wt(e,"opacity");return""===n?"1":n}}}},cssNumber:{columnCount:!0,fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":x.support.cssFloat?"cssFloat":"styleFloat"},style:function(e,n,r,i){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var o,a,s,l=x.camelCase(n),u=e.style;if(n=x.cssProps[l]||(x.cssProps[l]=tn(u,l)),s=x.cssHooks[n]||x.cssHooks[l],r===t)return s&&"get"in s&&(o=s.get(e,!1,i))!==t?o:u[n];if(a=typeof r,"string"===a&&(o=Jt.exec(r))&&(r=(o[1]+1)*o[2]+parseFloat(x.css(e,n)),a="number"),!(null==r||"number"===a&&isNaN(r)||("number"!==a||x.cssNumber[l]||(r+="px"),x.support.clearCloneStyle||""!==r||0!==n.indexOf("background")||(u[n]="inherit"),s&&"set"in s&&(r=s.set(e,r,i))===t)))try{u[n]=r}catch(c){}}},css:function(e,n,r,i){var o,a,s,l=x.camelCase(n);return n=x.cssProps[l]||(x.cssProps[l]=tn(e.style,l)),s=x.cssHooks[n]||x.cssHooks[l],s&&"get"in s&&(a=s.get(e,!0,r)),a===t&&(a=Wt(e,n,i)),"normal"===a&&n in Kt&&(a=Kt[n]),""===r||r?(o=parseFloat(a),r===!0||x.isNumeric(o)?o||0:a):a}}),e.getComputedStyle?(Rt=function(t){return e.getComputedStyle(t,null)},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),l=s?s.getPropertyValue(n)||s[n]:t,u=e.style;return s&&(""!==l||x.contains(e.ownerDocument,e)||(l=x.style(e,n)),Yt.test(l)&&Ut.test(n)&&(i=u.width,o=u.minWidth,a=u.maxWidth,u.minWidth=u.maxWidth=u.width=l,l=s.width,u.width=i,u.minWidth=o,u.maxWidth=a)),l}):a.documentElement.currentStyle&&(Rt=function(e){return e.currentStyle},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),l=s?s[n]:t,u=e.style;return null==l&&u&&u[n]&&(l=u[n]),Yt.test(l)&&!zt.test(n)&&(i=u.left,o=e.runtimeStyle,a=o&&o.left,a&&(o.left=e.currentStyle.left),u.left="fontSize"===n?"1em":l,l=u.pixelLeft+"px",u.left=i,a&&(o.left=a)),""===l?"auto":l});function on(e,t,n){var r=Vt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function an(e,t,n,r,i){var o=n===(r?"border":"content")?4:"width"===t?1:0,a=0;for(;4>o;o+=2)"margin"===n&&(a+=x.css(e,n+Zt[o],!0,i)),r?("content"===n&&(a-=x.css(e,"padding"+Zt[o],!0,i)),"margin"!==n&&(a-=x.css(e,"border"+Zt[o]+"Width",!0,i))):(a+=x.css(e,"padding"+Zt[o],!0,i),"padding"!==n&&(a+=x.css(e,"border"+Zt[o]+"Width",!0,i)));return a}function sn(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=Rt(e),a=x.support.boxSizing&&"border-box"===x.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=Wt(e,t,o),(0>i||null==i)&&(i=e.style[t]),Yt.test(i))return i;r=a&&(x.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+an(e,t,n||(a?"border":"content"),r,o)+"px"}function ln(e){var t=a,n=Gt[e];return n||(n=un(e,t),"none"!==n&&n||(Pt=(Pt||x("<iframe frameborder='0' width='0' height='0'/>").css("cssText","display:block !important")).appendTo(t.documentElement),t=(Pt[0].contentWindow||Pt[0].contentDocument).document,t.write("<!doctype html><html><body>"),t.close(),n=un(e,t),Pt.detach()),Gt[e]=n),n}function un(e,t){var n=x(t.createElement(e)).appendTo(t.body),r=x.css(n[0],"display");return n.remove(),r}x.each(["height","width"],function(e,n){x.cssHooks[n]={get:function(e,r,i){return r?0===e.offsetWidth&&Xt.test(x.css(e,"display"))?x.swap(e,Qt,function(){return sn(e,n,i)}):sn(e,n,i):t},set:function(e,t,r){var i=r&&Rt(e);return on(e,t,r?an(e,n,r,x.support.boxSizing&&"border-box"===x.css(e,"boxSizing",!1,i),i):0)}}}),x.support.opacity||(x.cssHooks.opacity={get:function(e,t){return It.test((t&&e.currentStyle?e.currentStyle.filter:e.style.filter)||"")?.01*parseFloat(RegExp.$1)+"":t?"1":""},set:function(e,t){var n=e.style,r=e.currentStyle,i=x.isNumeric(t)?"alpha(opacity="+100*t+")":"",o=r&&r.filter||n.filter||"";n.zoom=1,(t>=1||""===t)&&""===x.trim(o.replace($t,""))&&n.removeAttribute&&(n.removeAttribute("filter"),""===t||r&&!r.filter)||(n.filter=$t.test(o)?o.replace($t,i):o+" "+i)}}),x(function(){x.support.reliableMarginRight||(x.cssHooks.marginRight={get:function(e,n){return n?x.swap(e,{display:"inline-block"},Wt,[e,"marginRight"]):t}}),!x.support.pixelPosition&&x.fn.position&&x.each(["top","left"],function(e,n){x.cssHooks[n]={get:function(e,r){return r?(r=Wt(e,n),Yt.test(r)?x(e).position()[n]+"px":r):t}}})}),x.expr&&x.expr.filters&&(x.expr.filters.hidden=function(e){return 0>=e.offsetWidth&&0>=e.offsetHeight||!x.support.reliableHiddenOffsets&&"none"===(e.style&&e.style.display||x.css(e,"display"))},x.expr.filters.visible=function(e){return!x.expr.filters.hidden(e)}),x.each({margin:"",padding:"",border:"Width"},function(e,t){x.cssHooks[e+t]={expand:function(n){var r=0,i={},o="string"==typeof n?n.split(" "):[n];for(;4>r;r++)i[e+Zt[r]+t]=o[r]||o[r-2]||o[0];return i}},Ut.test(e)||(x.cssHooks[e+t].set=on)});var cn=/%20/g,pn=/\[\]$/,fn=/\r?\n/g,dn=/^(?:submit|button|image|reset|file)$/i,hn=/^(?:input|select|textarea|keygen)/i;x.fn.extend({serialize:function(){return x.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var e=x.prop(this,"elements");return e?x.makeArray(e):this}).filter(function(){var e=this.type;return this.name&&!x(this).is(":disabled")&&hn.test(this.nodeName)&&!dn.test(e)&&(this.checked||!Ct.test(e))}).map(function(e,t){var n=x(this).val();return null==n?null:x.isArray(n)?x.map(n,function(e){return{name:t.name,value:e.replace(fn,"\r\n")}}):{name:t.name,value:n.replace(fn,"\r\n")}}).get()}}),x.param=function(e,n){var r,i=[],o=function(e,t){t=x.isFunction(t)?t():null==t?"":t,i[i.length]=encodeURIComponent(e)+"="+encodeURIComponent(t)};if(n===t&&(n=x.ajaxSettings&&x.ajaxSettings.traditional),x.isArray(e)||e.jquery&&!x.isPlainObject(e))x.each(e,function(){o(this.name,this.value)});else for(r in e)gn(r,e[r],n,o);return i.join("&").replace(cn,"+")};function gn(e,t,n,r){var i;if(x.isArray(t))x.each(t,function(t,i){n||pn.test(e)?r(e,i):gn(e+"["+("object"==typeof i?t:"")+"]",i,n,r)});else if(n||"object"!==x.type(t))r(e,t);else for(i in t)gn(e+"["+i+"]",t[i],n,r)}x.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error contextmenu".split(" "),function(e,t){x.fn[t]=function(e,n){return arguments.length>0?this.on(t,null,e,n):this.trigger(t)}}),x.fn.extend({hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)},bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)}});var mn,yn,vn=x.now(),bn=/\?/,xn=/#.*$/,wn=/([?&])_=[^&]*/,Tn=/^(.*?):[ \t]*([^\r\n]*)\r?$/gm,Cn=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,Nn=/^(?:GET|HEAD)$/,kn=/^\/\//,En=/^([\w.+-]+:)(?:\/\/([^\/?#:]*)(?::(\d+)|)|)/,Sn=x.fn.load,An={},jn={},Dn="*/".concat("*");try{yn=o.href}catch(Ln){yn=a.createElement("a"),yn.href="",yn=yn.href}mn=En.exec(yn.toLowerCase())||[];function Hn(e){return function(t,n){"string"!=typeof t&&(n=t,t="*");var r,i=0,o=t.toLowerCase().match(T)||[];if(x.isFunction(n))while(r=o[i++])"+"===r[0]?(r=r.slice(1)||"*",(e[r]=e[r]||[]).unshift(n)):(e[r]=e[r]||[]).push(n)}}function qn(e,n,r,i){var o={},a=e===jn;function s(l){var u;return o[l]=!0,x.each(e[l]||[],function(e,l){var c=l(n,r,i);return"string"!=typeof c||a||o[c]?a?!(u=c):t:(n.dataTypes.unshift(c),s(c),!1)}),u}return s(n.dataTypes[0])||!o["*"]&&s("*")}function _n(e,n){var r,i,o=x.ajaxSettings.flatOptions||{};for(i in n)n[i]!==t&&((o[i]?e:r||(r={}))[i]=n[i]);return r&&x.extend(!0,e,r),e}x.fn.load=function(e,n,r){if("string"!=typeof e&&Sn)return Sn.apply(this,arguments);var i,o,a,s=this,l=e.indexOf(" ");return l>=0&&(i=e.slice(l,e.length),e=e.slice(0,l)),x.isFunction(n)?(r=n,n=t):n&&"object"==typeof n&&(a="POST"),s.length>0&&x.ajax({url:e,type:a,dataType:"html",data:n}).done(function(e){o=arguments,s.html(i?x("<div>").append(x.parseHTML(e)).find(i):e)}).complete(r&&function(e,t){s.each(r,o||[e.responseText,t,e])}),this},x.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){x.fn[t]=function(e){return this.on(t,e)}}),x.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:yn,type:"GET",isLocal:Cn.test(mn[1]),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":Dn,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":x.parseJSON,"text xml":x.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(e,t){return t?_n(_n(e,x.ajaxSettings),t):_n(x.ajaxSettings,e)},ajaxPrefilter:Hn(An),ajaxTransport:Hn(jn),ajax:function(e,n){"object"==typeof e&&(n=e,e=t),n=n||{};var r,i,o,a,s,l,u,c,p=x.ajaxSetup({},n),f=p.context||p,d=p.context&&(f.nodeType||f.jquery)?x(f):x.event,h=x.Deferred(),g=x.Callbacks("once memory"),m=p.statusCode||{},y={},v={},b=0,w="canceled",C={readyState:0,getResponseHeader:function(e){var t;if(2===b){if(!c){c={};while(t=Tn.exec(a))c[t[1].toLowerCase()]=t[2]}t=c[e.toLowerCase()]}return null==t?null:t},getAllResponseHeaders:function(){return 2===b?a:null},setRequestHeader:function(e,t){var n=e.toLowerCase();return b||(e=v[n]=v[n]||e,y[e]=t),this},overrideMimeType:function(e){return b||(p.mimeType=e),this},statusCode:function(e){var t;if(e)if(2>b)for(t in e)m[t]=[m[t],e[t]];else C.always(e[C.status]);return this},abort:function(e){var t=e||w;return u&&u.abort(t),k(0,t),this}};if(h.promise(C).complete=g.add,C.success=C.done,C.error=C.fail,p.url=((e||p.url||yn)+"").replace(xn,"").replace(kn,mn[1]+"//"),p.type=n.method||n.type||p.method||p.type,p.dataTypes=x.trim(p.dataType||"*").toLowerCase().match(T)||[""],null==p.crossDomain&&(r=En.exec(p.url.toLowerCase()),p.crossDomain=!(!r||r[1]===mn[1]&&r[2]===mn[2]&&(r[3]||("http:"===r[1]?"80":"443"))===(mn[3]||("http:"===mn[1]?"80":"443")))),p.data&&p.processData&&"string"!=typeof p.data&&(p.data=x.param(p.data,p.traditional)),qn(An,p,n,C),2===b)return C;l=p.global,l&&0===x.active++&&x.event.trigger("ajaxStart"),p.type=p.type.toUpperCase(),p.hasContent=!Nn.test(p.type),o=p.url,p.hasContent||(p.data&&(o=p.url+=(bn.test(o)?"&":"?")+p.data,delete p.data),p.cache===!1&&(p.url=wn.test(o)?o.replace(wn,"$1_="+vn++):o+(bn.test(o)?"&":"?")+"_="+vn++)),p.ifModified&&(x.lastModified[o]&&C.setRequestHeader("If-Modified-Since",x.lastModified[o]),x.etag[o]&&C.setRequestHeader("If-None-Match",x.etag[o])),(p.data&&p.hasContent&&p.contentType!==!1||n.contentType)&&C.setRequestHeader("Content-Type",p.contentType),C.setRequestHeader("Accept",p.dataTypes[0]&&p.accepts[p.dataTypes[0]]?p.accepts[p.dataTypes[0]]+("*"!==p.dataTypes[0]?", "+Dn+"; q=0.01":""):p.accepts["*"]);for(i in p.headers)C.setRequestHeader(i,p.headers[i]);if(p.beforeSend&&(p.beforeSend.call(f,C,p)===!1||2===b))return C.abort();w="abort";for(i in{success:1,error:1,complete:1})C[i](p[i]);if(u=qn(jn,p,n,C)){C.readyState=1,l&&d.trigger("ajaxSend",[C,p]),p.async&&p.timeout>0&&(s=setTimeout(function(){C.abort("timeout")},p.timeout));try{b=1,u.send(y,k)}catch(N){if(!(2>b))throw N;k(-1,N)}}else k(-1,"No Transport");function k(e,n,r,i){var c,y,v,w,T,N=n;2!==b&&(b=2,s&&clearTimeout(s),u=t,a=i||"",C.readyState=e>0?4:0,c=e>=200&&300>e||304===e,r&&(w=Mn(p,C,r)),w=On(p,w,C,c),c?(p.ifModified&&(T=C.getResponseHeader("Last-Modified"),T&&(x.lastModified[o]=T),T=C.getResponseHeader("etag"),T&&(x.etag[o]=T)),204===e||"HEAD"===p.type?N="nocontent":304===e?N="notmodified":(N=w.state,y=w.data,v=w.error,c=!v)):(v=N,(e||!N)&&(N="error",0>e&&(e=0))),C.status=e,C.statusText=(n||N)+"",c?h.resolveWith(f,[y,N,C]):h.rejectWith(f,[C,N,v]),C.statusCode(m),m=t,l&&d.trigger(c?"ajaxSuccess":"ajaxError",[C,p,c?y:v]),g.fireWith(f,[C,N]),l&&(d.trigger("ajaxComplete",[C,p]),--x.active||x.event.trigger("ajaxStop")))}return C},getJSON:function(e,t,n){return x.get(e,t,n,"json")},getScript:function(e,n){return x.get(e,t,n,"script")}}),x.each(["get","post"],function(e,n){x[n]=function(e,r,i,o){return x.isFunction(r)&&(o=o||i,i=r,r=t),x.ajax({url:e,type:n,dataType:o,data:r,success:i})}});function Mn(e,n,r){var i,o,a,s,l=e.contents,u=e.dataTypes;while("*"===u[0])u.shift(),o===t&&(o=e.mimeType||n.getResponseHeader("Content-Type"));if(o)for(s in l)if(l[s]&&l[s].test(o)){u.unshift(s);break}if(u[0]in r)a=u[0];else{for(s in r){if(!u[0]||e.converters[s+" "+u[0]]){a=s;break}i||(i=s)}a=a||i}return a?(a!==u[0]&&u.unshift(a),r[a]):t}function On(e,t,n,r){var i,o,a,s,l,u={},c=e.dataTypes.slice();if(c[1])for(a in e.converters)u[a.toLowerCase()]=e.converters[a];o=c.shift();while(o)if(e.responseFields[o]&&(n[e.responseFields[o]]=t),!l&&r&&e.dataFilter&&(t=e.dataFilter(t,e.dataType)),l=o,o=c.shift())if("*"===o)o=l;else if("*"!==l&&l!==o){if(a=u[l+" "+o]||u["* "+o],!a)for(i in u)if(s=i.split(" "),s[1]===o&&(a=u[l+" "+s[0]]||u["* "+s[0]])){a===!0?a=u[i]:u[i]!==!0&&(o=s[0],c.unshift(s[1]));break}if(a!==!0)if(a&&e["throws"])t=a(t);else try{t=a(t)}catch(p){return{state:"parsererror",error:a?p:"No conversion from "+l+" to "+o}}}return{state:"success",data:t}}x.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/(?:java|ecma)script/},converters:{"text script":function(e){return x.globalEval(e),e}}}),x.ajaxPrefilter("script",function(e){e.cache===t&&(e.cache=!1),e.crossDomain&&(e.type="GET",e.global=!1)}),x.ajaxTransport("script",function(e){if(e.crossDomain){var n,r=a.head||x("head")[0]||a.documentElement;return{send:function(t,i){n=a.createElement("script"),n.async=!0,e.scriptCharset&&(n.charset=e.scriptCharset),n.src=e.url,n.onload=n.onreadystatechange=function(e,t){(t||!n.readyState||/loaded|complete/.test(n.readyState))&&(n.onload=n.onreadystatechange=null,n.parentNode&&n.parentNode.removeChild(n),n=null,t||i(200,"success"))},r.insertBefore(n,r.firstChild)},abort:function(){n&&n.onload(t,!0)}}}});var Fn=[],Bn=/(=)\?(?=&|$)|\?\?/;x.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Fn.pop()||x.expando+"_"+vn++;return this[e]=!0,e}}),x.ajaxPrefilter("json jsonp",function(n,r,i){var o,a,s,l=n.jsonp!==!1&&(Bn.test(n.url)?"url":"string"==typeof n.data&&!(n.contentType||"").indexOf("application/x-www-form-urlencoded")&&Bn.test(n.data)&&"data");return l||"jsonp"===n.dataTypes[0]?(o=n.jsonpCallback=x.isFunction(n.jsonpCallback)?n.jsonpCallback():n.jsonpCallback,l?n[l]=n[l].replace(Bn,"$1"+o):n.jsonp!==!1&&(n.url+=(bn.test(n.url)?"&":"?")+n.jsonp+"="+o),n.converters["script json"]=function(){return s||x.error(o+" was not called"),s[0]},n.dataTypes[0]="json",a=e[o],e[o]=function(){s=arguments},i.always(function(){e[o]=a,n[o]&&(n.jsonpCallback=r.jsonpCallback,Fn.push(o)),s&&x.isFunction(a)&&a(s[0]),s=a=t}),"script"):t});var Pn,Rn,Wn=0,$n=e.ActiveXObject&&function(){var e;for(e in Pn)Pn[e](t,!0)};function In(){try{return new e.XMLHttpRequest}catch(t){}}function zn(){try{return new e.ActiveXObject("Microsoft.XMLHTTP")}catch(t){}}x.ajaxSettings.xhr=e.ActiveXObject?function(){return!this.isLocal&&In()||zn()}:In,Rn=x.ajaxSettings.xhr(),x.support.cors=!!Rn&&"withCredentials"in Rn,Rn=x.support.ajax=!!Rn,Rn&&x.ajaxTransport(function(n){if(!n.crossDomain||x.support.cors){var r;return{send:function(i,o){var a,s,l=n.xhr();if(n.username?l.open(n.type,n.url,n.async,n.username,n.password):l.open(n.type,n.url,n.async),n.xhrFields)for(s in n.xhrFields)l[s]=n.xhrFields[s];n.mimeType&&l.overrideMimeType&&l.overrideMimeType(n.mimeType),n.crossDomain||i["X-Requested-With"]||(i["X-Requested-With"]="XMLHttpRequest");try{for(s in i)l.setRequestHeader(s,i[s])}catch(u){}l.send(n.hasContent&&n.data||null),r=function(e,i){var s,u,c,p;try{if(r&&(i||4===l.readyState))if(r=t,a&&(l.onreadystatechange=x.noop,$n&&delete Pn[a]),i)4!==l.readyState&&l.abort();else{p={},s=l.status,u=l.getAllResponseHeaders(),"string"==typeof l.responseText&&(p.text=l.responseText);try{c=l.statusText}catch(f){c=""}s||!n.isLocal||n.crossDomain?1223===s&&(s=204):s=p.text?200:404}}catch(d){i||o(-1,d)}p&&o(s,c,p,u)},n.async?4===l.readyState?setTimeout(r):(a=++Wn,$n&&(Pn||(Pn={},x(e).unload($n)),Pn[a]=r),l.onreadystatechange=r):r()},abort:function(){r&&r(t,!0)}}}});var Xn,Un,Vn=/^(?:toggle|show|hide)$/,Yn=RegExp("^(?:([+-])=|)("+w+")([a-z%]*)$","i"),Jn=/queueHooks$/,Gn=[nr],Qn={"*":[function(e,t){var n=this.createTween(e,t),r=n.cur(),i=Yn.exec(t),o=i&&i[3]||(x.cssNumber[e]?"":"px"),a=(x.cssNumber[e]||"px"!==o&&+r)&&Yn.exec(x.css(n.elem,e)),s=1,l=20;if(a&&a[3]!==o){o=o||a[3],i=i||[],a=+r||1;do s=s||".5",a/=s,x.style(n.elem,e,a+o);while(s!==(s=n.cur()/r)&&1!==s&&--l)}return i&&(a=n.start=+a||+r||0,n.unit=o,n.end=i[1]?a+(i[1]+1)*i[2]:+i[2]),n}]};function Kn(){return setTimeout(function(){Xn=t}),Xn=x.now()}function Zn(e,t,n){var r,i=(Qn[t]||[]).concat(Qn["*"]),o=0,a=i.length;for(;a>o;o++)if(r=i[o].call(n,t,e))return r}function er(e,t,n){var r,i,o=0,a=Gn.length,s=x.Deferred().always(function(){delete l.elem}),l=function(){if(i)return!1;var t=Xn||Kn(),n=Math.max(0,u.startTime+u.duration-t),r=n/u.duration||0,o=1-r,a=0,l=u.tweens.length;for(;l>a;a++)u.tweens[a].run(o);return s.notifyWith(e,[u,o,n]),1>o&&l?n:(s.resolveWith(e,[u]),!1)},u=s.promise({elem:e,props:x.extend({},t),opts:x.extend(!0,{specialEasing:{}},n),originalProperties:t,originalOptions:n,startTime:Xn||Kn(),duration:n.duration,tweens:[],createTween:function(t,n){var r=x.Tween(e,u.opts,t,n,u.opts.specialEasing[t]||u.opts.easing);return u.tweens.push(r),r},stop:function(t){var n=0,r=t?u.tweens.length:0;if(i)return this;for(i=!0;r>n;n++)u.tweens[n].run(1);return t?s.resolveWith(e,[u,t]):s.rejectWith(e,[u,t]),this}}),c=u.props;for(tr(c,u.opts.specialEasing);a>o;o++)if(r=Gn[o].call(u,e,c,u.opts))return r;return x.map(c,Zn,u),x.isFunction(u.opts.start)&&u.opts.start.call(e,u),x.fx.timer(x.extend(l,{elem:e,anim:u,queue:u.opts.queue})),u.progress(u.opts.progress).done(u.opts.done,u.opts.complete).fail(u.opts.fail).always(u.opts.always)}function tr(e,t){var n,r,i,o,a;for(n in e)if(r=x.camelCase(n),i=t[r],o=e[n],x.isArray(o)&&(i=o[1],o=e[n]=o[0]),n!==r&&(e[r]=o,delete e[n]),a=x.cssHooks[r],a&&"expand"in a){o=a.expand(o),delete e[r];for(n in o)n in e||(e[n]=o[n],t[n]=i)}else t[r]=i}x.Animation=x.extend(er,{tweener:function(e,t){x.isFunction(e)?(t=e,e=["*"]):e=e.split(" ");var n,r=0,i=e.length;for(;i>r;r++)n=e[r],Qn[n]=Qn[n]||[],Qn[n].unshift(t)},prefilter:function(e,t){t?Gn.unshift(e):Gn.push(e)}});function nr(e,t,n){var r,i,o,a,s,l,u=this,c={},p=e.style,f=e.nodeType&&nn(e),d=x._data(e,"fxshow");n.queue||(s=x._queueHooks(e,"fx"),null==s.unqueued&&(s.unqueued=0,l=s.empty.fire,s.empty.fire=function(){s.unqueued||l()}),s.unqueued++,u.always(function(){u.always(function(){s.unqueued--,x.queue(e,"fx").length||s.empty.fire()})})),1===e.nodeType&&("height"in t||"width"in t)&&(n.overflow=[p.overflow,p.overflowX,p.overflowY],"inline"===x.css(e,"display")&&"none"===x.css(e,"float")&&(x.support.inlineBlockNeedsLayout&&"inline"!==ln(e.nodeName)?p.zoom=1:p.display="inline-block")),n.overflow&&(p.overflow="hidden",x.support.shrinkWrapBlocks||u.always(function(){p.overflow=n.overflow[0],p.overflowX=n.overflow[1],p.overflowY=n.overflow[2]}));for(r in t)if(i=t[r],Vn.exec(i)){if(delete t[r],o=o||"toggle"===i,i===(f?"hide":"show"))continue;c[r]=d&&d[r]||x.style(e,r)}if(!x.isEmptyObject(c)){d?"hidden"in d&&(f=d.hidden):d=x._data(e,"fxshow",{}),o&&(d.hidden=!f),f?x(e).show():u.done(function(){x(e).hide()}),u.done(function(){var t;x._removeData(e,"fxshow");for(t in c)x.style(e,t,c[t])});for(r in c)a=Zn(f?d[r]:0,r,u),r in d||(d[r]=a.start,f&&(a.end=a.start,a.start="width"===r||"height"===r?1:0))}}function rr(e,t,n,r,i){return new rr.prototype.init(e,t,n,r,i)}x.Tween=rr,rr.prototype={constructor:rr,init:function(e,t,n,r,i,o){this.elem=e,this.prop=n,this.easing=i||"swing",this.options=t,this.start=this.now=this.cur(),this.end=r,this.unit=o||(x.cssNumber[n]?"":"px")},cur:function(){var e=rr.propHooks[this.prop];return e&&e.get?e.get(this):rr.propHooks._default.get(this)},run:function(e){var t,n=rr.propHooks[this.prop];return this.pos=t=this.options.duration?x.easing[this.easing](e,this.options.duration*e,0,1,this.options.duration):e,this.now=(this.end-this.start)*t+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),n&&n.set?n.set(this):rr.propHooks._default.set(this),this}},rr.prototype.init.prototype=rr.prototype,rr.propHooks={_default:{get:function(e){var t;return null==e.elem[e.prop]||e.elem.style&&null!=e.elem.style[e.prop]?(t=x.css(e.elem,e.prop,""),t&&"auto"!==t?t:0):e.elem[e.prop]},set:function(e){x.fx.step[e.prop]?x.fx.step[e.prop](e):e.elem.style&&(null!=e.elem.style[x.cssProps[e.prop]]||x.cssHooks[e.prop])?x.style(e.elem,e.prop,e.now+e.unit):e.elem[e.prop]=e.now}}},rr.propHooks.scrollTop=rr.propHooks.scrollLeft={set:function(e){e.elem.nodeType&&e.elem.parentNode&&(e.elem[e.prop]=e.now)}},x.each(["toggle","show","hide"],function(e,t){var n=x.fn[t];x.fn[t]=function(e,r,i){return null==e||"boolean"==typeof e?n.apply(this,arguments):this.animate(ir(t,!0),e,r,i)}}),x.fn.extend({fadeTo:function(e,t,n,r){return this.filter(nn).css("opacity",0).show().end().animate({opacity:t},e,n,r)},animate:function(e,t,n,r){var i=x.isEmptyObject(e),o=x.speed(t,n,r),a=function(){var t=er(this,x.extend({},e),o);(i||x._data(this,"finish"))&&t.stop(!0)};return a.finish=a,i||o.queue===!1?this.each(a):this.queue(o.queue,a)},stop:function(e,n,r){var i=function(e){var t=e.stop;delete e.stop,t(r)};return"string"!=typeof e&&(r=n,n=e,e=t),n&&e!==!1&&this.queue(e||"fx",[]),this.each(function(){var t=!0,n=null!=e&&e+"queueHooks",o=x.timers,a=x._data(this);if(n)a[n]&&a[n].stop&&i(a[n]);else for(n in a)a[n]&&a[n].stop&&Jn.test(n)&&i(a[n]);for(n=o.length;n--;)o[n].elem!==this||null!=e&&o[n].queue!==e||(o[n].anim.stop(r),t=!1,o.splice(n,1));(t||!r)&&x.dequeue(this,e)})},finish:function(e){return e!==!1&&(e=e||"fx"),this.each(function(){var t,n=x._data(this),r=n[e+"queue"],i=n[e+"queueHooks"],o=x.timers,a=r?r.length:0;for(n.finish=!0,x.queue(this,e,[]),i&&i.stop&&i.stop.call(this,!0),t=o.length;t--;)o[t].elem===this&&o[t].queue===e&&(o[t].anim.stop(!0),o.splice(t,1));for(t=0;a>t;t++)r[t]&&r[t].finish&&r[t].finish.call(this);delete n.finish})}});function ir(e,t){var n,r={height:e},i=0;for(t=t?1:0;4>i;i+=2-t)n=Zt[i],r["margin"+n]=r["padding"+n]=e;return t&&(r.opacity=r.width=e),r}x.each({slideDown:ir("show"),slideUp:ir("hide"),slideToggle:ir("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(e,t){x.fn[e]=function(e,n,r){return this.animate(t,e,n,r)}}),x.speed=function(e,t,n){var r=e&&"object"==typeof e?x.extend({},e):{complete:n||!n&&t||x.isFunction(e)&&e,duration:e,easing:n&&t||t&&!x.isFunction(t)&&t};return r.duration=x.fx.off?0:"number"==typeof r.duration?r.duration:r.duration in x.fx.speeds?x.fx.speeds[r.duration]:x.fx.speeds._default,(null==r.queue||r.queue===!0)&&(r.queue="fx"),r.old=r.complete,r.complete=function(){x.isFunction(r.old)&&r.old.call(this),r.queue&&x.dequeue(this,r.queue)},r},x.easing={linear:function(e){return e},swing:function(e){return.5-Math.cos(e*Math.PI)/2}},x.timers=[],x.fx=rr.prototype.init,x.fx.tick=function(){var e,n=x.timers,r=0;for(Xn=x.now();n.length>r;r++)e=n[r],e()||n[r]!==e||n.splice(r--,1);n.length||x.fx.stop(),Xn=t},x.fx.timer=function(e){e()&&x.timers.push(e)&&x.fx.start()},x.fx.interval=13,x.fx.start=function(){Un||(Un=setInterval(x.fx.tick,x.fx.interval))},x.fx.stop=function(){clearInterval(Un),Un=null},x.fx.speeds={slow:600,fast:200,_default:400},x.fx.step={},x.expr&&x.expr.filters&&(x.expr.filters.animated=function(e){return x.grep(x.timers,function(t){return e===t.elem}).length}),x.fn.offset=function(e){if(arguments.length)return e===t?this:this.each(function(t){x.offset.setOffset(this,e,t)});var n,r,o={top:0,left:0},a=this[0],s=a&&a.ownerDocument;if(s)return n=s.documentElement,x.contains(n,a)?(typeof a.getBoundingClientRect!==i&&(o=a.getBoundingClientRect()),r=or(s),{top:o.top+(r.pageYOffset||n.scrollTop)-(n.clientTop||0),left:o.left+(r.pageXOffset||n.scrollLeft)-(n.clientLeft||0)}):o},x.offset={setOffset:function(e,t,n){var r=x.css(e,"position");"static"===r&&(e.style.position="relative");var i=x(e),o=i.offset(),a=x.css(e,"top"),s=x.css(e,"left"),l=("absolute"===r||"fixed"===r)&&x.inArray("auto",[a,s])>-1,u={},c={},p,f;l?(c=i.position(),p=c.top,f=c.left):(p=parseFloat(a)||0,f=parseFloat(s)||0),x.isFunction(t)&&(t=t.call(e,n,o)),null!=t.top&&(u.top=t.top-o.top+p),null!=t.left&&(u.left=t.left-o.left+f),"using"in t?t.using.call(e,u):i.css(u)}},x.fn.extend({position:function(){if(this[0]){var e,t,n={top:0,left:0},r=this[0];return"fixed"===x.css(r,"position")?t=r.getBoundingClientRect():(e=this.offsetParent(),t=this.offset(),x.nodeName(e[0],"html")||(n=e.offset()),n.top+=x.css(e[0],"borderTopWidth",!0),n.left+=x.css(e[0],"borderLeftWidth",!0)),{top:t.top-n.top-x.css(r,"marginTop",!0),left:t.left-n.left-x.css(r,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var e=this.offsetParent||s;while(e&&!x.nodeName(e,"html")&&"static"===x.css(e,"position"))e=e.offsetParent;return e||s})}}),x.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(e,n){var r=/Y/.test(n);x.fn[e]=function(i){return x.access(this,function(e,i,o){var a=or(e);return o===t?a?n in a?a[n]:a.document.documentElement[i]:e[i]:(a?a.scrollTo(r?x(a).scrollLeft():o,r?o:x(a).scrollTop()):e[i]=o,t)},e,i,arguments.length,null)}});function or(e){return x.isWindow(e)?e:9===e.nodeType?e.defaultView||e.parentWindow:!1}x.each({Height:"height",Width:"width"},function(e,n){x.each({padding:"inner"+e,content:n,"":"outer"+e},function(r,i){x.fn[i]=function(i,o){var a=arguments.length&&(r||"boolean"!=typeof i),s=r||(i===!0||o===!0?"margin":"border");return x.access(this,function(n,r,i){var o;return x.isWindow(n)?n.document.documentElement["client"+e]:9===n.nodeType?(o=n.documentElement,Math.max(n.body["scroll"+e],o["scroll"+e],n.body["offset"+e],o["offset"+e],o["client"+e])):i===t?x.css(n,r,s):x.style(n,r,i,s)},n,a?i:t,a,null)}})}),x.fn.size=function(){return this.length},x.fn.andSelf=x.fn.addBack,"object"==typeof module&&module&&"object"==typeof module.exports?module.exports=x:(e.jQuery=e.$=x,"function"==typeof define&&define.amd&&define("jquery",[],function(){return x}))})(window);
diff --git a/www/js/jquery-deprecated-sizzle.js b/www/js/jquery-deprecated-sizzle.js
deleted file mode 100644 (file)
index 19d7d4d..0000000
+++ /dev/null
@@ -1,7281 +0,0 @@
-/*!
- * jQuery JavaScript Library v2.1.1 -deprecated,-css/hiddenVisibleSelectors,-effects/animatedSelector
- * http://jquery.com/
- *
- * Includes Sizzle.js
- * http://sizzlejs.com/
- *
- * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
- * Released under the MIT license
- * http://jquery.org/license
- *
- * Date: 2014-09-28T02:59Z
- */
-
-(function( global, factory ) {
-
-       if ( typeof module === "object" && typeof module.exports === "object" ) {
-               // For CommonJS and CommonJS-like environments where a proper window is present,
-               // execute the factory and get jQuery
-               // For environments that do not inherently posses a window with a document
-               // (such as Node.js), expose a jQuery-making factory as module.exports
-               // This accentuates the need for the creation of a real window
-               // e.g. var jQuery = require("jquery")(window);
-               // See ticket #14549 for more info
-               module.exports = global.document ?
-                       factory( global, true ) :
-                       function( w ) {
-                               if ( !w.document ) {
-                                       throw new Error( "jQuery requires a window with a document" );
-                               }
-                               return factory( w );
-                       };
-       } else {
-               factory( global );
-       }
-
-// Pass this if window is not defined yet
-}(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
-
-// Can't do this because several apps including ASP.NET trace
-// the stack via arguments.caller.callee and Firefox dies if
-// you try to trace through "use strict" call chains. (#13335)
-// Support: Firefox 18+
-//
-
-var arr = [];
-
-var slice = arr.slice;
-
-var concat = arr.concat;
-
-var push = arr.push;
-
-var indexOf = arr.indexOf;
-
-var class2type = {};
-
-var toString = class2type.toString;
-
-var hasOwn = class2type.hasOwnProperty;
-
-var support = {};
-
-
-
-var
-       // Use the correct document accordingly with window argument (sandbox)
-       document = window.document,
-
-       version = "2.1.1 -deprecated,-css/hiddenVisibleSelectors,-effects/animatedSelector",
-
-       // Define a local copy of jQuery
-       jQuery = function( selector, context ) {
-               // The jQuery object is actually just the init constructor 'enhanced'
-               // Need init if jQuery is called (just allow error to be thrown if not included)
-               return new jQuery.fn.init( selector, context );
-       },
-
-       // Support: Android<4.1
-       // Make sure we trim BOM and NBSP
-       rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
-
-       // Matches dashed string for camelizing
-       rmsPrefix = /^-ms-/,
-       rdashAlpha = /-([\da-z])/gi,
-
-       // Used by jQuery.camelCase as callback to replace()
-       fcamelCase = function( all, letter ) {
-               return letter.toUpperCase();
-       };
-
-jQuery.fn = jQuery.prototype = {
-       // The current version of jQuery being used
-       jquery: version,
-
-       constructor: jQuery,
-
-       // Start with an empty selector
-       selector: "",
-
-       // The default length of a jQuery object is 0
-       length: 0,
-
-       toArray: function() {
-               return slice.call( this );
-       },
-
-       // Get the Nth element in the matched element set OR
-       // Get the whole matched element set as a clean array
-       get: function( num ) {
-               return num != null ?
-
-                       // Return just the one element from the set
-                       ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
-
-                       // Return all the elements in a clean array
-                       slice.call( this );
-       },
-
-       // Take an array of elements and push it onto the stack
-       // (returning the new matched element set)
-       pushStack: function( elems ) {
-
-               // Build a new jQuery matched element set
-               var ret = jQuery.merge( this.constructor(), elems );
-
-               // Add the old object onto the stack (as a reference)
-               ret.prevObject = this;
-               ret.context = this.context;
-
-               // Return the newly-formed element set
-               return ret;
-       },
-
-       // Execute a callback for every element in the matched set.
-       // (You can seed the arguments with an array of args, but this is
-       // only used internally.)
-       each: function( callback, args ) {
-               return jQuery.each( this, callback, args );
-       },
-
-       map: function( callback ) {
-               return this.pushStack( jQuery.map(this, function( elem, i ) {
-                       return callback.call( elem, i, elem );
-               }));
-       },
-
-       slice: function() {
-               return this.pushStack( slice.apply( this, arguments ) );
-       },
-
-       first: function() {
-               return this.eq( 0 );
-       },
-
-       last: function() {
-               return this.eq( -1 );
-       },
-
-       eq: function( i ) {
-               var len = this.length,
-                       j = +i + ( i < 0 ? len : 0 );
-               return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
-       },
-
-       end: function() {
-               return this.prevObject || this.constructor(null);
-       },
-
-       // For internal use only.
-       // Behaves like an Array's method, not like a jQuery method.
-       push: push,
-       sort: arr.sort,
-       splice: arr.splice
-};
-
-jQuery.extend = jQuery.fn.extend = function() {
-       var options, name, src, copy, copyIsArray, clone,
-               target = arguments[0] || {},
-               i = 1,
-               length = arguments.length,
-               deep = false;
-
-       // Handle a deep copy situation
-       if ( typeof target === "boolean" ) {
-               deep = target;
-
-               // skip the boolean and the target
-               target = arguments[ i ] || {};
-               i++;
-       }
-
-       // Handle case when target is a string or something (possible in deep copy)
-       if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
-               target = {};
-       }
-
-       // extend jQuery itself if only one argument is passed
-       if ( i === length ) {
-               target = this;
-               i--;
-       }
-
-       for ( ; i < length; i++ ) {
-               // Only deal with non-null/undefined values
-               if ( (options = arguments[ i ]) != null ) {
-                       // Extend the base object
-                       for ( name in options ) {
-                               src = target[ name ];
-                               copy = options[ name ];
-
-                               // Prevent never-ending loop
-                               if ( target === copy ) {
-                                       continue;
-                               }
-
-                               // Recurse if we're merging plain objects or arrays
-                               if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
-                                       if ( copyIsArray ) {
-                                               copyIsArray = false;
-                                               clone = src && jQuery.isArray(src) ? src : [];
-
-                                       } else {
-                                               clone = src && jQuery.isPlainObject(src) ? src : {};
-                                       }
-
-                                       // Never move original objects, clone them
-                                       target[ name ] = jQuery.extend( deep, clone, copy );
-
-                               // Don't bring in undefined values
-                               } else if ( copy !== undefined ) {
-                                       target[ name ] = copy;
-                               }
-                       }
-               }
-       }
-
-       // Return the modified object
-       return target;
-};
-
-jQuery.extend({
-       // Unique for each copy of jQuery on the page
-       expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
-
-       // Assume jQuery is ready without the ready module
-       isReady: true,
-
-       error: function( msg ) {
-               throw new Error( msg );
-       },
-
-       noop: function() {},
-
-       // See test/unit/core.js for details concerning isFunction.
-       // Since version 1.3, DOM methods and functions like alert
-       // aren't supported. They return false on IE (#2968).
-       isFunction: function( obj ) {
-               return jQuery.type(obj) === "function";
-       },
-
-       isArray: Array.isArray,
-
-       isWindow: function( obj ) {
-               return obj != null && obj === obj.window;
-       },
-
-       isNumeric: function( obj ) {
-               // parseFloat NaNs numeric-cast false positives (null|true|false|"")
-               // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
-               // subtraction forces infinities to NaN
-               return !jQuery.isArray( obj ) && obj - parseFloat( obj ) >= 0;
-       },
-
-       isPlainObject: function( obj ) {
-               // Not plain objects:
-               // - Any object or value whose internal [[Class]] property is not "[object Object]"
-               // - DOM nodes
-               // - window
-               if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
-                       return false;
-               }
-
-               if ( obj.constructor &&
-                               !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
-                       return false;
-               }
-
-               // If the function hasn't returned already, we're confident that
-               // |obj| is a plain object, created by {} or constructed with new Object
-               return true;
-       },
-
-       isEmptyObject: function( obj ) {
-               var name;
-               for ( name in obj ) {
-                       return false;
-               }
-               return true;
-       },
-
-       type: function( obj ) {
-               if ( obj == null ) {
-                       return obj + "";
-               }
-               // Support: Android < 4.0, iOS < 6 (functionish RegExp)
-               return typeof obj === "object" || typeof obj === "function" ?
-                       class2type[ toString.call(obj) ] || "object" :
-                       typeof obj;
-       },
-
-       // Evaluates a script in a global context
-       globalEval: function( code ) {
-               var script,
-                       indirect = eval;
-
-               code = jQuery.trim( code );
-
-               if ( code ) {
-                       // If the code includes a valid, prologue position
-                       // strict mode pragma, execute code by injecting a
-                       // script tag into the document.
-                       if ( code.indexOf("use strict") === 1 ) {
-                               script = document.createElement("script");
-                               script.text = code;
-                               document.head.appendChild( script ).parentNode.removeChild( script );
-                       } else {
-                       // Otherwise, avoid the DOM node creation, insertion
-                       // and removal by using an indirect global eval
-                               indirect( code );
-                       }
-               }
-       },
-
-       // Convert dashed to camelCase; used by the css and data modules
-       // Microsoft forgot to hump their vendor prefix (#9572)
-       camelCase: function( string ) {
-               return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
-       },
-
-       nodeName: function( elem, name ) {
-               return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
-       },
-
-       // args is for internal usage only
-       each: function( obj, callback, args ) {
-               var value,
-                       i = 0,
-                       length = obj.length,
-                       isArray = isArraylike( obj );
-
-               if ( args ) {
-                       if ( isArray ) {
-                               for ( ; i < length; i++ ) {
-                                       value = callback.apply( obj[ i ], args );
-
-                                       if ( value === false ) {
-                                               break;
-                                       }
-                               }
-                       } else {
-                               for ( i in obj ) {
-                                       value = callback.apply( obj[ i ], args );
-
-                                       if ( value === false ) {
-                                               break;
-                                       }
-                               }
-                       }
-
-               // A special, fast, case for the most common use of each
-               } else {
-                       if ( isArray ) {
-                               for ( ; i < length; i++ ) {
-                                       value = callback.call( obj[ i ], i, obj[ i ] );
-
-                                       if ( value === false ) {
-                                               break;
-                                       }
-                               }
-                       } else {
-                               for ( i in obj ) {
-                                       value = callback.call( obj[ i ], i, obj[ i ] );
-
-                                       if ( value === false ) {
-                                               break;
-                                       }
-                               }
-                       }
-               }
-
-               return obj;
-       },
-
-       // Support: Android<4.1
-       trim: function( text ) {
-               return text == null ?
-                       "" :
-                       ( text + "" ).replace( rtrim, "" );
-       },
-
-       // results is for internal usage only
-       makeArray: function( arr, results ) {
-               var ret = results || [];
-
-               if ( arr != null ) {
-                       if ( isArraylike( Object(arr) ) ) {
-                               jQuery.merge( ret,
-                                       typeof arr === "string" ?
-                                       [ arr ] : arr
-                               );
-                       } else {
-                               push.call( ret, arr );
-                       }
-               }
-
-               return ret;
-       },
-
-       inArray: function( elem, arr, i ) {
-               return arr == null ? -1 : indexOf.call( arr, elem, i );
-       },
-
-       merge: function( first, second ) {
-               var len = +second.length,
-                       j = 0,
-                       i = first.length;
-
-               for ( ; j < len; j++ ) {
-                       first[ i++ ] = second[ j ];
-               }
-
-               first.length = i;
-
-               return first;
-       },
-
-       grep: function( elems, callback, invert ) {
-               var callbackInverse,
-                       matches = [],
-                       i = 0,
-                       length = elems.length,
-                       callbackExpect = !invert;
-
-               // Go through the array, only saving the items
-               // that pass the validator function
-               for ( ; i < length; i++ ) {
-                       callbackInverse = !callback( elems[ i ], i );
-                       if ( callbackInverse !== callbackExpect ) {
-                               matches.push( elems[ i ] );
-                       }
-               }
-
-               return matches;
-       },
-
-       // arg is for internal usage only
-       map: function( elems, callback, arg ) {
-               var value,
-                       i = 0,
-                       length = elems.length,
-                       isArray = isArraylike( elems ),
-                       ret = [];
-
-               // Go through the array, translating each of the items to their new values
-               if ( isArray ) {
-                       for ( ; i < length; i++ ) {
-                               value = callback( elems[ i ], i, arg );
-
-                               if ( value != null ) {
-                                       ret.push( value );
-                               }
-                       }
-
-               // Go through every key on the object,
-               } else {
-                       for ( i in elems ) {
-                               value = callback( elems[ i ], i, arg );
-
-                               if ( value != null ) {
-                                       ret.push( value );
-                               }
-                       }
-               }
-
-               // Flatten any nested arrays
-               return concat.apply( [], ret );
-       },
-
-       // A global GUID counter for objects
-       guid: 1,
-
-       // Bind a function to a context, optionally partially applying any
-       // arguments.
-       proxy: function( fn, context ) {
-               var tmp, args, proxy;
-
-               if ( typeof context === "string" ) {
-                       tmp = fn[ context ];
-                       context = fn;
-                       fn = tmp;
-               }
-
-               // Quick check to determine if target is callable, in the spec
-               // this throws a TypeError, but we will just return undefined.
-               if ( !jQuery.isFunction( fn ) ) {
-                       return undefined;
-               }
-
-               // Simulated bind
-               args = slice.call( arguments, 2 );
-               proxy = function() {
-                       return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
-               };
-
-               // Set the guid of unique handler to the same of original handler, so it can be removed
-               proxy.guid = fn.guid = fn.guid || jQuery.guid++;
-
-               return proxy;
-       },
-
-       now: Date.now,
-
-       // jQuery.support is not used in Core but other projects attach their
-       // properties to it so it needs to exist.
-       support: support
-});
-
-// Populate the class2type map
-jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
-       class2type[ "[object " + name + "]" ] = name.toLowerCase();
-});
-
-function isArraylike( obj ) {
-       var length = obj.length,
-               type = jQuery.type( obj );
-
-       if ( type === "function" || jQuery.isWindow( obj ) ) {
-               return false;
-       }
-
-       if ( obj.nodeType === 1 && length ) {
-               return true;
-       }
-
-       return type === "array" || length === 0 ||
-               typeof length === "number" && length > 0 && ( length - 1 ) in obj;
-}
-
-
-/*
- * Optional (non-Sizzle) selector module for custom builds.
- *
- * Note that this DOES NOT SUPPORT many documented jQuery
- * features in exchange for its smaller size:
- *
- * Attribute not equal selector
- * Positional selectors (:first; :eq(n); :odd; etc.)
- * Type selectors (:input; :checkbox; :button; etc.)
- * State-based selectors (:animated; :visible; :hidden; etc.)
- * :has(selector)
- * :not(complex selector)
- * custom selectors via Sizzle extensions
- * Leading combinators (e.g., $collection.find("> *"))
- * Reliable functionality on XML fragments
- * Requiring all parts of a selector to match elements under context
- *   (e.g., $div.find("div > *") now matches children of $div)
- * Matching against non-elements
- * Reliable sorting of disconnected nodes
- * querySelectorAll bug fixes (e.g., unreliable :focus on WebKit)
- *
- * If any of these are unacceptable tradeoffs, either use Sizzle or
- * customize this stub for the project's specific needs.
- */
-
-var docElem = window.document.documentElement,
-       selector_hasDuplicate,
-       matches = docElem.matches ||
-               docElem.webkitMatchesSelector ||
-               docElem.mozMatchesSelector ||
-               docElem.oMatchesSelector ||
-               docElem.msMatchesSelector,
-       selector_sortOrder = function( a, b ) {
-               // Flag for duplicate removal
-               if ( a === b ) {
-                       selector_hasDuplicate = true;
-                       return 0;
-               }
-
-               var compare = b.compareDocumentPosition && a.compareDocumentPosition && a.compareDocumentPosition( b );
-
-               if ( compare ) {
-                       // Disconnected nodes
-                       if ( compare & 1 ) {
-
-                               // Choose the first element that is related to our document
-                               if ( a === document || jQuery.contains(document, a) ) {
-                                       return -1;
-                               }
-                               if ( b === document || jQuery.contains(document, b) ) {
-                                       return 1;
-                               }
-
-                               // Maintain original order
-                               return 0;
-                       }
-
-                       return compare & 4 ? -1 : 1;
-               }
-
-               // Not directly comparable, sort on existence of method
-               return a.compareDocumentPosition ? -1 : 1;
-       };
-
-jQuery.extend({
-       find: function( selector, context, results, seed ) {
-               var elem, nodeType,
-                       i = 0;
-
-               results = results || [];
-               context = context || document;
-
-               // Same basic safeguard as Sizzle
-               if ( !selector || typeof selector !== "string" ) {
-                       return results;
-               }
-
-               // Early return if context is not an element or document
-               if ( (nodeType = context.nodeType) !== 1 && nodeType !== 9 ) {
-                       return [];
-               }
-
-               if ( seed ) {
-                       while ( (elem = seed[i++]) ) {
-                               if ( jQuery.find.matchesSelector(elem, selector) ) {
-                                       results.push( elem );
-                               }
-                       }
-               } else {
-                       jQuery.merge( results, context.querySelectorAll(selector) );
-               }
-
-               return results;
-       },
-       unique: function( results ) {
-               var elem,
-                       duplicates = [],
-                       i = 0,
-                       j = 0;
-
-               selector_hasDuplicate = false;
-               results.sort( selector_sortOrder );
-
-               if ( selector_hasDuplicate ) {
-                       while ( (elem = results[i++]) ) {
-                               if ( elem === results[ i ] ) {
-                                       j = duplicates.push( i );
-                               }
-                       }
-                       while ( j-- ) {
-                               results.splice( duplicates[ j ], 1 );
-                       }
-               }
-
-               return results;
-       },
-       text: function( elem ) {
-               var node,
-                       ret = "",
-                       i = 0,
-                       nodeType = elem.nodeType;
-
-               if ( !nodeType ) {
-                       // If no nodeType, this is expected to be an array
-                       while ( (node = elem[i++]) ) {
-                               // Do not traverse comment nodes
-                               ret += jQuery.text( node );
-                       }
-               } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
-                       // Use textContent for elements
-                       return elem.textContent;
-               } else if ( nodeType === 3 || nodeType === 4 ) {
-                       return elem.nodeValue;
-               }
-               // Do not include comment or processing instruction nodes
-
-               return ret;
-       },
-       contains: function( a, b ) {
-               var adown = a.nodeType === 9 ? a.documentElement : a,
-                       bup = b && b.parentNode;
-               return a === bup || !!( bup && bup.nodeType === 1 && adown.contains(bup) );
-       },
-       isXMLDoc: function( elem ) {
-               return (elem.ownerDocument || elem).documentElement.nodeName !== "HTML";
-       },
-       expr: {
-               attrHandle: {},
-               match: {
-                       bool: /^(?:checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped)$/i,
-                       needsContext: /^[\x20\t\r\n\f]*[>+~]/
-               }
-       }
-});
-
-jQuery.extend( jQuery.find, {
-       matches: function( expr, elements ) {
-               return jQuery.find( expr, null, null, elements );
-       },
-       matchesSelector: function( elem, expr ) {
-               return matches.call( elem, expr );
-       },
-       attr: function( elem, name ) {
-               return elem.getAttribute( name );
-       }
-});
-
-
-
-var rneedsContext = jQuery.expr.match.needsContext;
-
-var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
-
-
-
-var risSimple = /^.[^:#\[\.,]*$/;
-
-// Implement the identical functionality for filter and not
-function winnow( elements, qualifier, not ) {
-       if ( jQuery.isFunction( qualifier ) ) {
-               return jQuery.grep( elements, function( elem, i ) {
-                       /* jshint -W018 */
-                       return !!qualifier.call( elem, i, elem ) !== not;
-               });
-
-       }
-
-       if ( qualifier.nodeType ) {
-               return jQuery.grep( elements, function( elem ) {
-                       return ( elem === qualifier ) !== not;
-               });
-
-       }
-
-       if ( typeof qualifier === "string" ) {
-               if ( risSimple.test( qualifier ) ) {
-                       return jQuery.filter( qualifier, elements, not );
-               }
-
-               qualifier = jQuery.filter( qualifier, elements );
-       }
-
-       return jQuery.grep( elements, function( elem ) {
-               return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
-       });
-}
-
-jQuery.filter = function( expr, elems, not ) {
-       var elem = elems[ 0 ];
-
-       if ( not ) {
-               expr = ":not(" + expr + ")";
-       }
-
-       return elems.length === 1 && elem.nodeType === 1 ?
-               jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
-               jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
-                       return elem.nodeType === 1;
-               }));
-};
-
-jQuery.fn.extend({
-       find: function( selector ) {
-               var i,
-                       len = this.length,
-                       ret = [],
-                       self = this;
-
-               if ( typeof selector !== "string" ) {
-                       return this.pushStack( jQuery( selector ).filter(function() {
-                               for ( i = 0; i < len; i++ ) {
-                                       if ( jQuery.contains( self[ i ], this ) ) {
-                                               return true;
-                                       }
-                               }
-                       }) );
-               }
-
-               for ( i = 0; i < len; i++ ) {
-                       jQuery.find( selector, self[ i ], ret );
-               }
-
-               // Needed because $( selector, context ) becomes $( context ).find( selector )
-               ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
-               ret.selector = this.selector ? this.selector + " " + selector : selector;
-               return ret;
-       },
-       filter: function( selector ) {
-               return this.pushStack( winnow(this, selector || [], false) );
-       },
-       not: function( selector ) {
-               return this.pushStack( winnow(this, selector || [], true) );
-       },
-       is: function( selector ) {
-               return !!winnow(
-                       this,
-
-                       // If this is a positional/relative selector, check membership in the returned set
-                       // so $("p:first").is("p:last") won't return true for a doc with two "p".
-                       typeof selector === "string" && rneedsContext.test( selector ) ?
-                               jQuery( selector ) :
-                               selector || [],
-                       false
-               ).length;
-       }
-});
-
-
-// Initialize a jQuery object
-
-
-// A central reference to the root jQuery(document)
-var rootjQuery,
-
-       // A simple way to check for HTML strings
-       // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
-       // Strict HTML recognition (#11290: must start with <)
-       rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
-
-       init = jQuery.fn.init = function( selector, context ) {
-               var match, elem;
-
-               // HANDLE: $(""), $(null), $(undefined), $(false)
-               if ( !selector ) {
-                       return this;
-               }
-
-               // Handle HTML strings
-               if ( typeof selector === "string" ) {
-                       if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
-                               // Assume that strings that start and end with <> are HTML and skip the regex check
-                               match = [ null, selector, null ];
-
-                       } else {
-                               match = rquickExpr.exec( selector );
-                       }
-
-                       // Match html or make sure no context is specified for #id
-                       if ( match && (match[1] || !context) ) {
-
-                               // HANDLE: $(html) -> $(array)
-                               if ( match[1] ) {
-                                       context = context instanceof jQuery ? context[0] : context;
-
-                                       // scripts is true for back-compat
-                                       // Intentionally let the error be thrown if parseHTML is not present
-                                       jQuery.merge( this, jQuery.parseHTML(
-                                               match[1],
-                                               context && context.nodeType ? context.ownerDocument || context : document,
-                                               true
-                                       ) );
-
-                                       // HANDLE: $(html, props)
-                                       if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
-                                               for ( match in context ) {
-                                                       // Properties of context are called as methods if possible
-                                                       if ( jQuery.isFunction( this[ match ] ) ) {
-                                                               this[ match ]( context[ match ] );
-
-                                                       // ...and otherwise set as attributes
-                                                       } else {
-                                                               this.attr( match, context[ match ] );
-                                                       }
-                                               }
-                                       }
-
-                                       return this;
-
-                               // HANDLE: $(#id)
-                               } else {
-                                       elem = document.getElementById( match[2] );
-
-                                       // Check parentNode to catch when Blackberry 4.6 returns
-                                       // nodes that are no longer in the document #6963
-                                       if ( elem && elem.parentNode ) {
-                                               // Inject the element directly into the jQuery object
-                                               this.length = 1;
-                                               this[0] = elem;
-                                       }
-
-                                       this.context = document;
-                                       this.selector = selector;
-                                       return this;
-                               }
-
-                       // HANDLE: $(expr, $(...))
-                       } else if ( !context || context.jquery ) {
-                               return ( context || rootjQuery ).find( selector );
-
-                       // HANDLE: $(expr, context)
-                       // (which is just equivalent to: $(context).find(expr)
-                       } else {
-                               return this.constructor( context ).find( selector );
-                       }
-
-               // HANDLE: $(DOMElement)
-               } else if ( selector.nodeType ) {
-                       this.context = this[0] = selector;
-                       this.length = 1;
-                       return this;
-
-               // HANDLE: $(function)
-               // Shortcut for document ready
-               } else if ( jQuery.isFunction( selector ) ) {
-                       return typeof rootjQuery.ready !== "undefined" ?
-                               rootjQuery.ready( selector ) :
-                               // Execute immediately if ready is not present
-                               selector( jQuery );
-               }
-
-               if ( selector.selector !== undefined ) {
-                       this.selector = selector.selector;
-                       this.context = selector.context;
-               }
-
-               return jQuery.makeArray( selector, this );
-       };
-
-// Give the init function the jQuery prototype for later instantiation
-init.prototype = jQuery.fn;
-
-// Initialize central reference
-rootjQuery = jQuery( document );
-
-
-var rparentsprev = /^(?:parents|prev(?:Until|All))/,
-       // methods guaranteed to produce a unique set when starting from a unique set
-       guaranteedUnique = {
-               children: true,
-               contents: true,
-               next: true,
-               prev: true
-       };
-
-jQuery.extend({
-       dir: function( elem, dir, until ) {
-               var matched = [],
-                       truncate = until !== undefined;
-
-               while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
-                       if ( elem.nodeType === 1 ) {
-                               if ( truncate && jQuery( elem ).is( until ) ) {
-                                       break;
-                               }
-                               matched.push( elem );
-                       }
-               }
-               return matched;
-       },
-
-       sibling: function( n, elem ) {
-               var matched = [];
-
-               for ( ; n; n = n.nextSibling ) {
-                       if ( n.nodeType === 1 && n !== elem ) {
-                               matched.push( n );
-                       }
-               }
-
-               return matched;
-       }
-});
-
-jQuery.fn.extend({
-       has: function( target ) {
-               var targets = jQuery( target, this ),
-                       l = targets.length;
-
-               return this.filter(function() {
-                       var i = 0;
-                       for ( ; i < l; i++ ) {
-                               if ( jQuery.contains( this, targets[i] ) ) {
-                                       return true;
-                               }
-                       }
-               });
-       },
-
-       closest: function( selectors, context ) {
-               var cur,
-                       i = 0,
-                       l = this.length,
-                       matched = [],
-                       pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
-                               jQuery( selectors, context || this.context ) :
-                               0;
-
-               for ( ; i < l; i++ ) {
-                       for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
-                               // Always skip document fragments
-                               if ( cur.nodeType < 11 && (pos ?
-                                       pos.index(cur) > -1 :
-
-                                       // Don't pass non-elements to Sizzle
-                                       cur.nodeType === 1 &&
-                                               jQuery.find.matchesSelector(cur, selectors)) ) {
-
-                                       matched.push( cur );
-                                       break;
-                               }
-                       }
-               }
-
-               return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
-       },
-
-       // Determine the position of an element within
-       // the matched set of elements
-       index: function( elem ) {
-
-               // No argument, return index in parent
-               if ( !elem ) {
-                       return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
-               }
-
-               // index in selector
-               if ( typeof elem === "string" ) {
-                       return indexOf.call( jQuery( elem ), this[ 0 ] );
-               }
-
-               // Locate the position of the desired element
-               return indexOf.call( this,
-
-                       // If it receives a jQuery object, the first element is used
-                       elem.jquery ? elem[ 0 ] : elem
-               );
-       },
-
-       add: function( selector, context ) {
-               return this.pushStack(
-                       jQuery.unique(
-                               jQuery.merge( this.get(), jQuery( selector, context ) )
-                       )
-               );
-       },
-
-       addBack: function( selector ) {
-               return this.add( selector == null ?
-                       this.prevObject : this.prevObject.filter(selector)
-               );
-       }
-});
-
-function sibling( cur, dir ) {
-       while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
-       return cur;
-}
-
-jQuery.each({
-       parent: function( elem ) {
-               var parent = elem.parentNode;
-               return parent && parent.nodeType !== 11 ? parent : null;
-       },
-       parents: function( elem ) {
-               return jQuery.dir( elem, "parentNode" );
-       },
-       parentsUntil: function( elem, i, until ) {
-               return jQuery.dir( elem, "parentNode", until );
-       },
-       next: function( elem ) {
-               return sibling( elem, "nextSibling" );
-       },
-       prev: function( elem ) {
-               return sibling( elem, "previousSibling" );
-       },
-       nextAll: function( elem ) {
-               return jQuery.dir( elem, "nextSibling" );
-       },
-       prevAll: function( elem ) {
-               return jQuery.dir( elem, "previousSibling" );
-       },
-       nextUntil: function( elem, i, until ) {
-               return jQuery.dir( elem, "nextSibling", until );
-       },
-       prevUntil: function( elem, i, until ) {
-               return jQuery.dir( elem, "previousSibling", until );
-       },
-       siblings: function( elem ) {
-               return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
-       },
-       children: function( elem ) {
-               return jQuery.sibling( elem.firstChild );
-       },
-       contents: function( elem ) {
-               return elem.contentDocument || jQuery.merge( [], elem.childNodes );
-       }
-}, function( name, fn ) {
-       jQuery.fn[ name ] = function( until, selector ) {
-               var matched = jQuery.map( this, fn, until );
-
-               if ( name.slice( -5 ) !== "Until" ) {
-                       selector = until;
-               }
-
-               if ( selector && typeof selector === "string" ) {
-                       matched = jQuery.filter( selector, matched );
-               }
-
-               if ( this.length > 1 ) {
-                       // Remove duplicates
-                       if ( !guaranteedUnique[ name ] ) {
-                               jQuery.unique( matched );
-                       }
-
-                       // Reverse order for parents* and prev-derivatives
-                       if ( rparentsprev.test( name ) ) {
-                               matched.reverse();
-                       }
-               }
-
-               return this.pushStack( matched );
-       };
-});
-var rnotwhite = (/\S+/g);
-
-
-
-// String to Object options format cache
-var optionsCache = {};
-
-// Convert String-formatted options into Object-formatted ones and store in cache
-function createOptions( options ) {
-       var object = optionsCache[ options ] = {};
-       jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
-               object[ flag ] = true;
-       });
-       return object;
-}
-
-/*
- * Create a callback list using the following parameters:
- *
- *     options: an optional list of space-separated options that will change how
- *                     the callback list behaves or a more traditional option object
- *
- * By default a callback list will act like an event callback list and can be
- * "fired" multiple times.
- *
- * Possible options:
- *
- *     once:                   will ensure the callback list can only be fired once (like a Deferred)
- *
- *     memory:                 will keep track of previous values and will call any callback added
- *                                     after the list has been fired right away with the latest "memorized"
- *                                     values (like a Deferred)
- *
- *     unique:                 will ensure a callback can only be added once (no duplicate in the list)
- *
- *     stopOnFalse:    interrupt callings when a callback returns false
- *
- */
-jQuery.Callbacks = function( options ) {
-
-       // Convert options from String-formatted to Object-formatted if needed
-       // (we check in cache first)
-       options = typeof options === "string" ?
-               ( optionsCache[ options ] || createOptions( options ) ) :
-               jQuery.extend( {}, options );
-
-       var // Last fire value (for non-forgettable lists)
-               memory,
-               // Flag to know if list was already fired
-               fired,
-               // Flag to know if list is currently firing
-               firing,
-               // First callback to fire (used internally by add and fireWith)
-               firingStart,
-               // End of the loop when firing
-               firingLength,
-               // Index of currently firing callback (modified by remove if needed)
-               firingIndex,
-               // Actual callback list
-               list = [],
-               // Stack of fire calls for repeatable lists
-               stack = !options.once && [],
-               // Fire callbacks
-               fire = function( data ) {
-                       memory = options.memory && data;
-                       fired = true;
-                       firingIndex = firingStart || 0;
-                       firingStart = 0;
-                       firingLength = list.length;
-                       firing = true;
-                       for ( ; list && firingIndex < firingLength; firingIndex++ ) {
-                               if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
-                                       memory = false; // To prevent further calls using add
-                                       break;
-                               }
-                       }
-                       firing = false;
-                       if ( list ) {
-                               if ( stack ) {
-                                       if ( stack.length ) {
-                                               fire( stack.shift() );
-                                       }
-                               } else if ( memory ) {
-                                       list = [];
-                               } else {
-                                       self.disable();
-                               }
-                       }
-               },
-               // Actual Callbacks object
-               self = {
-                       // Add a callback or a collection of callbacks to the list
-                       add: function() {
-                               if ( list ) {
-                                       // First, we save the current length
-                                       var start = list.length;
-                                       (function add( args ) {
-                                               jQuery.each( args, function( _, arg ) {
-                                                       var type = jQuery.type( arg );
-                                                       if ( type === "function" ) {
-                                                               if ( !options.unique || !self.has( arg ) ) {
-                                                                       list.push( arg );
-                                                               }
-                                                       } else if ( arg && arg.length && type !== "string" ) {
-                                                               // Inspect recursively
-                                                               add( arg );
-                                                       }
-                                               });
-                                       })( arguments );
-                                       // Do we need to add the callbacks to the
-                                       // current firing batch?
-                                       if ( firing ) {
-                                               firingLength = list.length;
-                                       // With memory, if we're not firing then
-                                       // we should call right away
-                                       } else if ( memory ) {
-                                               firingStart = start;
-                                               fire( memory );
-                                       }
-                               }
-                               return this;
-                       },
-                       // Remove a callback from the list
-                       remove: function() {
-                               if ( list ) {
-                                       jQuery.each( arguments, function( _, arg ) {
-                                               var index;
-                                               while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
-                                                       list.splice( index, 1 );
-                                                       // Handle firing indexes
-                                                       if ( firing ) {
-                                                               if ( index <= firingLength ) {
-                                                                       firingLength--;
-                                                               }
-                                                               if ( index <= firingIndex ) {
-                                                                       firingIndex--;
-                                                               }
-                                                       }
-                                               }
-                                       });
-                               }
-                               return this;
-                       },
-                       // Check if a given callback is in the list.
-                       // If no argument is given, return whether or not list has callbacks attached.
-                       has: function( fn ) {
-                               return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
-                       },
-                       // Remove all callbacks from the list
-                       empty: function() {
-                               list = [];
-                               firingLength = 0;
-                               return this;
-                       },
-                       // Have the list do nothing anymore
-                       disable: function() {
-                               list = stack = memory = undefined;
-                               return this;
-                       },
-                       // Is it disabled?
-                       disabled: function() {
-                               return !list;
-                       },
-                       // Lock the list in its current state
-                       lock: function() {
-                               stack = undefined;
-                               if ( !memory ) {
-                                       self.disable();
-                               }
-                               return this;
-                       },
-                       // Is it locked?
-                       locked: function() {
-                               return !stack;
-                       },
-                       // Call all callbacks with the given context and arguments
-                       fireWith: function( context, args ) {
-                               if ( list && ( !fired || stack ) ) {
-                                       args = args || [];
-                                       args = [ context, args.slice ? args.slice() : args ];
-                                       if ( firing ) {
-                                               stack.push( args );
-                                       } else {
-                                               fire( args );
-                                       }
-                               }
-                               return this;
-                       },
-                       // Call all the callbacks with the given arguments
-                       fire: function() {
-                               self.fireWith( this, arguments );
-                               return this;
-                       },
-                       // To know if the callbacks have already been called at least once
-                       fired: function() {
-                               return !!fired;
-                       }
-               };
-
-       return self;
-};
-
-
-jQuery.extend({
-
-       Deferred: function( func ) {
-               var tuples = [
-                               // action, add listener, listener list, final state
-                               [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
-                               [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
-                               [ "notify", "progress", jQuery.Callbacks("memory") ]
-                       ],
-                       state = "pending",
-                       promise = {
-                               state: function() {
-                                       return state;
-                               },
-                               always: function() {
-                                       deferred.done( arguments ).fail( arguments );
-                                       return this;
-                               },
-                               then: function( /* fnDone, fnFail, fnProgress */ ) {
-                                       var fns = arguments;
-                                       return jQuery.Deferred(function( newDefer ) {
-                                               jQuery.each( tuples, function( i, tuple ) {
-                                                       var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
-                                                       // deferred[ done | fail | progress ] for forwarding actions to newDefer
-                                                       deferred[ tuple[1] ](function() {
-                                                               var returned = fn && fn.apply( this, arguments );
-                                                               if ( returned && jQuery.isFunction( returned.promise ) ) {
-                                                                       returned.promise()
-                                                                               .done( newDefer.resolve )
-                                                                               .fail( newDefer.reject )
-                                                                               .progress( newDefer.notify );
-                                                               } else {
-                                                                       newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
-                                                               }
-                                                       });
-                                               });
-                                               fns = null;
-                                       }).promise();
-                               },
-                               // Get a promise for this deferred
-                               // If obj is provided, the promise aspect is added to the object
-                               promise: function( obj ) {
-                                       return obj != null ? jQuery.extend( obj, promise ) : promise;
-                               }
-                       },
-                       deferred = {};
-
-               // Keep pipe for back-compat
-               promise.pipe = promise.then;
-
-               // Add list-specific methods
-               jQuery.each( tuples, function( i, tuple ) {
-                       var list = tuple[ 2 ],
-                               stateString = tuple[ 3 ];
-
-                       // promise[ done | fail | progress ] = list.add
-                       promise[ tuple[1] ] = list.add;
-
-                       // Handle state
-                       if ( stateString ) {
-                               list.add(function() {
-                                       // state = [ resolved | rejected ]
-                                       state = stateString;
-
-                               // [ reject_list | resolve_list ].disable; progress_list.lock
-                               }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
-                       }
-
-                       // deferred[ resolve | reject | notify ]
-                       deferred[ tuple[0] ] = function() {
-                               deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
-                               return this;
-                       };
-                       deferred[ tuple[0] + "With" ] = list.fireWith;
-               });
-
-               // Make the deferred a promise
-               promise.promise( deferred );
-
-               // Call given func if any
-               if ( func ) {
-                       func.call( deferred, deferred );
-               }
-
-               // All done!
-               return deferred;
-       },
-
-       // Deferred helper
-       when: function( subordinate /* , ..., subordinateN */ ) {
-               var i = 0,
-                       resolveValues = slice.call( arguments ),
-                       length = resolveValues.length,
-
-                       // the count of uncompleted subordinates
-                       remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
-
-                       // the master Deferred. If resolveValues consist of only a single Deferred, just use that.
-                       deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
-
-                       // Update function for both resolve and progress values
-                       updateFunc = function( i, contexts, values ) {
-                               return function( value ) {
-                                       contexts[ i ] = this;
-                                       values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
-                                       if ( values === progressValues ) {
-                                               deferred.notifyWith( contexts, values );
-                                       } else if ( !( --remaining ) ) {
-                                               deferred.resolveWith( contexts, values );
-                                       }
-                               };
-                       },
-
-                       progressValues, progressContexts, resolveContexts;
-
-               // add listeners to Deferred subordinates; treat others as resolved
-               if ( length > 1 ) {
-                       progressValues = new Array( length );
-                       progressContexts = new Array( length );
-                       resolveContexts = new Array( length );
-                       for ( ; i < length; i++ ) {
-                               if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
-                                       resolveValues[ i ].promise()
-                                               .done( updateFunc( i, resolveContexts, resolveValues ) )
-                                               .fail( deferred.reject )
-                                               .progress( updateFunc( i, progressContexts, progressValues ) );
-                               } else {
-                                       --remaining;
-                               }
-                       }
-               }
-
-               // if we're not waiting on anything, resolve the master
-               if ( !remaining ) {
-                       deferred.resolveWith( resolveContexts, resolveValues );
-               }
-
-               return deferred.promise();
-       }
-});
-
-
-// The deferred used on DOM ready
-var readyList;
-
-jQuery.fn.ready = function( fn ) {
-       // Add the callback
-       jQuery.ready.promise().done( fn );
-
-       return this;
-};
-
-jQuery.extend({
-       // Is the DOM ready to be used? Set to true once it occurs.
-       isReady: false,
-
-       // A counter to track how many items to wait for before
-       // the ready event fires. See #6781
-       readyWait: 1,
-
-       // Hold (or release) the ready event
-       holdReady: function( hold ) {
-               if ( hold ) {
-                       jQuery.readyWait++;
-               } else {
-                       jQuery.ready( true );
-               }
-       },
-
-       // Handle when the DOM is ready
-       ready: function( wait ) {
-
-               // Abort if there are pending holds or we're already ready
-               if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
-                       return;
-               }
-
-               // Remember that the DOM is ready
-               jQuery.isReady = true;
-
-               // If a normal DOM Ready event fired, decrement, and wait if need be
-               if ( wait !== true && --jQuery.readyWait > 0 ) {
-                       return;
-               }
-
-               // If there are functions bound, to execute
-               readyList.resolveWith( document, [ jQuery ] );
-
-               // Trigger any bound ready events
-               if ( jQuery.fn.triggerHandler ) {
-                       jQuery( document ).triggerHandler( "ready" );
-                       jQuery( document ).off( "ready" );
-               }
-       }
-});
-
-/**
- * The ready event handler and self cleanup method
- */
-function completed() {
-       document.removeEventListener( "DOMContentLoaded", completed, false );
-       window.removeEventListener( "load", completed, false );
-       jQuery.ready();
-}
-
-jQuery.ready.promise = function( obj ) {
-       if ( !readyList ) {
-
-               readyList = jQuery.Deferred();
-
-               // Catch cases where $(document).ready() is called after the browser event has already occurred.
-               // we once tried to use readyState "interactive" here, but it caused issues like the one
-               // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
-               if ( document.readyState === "complete" ) {
-                       // Handle it asynchronously to allow scripts the opportunity to delay ready
-                       setTimeout( jQuery.ready );
-
-               } else {
-
-                       // Use the handy event callback
-                       document.addEventListener( "DOMContentLoaded", completed, false );
-
-                       // A fallback to window.onload, that will always work
-                       window.addEventListener( "load", completed, false );
-               }
-       }
-       return readyList.promise( obj );
-};
-
-// Kick off the DOM ready check even if the user does not
-jQuery.ready.promise();
-
-
-
-
-// Multifunctional method to get and set values of a collection
-// The value/s can optionally be executed if it's a function
-var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
-       var i = 0,
-               len = elems.length,
-               bulk = key == null;
-
-       // Sets many values
-       if ( jQuery.type( key ) === "object" ) {
-               chainable = true;
-               for ( i in key ) {
-                       jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
-               }
-
-       // Sets one value
-       } else if ( value !== undefined ) {
-               chainable = true;
-
-               if ( !jQuery.isFunction( value ) ) {
-                       raw = true;
-               }
-
-               if ( bulk ) {
-                       // Bulk operations run against the entire set
-                       if ( raw ) {
-                               fn.call( elems, value );
-                               fn = null;
-
-                       // ...except when executing function values
-                       } else {
-                               bulk = fn;
-                               fn = function( elem, key, value ) {
-                                       return bulk.call( jQuery( elem ), value );
-                               };
-                       }
-               }
-
-               if ( fn ) {
-                       for ( ; i < len; i++ ) {
-                               fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
-                       }
-               }
-       }
-
-       return chainable ?
-               elems :
-
-               // Gets
-               bulk ?
-                       fn.call( elems ) :
-                       len ? fn( elems[0], key ) : emptyGet;
-};
-
-
-/**
- * Determines whether an object can have data
- */
-jQuery.acceptData = function( owner ) {
-       // Accepts only:
-       //  - Node
-       //    - Node.ELEMENT_NODE
-       //    - Node.DOCUMENT_NODE
-       //  - Object
-       //    - Any
-       /* jshint -W018 */
-       return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
-};
-
-
-function Data() {
-       // Support: Android < 4,
-       // Old WebKit does not have Object.preventExtensions/freeze method,
-       // return new empty object instead with no [[set]] accessor
-       Object.defineProperty( this.cache = {}, 0, {
-               get: function() {
-                       return {};
-               }
-       });
-
-       this.expando = jQuery.expando + Math.random();
-}
-
-Data.uid = 1;
-Data.accepts = jQuery.acceptData;
-
-Data.prototype = {
-       key: function( owner ) {
-               // We can accept data for non-element nodes in modern browsers,
-               // but we should not, see #8335.
-               // Always return the key for a frozen object.
-               if ( !Data.accepts( owner ) ) {
-                       return 0;
-               }
-
-               var descriptor = {},
-                       // Check if the owner object already has a cache key
-                       unlock = owner[ this.expando ];
-
-               // If not, create one
-               if ( !unlock ) {
-                       unlock = Data.uid++;
-
-                       // Secure it in a non-enumerable, non-writable property
-                       try {
-                               descriptor[ this.expando ] = { value: unlock };
-                               Object.defineProperties( owner, descriptor );
-
-                       // Support: Android < 4
-                       // Fallback to a less secure definition
-                       } catch ( e ) {
-                               descriptor[ this.expando ] = unlock;
-                               jQuery.extend( owner, descriptor );
-                       }
-               }
-
-               // Ensure the cache object
-               if ( !this.cache[ unlock ] ) {
-                       this.cache[ unlock ] = {};
-               }
-
-               return unlock;
-       },
-       set: function( owner, data, value ) {
-               var prop,
-                       // There may be an unlock assigned to this node,
-                       // if there is no entry for this "owner", create one inline
-                       // and set the unlock as though an owner entry had always existed
-                       unlock = this.key( owner ),
-                       cache = this.cache[ unlock ];
-
-               // Handle: [ owner, key, value ] args
-               if ( typeof data === "string" ) {
-                       cache[ data ] = value;
-
-               // Handle: [ owner, { properties } ] args
-               } else {
-                       // Fresh assignments by object are shallow copied
-                       if ( jQuery.isEmptyObject( cache ) ) {
-                               jQuery.extend( this.cache[ unlock ], data );
-                       // Otherwise, copy the properties one-by-one to the cache object
-                       } else {
-                               for ( prop in data ) {
-                                       cache[ prop ] = data[ prop ];
-                               }
-                       }
-               }
-               return cache;
-       },
-       get: function( owner, key ) {
-               // Either a valid cache is found, or will be created.
-               // New caches will be created and the unlock returned,
-               // allowing direct access to the newly created
-               // empty data object. A valid owner object must be provided.
-               var cache = this.cache[ this.key( owner ) ];
-
-               return key === undefined ?
-                       cache : cache[ key ];
-       },
-       access: function( owner, key, value ) {
-               var stored;
-               // In cases where either:
-               //
-               //   1. No key was specified
-               //   2. A string key was specified, but no value provided
-               //
-               // Take the "read" path and allow the get method to determine
-               // which value to return, respectively either:
-               //
-               //   1. The entire cache object
-               //   2. The data stored at the key
-               //
-               if ( key === undefined ||
-                               ((key && typeof key === "string") && value === undefined) ) {
-
-                       stored = this.get( owner, key );
-
-                       return stored !== undefined ?
-                               stored : this.get( owner, jQuery.camelCase(key) );
-               }
-
-               // [*]When the key is not a string, or both a key and value
-               // are specified, set or extend (existing objects) with either:
-               //
-               //   1. An object of properties
-               //   2. A key and value
-               //
-               this.set( owner, key, value );
-
-               // Since the "set" path can have two possible entry points
-               // return the expected data based on which path was taken[*]
-               return value !== undefined ? value : key;
-       },
-       remove: function( owner, key ) {
-               var i, name, camel,
-                       unlock = this.key( owner ),
-                       cache = this.cache[ unlock ];
-
-               if ( key === undefined ) {
-                       this.cache[ unlock ] = {};
-
-               } else {
-                       // Support array or space separated string of keys
-                       if ( jQuery.isArray( key ) ) {
-                               // If "name" is an array of keys...
-                               // When data is initially created, via ("key", "val") signature,
-                               // keys will be converted to camelCase.
-                               // Since there is no way to tell _how_ a key was added, remove
-                               // both plain key and camelCase key. #12786
-                               // This will only penalize the array argument path.
-                               name = key.concat( key.map( jQuery.camelCase ) );
-                       } else {
-                               camel = jQuery.camelCase( key );
-                               // Try the string as a key before any manipulation
-                               if ( key in cache ) {
-                                       name = [ key, camel ];
-                               } else {
-                                       // If a key with the spaces exists, use it.
-                                       // Otherwise, create an array by matching non-whitespace
-                                       name = camel;
-                                       name = name in cache ?
-                                               [ name ] : ( name.match( rnotwhite ) || [] );
-                               }
-                       }
-
-                       i = name.length;
-                       while ( i-- ) {
-                               delete cache[ name[ i ] ];
-                       }
-               }
-       },
-       hasData: function( owner ) {
-               return !jQuery.isEmptyObject(
-                       this.cache[ owner[ this.expando ] ] || {}
-               );
-       },
-       discard: function( owner ) {
-               if ( owner[ this.expando ] ) {
-                       delete this.cache[ owner[ this.expando ] ];
-               }
-       }
-};
-var data_priv = new Data();
-
-var data_user = new Data();
-
-
-
-/*
-       Implementation Summary
-
-       1. Enforce API surface and semantic compatibility with 1.9.x branch
-       2. Improve the module's maintainability by reducing the storage
-               paths to a single mechanism.
-       3. Use the same single mechanism to support "private" and "user" data.
-       4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
-       5. Avoid exposing implementation details on user objects (eg. expando properties)
-       6. Provide a clear path for implementation upgrade to WeakMap in 2014
-*/
-var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
-       rmultiDash = /([A-Z])/g;
-
-function dataAttr( elem, key, data ) {
-       var name;
-
-       // If nothing was found internally, try to fetch any
-       // data from the HTML5 data-* attribute
-       if ( data === undefined && elem.nodeType === 1 ) {
-               name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
-               data = elem.getAttribute( name );
-
-               if ( typeof data === "string" ) {
-                       try {
-                               data = data === "true" ? true :
-                                       data === "false" ? false :
-                                       data === "null" ? null :
-                                       // Only convert to a number if it doesn't change the string
-                                       +data + "" === data ? +data :
-                                       rbrace.test( data ) ? jQuery.parseJSON( data ) :
-                                       data;
-                       } catch( e ) {}
-
-                       // Make sure we set the data so it isn't changed later
-                       data_user.set( elem, key, data );
-               } else {
-                       data = undefined;
-               }
-       }
-       return data;
-}
-
-jQuery.extend({
-       hasData: function( elem ) {
-               return data_user.hasData( elem ) || data_priv.hasData( elem );
-       },
-
-       data: function( elem, name, data ) {
-               return data_user.access( elem, name, data );
-       },
-
-       removeData: function( elem, name ) {
-               data_user.remove( elem, name );
-       },
-
-       // TODO: Now that all calls to _data and _removeData have been replaced
-       // with direct calls to data_priv methods, these can be deprecated.
-       _data: function( elem, name, data ) {
-               return data_priv.access( elem, name, data );
-       },
-
-       _removeData: function( elem, name ) {
-               data_priv.remove( elem, name );
-       }
-});
-
-jQuery.fn.extend({
-       data: function( key, value ) {
-               var i, name, data,
-                       elem = this[ 0 ],
-                       attrs = elem && elem.attributes;
-
-               // Gets all values
-               if ( key === undefined ) {
-                       if ( this.length ) {
-                               data = data_user.get( elem );
-
-                               if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
-                                       i = attrs.length;
-                                       while ( i-- ) {
-
-                                               // Support: IE11+
-                                               // The attrs elements can be null (#14894)
-                                               if ( attrs[ i ] ) {
-                                                       name = attrs[ i ].name;
-                                                       if ( name.indexOf( "data-" ) === 0 ) {
-                                                               name = jQuery.camelCase( name.slice(5) );
-                                                               dataAttr( elem, name, data[ name ] );
-                                                       }
-                                               }
-                                       }
-                                       data_priv.set( elem, "hasDataAttrs", true );
-                               }
-                       }
-
-                       return data;
-               }
-
-               // Sets multiple values
-               if ( typeof key === "object" ) {
-                       return this.each(function() {
-                               data_user.set( this, key );
-                       });
-               }
-
-               return access( this, function( value ) {
-                       var data,
-                               camelKey = jQuery.camelCase( key );
-
-                       // The calling jQuery object (element matches) is not empty
-                       // (and therefore has an element appears at this[ 0 ]) and the
-                       // `value` parameter was not undefined. An empty jQuery object
-                       // will result in `undefined` for elem = this[ 0 ] which will
-                       // throw an exception if an attempt to read a data cache is made.
-                       if ( elem && value === undefined ) {
-                               // Attempt to get data from the cache
-                               // with the key as-is
-                               data = data_user.get( elem, key );
-                               if ( data !== undefined ) {
-                                       return data;
-                               }
-
-                               // Attempt to get data from the cache
-                               // with the key camelized
-                               data = data_user.get( elem, camelKey );
-                               if ( data !== undefined ) {
-                                       return data;
-                               }
-
-                               // Attempt to "discover" the data in
-                               // HTML5 custom data-* attrs
-                               data = dataAttr( elem, camelKey, undefined );
-                               if ( data !== undefined ) {
-                                       return data;
-                               }
-
-                               // We tried really hard, but the data doesn't exist.
-                               return;
-                       }
-
-                       // Set the data...
-                       this.each(function() {
-                               // First, attempt to store a copy or reference of any
-                               // data that might've been store with a camelCased key.
-                               var data = data_user.get( this, camelKey );
-
-                               // For HTML5 data-* attribute interop, we have to
-                               // store property names with dashes in a camelCase form.
-                               // This might not apply to all properties...*
-                               data_user.set( this, camelKey, value );
-
-                               // *... In the case of properties that might _actually_
-                               // have dashes, we need to also store a copy of that
-                               // unchanged property.
-                               if ( key.indexOf("-") !== -1 && data !== undefined ) {
-                                       data_user.set( this, key, value );
-                               }
-                       });
-               }, null, value, arguments.length > 1, null, true );
-       },
-
-       removeData: function( key ) {
-               return this.each(function() {
-                       data_user.remove( this, key );
-               });
-       }
-});
-
-
-jQuery.extend({
-       queue: function( elem, type, data ) {
-               var queue;
-
-               if ( elem ) {
-                       type = ( type || "fx" ) + "queue";
-                       queue = data_priv.get( elem, type );
-
-                       // Speed up dequeue by getting out quickly if this is just a lookup
-                       if ( data ) {
-                               if ( !queue || jQuery.isArray( data ) ) {
-                                       queue = data_priv.access( elem, type, jQuery.makeArray(data) );
-                               } else {
-                                       queue.push( data );
-                               }
-                       }
-                       return queue || [];
-               }
-       },
-
-       dequeue: function( elem, type ) {
-               type = type || "fx";
-
-               var queue = jQuery.queue( elem, type ),
-                       startLength = queue.length,
-                       fn = queue.shift(),
-                       hooks = jQuery._queueHooks( elem, type ),
-                       next = function() {
-                               jQuery.dequeue( elem, type );
-                       };
-
-               // If the fx queue is dequeued, always remove the progress sentinel
-               if ( fn === "inprogress" ) {
-                       fn = queue.shift();
-                       startLength--;
-               }
-
-               if ( fn ) {
-
-                       // Add a progress sentinel to prevent the fx queue from being
-                       // automatically dequeued
-                       if ( type === "fx" ) {
-                               queue.unshift( "inprogress" );
-                       }
-
-                       // clear up the last queue stop function
-                       delete hooks.stop;
-                       fn.call( elem, next, hooks );
-               }
-
-               if ( !startLength && hooks ) {
-                       hooks.empty.fire();
-               }
-       },
-
-       // not intended for public consumption - generates a queueHooks object, or returns the current one
-       _queueHooks: function( elem, type ) {
-               var key = type + "queueHooks";
-               return data_priv.get( elem, key ) || data_priv.access( elem, key, {
-                       empty: jQuery.Callbacks("once memory").add(function() {
-                               data_priv.remove( elem, [ type + "queue", key ] );
-                       })
-               });
-       }
-});
-
-jQuery.fn.extend({
-       queue: function( type, data ) {
-               var setter = 2;
-
-               if ( typeof type !== "string" ) {
-                       data = type;
-                       type = "fx";
-                       setter--;
-               }
-
-               if ( arguments.length < setter ) {
-                       return jQuery.queue( this[0], type );
-               }
-
-               return data === undefined ?
-                       this :
-                       this.each(function() {
-                               var queue = jQuery.queue( this, type, data );
-
-                               // ensure a hooks for this queue
-                               jQuery._queueHooks( this, type );
-
-                               if ( type === "fx" && queue[0] !== "inprogress" ) {
-                                       jQuery.dequeue( this, type );
-                               }
-                       });
-       },
-       dequeue: function( type ) {
-               return this.each(function() {
-                       jQuery.dequeue( this, type );
-               });
-       },
-       clearQueue: function( type ) {
-               return this.queue( type || "fx", [] );
-       },
-       // Get a promise resolved when queues of a certain type
-       // are emptied (fx is the type by default)
-       promise: function( type, obj ) {
-               var tmp,
-                       count = 1,
-                       defer = jQuery.Deferred(),
-                       elements = this,
-                       i = this.length,
-                       resolve = function() {
-                               if ( !( --count ) ) {
-                                       defer.resolveWith( elements, [ elements ] );
-                               }
-                       };
-
-               if ( typeof type !== "string" ) {
-                       obj = type;
-                       type = undefined;
-               }
-               type = type || "fx";
-
-               while ( i-- ) {
-                       tmp = data_priv.get( elements[ i ], type + "queueHooks" );
-                       if ( tmp && tmp.empty ) {
-                               count++;
-                               tmp.empty.add( resolve );
-                       }
-               }
-               resolve();
-               return defer.promise( obj );
-       }
-});
-var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
-
-var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
-
-var isHidden = function( elem, el ) {
-               // isHidden might be called from jQuery#filter function;
-               // in that case, element will be second argument
-               elem = el || elem;
-               return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
-       };
-
-var rcheckableType = (/^(?:checkbox|radio)$/i);
-
-
-
-(function() {
-       var fragment = document.createDocumentFragment(),
-               div = fragment.appendChild( document.createElement( "div" ) ),
-               input = document.createElement( "input" );
-
-       // #11217 - WebKit loses check when the name is after the checked attribute
-       // Support: Windows Web Apps (WWA)
-       // `name` and `type` need .setAttribute for WWA
-       input.setAttribute( "type", "radio" );
-       input.setAttribute( "checked", "checked" );
-       input.setAttribute( "name", "t" );
-
-       div.appendChild( input );
-
-       // Support: Safari 5.1, iOS 5.1, Android 4.x, Android 2.3
-       // old WebKit doesn't clone checked state correctly in fragments
-       support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
-
-       // Make sure textarea (and checkbox) defaultValue is properly cloned
-       // Support: IE9-IE11+
-       div.innerHTML = "<textarea>x</textarea>";
-       support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
-})();
-var strundefined = typeof undefined;
-
-
-
-support.focusinBubbles = "onfocusin" in window;
-
-
-var
-       rkeyEvent = /^key/,
-       rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
-       rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
-       rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
-
-function returnTrue() {
-       return true;
-}
-
-function returnFalse() {
-       return false;
-}
-
-function safeActiveElement() {
-       try {
-               return document.activeElement;
-       } catch ( err ) { }
-}
-
-/*
- * Helper functions for managing events -- not part of the public interface.
- * Props to Dean Edwards' addEvent library for many of the ideas.
- */
-jQuery.event = {
-
-       global: {},
-
-       add: function( elem, types, handler, data, selector ) {
-
-               var handleObjIn, eventHandle, tmp,
-                       events, t, handleObj,
-                       special, handlers, type, namespaces, origType,
-                       elemData = data_priv.get( elem );
-
-               // Don't attach events to noData or text/comment nodes (but allow plain objects)
-               if ( !elemData ) {
-                       return;
-               }
-
-               // Caller can pass in an object of custom data in lieu of the handler
-               if ( handler.handler ) {
-                       handleObjIn = handler;
-                       handler = handleObjIn.handler;
-                       selector = handleObjIn.selector;
-               }
-
-               // Make sure that the handler has a unique ID, used to find/remove it later
-               if ( !handler.guid ) {
-                       handler.guid = jQuery.guid++;
-               }
-
-               // Init the element's event structure and main handler, if this is the first
-               if ( !(events = elemData.events) ) {
-                       events = elemData.events = {};
-               }
-               if ( !(eventHandle = elemData.handle) ) {
-                       eventHandle = elemData.handle = function( e ) {
-                               // Discard the second event of a jQuery.event.trigger() and
-                               // when an event is called after a page has unloaded
-                               return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
-                                       jQuery.event.dispatch.apply( elem, arguments ) : undefined;
-                       };
-               }
-
-               // Handle multiple events separated by a space
-               types = ( types || "" ).match( rnotwhite ) || [ "" ];
-               t = types.length;
-               while ( t-- ) {
-                       tmp = rtypenamespace.exec( types[t] ) || [];
-                       type = origType = tmp[1];
-                       namespaces = ( tmp[2] || "" ).split( "." ).sort();
-
-                       // There *must* be a type, no attaching namespace-only handlers
-                       if ( !type ) {
-                               continue;
-                       }
-
-                       // If event changes its type, use the special event handlers for the changed type
-                       special = jQuery.event.special[ type ] || {};
-
-                       // If selector defined, determine special event api type, otherwise given type
-                       type = ( selector ? special.delegateType : special.bindType ) || type;
-
-                       // Update special based on newly reset type
-                       special = jQuery.event.special[ type ] || {};
-
-                       // handleObj is passed to all event handlers
-                       handleObj = jQuery.extend({
-                               type: type,
-                               origType: origType,
-                               data: data,
-                               handler: handler,
-                               guid: handler.guid,
-                               selector: selector,
-                               needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
-                               namespace: namespaces.join(".")
-                       }, handleObjIn );
-
-                       // Init the event handler queue if we're the first
-                       if ( !(handlers = events[ type ]) ) {
-                               handlers = events[ type ] = [];
-                               handlers.delegateCount = 0;
-
-                               // Only use addEventListener if the special events handler returns false
-                               if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
-                                       if ( elem.addEventListener ) {
-                                               elem.addEventListener( type, eventHandle, false );
-                                       }
-                               }
-                       }
-
-                       if ( special.add ) {
-                               special.add.call( elem, handleObj );
-
-                               if ( !handleObj.handler.guid ) {
-                                       handleObj.handler.guid = handler.guid;
-                               }
-                       }
-
-                       // Add to the element's handler list, delegates in front
-                       if ( selector ) {
-                               handlers.splice( handlers.delegateCount++, 0, handleObj );
-                       } else {
-                               handlers.push( handleObj );
-                       }
-
-                       // Keep track of which events have ever been used, for event optimization
-                       jQuery.event.global[ type ] = true;
-               }
-
-       },
-
-       // Detach an event or set of events from an element
-       remove: function( elem, types, handler, selector, mappedTypes ) {
-
-               var j, origCount, tmp,
-                       events, t, handleObj,
-                       special, handlers, type, namespaces, origType,
-                       elemData = data_priv.hasData( elem ) && data_priv.get( elem );
-
-               if ( !elemData || !(events = elemData.events) ) {
-                       return;
-               }
-
-               // Once for each type.namespace in types; type may be omitted
-               types = ( types || "" ).match( rnotwhite ) || [ "" ];
-               t = types.length;
-               while ( t-- ) {
-                       tmp = rtypenamespace.exec( types[t] ) || [];
-                       type = origType = tmp[1];
-                       namespaces = ( tmp[2] || "" ).split( "." ).sort();
-
-                       // Unbind all events (on this namespace, if provided) for the element
-                       if ( !type ) {
-                               for ( type in events ) {
-                                       jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
-                               }
-                               continue;
-                       }
-
-                       special = jQuery.event.special[ type ] || {};
-                       type = ( selector ? special.delegateType : special.bindType ) || type;
-                       handlers = events[ type ] || [];
-                       tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
-
-                       // Remove matching events
-                       origCount = j = handlers.length;
-                       while ( j-- ) {
-                               handleObj = handlers[ j ];
-
-                               if ( ( mappedTypes || origType === handleObj.origType ) &&
-                                       ( !handler || handler.guid === handleObj.guid ) &&
-                                       ( !tmp || tmp.test( handleObj.namespace ) ) &&
-                                       ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
-                                       handlers.splice( j, 1 );
-
-                                       if ( handleObj.selector ) {
-                                               handlers.delegateCount--;
-                                       }
-                                       if ( special.remove ) {
-                                               special.remove.call( elem, handleObj );
-                                       }
-                               }
-                       }
-
-                       // Remove generic event handler if we removed something and no more handlers exist
-                       // (avoids potential for endless recursion during removal of special event handlers)
-                       if ( origCount && !handlers.length ) {
-                               if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
-                                       jQuery.removeEvent( elem, type, elemData.handle );
-                               }
-
-                               delete events[ type ];
-                       }
-               }
-
-               // Remove the expando if it's no longer used
-               if ( jQuery.isEmptyObject( events ) ) {
-                       delete elemData.handle;
-                       data_priv.remove( elem, "events" );
-               }
-       },
-
-       trigger: function( event, data, elem, onlyHandlers ) {
-
-               var i, cur, tmp, bubbleType, ontype, handle, special,
-                       eventPath = [ elem || document ],
-                       type = hasOwn.call( event, "type" ) ? event.type : event,
-                       namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
-
-               cur = tmp = elem = elem || document;
-
-               // Don't do events on text and comment nodes
-               if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
-                       return;
-               }
-
-               // focus/blur morphs to focusin/out; ensure we're not firing them right now
-               if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
-                       return;
-               }
-
-               if ( type.indexOf(".") >= 0 ) {
-                       // Namespaced trigger; create a regexp to match event type in handle()
-                       namespaces = type.split(".");
-                       type = namespaces.shift();
-                       namespaces.sort();
-               }
-               ontype = type.indexOf(":") < 0 && "on" + type;
-
-               // Caller can pass in a jQuery.Event object, Object, or just an event type string
-               event = event[ jQuery.expando ] ?
-                       event :
-                       new jQuery.Event( type, typeof event === "object" && event );
-
-               // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
-               event.isTrigger = onlyHandlers ? 2 : 3;
-               event.namespace = namespaces.join(".");
-               event.namespace_re = event.namespace ?
-                       new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
-                       null;
-
-               // Clean up the event in case it is being reused
-               event.result = undefined;
-               if ( !event.target ) {
-                       event.target = elem;
-               }
-
-               // Clone any incoming data and prepend the event, creating the handler arg list
-               data = data == null ?
-                       [ event ] :
-                       jQuery.makeArray( data, [ event ] );
-
-               // Allow special events to draw outside the lines
-               special = jQuery.event.special[ type ] || {};
-               if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
-                       return;
-               }
-
-               // Determine event propagation path in advance, per W3C events spec (#9951)
-               // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
-               if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
-
-                       bubbleType = special.delegateType || type;
-                       if ( !rfocusMorph.test( bubbleType + type ) ) {
-                               cur = cur.parentNode;
-                       }
-                       for ( ; cur; cur = cur.parentNode ) {
-                               eventPath.push( cur );
-                               tmp = cur;
-                       }
-
-                       // Only add window if we got to document (e.g., not plain obj or detached DOM)
-                       if ( tmp === (elem.ownerDocument || document) ) {
-                               eventPath.push( tmp.defaultView || tmp.parentWindow || window );
-                       }
-               }
-
-               // Fire handlers on the event path
-               i = 0;
-               while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
-
-                       event.type = i > 1 ?
-                               bubbleType :
-                               special.bindType || type;
-
-                       // jQuery handler
-                       handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
-                       if ( handle ) {
-                               handle.apply( cur, data );
-                       }
-
-                       // Native handler
-                       handle = ontype && cur[ ontype ];
-                       if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
-                               event.result = handle.apply( cur, data );
-                               if ( event.result === false ) {
-                                       event.preventDefault();
-                               }
-                       }
-               }
-               event.type = type;
-
-               // If nobody prevented the default action, do it now
-               if ( !onlyHandlers && !event.isDefaultPrevented() ) {
-
-                       if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
-                               jQuery.acceptData( elem ) ) {
-
-                               // Call a native DOM method on the target with the same name name as the event.
-                               // Don't do default actions on window, that's where global variables be (#6170)
-                               if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
-
-                                       // Don't re-trigger an onFOO event when we call its FOO() method
-                                       tmp = elem[ ontype ];
-
-                                       if ( tmp ) {
-                                               elem[ ontype ] = null;
-                                       }
-
-                                       // Prevent re-triggering of the same event, since we already bubbled it above
-                                       jQuery.event.triggered = type;
-                                       elem[ type ]();
-                                       jQuery.event.triggered = undefined;
-
-                                       if ( tmp ) {
-                                               elem[ ontype ] = tmp;
-                                       }
-                               }
-                       }
-               }
-
-               return event.result;
-       },
-
-       dispatch: function( event ) {
-
-               // Make a writable jQuery.Event from the native event object
-               event = jQuery.event.fix( event );
-
-               var i, j, ret, matched, handleObj,
-                       handlerQueue = [],
-                       args = slice.call( arguments ),
-                       handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
-                       special = jQuery.event.special[ event.type ] || {};
-
-               // Use the fix-ed jQuery.Event rather than the (read-only) native event
-               args[0] = event;
-               event.delegateTarget = this;
-
-               // Call the preDispatch hook for the mapped type, and let it bail if desired
-               if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
-                       return;
-               }
-
-               // Determine handlers
-               handlerQueue = jQuery.event.handlers.call( this, event, handlers );
-
-               // Run delegates first; they may want to stop propagation beneath us
-               i = 0;
-               while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
-                       event.currentTarget = matched.elem;
-
-                       j = 0;
-                       while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
-
-                               // Triggered event must either 1) have no namespace, or
-                               // 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace).
-                               if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
-
-                                       event.handleObj = handleObj;
-                                       event.data = handleObj.data;
-
-                                       ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
-                                                       .apply( matched.elem, args );
-
-                                       if ( ret !== undefined ) {
-                                               if ( (event.result = ret) === false ) {
-                                                       event.preventDefault();
-                                                       event.stopPropagation();
-                                               }
-                                       }
-                               }
-                       }
-               }
-
-               // Call the postDispatch hook for the mapped type
-               if ( special.postDispatch ) {
-                       special.postDispatch.call( this, event );
-               }
-
-               return event.result;
-       },
-
-       handlers: function( event, handlers ) {
-               var i, matches, sel, handleObj,
-                       handlerQueue = [],
-                       delegateCount = handlers.delegateCount,
-                       cur = event.target;
-
-               // Find delegate handlers
-               // Black-hole SVG <use> instance trees (#13180)
-               // Avoid non-left-click bubbling in Firefox (#3861)
-               if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) {
-
-                       for ( ; cur !== this; cur = cur.parentNode || this ) {
-
-                               // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
-                               if ( cur.disabled !== true || event.type !== "click" ) {
-                                       matches = [];
-                                       for ( i = 0; i < delegateCount; i++ ) {
-                                               handleObj = handlers[ i ];
-
-                                               // Don't conflict with Object.prototype properties (#13203)
-                                               sel = handleObj.selector + " ";
-
-                                               if ( matches[ sel ] === undefined ) {
-                                                       matches[ sel ] = handleObj.needsContext ?
-                                                               jQuery( sel, this ).index( cur ) >= 0 :
-                                                               jQuery.find( sel, this, null, [ cur ] ).length;
-                                               }
-                                               if ( matches[ sel ] ) {
-                                                       matches.push( handleObj );
-                                               }
-                                       }
-                                       if ( matches.length ) {
-                                               handlerQueue.push({ elem: cur, handlers: matches });
-                                       }
-                               }
-                       }
-               }
-
-               // Add the remaining (directly-bound) handlers
-               if ( delegateCount < handlers.length ) {
-                       handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
-               }
-
-               return handlerQueue;
-       },
-
-       // Includes some event props shared by KeyEvent and MouseEvent
-       props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
-
-       fixHooks: {},
-
-       keyHooks: {
-               props: "char charCode key keyCode".split(" "),
-               filter: function( event, original ) {
-
-                       // Add which for key events
-                       if ( event.which == null ) {
-                               event.which = original.charCode != null ? original.charCode : original.keyCode;
-                       }
-
-                       return event;
-               }
-       },
-
-       mouseHooks: {
-               props: "button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
-               filter: function( event, original ) {
-                       var eventDoc, doc, body,
-                               button = original.button;
-
-                       // Calculate pageX/Y if missing and clientX/Y available
-                       if ( event.pageX == null && original.clientX != null ) {
-                               eventDoc = event.target.ownerDocument || document;
-                               doc = eventDoc.documentElement;
-                               body = eventDoc.body;
-
-                               event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
-                               event.pageY = original.clientY + ( doc && doc.scrollTop  || body && body.scrollTop  || 0 ) - ( doc && doc.clientTop  || body && body.clientTop  || 0 );
-                       }
-
-                       // Add which for click: 1 === left; 2 === middle; 3 === right
-                       // Note: button is not normalized, so don't use it
-                       if ( !event.which && button !== undefined ) {
-                               event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
-                       }
-
-                       return event;
-               }
-       },
-
-       fix: function( event ) {
-               if ( event[ jQuery.expando ] ) {
-                       return event;
-               }
-
-               // Create a writable copy of the event object and normalize some properties
-               var i, prop, copy,
-                       type = event.type,
-                       originalEvent = event,
-                       fixHook = this.fixHooks[ type ];
-
-               if ( !fixHook ) {
-                       this.fixHooks[ type ] = fixHook =
-                               rmouseEvent.test( type ) ? this.mouseHooks :
-                               rkeyEvent.test( type ) ? this.keyHooks :
-                               {};
-               }
-               copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
-
-               event = new jQuery.Event( originalEvent );
-
-               i = copy.length;
-               while ( i-- ) {
-                       prop = copy[ i ];
-                       event[ prop ] = originalEvent[ prop ];
-               }
-
-               // Support: Cordova 2.5 (WebKit) (#13255)
-               // All events should have a target; Cordova deviceready doesn't
-               if ( !event.target ) {
-                       event.target = document;
-               }
-
-               // Support: Safari 6.0+, Chrome < 28
-               // Target should not be a text node (#504, #13143)
-               if ( event.target.nodeType === 3 ) {
-                       event.target = event.target.parentNode;
-               }
-
-               return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
-       },
-
-       special: {
-               load: {
-                       // Prevent triggered image.load events from bubbling to window.load
-                       noBubble: true
-               },
-               focus: {
-                       // Fire native event if possible so blur/focus sequence is correct
-                       trigger: function() {
-                               if ( this !== safeActiveElement() && this.focus ) {
-                                       this.focus();
-                                       return false;
-                               }
-                       },
-                       delegateType: "focusin"
-               },
-               blur: {
-                       trigger: function() {
-                               if ( this === safeActiveElement() && this.blur ) {
-                                       this.blur();
-                                       return false;
-                               }
-                       },
-                       delegateType: "focusout"
-               },
-               click: {
-                       // For checkbox, fire native event so checked state will be right
-                       trigger: function() {
-                               if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
-                                       this.click();
-                                       return false;
-                               }
-                       },
-
-                       // For cross-browser consistency, don't fire native .click() on links
-                       _default: function( event ) {
-                               return jQuery.nodeName( event.target, "a" );
-                       }
-               },
-
-               beforeunload: {
-                       postDispatch: function( event ) {
-
-                               // Support: Firefox 20+
-                               // Firefox doesn't alert if the returnValue field is not set.
-                               if ( event.result !== undefined && event.originalEvent ) {
-                                       event.originalEvent.returnValue = event.result;
-                               }
-                       }
-               }
-       },
-
-       simulate: function( type, elem, event, bubble ) {
-               // Piggyback on a donor event to simulate a different one.
-               // Fake originalEvent to avoid donor's stopPropagation, but if the
-               // simulated event prevents default then we do the same on the donor.
-               var e = jQuery.extend(
-                       new jQuery.Event(),
-                       event,
-                       {
-                               type: type,
-                               isSimulated: true,
-                               originalEvent: {}
-                       }
-               );
-               if ( bubble ) {
-                       jQuery.event.trigger( e, null, elem );
-               } else {
-                       jQuery.event.dispatch.call( elem, e );
-               }
-               if ( e.isDefaultPrevented() ) {
-                       event.preventDefault();
-               }
-       }
-};
-
-jQuery.removeEvent = function( elem, type, handle ) {
-       if ( elem.removeEventListener ) {
-               elem.removeEventListener( type, handle, false );
-       }
-};
-
-jQuery.Event = function( src, props ) {
-       // Allow instantiation without the 'new' keyword
-       if ( !(this instanceof jQuery.Event) ) {
-               return new jQuery.Event( src, props );
-       }
-
-       // Event object
-       if ( src && src.type ) {
-               this.originalEvent = src;
-               this.type = src.type;
-
-               // Events bubbling up the document may have been marked as prevented
-               // by a handler lower down the tree; reflect the correct value.
-               this.isDefaultPrevented = src.defaultPrevented ||
-                               src.defaultPrevented === undefined &&
-                               // Support: Android < 4.0
-                               src.returnValue === false ?
-                       returnTrue :
-                       returnFalse;
-
-       // Event type
-       } else {
-               this.type = src;
-       }
-
-       // Put explicitly provided properties onto the event object
-       if ( props ) {
-               jQuery.extend( this, props );
-       }
-
-       // Create a timestamp if incoming event doesn't have one
-       this.timeStamp = src && src.timeStamp || jQuery.now();
-
-       // Mark it as fixed
-       this[ jQuery.expando ] = true;
-};
-
-// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
-// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
-jQuery.Event.prototype = {
-       isDefaultPrevented: returnFalse,
-       isPropagationStopped: returnFalse,
-       isImmediatePropagationStopped: returnFalse,
-
-       preventDefault: function() {
-               var e = this.originalEvent;
-
-               this.isDefaultPrevented = returnTrue;
-
-               if ( e && e.preventDefault ) {
-                       e.preventDefault();
-               }
-       },
-       stopPropagation: function() {
-               var e = this.originalEvent;
-
-               this.isPropagationStopped = returnTrue;
-
-               if ( e && e.stopPropagation ) {
-                       e.stopPropagation();
-               }
-       },
-       stopImmediatePropagation: function() {
-               var e = this.originalEvent;
-
-               this.isImmediatePropagationStopped = returnTrue;
-
-               if ( e && e.stopImmediatePropagation ) {
-                       e.stopImmediatePropagation();
-               }
-
-               this.stopPropagation();
-       }
-};
-
-// Create mouseenter/leave events using mouseover/out and event-time checks
-// Support: Chrome 15+
-jQuery.each({
-       mouseenter: "mouseover",
-       mouseleave: "mouseout",
-       pointerenter: "pointerover",
-       pointerleave: "pointerout"
-}, function( orig, fix ) {
-       jQuery.event.special[ orig ] = {
-               delegateType: fix,
-               bindType: fix,
-
-               handle: function( event ) {
-                       var ret,
-                               target = this,
-                               related = event.relatedTarget,
-                               handleObj = event.handleObj;
-
-                       // For mousenter/leave call the handler if related is outside the target.
-                       // NB: No relatedTarget if the mouse left/entered the browser window
-                       if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
-                               event.type = handleObj.origType;
-                               ret = handleObj.handler.apply( this, arguments );
-                               event.type = fix;
-                       }
-                       return ret;
-               }
-       };
-});
-
-// Create "bubbling" focus and blur events
-// Support: Firefox, Chrome, Safari
-if ( !support.focusinBubbles ) {
-       jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
-
-               // Attach a single capturing handler on the document while someone wants focusin/focusout
-               var handler = function( event ) {
-                               jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
-                       };
-
-               jQuery.event.special[ fix ] = {
-                       setup: function() {
-                               var doc = this.ownerDocument || this,
-                                       attaches = data_priv.access( doc, fix );
-
-                               if ( !attaches ) {
-                                       doc.addEventListener( orig, handler, true );
-                               }
-                               data_priv.access( doc, fix, ( attaches || 0 ) + 1 );
-                       },
-                       teardown: function() {
-                               var doc = this.ownerDocument || this,
-                                       attaches = data_priv.access( doc, fix ) - 1;
-
-                               if ( !attaches ) {
-                                       doc.removeEventListener( orig, handler, true );
-                                       data_priv.remove( doc, fix );
-
-                               } else {
-                                       data_priv.access( doc, fix, attaches );
-                               }
-                       }
-               };
-       });
-}
-
-jQuery.fn.extend({
-
-       on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
-               var origFn, type;
-
-               // Types can be a map of types/handlers
-               if ( typeof types === "object" ) {
-                       // ( types-Object, selector, data )
-                       if ( typeof selector !== "string" ) {
-                               // ( types-Object, data )
-                               data = data || selector;
-                               selector = undefined;
-                       }
-                       for ( type in types ) {
-                               this.on( type, selector, data, types[ type ], one );
-                       }
-                       return this;
-               }
-
-               if ( data == null && fn == null ) {
-                       // ( types, fn )
-                       fn = selector;
-                       data = selector = undefined;
-               } else if ( fn == null ) {
-                       if ( typeof selector === "string" ) {
-                               // ( types, selector, fn )
-                               fn = data;
-                               data = undefined;
-                       } else {
-                               // ( types, data, fn )
-                               fn = data;
-                               data = selector;
-                               selector = undefined;
-                       }
-               }
-               if ( fn === false ) {
-                       fn = returnFalse;
-               } else if ( !fn ) {
-                       return this;
-               }
-
-               if ( one === 1 ) {
-                       origFn = fn;
-                       fn = function( event ) {
-                               // Can use an empty set, since event contains the info
-                               jQuery().off( event );
-                               return origFn.apply( this, arguments );
-                       };
-                       // Use same guid so caller can remove using origFn
-                       fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
-               }
-               return this.each( function() {
-                       jQuery.event.add( this, types, fn, data, selector );
-               });
-       },
-       one: function( types, selector, data, fn ) {
-               return this.on( types, selector, data, fn, 1 );
-       },
-       off: function( types, selector, fn ) {
-               var handleObj, type;
-               if ( types && types.preventDefault && types.handleObj ) {
-                       // ( event )  dispatched jQuery.Event
-                       handleObj = types.handleObj;
-                       jQuery( types.delegateTarget ).off(
-                               handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
-                               handleObj.selector,
-                               handleObj.handler
-                       );
-                       return this;
-               }
-               if ( typeof types === "object" ) {
-                       // ( types-object [, selector] )
-                       for ( type in types ) {
-                               this.off( type, selector, types[ type ] );
-                       }
-                       return this;
-               }
-               if ( selector === false || typeof selector === "function" ) {
-                       // ( types [, fn] )
-                       fn = selector;
-                       selector = undefined;
-               }
-               if ( fn === false ) {
-                       fn = returnFalse;
-               }
-               return this.each(function() {
-                       jQuery.event.remove( this, types, fn, selector );
-               });
-       },
-
-       trigger: function( type, data ) {
-               return this.each(function() {
-                       jQuery.event.trigger( type, data, this );
-               });
-       },
-       triggerHandler: function( type, data ) {
-               var elem = this[0];
-               if ( elem ) {
-                       return jQuery.event.trigger( type, data, elem, true );
-               }
-       }
-});
-
-
-var
-       rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
-       rtagName = /<([\w:]+)/,
-       rhtml = /<|&#?\w+;/,
-       rnoInnerhtml = /<(?:script|style|link)/i,
-       // checked="checked" or checked
-       rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
-       rscriptType = /^$|\/(?:java|ecma)script/i,
-       rscriptTypeMasked = /^true\/(.*)/,
-       rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
-
-       // We have to close these tags to support XHTML (#13200)
-       wrapMap = {
-
-               // Support: IE 9
-               option: [ 1, "<select multiple='multiple'>", "</select>" ],
-
-               thead: [ 1, "<table>", "</table>" ],
-               col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
-               tr: [ 2, "<table><tbody>", "</tbody></table>" ],
-               td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
-
-               _default: [ 0, "", "" ]
-       };
-
-// Support: IE 9
-wrapMap.optgroup = wrapMap.option;
-
-wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
-wrapMap.th = wrapMap.td;
-
-// Support: 1.x compatibility
-// Manipulating tables requires a tbody
-function manipulationTarget( elem, content ) {
-       return jQuery.nodeName( elem, "table" ) &&
-               jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
-
-               elem.getElementsByTagName("tbody")[0] ||
-                       elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
-               elem;
-}
-
-// Replace/restore the type attribute of script elements for safe DOM manipulation
-function disableScript( elem ) {
-       elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
-       return elem;
-}
-function restoreScript( elem ) {
-       var match = rscriptTypeMasked.exec( elem.type );
-
-       if ( match ) {
-               elem.type = match[ 1 ];
-       } else {
-               elem.removeAttribute("type");
-       }
-
-       return elem;
-}
-
-// Mark scripts as having already been evaluated
-function setGlobalEval( elems, refElements ) {
-       var i = 0,
-               l = elems.length;
-
-       for ( ; i < l; i++ ) {
-               data_priv.set(
-                       elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
-               );
-       }
-}
-
-function cloneCopyEvent( src, dest ) {
-       var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
-
-       if ( dest.nodeType !== 1 ) {
-               return;
-       }
-
-       // 1. Copy private data: events, handlers, etc.
-       if ( data_priv.hasData( src ) ) {
-               pdataOld = data_priv.access( src );
-               pdataCur = data_priv.set( dest, pdataOld );
-               events = pdataOld.events;
-
-               if ( events ) {
-                       delete pdataCur.handle;
-                       pdataCur.events = {};
-
-                       for ( type in events ) {
-                               for ( i = 0, l = events[ type ].length; i < l; i++ ) {
-                                       jQuery.event.add( dest, type, events[ type ][ i ] );
-                               }
-                       }
-               }
-       }
-
-       // 2. Copy user data
-       if ( data_user.hasData( src ) ) {
-               udataOld = data_user.access( src );
-               udataCur = jQuery.extend( {}, udataOld );
-
-               data_user.set( dest, udataCur );
-       }
-}
-
-function getAll( context, tag ) {
-       var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
-                       context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
-                       [];
-
-       return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
-               jQuery.merge( [ context ], ret ) :
-               ret;
-}
-
-// Support: IE >= 9
-function fixInput( src, dest ) {
-       var nodeName = dest.nodeName.toLowerCase();
-
-       // Fails to persist the checked state of a cloned checkbox or radio button.
-       if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
-               dest.checked = src.checked;
-
-       // Fails to return the selected option to the default selected state when cloning options
-       } else if ( nodeName === "input" || nodeName === "textarea" ) {
-               dest.defaultValue = src.defaultValue;
-       }
-}
-
-jQuery.extend({
-       clone: function( elem, dataAndEvents, deepDataAndEvents ) {
-               var i, l, srcElements, destElements,
-                       clone = elem.cloneNode( true ),
-                       inPage = jQuery.contains( elem.ownerDocument, elem );
-
-               // Support: IE >= 9
-               // Fix Cloning issues
-               if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
-                               !jQuery.isXMLDoc( elem ) ) {
-
-                       // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
-                       destElements = getAll( clone );
-                       srcElements = getAll( elem );
-
-                       for ( i = 0, l = srcElements.length; i < l; i++ ) {
-                               fixInput( srcElements[ i ], destElements[ i ] );
-                       }
-               }
-
-               // Copy the events from the original to the clone
-               if ( dataAndEvents ) {
-                       if ( deepDataAndEvents ) {
-                               srcElements = srcElements || getAll( elem );
-                               destElements = destElements || getAll( clone );
-
-                               for ( i = 0, l = srcElements.length; i < l; i++ ) {
-                                       cloneCopyEvent( srcElements[ i ], destElements[ i ] );
-                               }
-                       } else {
-                               cloneCopyEvent( elem, clone );
-                       }
-               }
-
-               // Preserve script evaluation history
-               destElements = getAll( clone, "script" );
-               if ( destElements.length > 0 ) {
-                       setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
-               }
-
-               // Return the cloned set
-               return clone;
-       },
-
-       buildFragment: function( elems, context, scripts, selection ) {
-               var elem, tmp, tag, wrap, contains, j,
-                       fragment = context.createDocumentFragment(),
-                       nodes = [],
-                       i = 0,
-                       l = elems.length;
-
-               for ( ; i < l; i++ ) {
-                       elem = elems[ i ];
-
-                       if ( elem || elem === 0 ) {
-
-                               // Add nodes directly
-                               if ( jQuery.type( elem ) === "object" ) {
-                                       // Support: QtWebKit
-                                       // jQuery.merge because push.apply(_, arraylike) throws
-                                       jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
-
-                               // Convert non-html into a text node
-                               } else if ( !rhtml.test( elem ) ) {
-                                       nodes.push( context.createTextNode( elem ) );
-
-                               // Convert html into DOM nodes
-                               } else {
-                                       tmp = tmp || fragment.appendChild( context.createElement("div") );
-
-                                       // Deserialize a standard representation
-                                       tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
-                                       wrap = wrapMap[ tag ] || wrapMap._default;
-                                       tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];
-
-                                       // Descend through wrappers to the right content
-                                       j = wrap[ 0 ];
-                                       while ( j-- ) {
-                                               tmp = tmp.lastChild;
-                                       }
-
-                                       // Support: QtWebKit
-                                       // jQuery.merge because push.apply(_, arraylike) throws
-                                       jQuery.merge( nodes, tmp.childNodes );
-
-                                       // Remember the top-level container
-                                       tmp = fragment.firstChild;
-
-                                       // Fixes #12346
-                                       // Support: Webkit, IE
-                                       tmp.textContent = "";
-                               }
-                       }
-               }
-
-               // Remove wrapper from fragment
-               fragment.textContent = "";
-
-               i = 0;
-               while ( (elem = nodes[ i++ ]) ) {
-
-                       // #4087 - If origin and destination elements are the same, and this is
-                       // that element, do not do anything
-                       if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
-                               continue;
-                       }
-
-                       contains = jQuery.contains( elem.ownerDocument, elem );
-
-                       // Append to fragment
-                       tmp = getAll( fragment.appendChild( elem ), "script" );
-
-                       // Preserve script evaluation history
-                       if ( contains ) {
-                               setGlobalEval( tmp );
-                       }
-
-                       // Capture executables
-                       if ( scripts ) {
-                               j = 0;
-                               while ( (elem = tmp[ j++ ]) ) {
-                                       if ( rscriptType.test( elem.type || "" ) ) {
-                                               scripts.push( elem );
-                                       }
-                               }
-                       }
-               }
-
-               return fragment;
-       },
-
-       cleanData: function( elems ) {
-               var data, elem, type, key,
-                       special = jQuery.event.special,
-                       i = 0;
-
-               for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
-                       if ( jQuery.acceptData( elem ) ) {
-                               key = elem[ data_priv.expando ];
-
-                               if ( key && (data = data_priv.cache[ key ]) ) {
-                                       if ( data.events ) {
-                                               for ( type in data.events ) {
-                                                       if ( special[ type ] ) {
-                                                               jQuery.event.remove( elem, type );
-
-                                                       // This is a shortcut to avoid jQuery.event.remove's overhead
-                                                       } else {
-                                                               jQuery.removeEvent( elem, type, data.handle );
-                                                       }
-                                               }
-                                       }
-                                       if ( data_priv.cache[ key ] ) {
-                                               // Discard any remaining `private` data
-                                               delete data_priv.cache[ key ];
-                                       }
-                               }
-                       }
-                       // Discard any remaining `user` data
-                       delete data_user.cache[ elem[ data_user.expando ] ];
-               }
-       }
-});
-
-jQuery.fn.extend({
-       text: function( value ) {
-               return access( this, function( value ) {
-                       return value === undefined ?
-                               jQuery.text( this ) :
-                               this.empty().each(function() {
-                                       if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
-                                               this.textContent = value;
-                                       }
-                               });
-               }, null, value, arguments.length );
-       },
-
-       append: function() {
-               return this.domManip( arguments, function( elem ) {
-                       if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
-                               var target = manipulationTarget( this, elem );
-                               target.appendChild( elem );
-                       }
-               });
-       },
-
-       prepend: function() {
-               return this.domManip( arguments, function( elem ) {
-                       if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
-                               var target = manipulationTarget( this, elem );
-                               target.insertBefore( elem, target.firstChild );
-                       }
-               });
-       },
-
-       before: function() {
-               return this.domManip( arguments, function( elem ) {
-                       if ( this.parentNode ) {
-                               this.parentNode.insertBefore( elem, this );
-                       }
-               });
-       },
-
-       after: function() {
-               return this.domManip( arguments, function( elem ) {
-                       if ( this.parentNode ) {
-                               this.parentNode.insertBefore( elem, this.nextSibling );
-                       }
-               });
-       },
-
-       remove: function( selector, keepData /* Internal Use Only */ ) {
-               var elem,
-                       elems = selector ? jQuery.filter( selector, this ) : this,
-                       i = 0;
-
-               for ( ; (elem = elems[i]) != null; i++ ) {
-                       if ( !keepData && elem.nodeType === 1 ) {
-                               jQuery.cleanData( getAll( elem ) );
-                       }
-
-                       if ( elem.parentNode ) {
-                               if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
-                                       setGlobalEval( getAll( elem, "script" ) );
-                               }
-                               elem.parentNode.removeChild( elem );
-                       }
-               }
-
-               return this;
-       },
-
-       empty: function() {
-               var elem,
-                       i = 0;
-
-               for ( ; (elem = this[i]) != null; i++ ) {
-                       if ( elem.nodeType === 1 ) {
-
-                               // Prevent memory leaks
-                               jQuery.cleanData( getAll( elem, false ) );
-
-                               // Remove any remaining nodes
-                               elem.textContent = "";
-                       }
-               }
-
-               return this;
-       },
-
-       clone: function( dataAndEvents, deepDataAndEvents ) {
-               dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
-               deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
-
-               return this.map(function() {
-                       return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
-               });
-       },
-
-       html: function( value ) {
-               return access( this, function( value ) {
-                       var elem = this[ 0 ] || {},
-                               i = 0,
-                               l = this.length;
-
-                       if ( value === undefined && elem.nodeType === 1 ) {
-                               return elem.innerHTML;
-                       }
-
-                       // See if we can take a shortcut and just use innerHTML
-                       if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
-                               !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
-
-                               value = value.replace( rxhtmlTag, "<$1></$2>" );
-
-                               try {
-                                       for ( ; i < l; i++ ) {
-                                               elem = this[ i ] || {};
-
-                                               // Remove element nodes and prevent memory leaks
-                                               if ( elem.nodeType === 1 ) {
-                                                       jQuery.cleanData( getAll( elem, false ) );
-                                                       elem.innerHTML = value;
-                                               }
-                                       }
-
-                                       elem = 0;
-
-                               // If using innerHTML throws an exception, use the fallback method
-                               } catch( e ) {}
-                       }
-
-                       if ( elem ) {
-                               this.empty().append( value );
-                       }
-               }, null, value, arguments.length );
-       },
-
-       replaceWith: function() {
-               var arg = arguments[ 0 ];
-
-               // Make the changes, replacing each context element with the new content
-               this.domManip( arguments, function( elem ) {
-                       arg = this.parentNode;
-
-                       jQuery.cleanData( getAll( this ) );
-
-                       if ( arg ) {
-                               arg.replaceChild( elem, this );
-                       }
-               });
-
-               // Force removal if there was no new content (e.g., from empty arguments)
-               return arg && (arg.length || arg.nodeType) ? this : this.remove();
-       },
-
-       detach: function( selector ) {
-               return this.remove( selector, true );
-       },
-
-       domManip: function( args, callback ) {
-
-               // Flatten any nested arrays
-               args = concat.apply( [], args );
-
-               var fragment, first, scripts, hasScripts, node, doc,
-                       i = 0,
-                       l = this.length,
-                       set = this,
-                       iNoClone = l - 1,
-                       value = args[ 0 ],
-                       isFunction = jQuery.isFunction( value );
-
-               // We can't cloneNode fragments that contain checked, in WebKit
-               if ( isFunction ||
-                               ( l > 1 && typeof value === "string" &&
-                                       !support.checkClone && rchecked.test( value ) ) ) {
-                       return this.each(function( index ) {
-                               var self = set.eq( index );
-                               if ( isFunction ) {
-                                       args[ 0 ] = value.call( this, index, self.html() );
-                               }
-                               self.domManip( args, callback );
-                       });
-               }
-
-               if ( l ) {
-                       fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
-                       first = fragment.firstChild;
-
-                       if ( fragment.childNodes.length === 1 ) {
-                               fragment = first;
-                       }
-
-                       if ( first ) {
-                               scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
-                               hasScripts = scripts.length;
-
-                               // Use the original fragment for the last item instead of the first because it can end up
-                               // being emptied incorrectly in certain situations (#8070).
-                               for ( ; i < l; i++ ) {
-                                       node = fragment;
-
-                                       if ( i !== iNoClone ) {
-                                               node = jQuery.clone( node, true, true );
-
-                                               // Keep references to cloned scripts for later restoration
-                                               if ( hasScripts ) {
-                                                       // Support: QtWebKit
-                                                       // jQuery.merge because push.apply(_, arraylike) throws
-                                                       jQuery.merge( scripts, getAll( node, "script" ) );
-                                               }
-                                       }
-
-                                       callback.call( this[ i ], node, i );
-                               }
-
-                               if ( hasScripts ) {
-                                       doc = scripts[ scripts.length - 1 ].ownerDocument;
-
-                                       // Reenable scripts
-                                       jQuery.map( scripts, restoreScript );
-
-                                       // Evaluate executable scripts on first document insertion
-                                       for ( i = 0; i < hasScripts; i++ ) {
-                                               node = scripts[ i ];
-                                               if ( rscriptType.test( node.type || "" ) &&
-                                                       !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
-
-                                                       if ( node.src ) {
-                                                               // Optional AJAX dependency, but won't run scripts if not present
-                                                               if ( jQuery._evalUrl ) {
-                                                                       jQuery._evalUrl( node.src );
-                                                               }
-                                                       } else {
-                                                               jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-               }
-
-               return this;
-       }
-});
-
-jQuery.each({
-       appendTo: "append",
-       prependTo: "prepend",
-       insertBefore: "before",
-       insertAfter: "after",
-       replaceAll: "replaceWith"
-}, function( name, original ) {
-       jQuery.fn[ name ] = function( selector ) {
-               var elems,
-                       ret = [],
-                       insert = jQuery( selector ),
-                       last = insert.length - 1,
-                       i = 0;
-
-               for ( ; i <= last; i++ ) {
-                       elems = i === last ? this : this.clone( true );
-                       jQuery( insert[ i ] )[ original ]( elems );
-
-                       // Support: QtWebKit
-                       // .get() because push.apply(_, arraylike) throws
-                       push.apply( ret, elems.get() );
-               }
-
-               return this.pushStack( ret );
-       };
-});
-
-
-var iframe,
-       elemdisplay = {};
-
-/**
- * Retrieve the actual display of a element
- * @param {String} name nodeName of the element
- * @param {Object} doc Document object
- */
-// Called only from within defaultDisplay
-function actualDisplay( name, doc ) {
-       var style,
-               elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
-
-               // getDefaultComputedStyle might be reliably used only on attached element
-               display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
-
-                       // Use of this method is a temporary fix (more like optmization) until something better comes along,
-                       // since it was removed from specification and supported only in FF
-                       style.display : jQuery.css( elem[ 0 ], "display" );
-
-       // We don't have any data stored on the element,
-       // so use "detach" method as fast way to get rid of the element
-       elem.detach();
-
-       return display;
-}
-
-/**
- * Try to determine the default display value of an element
- * @param {String} nodeName
- */
-function defaultDisplay( nodeName ) {
-       var doc = document,
-               display = elemdisplay[ nodeName ];
-
-       if ( !display ) {
-               display = actualDisplay( nodeName, doc );
-
-               // If the simple way fails, read from inside an iframe
-               if ( display === "none" || !display ) {
-
-                       // Use the already-created iframe if possible
-                       iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
-
-                       // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
-                       doc = iframe[ 0 ].contentDocument;
-
-                       // Support: IE
-                       doc.write();
-                       doc.close();
-
-                       display = actualDisplay( nodeName, doc );
-                       iframe.detach();
-               }
-
-               // Store the correct default display
-               elemdisplay[ nodeName ] = display;
-       }
-
-       return display;
-}
-var rmargin = (/^margin/);
-
-var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
-
-var getStyles = function( elem ) {
-               return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
-       };
-
-
-
-function curCSS( elem, name, computed ) {
-       var width, minWidth, maxWidth, ret,
-               style = elem.style;
-
-       computed = computed || getStyles( elem );
-
-       // Support: IE9
-       // getPropertyValue is only needed for .css('filter') in IE9, see #12537
-       if ( computed ) {
-               ret = computed.getPropertyValue( name ) || computed[ name ];
-       }
-
-       if ( computed ) {
-
-               if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
-                       ret = jQuery.style( elem, name );
-               }
-
-               // Support: iOS < 6
-               // A tribute to the "awesome hack by Dean Edwards"
-               // iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
-               // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
-               if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
-
-                       // Remember the original values
-                       width = style.width;
-                       minWidth = style.minWidth;
-                       maxWidth = style.maxWidth;
-
-                       // Put in the new values to get a computed value out
-                       style.minWidth = style.maxWidth = style.width = ret;
-                       ret = computed.width;
-
-                       // Revert the changed values
-                       style.width = width;
-                       style.minWidth = minWidth;
-                       style.maxWidth = maxWidth;
-               }
-       }
-
-       return ret !== undefined ?
-               // Support: IE
-               // IE returns zIndex value as an integer.
-               ret + "" :
-               ret;
-}
-
-
-function addGetHookIf( conditionFn, hookFn ) {
-       // Define the hook, we'll check on the first run if it's really needed.
-       return {
-               get: function() {
-                       if ( conditionFn() ) {
-                               // Hook not needed (or it's not possible to use it due to missing dependency),
-                               // remove it.
-                               // Since there are no other hooks for marginRight, remove the whole object.
-                               delete this.get;
-                               return;
-                       }
-
-                       // Hook needed; redefine it so that the support test is not executed again.
-
-                       return (this.get = hookFn).apply( this, arguments );
-               }
-       };
-}
-
-
-(function() {
-       var pixelPositionVal, boxSizingReliableVal,
-               docElem = document.documentElement,
-               container = document.createElement( "div" ),
-               div = document.createElement( "div" );
-
-       if ( !div.style ) {
-               return;
-       }
-
-       div.style.backgroundClip = "content-box";
-       div.cloneNode( true ).style.backgroundClip = "";
-       support.clearCloneStyle = div.style.backgroundClip === "content-box";
-
-       container.style.cssText = "border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;" +
-               "position:absolute";
-       container.appendChild( div );
-
-       // Executing both pixelPosition & boxSizingReliable tests require only one layout
-       // so they're executed at the same time to save the second computation.
-       function computePixelPositionAndBoxSizingReliable() {
-               div.style.cssText =
-                       // Support: Firefox<29, Android 2.3
-                       // Vendor-prefix box-sizing
-                       "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
-                       "box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
-                       "border:1px;padding:1px;width:4px;position:absolute";
-               div.innerHTML = "";
-               docElem.appendChild( container );
-
-               var divStyle = window.getComputedStyle( div, null );
-               pixelPositionVal = divStyle.top !== "1%";
-               boxSizingReliableVal = divStyle.width === "4px";
-
-               docElem.removeChild( container );
-       }
-
-       // Support: node.js jsdom
-       // Don't assume that getComputedStyle is a property of the global object
-       if ( window.getComputedStyle ) {
-               jQuery.extend( support, {
-                       pixelPosition: function() {
-                               // This test is executed only once but we still do memoizing
-                               // since we can use the boxSizingReliable pre-computing.
-                               // No need to check if the test was already performed, though.
-                               computePixelPositionAndBoxSizingReliable();
-                               return pixelPositionVal;
-                       },
-                       boxSizingReliable: function() {
-                               if ( boxSizingReliableVal == null ) {
-                                       computePixelPositionAndBoxSizingReliable();
-                               }
-                               return boxSizingReliableVal;
-                       },
-                       reliableMarginRight: function() {
-                               // Support: Android 2.3
-                               // Check if div with explicit width and no margin-right incorrectly
-                               // gets computed margin-right based on width of container. (#3333)
-                               // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
-                               // This support function is only executed once so no memoizing is needed.
-                               var ret,
-                                       marginDiv = div.appendChild( document.createElement( "div" ) );
-
-                               // Reset CSS: box-sizing; display; margin; border; padding
-                               marginDiv.style.cssText = div.style.cssText =
-                                       // Support: Firefox<29, Android 2.3
-                                       // Vendor-prefix box-sizing
-                                       "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
-                                       "box-sizing:content-box;display:block;margin:0;border:0;padding:0";
-                               marginDiv.style.marginRight = marginDiv.style.width = "0";
-                               div.style.width = "1px";
-                               docElem.appendChild( container );
-
-                               ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
-
-                               docElem.removeChild( container );
-
-                               return ret;
-                       }
-               });
-       }
-})();
-
-
-// A method for quickly swapping in/out CSS properties to get correct calculations.
-jQuery.swap = function( elem, options, callback, args ) {
-       var ret, name,
-               old = {};
-
-       // Remember the old values, and insert the new ones
-       for ( name in options ) {
-               old[ name ] = elem.style[ name ];
-               elem.style[ name ] = options[ name ];
-       }
-
-       ret = callback.apply( elem, args || [] );
-
-       // Revert the old values
-       for ( name in options ) {
-               elem.style[ name ] = old[ name ];
-       }
-
-       return ret;
-};
-
-
-var
-       // swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
-       // see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
-       rdisplayswap = /^(none|table(?!-c[ea]).+)/,
-       rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
-       rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
-
-       cssShow = { position: "absolute", visibility: "hidden", display: "block" },
-       cssNormalTransform = {
-               letterSpacing: "0",
-               fontWeight: "400"
-       },
-
-       cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
-
-// return a css property mapped to a potentially vendor prefixed property
-function vendorPropName( style, name ) {
-
-       // shortcut for names that are not vendor prefixed
-       if ( name in style ) {
-               return name;
-       }
-
-       // check for vendor prefixed names
-       var capName = name[0].toUpperCase() + name.slice(1),
-               origName = name,
-               i = cssPrefixes.length;
-
-       while ( i-- ) {
-               name = cssPrefixes[ i ] + capName;
-               if ( name in style ) {
-                       return name;
-               }
-       }
-
-       return origName;
-}
-
-function setPositiveNumber( elem, value, subtract ) {
-       var matches = rnumsplit.exec( value );
-       return matches ?
-               // Guard against undefined "subtract", e.g., when used as in cssHooks
-               Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
-               value;
-}
-
-function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
-       var i = extra === ( isBorderBox ? "border" : "content" ) ?
-               // If we already have the right measurement, avoid augmentation
-               4 :
-               // Otherwise initialize for horizontal or vertical properties
-               name === "width" ? 1 : 0,
-
-               val = 0;
-
-       for ( ; i < 4; i += 2 ) {
-               // both box models exclude margin, so add it if we want it
-               if ( extra === "margin" ) {
-                       val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
-               }
-
-               if ( isBorderBox ) {
-                       // border-box includes padding, so remove it if we want content
-                       if ( extra === "content" ) {
-                               val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
-                       }
-
-                       // at this point, extra isn't border nor margin, so remove border
-                       if ( extra !== "margin" ) {
-                               val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
-                       }
-               } else {
-                       // at this point, extra isn't content, so add padding
-                       val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
-
-                       // at this point, extra isn't content nor padding, so add border
-                       if ( extra !== "padding" ) {
-                               val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
-                       }
-               }
-       }
-
-       return val;
-}
-
-function getWidthOrHeight( elem, name, extra ) {
-
-       // Start with offset property, which is equivalent to the border-box value
-       var valueIsBorderBox = true,
-               val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
-               styles = getStyles( elem ),
-               isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
-
-       // some non-html elements return undefined for offsetWidth, so check for null/undefined
-       // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
-       // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
-       if ( val <= 0 || val == null ) {
-               // Fall back to computed then uncomputed css if necessary
-               val = curCSS( elem, name, styles );
-               if ( val < 0 || val == null ) {
-                       val = elem.style[ name ];
-               }
-
-               // Computed unit is not pixels. Stop here and return.
-               if ( rnumnonpx.test(val) ) {
-                       return val;
-               }
-
-               // we need the check for style in case a browser which returns unreliable values
-               // for getComputedStyle silently falls back to the reliable elem.style
-               valueIsBorderBox = isBorderBox &&
-                       ( support.boxSizingReliable() || val === elem.style[ name ] );
-
-               // Normalize "", auto, and prepare for extra
-               val = parseFloat( val ) || 0;
-       }
-
-       // use the active box-sizing model to add/subtract irrelevant styles
-       return ( val +
-               augmentWidthOrHeight(
-                       elem,
-                       name,
-                       extra || ( isBorderBox ? "border" : "content" ),
-                       valueIsBorderBox,
-                       styles
-               )
-       ) + "px";
-}
-
-function showHide( elements, show ) {
-       var display, elem, hidden,
-               values = [],
-               index = 0,
-               length = elements.length;
-
-       for ( ; index < length; index++ ) {
-               elem = elements[ index ];
-               if ( !elem.style ) {
-                       continue;
-               }
-
-               values[ index ] = data_priv.get( elem, "olddisplay" );
-               display = elem.style.display;
-               if ( show ) {
-                       // Reset the inline display of this element to learn if it is
-                       // being hidden by cascaded rules or not
-                       if ( !values[ index ] && display === "none" ) {
-                               elem.style.display = "";
-                       }
-
-                       // Set elements which have been overridden with display: none
-                       // in a stylesheet to whatever the default browser style is
-                       // for such an element
-                       if ( elem.style.display === "" && isHidden( elem ) ) {
-                               values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
-                       }
-               } else {
-                       hidden = isHidden( elem );
-
-                       if ( display !== "none" || !hidden ) {
-                               data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
-                       }
-               }
-       }
-
-       // Set the display of most of the elements in a second loop
-       // to avoid the constant reflow
-       for ( index = 0; index < length; index++ ) {
-               elem = elements[ index ];
-               if ( !elem.style ) {
-                       continue;
-               }
-               if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
-                       elem.style.display = show ? values[ index ] || "" : "none";
-               }
-       }
-
-       return elements;
-}
-
-jQuery.extend({
-       // Add in style property hooks for overriding the default
-       // behavior of getting and setting a style property
-       cssHooks: {
-               opacity: {
-                       get: function( elem, computed ) {
-                               if ( computed ) {
-                                       // We should always get a number back from opacity
-                                       var ret = curCSS( elem, "opacity" );
-                                       return ret === "" ? "1" : ret;
-                               }
-                       }
-               }
-       },
-
-       // Don't automatically add "px" to these possibly-unitless properties
-       cssNumber: {
-               "columnCount": true,
-               "fillOpacity": true,
-               "flexGrow": true,
-               "flexShrink": true,
-               "fontWeight": true,
-               "lineHeight": true,
-               "opacity": true,
-               "order": true,
-               "orphans": true,
-               "widows": true,
-               "zIndex": true,
-               "zoom": true
-       },
-
-       // Add in properties whose names you wish to fix before
-       // setting or getting the value
-       cssProps: {
-               // normalize float css property
-               "float": "cssFloat"
-       },
-
-       // Get and set the style property on a DOM Node
-       style: function( elem, name, value, extra ) {
-               // Don't set styles on text and comment nodes
-               if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
-                       return;
-               }
-
-               // Make sure that we're working with the right name
-               var ret, type, hooks,
-                       origName = jQuery.camelCase( name ),
-                       style = elem.style;
-
-               name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
-
-               // gets hook for the prefixed version
-               // followed by the unprefixed version
-               hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
-
-               // Check if we're setting a value
-               if ( value !== undefined ) {
-                       type = typeof value;
-
-                       // convert relative number strings (+= or -=) to relative numbers. #7345
-                       if ( type === "string" && (ret = rrelNum.exec( value )) ) {
-                               value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
-                               // Fixes bug #9237
-                               type = "number";
-                       }
-
-                       // Make sure that null and NaN values aren't set. See: #7116
-                       if ( value == null || value !== value ) {
-                               return;
-                       }
-
-                       // If a number was passed in, add 'px' to the (except for certain CSS properties)
-                       if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
-                               value += "px";
-                       }
-
-                       // Fixes #8908, it can be done more correctly by specifying setters in cssHooks,
-                       // but it would mean to define eight (for every problematic property) identical functions
-                       if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
-                               style[ name ] = "inherit";
-                       }
-
-                       // If a hook was provided, use that value, otherwise just set the specified value
-                       if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
-                               style[ name ] = value;
-                       }
-
-               } else {
-                       // If a hook was provided get the non-computed value from there
-                       if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
-                               return ret;
-                       }
-
-                       // Otherwise just get the value from the style object
-                       return style[ name ];
-               }
-       },
-
-       css: function( elem, name, extra, styles ) {
-               var val, num, hooks,
-                       origName = jQuery.camelCase( name );
-
-               // Make sure that we're working with the right name
-               name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
-
-               // gets hook for the prefixed version
-               // followed by the unprefixed version
-               hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
-
-               // If a hook was provided get the computed value from there
-               if ( hooks && "get" in hooks ) {
-                       val = hooks.get( elem, true, extra );
-               }
-
-               // Otherwise, if a way to get the computed value exists, use that
-               if ( val === undefined ) {
-                       val = curCSS( elem, name, styles );
-               }
-
-               //convert "normal" to computed value
-               if ( val === "normal" && name in cssNormalTransform ) {
-                       val = cssNormalTransform[ name ];
-               }
-
-               // Return, converting to number if forced or a qualifier was provided and val looks numeric
-               if ( extra === "" || extra ) {
-                       num = parseFloat( val );
-                       return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
-               }
-               return val;
-       }
-});
-
-jQuery.each([ "height", "width" ], function( i, name ) {
-       jQuery.cssHooks[ name ] = {
-               get: function( elem, computed, extra ) {
-                       if ( computed ) {
-                               // certain elements can have dimension info if we invisibly show them
-                               // however, it must have a current display style that would benefit from this
-                               return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
-                                       jQuery.swap( elem, cssShow, function() {
-                                               return getWidthOrHeight( elem, name, extra );
-                                       }) :
-                                       getWidthOrHeight( elem, name, extra );
-                       }
-               },
-
-               set: function( elem, value, extra ) {
-                       var styles = extra && getStyles( elem );
-                       return setPositiveNumber( elem, value, extra ?
-                               augmentWidthOrHeight(
-                                       elem,
-                                       name,
-                                       extra,
-                                       jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
-                                       styles
-                               ) : 0
-                       );
-               }
-       };
-});
-
-// Support: Android 2.3
-jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
-       function( elem, computed ) {
-               if ( computed ) {
-                       // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
-                       // Work around by temporarily setting element display to inline-block
-                       return jQuery.swap( elem, { "display": "inline-block" },
-                               curCSS, [ elem, "marginRight" ] );
-               }
-       }
-);
-
-// These hooks are used by animate to expand properties
-jQuery.each({
-       margin: "",
-       padding: "",
-       border: "Width"
-}, function( prefix, suffix ) {
-       jQuery.cssHooks[ prefix + suffix ] = {
-               expand: function( value ) {
-                       var i = 0,
-                               expanded = {},
-
-                               // assumes a single number if not a string
-                               parts = typeof value === "string" ? value.split(" ") : [ value ];
-
-                       for ( ; i < 4; i++ ) {
-                               expanded[ prefix + cssExpand[ i ] + suffix ] =
-                                       parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
-                       }
-
-                       return expanded;
-               }
-       };
-
-       if ( !rmargin.test( prefix ) ) {
-               jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
-       }
-});
-
-jQuery.fn.extend({
-       css: function( name, value ) {
-               return access( this, function( elem, name, value ) {
-                       var styles, len,
-                               map = {},
-                               i = 0;
-
-                       if ( jQuery.isArray( name ) ) {
-                               styles = getStyles( elem );
-                               len = name.length;
-
-                               for ( ; i < len; i++ ) {
-                                       map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
-                               }
-
-                               return map;
-                       }
-
-                       return value !== undefined ?
-                               jQuery.style( elem, name, value ) :
-                               jQuery.css( elem, name );
-               }, name, value, arguments.length > 1 );
-       },
-       show: function() {
-               return showHide( this, true );
-       },
-       hide: function() {
-               return showHide( this );
-       },
-       toggle: function( state ) {
-               if ( typeof state === "boolean" ) {
-                       return state ? this.show() : this.hide();
-               }
-
-               return this.each(function() {
-                       if ( isHidden( this ) ) {
-                               jQuery( this ).show();
-                       } else {
-                               jQuery( this ).hide();
-                       }
-               });
-       }
-});
-
-
-function Tween( elem, options, prop, end, easing ) {
-       return new Tween.prototype.init( elem, options, prop, end, easing );
-}
-jQuery.Tween = Tween;
-
-Tween.prototype = {
-       constructor: Tween,
-       init: function( elem, options, prop, end, easing, unit ) {
-               this.elem = elem;
-               this.prop = prop;
-               this.easing = easing || "swing";
-               this.options = options;
-               this.start = this.now = this.cur();
-               this.end = end;
-               this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
-       },
-       cur: function() {
-               var hooks = Tween.propHooks[ this.prop ];
-
-               return hooks && hooks.get ?
-                       hooks.get( this ) :
-                       Tween.propHooks._default.get( this );
-       },
-       run: function( percent ) {
-               var eased,
-                       hooks = Tween.propHooks[ this.prop ];
-
-               if ( this.options.duration ) {
-                       this.pos = eased = jQuery.easing[ this.easing ](
-                               percent, this.options.duration * percent, 0, 1, this.options.duration
-                       );
-               } else {
-                       this.pos = eased = percent;
-               }
-               this.now = ( this.end - this.start ) * eased + this.start;
-
-               if ( this.options.step ) {
-                       this.options.step.call( this.elem, this.now, this );
-               }
-
-               if ( hooks && hooks.set ) {
-                       hooks.set( this );
-               } else {
-                       Tween.propHooks._default.set( this );
-               }
-               return this;
-       }
-};
-
-Tween.prototype.init.prototype = Tween.prototype;
-
-Tween.propHooks = {
-       _default: {
-               get: function( tween ) {
-                       var result;
-
-                       if ( tween.elem[ tween.prop ] != null &&
-                               (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
-                               return tween.elem[ tween.prop ];
-                       }
-
-                       // passing an empty string as a 3rd parameter to .css will automatically
-                       // attempt a parseFloat and fallback to a string if the parse fails
-                       // so, simple values such as "10px" are parsed to Float.
-                       // complex values such as "rotate(1rad)" are returned as is.
-                       result = jQuery.css( tween.elem, tween.prop, "" );
-                       // Empty strings, null, undefined and "auto" are converted to 0.
-                       return !result || result === "auto" ? 0 : result;
-               },
-               set: function( tween ) {
-                       // use step hook for back compat - use cssHook if its there - use .style if its
-                       // available and use plain properties where available
-                       if ( jQuery.fx.step[ tween.prop ] ) {
-                               jQuery.fx.step[ tween.prop ]( tween );
-                       } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
-                               jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
-                       } else {
-                               tween.elem[ tween.prop ] = tween.now;
-                       }
-               }
-       }
-};
-
-// Support: IE9
-// Panic based approach to setting things on disconnected nodes
-
-Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
-       set: function( tween ) {
-               if ( tween.elem.nodeType && tween.elem.parentNode ) {
-                       tween.elem[ tween.prop ] = tween.now;
-               }
-       }
-};
-
-jQuery.easing = {
-       linear: function( p ) {
-               return p;
-       },
-       swing: function( p ) {
-               return 0.5 - Math.cos( p * Math.PI ) / 2;
-       }
-};
-
-jQuery.fx = Tween.prototype.init;
-
-// Back Compat <1.8 extension point
-jQuery.fx.step = {};
-
-
-
-
-var
-       fxNow, timerId,
-       rfxtypes = /^(?:toggle|show|hide)$/,
-       rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
-       rrun = /queueHooks$/,
-       animationPrefilters = [ defaultPrefilter ],
-       tweeners = {
-               "*": [ function( prop, value ) {
-                       var tween = this.createTween( prop, value ),
-                               target = tween.cur(),
-                               parts = rfxnum.exec( value ),
-                               unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
-
-                               // Starting value computation is required for potential unit mismatches
-                               start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
-                                       rfxnum.exec( jQuery.css( tween.elem, prop ) ),
-                               scale = 1,
-                               maxIterations = 20;
-
-                       if ( start && start[ 3 ] !== unit ) {
-                               // Trust units reported by jQuery.css
-                               unit = unit || start[ 3 ];
-
-                               // Make sure we update the tween properties later on
-                               parts = parts || [];
-
-                               // Iteratively approximate from a nonzero starting point
-                               start = +target || 1;
-
-                               do {
-                                       // If previous iteration zeroed out, double until we get *something*
-                                       // Use a string for doubling factor so we don't accidentally see scale as unchanged below
-                                       scale = scale || ".5";
-
-                                       // Adjust and apply
-                                       start = start / scale;
-                                       jQuery.style( tween.elem, prop, start + unit );
-
-                               // Update scale, tolerating zero or NaN from tween.cur()
-                               // And breaking the loop if scale is unchanged or perfect, or if we've just had enough
-                               } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
-                       }
-
-                       // Update tween properties
-                       if ( parts ) {
-                               start = tween.start = +start || +target || 0;
-                               tween.unit = unit;
-                               // If a +=/-= token was provided, we're doing a relative animation
-                               tween.end = parts[ 1 ] ?
-                                       start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
-                                       +parts[ 2 ];
-                       }
-
-                       return tween;
-               } ]
-       };
-
-// Animations created synchronously will run synchronously
-function createFxNow() {
-       setTimeout(function() {
-               fxNow = undefined;
-       });
-       return ( fxNow = jQuery.now() );
-}
-
-// Generate parameters to create a standard animation
-function genFx( type, includeWidth ) {
-       var which,
-               i = 0,
-               attrs = { height: type };
-
-       // if we include width, step value is 1 to do all cssExpand values,
-       // if we don't include width, step value is 2 to skip over Left and Right
-       includeWidth = includeWidth ? 1 : 0;
-       for ( ; i < 4 ; i += 2 - includeWidth ) {
-               which = cssExpand[ i ];
-               attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
-       }
-
-       if ( includeWidth ) {
-               attrs.opacity = attrs.width = type;
-       }
-
-       return attrs;
-}
-
-function createTween( value, prop, animation ) {
-       var tween,
-               collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
-               index = 0,
-               length = collection.length;
-       for ( ; index < length; index++ ) {
-               if ( (tween = collection[ index ].call( animation, prop, value )) ) {
-
-                       // we're done with this property
-                       return tween;
-               }
-       }
-}
-
-function defaultPrefilter( elem, props, opts ) {
-       /* jshint validthis: true */
-       var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
-               anim = this,
-               orig = {},
-               style = elem.style,
-               hidden = elem.nodeType && isHidden( elem ),
-               dataShow = data_priv.get( elem, "fxshow" );
-
-       // handle queue: false promises
-       if ( !opts.queue ) {
-               hooks = jQuery._queueHooks( elem, "fx" );
-               if ( hooks.unqueued == null ) {
-                       hooks.unqueued = 0;
-                       oldfire = hooks.empty.fire;
-                       hooks.empty.fire = function() {
-                               if ( !hooks.unqueued ) {
-                                       oldfire();
-                               }
-                       };
-               }
-               hooks.unqueued++;
-
-               anim.always(function() {
-                       // doing this makes sure that the complete handler will be called
-                       // before this completes
-                       anim.always(function() {
-                               hooks.unqueued--;
-                               if ( !jQuery.queue( elem, "fx" ).length ) {
-                                       hooks.empty.fire();
-                               }
-                       });
-               });
-       }
-
-       // height/width overflow pass
-       if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
-               // Make sure that nothing sneaks out
-               // Record all 3 overflow attributes because IE9-10 do not
-               // change the overflow attribute when overflowX and
-               // overflowY are set to the same value
-               opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
-
-               // Set display property to inline-block for height/width
-               // animations on inline elements that are having width/height animated
-               display = jQuery.css( elem, "display" );
-
-               // Test default display if display is currently "none"
-               checkDisplay = display === "none" ?
-                       data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
-
-               if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
-                       style.display = "inline-block";
-               }
-       }
-
-       if ( opts.overflow ) {
-               style.overflow = "hidden";
-               anim.always(function() {
-                       style.overflow = opts.overflow[ 0 ];
-                       style.overflowX = opts.overflow[ 1 ];
-                       style.overflowY = opts.overflow[ 2 ];
-               });
-       }
-
-       // show/hide pass
-       for ( prop in props ) {
-               value = props[ prop ];
-               if ( rfxtypes.exec( value ) ) {
-                       delete props[ prop ];
-                       toggle = toggle || value === "toggle";
-                       if ( value === ( hidden ? "hide" : "show" ) ) {
-
-                               // If there is dataShow left over from a stopped hide or show and we are going to proceed with show, we should pretend to be hidden
-                               if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
-                                       hidden = true;
-                               } else {
-                                       continue;
-                               }
-                       }
-                       orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
-
-               // Any non-fx value stops us from restoring the original display value
-               } else {
-                       display = undefined;
-               }
-       }
-
-       if ( !jQuery.isEmptyObject( orig ) ) {
-               if ( dataShow ) {
-                       if ( "hidden" in dataShow ) {
-                               hidden = dataShow.hidden;
-                       }
-               } else {
-                       dataShow = data_priv.access( elem, "fxshow", {} );
-               }
-
-               // store state if its toggle - enables .stop().toggle() to "reverse"
-               if ( toggle ) {
-                       dataShow.hidden = !hidden;
-               }
-               if ( hidden ) {
-                       jQuery( elem ).show();
-               } else {
-                       anim.done(function() {
-                               jQuery( elem ).hide();
-                       });
-               }
-               anim.done(function() {
-                       var prop;
-
-                       data_priv.remove( elem, "fxshow" );
-                       for ( prop in orig ) {
-                               jQuery.style( elem, prop, orig[ prop ] );
-                       }
-               });
-               for ( prop in orig ) {
-                       tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
-
-                       if ( !( prop in dataShow ) ) {
-                               dataShow[ prop ] = tween.start;
-                               if ( hidden ) {
-                                       tween.end = tween.start;
-                                       tween.start = prop === "width" || prop === "height" ? 1 : 0;
-                               }
-                       }
-               }
-
-       // If this is a noop like .hide().hide(), restore an overwritten display value
-       } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
-               style.display = display;
-       }
-}
-
-function propFilter( props, specialEasing ) {
-       var index, name, easing, value, hooks;
-
-       // camelCase, specialEasing and expand cssHook pass
-       for ( index in props ) {
-               name = jQuery.camelCase( index );
-               easing = specialEasing[ name ];
-               value = props[ index ];
-               if ( jQuery.isArray( value ) ) {
-                       easing = value[ 1 ];
-                       value = props[ index ] = value[ 0 ];
-               }
-
-               if ( index !== name ) {
-                       props[ name ] = value;
-                       delete props[ index ];
-               }
-
-               hooks = jQuery.cssHooks[ name ];
-               if ( hooks && "expand" in hooks ) {
-                       value = hooks.expand( value );
-                       delete props[ name ];
-
-                       // not quite $.extend, this wont overwrite keys already present.
-                       // also - reusing 'index' from above because we have the correct "name"
-                       for ( index in value ) {
-                               if ( !( index in props ) ) {
-                                       props[ index ] = value[ index ];
-                                       specialEasing[ index ] = easing;
-                               }
-                       }
-               } else {
-                       specialEasing[ name ] = easing;
-               }
-       }
-}
-
-function Animation( elem, properties, options ) {
-       var result,
-               stopped,
-               index = 0,
-               length = animationPrefilters.length,
-               deferred = jQuery.Deferred().always( function() {
-                       // don't match elem in the :animated selector
-                       delete tick.elem;
-               }),
-               tick = function() {
-                       if ( stopped ) {
-                               return false;
-                       }
-                       var currentTime = fxNow || createFxNow(),
-                               remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
-                               // archaic crash bug won't allow us to use 1 - ( 0.5 || 0 ) (#12497)
-                               temp = remaining / animation.duration || 0,
-                               percent = 1 - temp,
-                               index = 0,
-                               length = animation.tweens.length;
-
-                       for ( ; index < length ; index++ ) {
-                               animation.tweens[ index ].run( percent );
-                       }
-
-                       deferred.notifyWith( elem, [ animation, percent, remaining ]);
-
-                       if ( percent < 1 && length ) {
-                               return remaining;
-                       } else {
-                               deferred.resolveWith( elem, [ animation ] );
-                               return false;
-                       }
-               },
-               animation = deferred.promise({
-                       elem: elem,
-                       props: jQuery.extend( {}, properties ),
-                       opts: jQuery.extend( true, { specialEasing: {} }, options ),
-                       originalProperties: properties,
-                       originalOptions: options,
-                       startTime: fxNow || createFxNow(),
-                       duration: options.duration,
-                       tweens: [],
-                       createTween: function( prop, end ) {
-                               var tween = jQuery.Tween( elem, animation.opts, prop, end,
-                                               animation.opts.specialEasing[ prop ] || animation.opts.easing );
-                               animation.tweens.push( tween );
-                               return tween;
-                       },
-                       stop: function( gotoEnd ) {
-                               var index = 0,
-                                       // if we are going to the end, we want to run all the tweens
-                                       // otherwise we skip this part
-                                       length = gotoEnd ? animation.tweens.length : 0;
-                               if ( stopped ) {
-                                       return this;
-                               }
-                               stopped = true;
-                               for ( ; index < length ; index++ ) {
-                                       animation.tweens[ index ].run( 1 );
-                               }
-
-                               // resolve when we played the last frame
-                               // otherwise, reject
-                               if ( gotoEnd ) {
-                                       deferred.resolveWith( elem, [ animation, gotoEnd ] );
-                               } else {
-                                       deferred.rejectWith( elem, [ animation, gotoEnd ] );
-                               }
-                               return this;
-                       }
-               }),
-               props = animation.props;
-
-       propFilter( props, animation.opts.specialEasing );
-
-       for ( ; index < length ; index++ ) {
-               result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
-               if ( result ) {
-                       return result;
-               }
-       }
-
-       jQuery.map( props, createTween, animation );
-
-       if ( jQuery.isFunction( animation.opts.start ) ) {
-               animation.opts.start.call( elem, animation );
-       }
-
-       jQuery.fx.timer(
-               jQuery.extend( tick, {
-                       elem: elem,
-                       anim: animation,
-                       queue: animation.opts.queue
-               })
-       );
-
-       // attach callbacks from options
-       return animation.progress( animation.opts.progress )
-               .done( animation.opts.done, animation.opts.complete )
-               .fail( animation.opts.fail )
-               .always( animation.opts.always );
-}
-
-jQuery.Animation = jQuery.extend( Animation, {
-
-       tweener: function( props, callback ) {
-               if ( jQuery.isFunction( props ) ) {
-                       callback = props;
-                       props = [ "*" ];
-               } else {
-                       props = props.split(" ");
-               }
-
-               var prop,
-                       index = 0,
-                       length = props.length;
-
-               for ( ; index < length ; index++ ) {
-                       prop = props[ index ];
-                       tweeners[ prop ] = tweeners[ prop ] || [];
-                       tweeners[ prop ].unshift( callback );
-               }
-       },
-
-       prefilter: function( callback, prepend ) {
-               if ( prepend ) {
-                       animationPrefilters.unshift( callback );
-               } else {
-                       animationPrefilters.push( callback );
-               }
-       }
-});
-
-jQuery.speed = function( speed, easing, fn ) {
-       var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
-               complete: fn || !fn && easing ||
-                       jQuery.isFunction( speed ) && speed,
-               duration: speed,
-               easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
-       };
-
-       opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
-               opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
-
-       // normalize opt.queue - true/undefined/null -> "fx"
-       if ( opt.queue == null || opt.queue === true ) {
-               opt.queue = "fx";
-       }
-
-       // Queueing
-       opt.old = opt.complete;
-
-       opt.complete = function() {
-               if ( jQuery.isFunction( opt.old ) ) {
-                       opt.old.call( this );
-               }
-
-               if ( opt.queue ) {
-                       jQuery.dequeue( this, opt.queue );
-               }
-       };
-
-       return opt;
-};
-
-jQuery.fn.extend({
-       fadeTo: function( speed, to, easing, callback ) {
-
-               // show any hidden elements after setting opacity to 0
-               return this.filter( isHidden ).css( "opacity", 0 ).show()
-
-                       // animate to the value specified
-                       .end().animate({ opacity: to }, speed, easing, callback );
-       },
-       animate: function( prop, speed, easing, callback ) {
-               var empty = jQuery.isEmptyObject( prop ),
-                       optall = jQuery.speed( speed, easing, callback ),
-                       doAnimation = function() {
-                               // Operate on a copy of prop so per-property easing won't be lost
-                               var anim = Animation( this, jQuery.extend( {}, prop ), optall );
-
-                               // Empty animations, or finishing resolves immediately
-                               if ( empty || data_priv.get( this, "finish" ) ) {
-                                       anim.stop( true );
-                               }
-                       };
-                       doAnimation.finish = doAnimation;
-
-               return empty || optall.queue === false ?
-                       this.each( doAnimation ) :
-                       this.queue( optall.queue, doAnimation );
-       },
-       stop: function( type, clearQueue, gotoEnd ) {
-               var stopQueue = function( hooks ) {
-                       var stop = hooks.stop;
-                       delete hooks.stop;
-                       stop( gotoEnd );
-               };
-
-               if ( typeof type !== "string" ) {
-                       gotoEnd = clearQueue;
-                       clearQueue = type;
-                       type = undefined;
-               }
-               if ( clearQueue && type !== false ) {
-                       this.queue( type || "fx", [] );
-               }
-
-               return this.each(function() {
-                       var dequeue = true,
-                               index = type != null && type + "queueHooks",
-                               timers = jQuery.timers,
-                               data = data_priv.get( this );
-
-                       if ( index ) {
-                               if ( data[ index ] && data[ index ].stop ) {
-                                       stopQueue( data[ index ] );
-                               }
-                       } else {
-                               for ( index in data ) {
-                                       if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
-                                               stopQueue( data[ index ] );
-                                       }
-                               }
-                       }
-
-                       for ( index = timers.length; index--; ) {
-                               if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
-                                       timers[ index ].anim.stop( gotoEnd );
-                                       dequeue = false;
-                                       timers.splice( index, 1 );
-                               }
-                       }
-
-                       // start the next in the queue if the last step wasn't forced
-                       // timers currently will call their complete callbacks, which will dequeue
-                       // but only if they were gotoEnd
-                       if ( dequeue || !gotoEnd ) {
-                               jQuery.dequeue( this, type );
-                       }
-               });
-       },
-       finish: function( type ) {
-               if ( type !== false ) {
-                       type = type || "fx";
-               }
-               return this.each(function() {
-                       var index,
-                               data = data_priv.get( this ),
-                               queue = data[ type + "queue" ],
-                               hooks = data[ type + "queueHooks" ],
-                               timers = jQuery.timers,
-                               length = queue ? queue.length : 0;
-
-                       // enable finishing flag on private data
-                       data.finish = true;
-
-                       // empty the queue first
-                       jQuery.queue( this, type, [] );
-
-                       if ( hooks && hooks.stop ) {
-                               hooks.stop.call( this, true );
-                       }
-
-                       // look for any active animations, and finish them
-                       for ( index = timers.length; index--; ) {
-                               if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
-                                       timers[ index ].anim.stop( true );
-                                       timers.splice( index, 1 );
-                               }
-                       }
-
-                       // look for any animations in the old queue and finish them
-                       for ( index = 0; index < length; index++ ) {
-                               if ( queue[ index ] && queue[ index ].finish ) {
-                                       queue[ index ].finish.call( this );
-                               }
-                       }
-
-                       // turn off finishing flag
-                       delete data.finish;
-               });
-       }
-});
-
-jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
-       var cssFn = jQuery.fn[ name ];
-       jQuery.fn[ name ] = function( speed, easing, callback ) {
-               return speed == null || typeof speed === "boolean" ?
-                       cssFn.apply( this, arguments ) :
-                       this.animate( genFx( name, true ), speed, easing, callback );
-       };
-});
-
-// Generate shortcuts for custom animations
-jQuery.each({
-       slideDown: genFx("show"),
-       slideUp: genFx("hide"),
-       slideToggle: genFx("toggle"),
-       fadeIn: { opacity: "show" },
-       fadeOut: { opacity: "hide" },
-       fadeToggle: { opacity: "toggle" }
-}, function( name, props ) {
-       jQuery.fn[ name ] = function( speed, easing, callback ) {
-               return this.animate( props, speed, easing, callback );
-       };
-});
-
-jQuery.timers = [];
-jQuery.fx.tick = function() {
-       var timer,
-               i = 0,
-               timers = jQuery.timers;
-
-       fxNow = jQuery.now();
-
-       for ( ; i < timers.length; i++ ) {
-               timer = timers[ i ];
-               // Checks the timer has not already been removed
-               if ( !timer() && timers[ i ] === timer ) {
-                       timers.splice( i--, 1 );
-               }
-       }
-
-       if ( !timers.length ) {
-               jQuery.fx.stop();
-       }
-       fxNow = undefined;
-};
-
-jQuery.fx.timer = function( timer ) {
-       jQuery.timers.push( timer );
-       if ( timer() ) {
-               jQuery.fx.start();
-       } else {
-               jQuery.timers.pop();
-       }
-};
-
-jQuery.fx.interval = 13;
-
-jQuery.fx.start = function() {
-       if ( !timerId ) {
-               timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
-       }
-};
-
-jQuery.fx.stop = function() {
-       clearInterval( timerId );
-       timerId = null;
-};
-
-jQuery.fx.speeds = {
-       slow: 600,
-       fast: 200,
-       // Default speed
-       _default: 400
-};
-
-
-// Based off of the plugin by Clint Helfers, with permission.
-// http://blindsignals.com/index.php/2009/07/jquery-delay/
-jQuery.fn.delay = function( time, type ) {
-       time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
-       type = type || "fx";
-
-       return this.queue( type, function( next, hooks ) {
-               var timeout = setTimeout( next, time );
-               hooks.stop = function() {
-                       clearTimeout( timeout );
-               };
-       });
-};
-
-
-(function() {
-       var input = document.createElement( "input" ),
-               select = document.createElement( "select" ),
-               opt = select.appendChild( document.createElement( "option" ) );
-
-       input.type = "checkbox";
-
-       // Support: iOS 5.1, Android 4.x, Android 2.3
-       // Check the default checkbox/radio value ("" on old WebKit; "on" elsewhere)
-       support.checkOn = input.value !== "";
-
-       // Must access the parent to make an option select properly
-       // Support: IE9, IE10
-       support.optSelected = opt.selected;
-
-       // Make sure that the options inside disabled selects aren't marked as disabled
-       // (WebKit marks them as disabled)
-       select.disabled = true;
-       support.optDisabled = !opt.disabled;
-
-       // Check if an input maintains its value after becoming a radio
-       // Support: IE9, IE10
-       input = document.createElement( "input" );
-       input.value = "t";
-       input.type = "radio";
-       support.radioValue = input.value === "t";
-})();
-
-
-var nodeHook, boolHook,
-       attrHandle = jQuery.expr.attrHandle;
-
-jQuery.fn.extend({
-       attr: function( name, value ) {
-               return access( this, jQuery.attr, name, value, arguments.length > 1 );
-       },
-
-       removeAttr: function( name ) {
-               return this.each(function() {
-                       jQuery.removeAttr( this, name );
-               });
-       }
-});
-
-jQuery.extend({
-       attr: function( elem, name, value ) {
-               var hooks, ret,
-                       nType = elem.nodeType;
-
-               // don't get/set attributes on text, comment and attribute nodes
-               if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
-                       return;
-               }
-
-               // Fallback to prop when attributes are not supported
-               if ( typeof elem.getAttribute === strundefined ) {
-                       return jQuery.prop( elem, name, value );
-               }
-
-               // All attributes are lowercase
-               // Grab necessary hook if one is defined
-               if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
-                       name = name.toLowerCase();
-                       hooks = jQuery.attrHooks[ name ] ||
-                               ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
-               }
-
-               if ( value !== undefined ) {
-
-                       if ( value === null ) {
-                               jQuery.removeAttr( elem, name );
-
-                       } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
-                               return ret;
-
-                       } else {
-                               elem.setAttribute( name, value + "" );
-                               return value;
-                       }
-
-               } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
-                       return ret;
-
-               } else {
-                       ret = jQuery.find.attr( elem, name );
-
-                       // Non-existent attributes return null, we normalize to undefined
-                       return ret == null ?
-                               undefined :
-                               ret;
-               }
-       },
-
-       removeAttr: function( elem, value ) {
-               var name, propName,
-                       i = 0,
-                       attrNames = value && value.match( rnotwhite );
-
-               if ( attrNames && elem.nodeType === 1 ) {
-                       while ( (name = attrNames[i++]) ) {
-                               propName = jQuery.propFix[ name ] || name;
-
-                               // Boolean attributes get special treatment (#10870)
-                               if ( jQuery.expr.match.bool.test( name ) ) {
-                                       // Set corresponding property to false
-                                       elem[ propName ] = false;
-                               }
-
-                               elem.removeAttribute( name );
-                       }
-               }
-       },
-
-       attrHooks: {
-               type: {
-                       set: function( elem, value ) {
-                               if ( !support.radioValue && value === "radio" &&
-                                       jQuery.nodeName( elem, "input" ) ) {
-                                       // Setting the type on a radio button after the value resets the value in IE6-9
-                                       // Reset value to default in case type is set after value during creation
-                                       var val = elem.value;
-                                       elem.setAttribute( "type", value );
-                                       if ( val ) {
-                                               elem.value = val;
-                                       }
-                                       return value;
-                               }
-                       }
-               }
-       }
-});
-
-// Hooks for boolean attributes
-boolHook = {
-       set: function( elem, value, name ) {
-               if ( value === false ) {
-                       // Remove boolean attributes when set to false
-                       jQuery.removeAttr( elem, name );
-               } else {
-                       elem.setAttribute( name, name );
-               }
-               return name;
-       }
-};
-jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
-       var getter = attrHandle[ name ] || jQuery.find.attr;
-
-       attrHandle[ name ] = function( elem, name, isXML ) {
-               var ret, handle;
-               if ( !isXML ) {
-                       // Avoid an infinite loop by temporarily removing this function from the getter
-                       handle = attrHandle[ name ];
-                       attrHandle[ name ] = ret;
-                       ret = getter( elem, name, isXML ) != null ?
-                               name.toLowerCase() :
-                               null;
-                       attrHandle[ name ] = handle;
-               }
-               return ret;
-       };
-});
-
-
-
-
-var rfocusable = /^(?:input|select|textarea|button)$/i;
-
-jQuery.fn.extend({
-       prop: function( name, value ) {
-               return access( this, jQuery.prop, name, value, arguments.length > 1 );
-       },
-
-       removeProp: function( name ) {
-               return this.each(function() {
-                       delete this[ jQuery.propFix[ name ] || name ];
-               });
-       }
-});
-
-jQuery.extend({
-       propFix: {
-               "for": "htmlFor",
-               "class": "className"
-       },
-
-       prop: function( elem, name, value ) {
-               var ret, hooks, notxml,
-                       nType = elem.nodeType;
-
-               // don't get/set properties on text, comment and attribute nodes
-               if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
-                       return;
-               }
-
-               notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
-
-               if ( notxml ) {
-                       // Fix name and attach hooks
-                       name = jQuery.propFix[ name ] || name;
-                       hooks = jQuery.propHooks[ name ];
-               }
-
-               if ( value !== undefined ) {
-                       return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
-                               ret :
-                               ( elem[ name ] = value );
-
-               } else {
-                       return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
-                               ret :
-                               elem[ name ];
-               }
-       },
-
-       propHooks: {
-               tabIndex: {
-                       get: function( elem ) {
-                               return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
-                                       elem.tabIndex :
-                                       -1;
-                       }
-               }
-       }
-});
-
-// Support: IE9+
-// Selectedness for an option in an optgroup can be inaccurate
-if ( !support.optSelected ) {
-       jQuery.propHooks.selected = {
-               get: function( elem ) {
-                       var parent = elem.parentNode;
-                       if ( parent && parent.parentNode ) {
-                               parent.parentNode.selectedIndex;
-                       }
-                       return null;
-               }
-       };
-}
-
-jQuery.each([
-       "tabIndex",
-       "readOnly",
-       "maxLength",
-       "cellSpacing",
-       "cellPadding",
-       "rowSpan",
-       "colSpan",
-       "useMap",
-       "frameBorder",
-       "contentEditable"
-], function() {
-       jQuery.propFix[ this.toLowerCase() ] = this;
-});
-
-
-
-
-var rclass = /[\t\r\n\f]/g;
-
-jQuery.fn.extend({
-       addClass: function( value ) {
-               var classes, elem, cur, clazz, j, finalValue,
-                       proceed = typeof value === "string" && value,
-                       i = 0,
-                       len = this.length;
-
-               if ( jQuery.isFunction( value ) ) {
-                       return this.each(function( j ) {
-                               jQuery( this ).addClass( value.call( this, j, this.className ) );
-                       });
-               }
-
-               if ( proceed ) {
-                       // The disjunction here is for better compressibility (see removeClass)
-                       classes = ( value || "" ).match( rnotwhite ) || [];
-
-                       for ( ; i < len; i++ ) {
-                               elem = this[ i ];
-                               cur = elem.nodeType === 1 && ( elem.className ?
-                                       ( " " + elem.className + " " ).replace( rclass, " " ) :
-                                       " "
-                               );
-
-                               if ( cur ) {
-                                       j = 0;
-                                       while ( (clazz = classes[j++]) ) {
-                                               if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
-                                                       cur += clazz + " ";
-                                               }
-                                       }
-
-                                       // only assign if different to avoid unneeded rendering.
-                                       finalValue = jQuery.trim( cur );
-                                       if ( elem.className !== finalValue ) {
-                                               elem.className = finalValue;
-                                       }
-                               }
-                       }
-               }
-
-               return this;
-       },
-
-       removeClass: function( value ) {
-               var classes, elem, cur, clazz, j, finalValue,
-                       proceed = arguments.length === 0 || typeof value === "string" && value,
-                       i = 0,
-                       len = this.length;
-
-               if ( jQuery.isFunction( value ) ) {
-                       return this.each(function( j ) {
-                               jQuery( this ).removeClass( value.call( this, j, this.className ) );
-                       });
-               }
-               if ( proceed ) {
-                       classes = ( value || "" ).match( rnotwhite ) || [];
-
-                       for ( ; i < len; i++ ) {
-                               elem = this[ i ];
-                               // This expression is here for better compressibility (see addClass)
-                               cur = elem.nodeType === 1 && ( elem.className ?
-                                       ( " " + elem.className + " " ).replace( rclass, " " ) :
-                                       ""
-                               );
-
-                               if ( cur ) {
-                                       j = 0;
-                                       while ( (clazz = classes[j++]) ) {
-                                               // Remove *all* instances
-                                               while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
-                                                       cur = cur.replace( " " + clazz + " ", " " );
-                                               }
-                                       }
-
-                                       // only assign if different to avoid unneeded rendering.
-                                       finalValue = value ? jQuery.trim( cur ) : "";
-                                       if ( elem.className !== finalValue ) {
-                                               elem.className = finalValue;
-                                       }
-                               }
-                       }
-               }
-
-               return this;
-       },
-
-       toggleClass: function( value, stateVal ) {
-               var type = typeof value;
-
-               if ( typeof stateVal === "boolean" && type === "string" ) {
-                       return stateVal ? this.addClass( value ) : this.removeClass( value );
-               }
-
-               if ( jQuery.isFunction( value ) ) {
-                       return this.each(function( i ) {
-                               jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
-                       });
-               }
-
-               return this.each(function() {
-                       if ( type === "string" ) {
-                               // toggle individual class names
-                               var className,
-                                       i = 0,
-                                       self = jQuery( this ),
-                                       classNames = value.match( rnotwhite ) || [];
-
-                               while ( (className = classNames[ i++ ]) ) {
-                                       // check each className given, space separated list
-                                       if ( self.hasClass( className ) ) {
-                                               self.removeClass( className );
-                                       } else {
-                                               self.addClass( className );
-                                       }
-                               }
-
-                       // Toggle whole class name
-                       } else if ( type === strundefined || type === "boolean" ) {
-                               if ( this.className ) {
-                                       // store className if set
-                                       data_priv.set( this, "__className__", this.className );
-                               }
-
-                               // If the element has a class name or if we're passed "false",
-                               // then remove the whole classname (if there was one, the above saved it).
-                               // Otherwise bring back whatever was previously saved (if anything),
-                               // falling back to the empty string if nothing was stored.
-                               this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
-                       }
-               });
-       },
-
-       hasClass: function( selector ) {
-               var className = " " + selector + " ",
-                       i = 0,
-                       l = this.length;
-               for ( ; i < l; i++ ) {
-                       if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
-                               return true;
-                       }
-               }
-
-               return false;
-       }
-});
-
-
-
-
-var rreturn = /\r/g;
-
-jQuery.fn.extend({
-       val: function( value ) {
-               var hooks, ret, isFunction,
-                       elem = this[0];
-
-               if ( !arguments.length ) {
-                       if ( elem ) {
-                               hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
-
-                               if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
-                                       return ret;
-                               }
-
-                               ret = elem.value;
-
-                               return typeof ret === "string" ?
-                                       // handle most common string cases
-                                       ret.replace(rreturn, "") :
-                                       // handle cases where value is null/undef or number
-                                       ret == null ? "" : ret;
-                       }
-
-                       return;
-               }
-
-               isFunction = jQuery.isFunction( value );
-
-               return this.each(function( i ) {
-                       var val;
-
-                       if ( this.nodeType !== 1 ) {
-                               return;
-                       }
-
-                       if ( isFunction ) {
-                               val = value.call( this, i, jQuery( this ).val() );
-                       } else {
-                               val = value;
-                       }
-
-                       // Treat null/undefined as ""; convert numbers to string
-                       if ( val == null ) {
-                               val = "";
-
-                       } else if ( typeof val === "number" ) {
-                               val += "";
-
-                       } else if ( jQuery.isArray( val ) ) {
-                               val = jQuery.map( val, function( value ) {
-                                       return value == null ? "" : value + "";
-                               });
-                       }
-
-                       hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
-
-                       // If set returns undefined, fall back to normal setting
-                       if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
-                               this.value = val;
-                       }
-               });
-       }
-});
-
-jQuery.extend({
-       valHooks: {
-               option: {
-                       get: function( elem ) {
-                               var val = jQuery.find.attr( elem, "value" );
-                               return val != null ?
-                                       val :
-                                       // Support: IE10-11+
-                                       // option.text throws exceptions (#14686, #14858)
-                                       jQuery.trim( jQuery.text( elem ) );
-                       }
-               },
-               select: {
-                       get: function( elem ) {
-                               var value, option,
-                                       options = elem.options,
-                                       index = elem.selectedIndex,
-                                       one = elem.type === "select-one" || index < 0,
-                                       values = one ? null : [],
-                                       max = one ? index + 1 : options.length,
-                                       i = index < 0 ?
-                                               max :
-                                               one ? index : 0;
-
-                               // Loop through all the selected options
-                               for ( ; i < max; i++ ) {
-                                       option = options[ i ];
-
-                                       // IE6-9 doesn't update selected after form reset (#2551)
-                                       if ( ( option.selected || i === index ) &&
-                                                       // Don't return options that are disabled or in a disabled optgroup
-                                                       ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
-                                                       ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
-
-                                               // Get the specific value for the option
-                                               value = jQuery( option ).val();
-
-                                               // We don't need an array for one selects
-                                               if ( one ) {
-                                                       return value;
-                                               }
-
-                                               // Multi-Selects return an array
-                                               values.push( value );
-                                       }
-                               }
-
-                               return values;
-                       },
-
-                       set: function( elem, value ) {
-                               var optionSet, option,
-                                       options = elem.options,
-                                       values = jQuery.makeArray( value ),
-                                       i = options.length;
-
-                               while ( i-- ) {
-                                       option = options[ i ];
-                                       if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
-                                               optionSet = true;
-                                       }
-                               }
-
-                               // force browsers to behave consistently when non-matching value is set
-                               if ( !optionSet ) {
-                                       elem.selectedIndex = -1;
-                               }
-                               return values;
-                       }
-               }
-       }
-});
-
-// Radios and checkboxes getter/setter
-jQuery.each([ "radio", "checkbox" ], function() {
-       jQuery.valHooks[ this ] = {
-               set: function( elem, value ) {
-                       if ( jQuery.isArray( value ) ) {
-                               return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
-                       }
-               }
-       };
-       if ( !support.checkOn ) {
-               jQuery.valHooks[ this ].get = function( elem ) {
-                       // Support: Webkit
-                       // "" is returned instead of "on" if a value isn't specified
-                       return elem.getAttribute("value") === null ? "on" : elem.value;
-               };
-       }
-});
-
-
-
-
-// Return jQuery for attributes-only inclusion
-
-
-jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
-       "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
-       "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
-
-       // Handle event binding
-       jQuery.fn[ name ] = function( data, fn ) {
-               return arguments.length > 0 ?
-                       this.on( name, null, data, fn ) :
-                       this.trigger( name );
-       };
-});
-
-jQuery.fn.extend({
-       hover: function( fnOver, fnOut ) {
-               return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
-       },
-
-       bind: function( types, data, fn ) {
-               return this.on( types, null, data, fn );
-       },
-       unbind: function( types, fn ) {
-               return this.off( types, null, fn );
-       },
-
-       delegate: function( selector, types, data, fn ) {
-               return this.on( types, selector, data, fn );
-       },
-       undelegate: function( selector, types, fn ) {
-               // ( namespace ) or ( selector, types [, fn] )
-               return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
-       }
-});
-
-
-var nonce = jQuery.now();
-
-var rquery = (/\?/);
-
-
-
-// Support: Android 2.3
-// Workaround failure to string-cast null input
-jQuery.parseJSON = function( data ) {
-       return JSON.parse( data + "" );
-};
-
-
-// Cross-browser xml parsing
-jQuery.parseXML = function( data ) {
-       var xml, tmp;
-       if ( !data || typeof data !== "string" ) {
-               return null;
-       }
-
-       // Support: IE9
-       try {
-               tmp = new DOMParser();
-               xml = tmp.parseFromString( data, "text/xml" );
-       } catch ( e ) {
-               xml = undefined;
-       }
-
-       if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
-               jQuery.error( "Invalid XML: " + data );
-       }
-       return xml;
-};
-
-
-var
-       // Document location
-       ajaxLocParts,
-       ajaxLocation,
-
-       rhash = /#.*$/,
-       rts = /([?&])_=[^&]*/,
-       rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
-       // #7653, #8125, #8152: local protocol detection
-       rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
-       rnoContent = /^(?:GET|HEAD)$/,
-       rprotocol = /^\/\//,
-       rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
-
-       /* Prefilters
-        * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
-        * 2) These are called:
-        *    - BEFORE asking for a transport
-        *    - AFTER param serialization (s.data is a string if s.processData is true)
-        * 3) key is the dataType
-        * 4) the catchall symbol "*" can be used
-        * 5) execution will start with transport dataType and THEN continue down to "*" if needed
-        */
-       prefilters = {},
-
-       /* Transports bindings
-        * 1) key is the dataType
-        * 2) the catchall symbol "*" can be used
-        * 3) selection will start with transport dataType and THEN go to "*" if needed
-        */
-       transports = {},
-
-       // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
-       allTypes = "*/".concat("*");
-
-// #8138, IE may throw an exception when accessing
-// a field from window.location if document.domain has been set
-try {
-       ajaxLocation = location.href;
-} catch( e ) {
-       // Use the href attribute of an A element
-       // since IE will modify it given document.location
-       ajaxLocation = document.createElement( "a" );
-       ajaxLocation.href = "";
-       ajaxLocation = ajaxLocation.href;
-}
-
-// Segment location into parts
-ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
-
-// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
-function addToPrefiltersOrTransports( structure ) {
-
-       // dataTypeExpression is optional and defaults to "*"
-       return function( dataTypeExpression, func ) {
-
-               if ( typeof dataTypeExpression !== "string" ) {
-                       func = dataTypeExpression;
-                       dataTypeExpression = "*";
-               }
-
-               var dataType,
-                       i = 0,
-                       dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
-
-               if ( jQuery.isFunction( func ) ) {
-                       // For each dataType in the dataTypeExpression
-                       while ( (dataType = dataTypes[i++]) ) {
-                               // Prepend if requested
-                               if ( dataType[0] === "+" ) {
-                                       dataType = dataType.slice( 1 ) || "*";
-                                       (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
-
-                               // Otherwise append
-                               } else {
-                                       (structure[ dataType ] = structure[ dataType ] || []).push( func );
-                               }
-                       }
-               }
-       };
-}
-
-// Base inspection function for prefilters and transports
-function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
-
-       var inspected = {},
-               seekingTransport = ( structure === transports );
-
-       function inspect( dataType ) {
-               var selected;
-               inspected[ dataType ] = true;
-               jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
-                       var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
-                       if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
-                               options.dataTypes.unshift( dataTypeOrTransport );
-                               inspect( dataTypeOrTransport );
-                               return false;
-                       } else if ( seekingTransport ) {
-                               return !( selected = dataTypeOrTransport );
-                       }
-               });
-               return selected;
-       }
-
-       return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
-}
-
-// A special extend for ajax options
-// that takes "flat" options (not to be deep extended)
-// Fixes #9887
-function ajaxExtend( target, src ) {
-       var key, deep,
-               flatOptions = jQuery.ajaxSettings.flatOptions || {};
-
-       for ( key in src ) {
-               if ( src[ key ] !== undefined ) {
-                       ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
-               }
-       }
-       if ( deep ) {
-               jQuery.extend( true, target, deep );
-       }
-
-       return target;
-}
-
-/* Handles responses to an ajax request:
- * - finds the right dataType (mediates between content-type and expected dataType)
- * - returns the corresponding response
- */
-function ajaxHandleResponses( s, jqXHR, responses ) {
-
-       var ct, type, finalDataType, firstDataType,
-               contents = s.contents,
-               dataTypes = s.dataTypes;
-
-       // Remove auto dataType and get content-type in the process
-       while ( dataTypes[ 0 ] === "*" ) {
-               dataTypes.shift();
-               if ( ct === undefined ) {
-                       ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
-               }
-       }
-
-       // Check if we're dealing with a known content-type
-       if ( ct ) {
-               for ( type in contents ) {
-                       if ( contents[ type ] && contents[ type ].test( ct ) ) {
-                               dataTypes.unshift( type );
-                               break;
-                       }
-               }
-       }
-
-       // Check to see if we have a response for the expected dataType
-       if ( dataTypes[ 0 ] in responses ) {
-               finalDataType = dataTypes[ 0 ];
-       } else {
-               // Try convertible dataTypes
-               for ( type in responses ) {
-                       if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
-                               finalDataType = type;
-                               break;
-                       }
-                       if ( !firstDataType ) {
-                               firstDataType = type;
-                       }
-               }
-               // Or just use first one
-               finalDataType = finalDataType || firstDataType;
-       }
-
-       // If we found a dataType
-       // We add the dataType to the list if needed
-       // and return the corresponding response
-       if ( finalDataType ) {
-               if ( finalDataType !== dataTypes[ 0 ] ) {
-                       dataTypes.unshift( finalDataType );
-               }
-               return responses[ finalDataType ];
-       }
-}
-
-/* Chain conversions given the request and the original response
- * Also sets the responseXXX fields on the jqXHR instance
- */
-function ajaxConvert( s, response, jqXHR, isSuccess ) {
-       var conv2, current, conv, tmp, prev,
-               converters = {},
-               // Work with a copy of dataTypes in case we need to modify it for conversion
-               dataTypes = s.dataTypes.slice();
-
-       // Create converters map with lowercased keys
-       if ( dataTypes[ 1 ] ) {
-               for ( conv in s.converters ) {
-                       converters[ conv.toLowerCase() ] = s.converters[ conv ];
-               }
-       }
-
-       current = dataTypes.shift();
-
-       // Convert to each sequential dataType
-       while ( current ) {
-
-               if ( s.responseFields[ current ] ) {
-                       jqXHR[ s.responseFields[ current ] ] = response;
-               }
-
-               // Apply the dataFilter if provided
-               if ( !prev && isSuccess && s.dataFilter ) {
-                       response = s.dataFilter( response, s.dataType );
-               }
-
-               prev = current;
-               current = dataTypes.shift();
-
-               if ( current ) {
-
-               // There's only work to do if current dataType is non-auto
-                       if ( current === "*" ) {
-
-                               current = prev;
-
-                       // Convert response if prev dataType is non-auto and differs from current
-                       } else if ( prev !== "*" && prev !== current ) {
-
-                               // Seek a direct converter
-                               conv = converters[ prev + " " + current ] || converters[ "* " + current ];
-
-                               // If none found, seek a pair
-                               if ( !conv ) {
-                                       for ( conv2 in converters ) {
-
-                                               // If conv2 outputs current
-                                               tmp = conv2.split( " " );
-                                               if ( tmp[ 1 ] === current ) {
-
-                                                       // If prev can be converted to accepted input
-                                                       conv = converters[ prev + " " + tmp[ 0 ] ] ||
-                                                               converters[ "* " + tmp[ 0 ] ];
-                                                       if ( conv ) {
-                                                               // Condense equivalence converters
-                                                               if ( conv === true ) {
-                                                                       conv = converters[ conv2 ];
-
-                                                               // Otherwise, insert the intermediate dataType
-                                                               } else if ( converters[ conv2 ] !== true ) {
-                                                                       current = tmp[ 0 ];
-                                                                       dataTypes.unshift( tmp[ 1 ] );
-                                                               }
-                                                               break;
-                                                       }
-                                               }
-                                       }
-                               }
-
-                               // Apply converter (if not an equivalence)
-                               if ( conv !== true ) {
-
-                                       // Unless errors are allowed to bubble, catch and return them
-                                       if ( conv && s[ "throws" ] ) {
-                                               response = conv( response );
-                                       } else {
-                                               try {
-                                                       response = conv( response );
-                                               } catch ( e ) {
-                                                       return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
-                                               }
-                                       }
-                               }
-                       }
-               }
-       }
-
-       return { state: "success", data: response };
-}
-
-jQuery.extend({
-
-       // Counter for holding the number of active queries
-       active: 0,
-
-       // Last-Modified header cache for next request
-       lastModified: {},
-       etag: {},
-
-       ajaxSettings: {
-               url: ajaxLocation,
-               type: "GET",
-               isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
-               global: true,
-               processData: true,
-               async: true,
-               contentType: "application/x-www-form-urlencoded; charset=UTF-8",
-               /*
-               timeout: 0,
-               data: null,
-               dataType: null,
-               username: null,
-               password: null,
-               cache: null,
-               throws: false,
-               traditional: false,
-               headers: {},
-               */
-
-               accepts: {
-                       "*": allTypes,
-                       text: "text/plain",
-                       html: "text/html",
-                       xml: "application/xml, text/xml",
-                       json: "application/json, text/javascript"
-               },
-
-               contents: {
-                       xml: /xml/,
-                       html: /html/,
-                       json: /json/
-               },
-
-               responseFields: {
-                       xml: "responseXML",
-                       text: "responseText",
-                       json: "responseJSON"
-               },
-
-               // Data converters
-               // Keys separate source (or catchall "*") and destination types with a single space
-               converters: {
-
-                       // Convert anything to text
-                       "* text": String,
-
-                       // Text to html (true = no transformation)
-                       "text html": true,
-
-                       // Evaluate text as a json expression
-                       "text json": jQuery.parseJSON,
-
-                       // Parse text as xml
-                       "text xml": jQuery.parseXML
-               },
-
-               // For options that shouldn't be deep extended:
-               // you can add your own custom options here if
-               // and when you create one that shouldn't be
-               // deep extended (see ajaxExtend)
-               flatOptions: {
-                       url: true,
-                       context: true
-               }
-       },
-
-       // Creates a full fledged settings object into target
-       // with both ajaxSettings and settings fields.
-       // If target is omitted, writes into ajaxSettings.
-       ajaxSetup: function( target, settings ) {
-               return settings ?
-
-                       // Building a settings object
-                       ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
-
-                       // Extending ajaxSettings
-                       ajaxExtend( jQuery.ajaxSettings, target );
-       },
-
-       ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
-       ajaxTransport: addToPrefiltersOrTransports( transports ),
-
-       // Main method
-       ajax: function( url, options ) {
-
-               // If url is an object, simulate pre-1.5 signature
-               if ( typeof url === "object" ) {
-                       options = url;
-                       url = undefined;
-               }
-
-               // Force options to be an object
-               options = options || {};
-
-               var transport,
-                       // URL without anti-cache param
-                       cacheURL,
-                       // Response headers
-                       responseHeadersString,
-                       responseHeaders,
-                       // timeout handle
-                       timeoutTimer,
-                       // Cross-domain detection vars
-                       parts,
-                       // To know if global events are to be dispatched
-                       fireGlobals,
-                       // Loop variable
-                       i,
-                       // Create the final options object
-                       s = jQuery.ajaxSetup( {}, options ),
-                       // Callbacks context
-                       callbackContext = s.context || s,
-                       // Context for global events is callbackContext if it is a DOM node or jQuery collection
-                       globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
-                               jQuery( callbackContext ) :
-                               jQuery.event,
-                       // Deferreds
-                       deferred = jQuery.Deferred(),
-                       completeDeferred = jQuery.Callbacks("once memory"),
-                       // Status-dependent callbacks
-                       statusCode = s.statusCode || {},
-                       // Headers (they are sent all at once)
-                       requestHeaders = {},
-                       requestHeadersNames = {},
-                       // The jqXHR state
-                       state = 0,
-                       // Default abort message
-                       strAbort = "canceled",
-                       // Fake xhr
-                       jqXHR = {
-                               readyState: 0,
-
-                               // Builds headers hashtable if needed
-                               getResponseHeader: function( key ) {
-                                       var match;
-                                       if ( state === 2 ) {
-                                               if ( !responseHeaders ) {
-                                                       responseHeaders = {};
-                                                       while ( (match = rheaders.exec( responseHeadersString )) ) {
-                                                               responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
-                                                       }
-                                               }
-                                               match = responseHeaders[ key.toLowerCase() ];
-                                       }
-                                       return match == null ? null : match;
-                               },
-
-                               // Raw string
-                               getAllResponseHeaders: function() {
-                                       return state === 2 ? responseHeadersString : null;
-                               },
-
-                               // Caches the header
-                               setRequestHeader: function( name, value ) {
-                                       var lname = name.toLowerCase();
-                                       if ( !state ) {
-                                               name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
-                                               requestHeaders[ name ] = value;
-                                       }
-                                       return this;
-                               },
-
-                               // Overrides response content-type header
-                               overrideMimeType: function( type ) {
-                                       if ( !state ) {
-                                               s.mimeType = type;
-                                       }
-                                       return this;
-                               },
-
-                               // Status-dependent callbacks
-                               statusCode: function( map ) {
-                                       var code;
-                                       if ( map ) {
-                                               if ( state < 2 ) {
-                                                       for ( code in map ) {
-                                                               // Lazy-add the new callback in a way that preserves old ones
-                                                               statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
-                                                       }
-                                               } else {
-                                                       // Execute the appropriate callbacks
-                                                       jqXHR.always( map[ jqXHR.status ] );
-                                               }
-                                       }
-                                       return this;
-                               },
-
-                               // Cancel the request
-                               abort: function( statusText ) {
-                                       var finalText = statusText || strAbort;
-                                       if ( transport ) {
-                                               transport.abort( finalText );
-                                       }
-                                       done( 0, finalText );
-                                       return this;
-                               }
-                       };
-
-               // Attach deferreds
-               deferred.promise( jqXHR ).complete = completeDeferred.add;
-               jqXHR.success = jqXHR.done;
-               jqXHR.error = jqXHR.fail;
-
-               // Remove hash character (#7531: and string promotion)
-               // Add protocol if not provided (prefilters might expect it)
-               // Handle falsy url in the settings object (#10093: consistency with old signature)
-               // We also use the url parameter if available
-               s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
-                       .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
-
-               // Alias method option to type as per ticket #12004
-               s.type = options.method || options.type || s.method || s.type;
-
-               // Extract dataTypes list
-               s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
-
-               // A cross-domain request is in order when we have a protocol:host:port mismatch
-               if ( s.crossDomain == null ) {
-                       parts = rurl.exec( s.url.toLowerCase() );
-                       s.crossDomain = !!( parts &&
-                               ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
-                                       ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
-                                               ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
-                       );
-               }
-
-               // Convert data if not already a string
-               if ( s.data && s.processData && typeof s.data !== "string" ) {
-                       s.data = jQuery.param( s.data, s.traditional );
-               }
-
-               // Apply prefilters
-               inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
-
-               // If request was aborted inside a prefilter, stop there
-               if ( state === 2 ) {
-                       return jqXHR;
-               }
-
-               // We can fire global events as of now if asked to
-               fireGlobals = s.global;
-
-               // Watch for a new set of requests
-               if ( fireGlobals && jQuery.active++ === 0 ) {
-                       jQuery.event.trigger("ajaxStart");
-               }
-
-               // Uppercase the type
-               s.type = s.type.toUpperCase();
-
-               // Determine if request has content
-               s.hasContent = !rnoContent.test( s.type );
-
-               // Save the URL in case we're toying with the If-Modified-Since
-               // and/or If-None-Match header later on
-               cacheURL = s.url;
-
-               // More options handling for requests with no content
-               if ( !s.hasContent ) {
-
-                       // If data is available, append data to url
-                       if ( s.data ) {
-                               cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
-                               // #9682: remove data so that it's not used in an eventual retry
-                               delete s.data;
-                       }
-
-                       // Add anti-cache in url if needed
-                       if ( s.cache === false ) {
-                               s.url = rts.test( cacheURL ) ?
-
-                                       // If there is already a '_' parameter, set its value
-                                       cacheURL.replace( rts, "$1_=" + nonce++ ) :
-
-                                       // Otherwise add one to the end
-                                       cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
-                       }
-               }
-
-               // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
-               if ( s.ifModified ) {
-                       if ( jQuery.lastModified[ cacheURL ] ) {
-                               jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
-                       }
-                       if ( jQuery.etag[ cacheURL ] ) {
-                               jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
-                       }
-               }
-
-               // Set the correct header, if data is being sent
-               if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
-                       jqXHR.setRequestHeader( "Content-Type", s.contentType );
-               }
-
-               // Set the Accepts header for the server, depending on the dataType
-               jqXHR.setRequestHeader(
-                       "Accept",
-                       s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
-                               s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
-                               s.accepts[ "*" ]
-               );
-
-               // Check for headers option
-               for ( i in s.headers ) {
-                       jqXHR.setRequestHeader( i, s.headers[ i ] );
-               }
-
-               // Allow custom headers/mimetypes and early abort
-               if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
-                       // Abort if not done already and return
-                       return jqXHR.abort();
-               }
-
-               // aborting is no longer a cancellation
-               strAbort = "abort";
-
-               // Install callbacks on deferreds
-               for ( i in { success: 1, error: 1, complete: 1 } ) {
-                       jqXHR[ i ]( s[ i ] );
-               }
-
-               // Get transport
-               transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
-
-               // If no transport, we auto-abort
-               if ( !transport ) {
-                       done( -1, "No Transport" );
-               } else {
-                       jqXHR.readyState = 1;
-
-                       // Send global event
-                       if ( fireGlobals ) {
-                               globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
-                       }
-                       // Timeout
-                       if ( s.async && s.timeout > 0 ) {
-                               timeoutTimer = setTimeout(function() {
-                                       jqXHR.abort("timeout");
-                               }, s.timeout );
-                       }
-
-                       try {
-                               state = 1;
-                               transport.send( requestHeaders, done );
-                       } catch ( e ) {
-                               // Propagate exception as error if not done
-                               if ( state < 2 ) {
-                                       done( -1, e );
-                               // Simply rethrow otherwise
-                               } else {
-                                       throw e;
-                               }
-                       }
-               }
-
-               // Callback for when everything is done
-               function done( status, nativeStatusText, responses, headers ) {
-                       var isSuccess, success, error, response, modified,
-                               statusText = nativeStatusText;
-
-                       // Called once
-                       if ( state === 2 ) {
-                               return;
-                       }
-
-                       // State is "done" now
-                       state = 2;
-
-                       // Clear timeout if it exists
-                       if ( timeoutTimer ) {
-                               clearTimeout( timeoutTimer );
-                       }
-
-                       // Dereference transport for early garbage collection
-                       // (no matter how long the jqXHR object will be used)
-                       transport = undefined;
-
-                       // Cache response headers
-                       responseHeadersString = headers || "";
-
-                       // Set readyState
-                       jqXHR.readyState = status > 0 ? 4 : 0;
-
-                       // Determine if successful
-                       isSuccess = status >= 200 && status < 300 || status === 304;
-
-                       // Get response data
-                       if ( responses ) {
-                               response = ajaxHandleResponses( s, jqXHR, responses );
-                       }
-
-                       // Convert no matter what (that way responseXXX fields are always set)
-                       response = ajaxConvert( s, response, jqXHR, isSuccess );
-
-                       // If successful, handle type chaining
-                       if ( isSuccess ) {
-
-                               // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
-                               if ( s.ifModified ) {
-                                       modified = jqXHR.getResponseHeader("Last-Modified");
-                                       if ( modified ) {
-                                               jQuery.lastModified[ cacheURL ] = modified;
-                                       }
-                                       modified = jqXHR.getResponseHeader("etag");
-                                       if ( modified ) {
-                                               jQuery.etag[ cacheURL ] = modified;
-                                       }
-                               }
-
-                               // if no content
-                               if ( status === 204 || s.type === "HEAD" ) {
-                                       statusText = "nocontent";
-
-                               // if not modified
-                               } else if ( status === 304 ) {
-                                       statusText = "notmodified";
-
-                               // If we have data, let's convert it
-                               } else {
-                                       statusText = response.state;
-                                       success = response.data;
-                                       error = response.error;
-                                       isSuccess = !error;
-                               }
-                       } else {
-                               // We extract error from statusText
-                               // then normalize statusText and status for non-aborts
-                               error = statusText;
-                               if ( status || !statusText ) {
-                                       statusText = "error";
-                                       if ( status < 0 ) {
-                                               status = 0;
-                                       }
-                               }
-                       }
-
-                       // Set data for the fake xhr object
-                       jqXHR.status = status;
-                       jqXHR.statusText = ( nativeStatusText || statusText ) + "";
-
-                       // Success/Error
-                       if ( isSuccess ) {
-                               deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
-                       } else {
-                               deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
-                       }
-
-                       // Status-dependent callbacks
-                       jqXHR.statusCode( statusCode );
-                       statusCode = undefined;
-
-                       if ( fireGlobals ) {
-                               globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
-                                       [ jqXHR, s, isSuccess ? success : error ] );
-                       }
-
-                       // Complete
-                       completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
-
-                       if ( fireGlobals ) {
-                               globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
-                               // Handle the global AJAX counter
-                               if ( !( --jQuery.active ) ) {
-                                       jQuery.event.trigger("ajaxStop");
-                               }
-                       }
-               }
-
-               return jqXHR;
-       },
-
-       getJSON: function( url, data, callback ) {
-               return jQuery.get( url, data, callback, "json" );
-       },
-
-       getScript: function( url, callback ) {
-               return jQuery.get( url, undefined, callback, "script" );
-       }
-});
-
-jQuery.each( [ "get", "post" ], function( i, method ) {
-       jQuery[ method ] = function( url, data, callback, type ) {
-               // shift arguments if data argument was omitted
-               if ( jQuery.isFunction( data ) ) {
-                       type = type || callback;
-                       callback = data;
-                       data = undefined;
-               }
-
-               return jQuery.ajax({
-                       url: url,
-                       type: method,
-                       dataType: type,
-                       data: data,
-                       success: callback
-               });
-       };
-});
-
-// Attach a bunch of functions for handling common AJAX events
-jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
-       jQuery.fn[ type ] = function( fn ) {
-               return this.on( type, fn );
-       };
-});
-
-
-jQuery._evalUrl = function( url ) {
-       return jQuery.ajax({
-               url: url,
-               type: "GET",
-               dataType: "script",
-               async: false,
-               global: false,
-               "throws": true
-       });
-};
-
-
-jQuery.fn.extend({
-       wrapAll: function( html ) {
-               var wrap;
-
-               if ( jQuery.isFunction( html ) ) {
-                       return this.each(function( i ) {
-                               jQuery( this ).wrapAll( html.call(this, i) );
-                       });
-               }
-
-               if ( this[ 0 ] ) {
-
-                       // The elements to wrap the target around
-                       wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
-
-                       if ( this[ 0 ].parentNode ) {
-                               wrap.insertBefore( this[ 0 ] );
-                       }
-
-                       wrap.map(function() {
-                               var elem = this;
-
-                               while ( elem.firstElementChild ) {
-                                       elem = elem.firstElementChild;
-                               }
-
-                               return elem;
-                       }).append( this );
-               }
-
-               return this;
-       },
-
-       wrapInner: function( html ) {
-               if ( jQuery.isFunction( html ) ) {
-                       return this.each(function( i ) {
-                               jQuery( this ).wrapInner( html.call(this, i) );
-                       });
-               }
-
-               return this.each(function() {
-                       var self = jQuery( this ),
-                               contents = self.contents();
-
-                       if ( contents.length ) {
-                               contents.wrapAll( html );
-
-                       } else {
-                               self.append( html );
-                       }
-               });
-       },
-
-       wrap: function( html ) {
-               var isFunction = jQuery.isFunction( html );
-
-               return this.each(function( i ) {
-                       jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
-               });
-       },
-
-       unwrap: function() {
-               return this.parent().each(function() {
-                       if ( !jQuery.nodeName( this, "body" ) ) {
-                               jQuery( this ).replaceWith( this.childNodes );
-                       }
-               }).end();
-       }
-});
-
-
-var r20 = /%20/g,
-       rbracket = /\[\]$/,
-       rCRLF = /\r?\n/g,
-       rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
-       rsubmittable = /^(?:input|select|textarea|keygen)/i;
-
-function buildParams( prefix, obj, traditional, add ) {
-       var name;
-
-       if ( jQuery.isArray( obj ) ) {
-               // Serialize array item.
-               jQuery.each( obj, function( i, v ) {
-                       if ( traditional || rbracket.test( prefix ) ) {
-                               // Treat each array item as a scalar.
-                               add( prefix, v );
-
-                       } else {
-                               // Item is non-scalar (array or object), encode its numeric index.
-                               buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
-                       }
-               });
-
-       } else if ( !traditional && jQuery.type( obj ) === "object" ) {
-               // Serialize object item.
-               for ( name in obj ) {
-                       buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
-               }
-
-       } else {
-               // Serialize scalar item.
-               add( prefix, obj );
-       }
-}
-
-// Serialize an array of form elements or a set of
-// key/values into a query string
-jQuery.param = function( a, traditional ) {
-       var prefix,
-               s = [],
-               add = function( key, value ) {
-                       // If value is a function, invoke it and return its value
-                       value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
-                       s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
-               };
-
-       // Set traditional to true for jQuery <= 1.3.2 behavior.
-       if ( traditional === undefined ) {
-               traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
-       }
-
-       // If an array was passed in, assume that it is an array of form elements.
-       if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
-               // Serialize the form elements
-               jQuery.each( a, function() {
-                       add( this.name, this.value );
-               });
-
-       } else {
-               // If traditional, encode the "old" way (the way 1.3.2 or older
-               // did it), otherwise encode params recursively.
-               for ( prefix in a ) {
-                       buildParams( prefix, a[ prefix ], traditional, add );
-               }
-       }
-
-       // Return the resulting serialization
-       return s.join( "&" ).replace( r20, "+" );
-};
-
-jQuery.fn.extend({
-       serialize: function() {
-               return jQuery.param( this.serializeArray() );
-       },
-       serializeArray: function() {
-               return this.map(function() {
-                       // Can add propHook for "elements" to filter or add form elements
-                       var elements = jQuery.prop( this, "elements" );
-                       return elements ? jQuery.makeArray( elements ) : this;
-               })
-               .filter(function() {
-                       var type = this.type;
-
-                       // Use .is( ":disabled" ) so that fieldset[disabled] works
-                       return this.name && !jQuery( this ).is( ":disabled" ) &&
-                               rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
-                               ( this.checked || !rcheckableType.test( type ) );
-               })
-               .map(function( i, elem ) {
-                       var val = jQuery( this ).val();
-
-                       return val == null ?
-                               null :
-                               jQuery.isArray( val ) ?
-                                       jQuery.map( val, function( val ) {
-                                               return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
-                                       }) :
-                                       { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
-               }).get();
-       }
-});
-
-
-jQuery.ajaxSettings.xhr = function() {
-       try {
-               return new XMLHttpRequest();
-       } catch( e ) {}
-};
-
-var xhrId = 0,
-       xhrCallbacks = {},
-       xhrSuccessStatus = {
-               // file protocol always yields status code 0, assume 200
-               0: 200,
-               // Support: IE9
-               // #1450: sometimes IE returns 1223 when it should be 204
-               1223: 204
-       },
-       xhrSupported = jQuery.ajaxSettings.xhr();
-
-// Support: IE9
-// Open requests must be manually aborted on unload (#5280)
-if ( window.ActiveXObject ) {
-       jQuery( window ).on( "unload", function() {
-               for ( var key in xhrCallbacks ) {
-                       xhrCallbacks[ key ]();
-               }
-       });
-}
-
-support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
-support.ajax = xhrSupported = !!xhrSupported;
-
-jQuery.ajaxTransport(function( options ) {
-       var callback;
-
-       // Cross domain only allowed if supported through XMLHttpRequest
-       if ( support.cors || xhrSupported && !options.crossDomain ) {
-               return {
-                       send: function( headers, complete ) {
-                               var i,
-                                       xhr = options.xhr(),
-                                       id = ++xhrId;
-
-                               xhr.open( options.type, options.url, options.async, options.username, options.password );
-
-                               // Apply custom fields if provided
-                               if ( options.xhrFields ) {
-                                       for ( i in options.xhrFields ) {
-                                               xhr[ i ] = options.xhrFields[ i ];
-                                       }
-                               }
-
-                               // Override mime type if needed
-                               if ( options.mimeType && xhr.overrideMimeType ) {
-                                       xhr.overrideMimeType( options.mimeType );
-                               }
-
-                               // X-Requested-With header
-                               // For cross-domain requests, seeing as conditions for a preflight are
-                               // akin to a jigsaw puzzle, we simply never set it to be sure.
-                               // (it can always be set on a per-request basis or even using ajaxSetup)
-                               // For same-domain requests, won't change header if already provided.
-                               if ( !options.crossDomain && !headers["X-Requested-With"] ) {
-                                       headers["X-Requested-With"] = "XMLHttpRequest";
-                               }
-
-                               // Set headers
-                               for ( i in headers ) {
-                                       xhr.setRequestHeader( i, headers[ i ] );
-                               }
-
-                               // Callback
-                               callback = function( type ) {
-                                       return function() {
-                                               if ( callback ) {
-                                                       delete xhrCallbacks[ id ];
-                                                       callback = xhr.onload = xhr.onerror = null;
-
-                                                       if ( type === "abort" ) {
-                                                               xhr.abort();
-                                                       } else if ( type === "error" ) {
-                                                               complete(
-                                                                       // file: protocol always yields status 0; see #8605, #14207
-                                                                       xhr.status,
-                                                                       xhr.statusText
-                                                               );
-                                                       } else {
-                                                               complete(
-                                                                       xhrSuccessStatus[ xhr.status ] || xhr.status,
-                                                                       xhr.statusText,
-                                                                       // Support: IE9
-                                                                       // Accessing binary-data responseText throws an exception
-                                                                       // (#11426)
-                                                                       typeof xhr.responseText === "string" ? {
-                                                                               text: xhr.responseText
-                                                                       } : undefined,
-                                                                       xhr.getAllResponseHeaders()
-                                                               );
-                                                       }
-                                               }
-                                       };
-                               };
-
-                               // Listen to events
-                               xhr.onload = callback();
-                               xhr.onerror = callback("error");
-
-                               // Create the abort callback
-                               callback = xhrCallbacks[ id ] = callback("abort");
-
-                               try {
-                                       // Do send the request (this may raise an exception)
-                                       xhr.send( options.hasContent && options.data || null );
-                               } catch ( e ) {
-                                       // #14683: Only rethrow if this hasn't been notified as an error yet
-                                       if ( callback ) {
-                                               throw e;
-                                       }
-                               }
-                       },
-
-                       abort: function() {
-                               if ( callback ) {
-                                       callback();
-                               }
-                       }
-               };
-       }
-});
-
-
-
-
-// Install script dataType
-jQuery.ajaxSetup({
-       accepts: {
-               script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
-       },
-       contents: {
-               script: /(?:java|ecma)script/
-       },
-       converters: {
-               "text script": function( text ) {
-                       jQuery.globalEval( text );
-                       return text;
-               }
-       }
-});
-
-// Handle cache's special case and crossDomain
-jQuery.ajaxPrefilter( "script", function( s ) {
-       if ( s.cache === undefined ) {
-               s.cache = false;
-       }
-       if ( s.crossDomain ) {
-               s.type = "GET";
-       }
-});
-
-// Bind script tag hack transport
-jQuery.ajaxTransport( "script", function( s ) {
-       // This transport only deals with cross domain requests
-       if ( s.crossDomain ) {
-               var script, callback;
-               return {
-                       send: function( _, complete ) {
-                               script = jQuery("<script>").prop({
-                                       async: true,
-                                       charset: s.scriptCharset,
-                                       src: s.url
-                               }).on(
-                                       "load error",
-                                       callback = function( evt ) {
-                                               script.remove();
-                                               callback = null;
-                                               if ( evt ) {
-                                                       complete( evt.type === "error" ? 404 : 200, evt.type );
-                                               }
-                                       }
-                               );
-                               document.head.appendChild( script[ 0 ] );
-                       },
-                       abort: function() {
-                               if ( callback ) {
-                                       callback();
-                               }
-                       }
-               };
-       }
-});
-
-
-
-
-var oldCallbacks = [],
-       rjsonp = /(=)\?(?=&|$)|\?\?/;
-
-// Default jsonp settings
-jQuery.ajaxSetup({
-       jsonp: "callback",
-       jsonpCallback: function() {
-               var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
-               this[ callback ] = true;
-               return callback;
-       }
-});
-
-// Detect, normalize options and install callbacks for jsonp requests
-jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
-
-       var callbackName, overwritten, responseContainer,
-               jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
-                       "url" :
-                       typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
-               );
-
-       // Handle iff the expected data type is "jsonp" or we have a parameter to set
-       if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
-
-               // Get callback name, remembering preexisting value associated with it
-               callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
-                       s.jsonpCallback() :
-                       s.jsonpCallback;
-
-               // Insert callback into url or form data
-               if ( jsonProp ) {
-                       s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
-               } else if ( s.jsonp !== false ) {
-                       s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
-               }
-
-               // Use data converter to retrieve json after script execution
-               s.converters["script json"] = function() {
-                       if ( !responseContainer ) {
-                               jQuery.error( callbackName + " was not called" );
-                       }
-                       return responseContainer[ 0 ];
-               };
-
-               // force json dataType
-               s.dataTypes[ 0 ] = "json";
-
-               // Install callback
-               overwritten = window[ callbackName ];
-               window[ callbackName ] = function() {
-                       responseContainer = arguments;
-               };
-
-               // Clean-up function (fires after converters)
-               jqXHR.always(function() {
-                       // Restore preexisting value
-                       window[ callbackName ] = overwritten;
-
-                       // Save back as free
-                       if ( s[ callbackName ] ) {
-                               // make sure that re-using the options doesn't screw things around
-                               s.jsonpCallback = originalSettings.jsonpCallback;
-
-                               // save the callback name for future use
-                               oldCallbacks.push( callbackName );
-                       }
-
-                       // Call if it was a function and we have a response
-                       if ( responseContainer && jQuery.isFunction( overwritten ) ) {
-                               overwritten( responseContainer[ 0 ] );
-                       }
-
-                       responseContainer = overwritten = undefined;
-               });
-
-               // Delegate to script
-               return "script";
-       }
-});
-
-
-
-
-// data: string of html
-// context (optional): If specified, the fragment will be created in this context, defaults to document
-// keepScripts (optional): If true, will include scripts passed in the html string
-jQuery.parseHTML = function( data, context, keepScripts ) {
-       if ( !data || typeof data !== "string" ) {
-               return null;
-       }
-       if ( typeof context === "boolean" ) {
-               keepScripts = context;
-               context = false;
-       }
-       context = context || document;
-
-       var parsed = rsingleTag.exec( data ),
-               scripts = !keepScripts && [];
-
-       // Single tag
-       if ( parsed ) {
-               return [ context.createElement( parsed[1] ) ];
-       }
-
-       parsed = jQuery.buildFragment( [ data ], context, scripts );
-
-       if ( scripts && scripts.length ) {
-               jQuery( scripts ).remove();
-       }
-
-       return jQuery.merge( [], parsed.childNodes );
-};
-
-
-// Keep a copy of the old load method
-var _load = jQuery.fn.load;
-
-/**
- * Load a url into a page
- */
-jQuery.fn.load = function( url, params, callback ) {
-       if ( typeof url !== "string" && _load ) {
-               return _load.apply( this, arguments );
-       }
-
-       var selector, type, response,
-               self = this,
-               off = url.indexOf(" ");
-
-       if ( off >= 0 ) {
-               selector = jQuery.trim( url.slice( off ) );
-               url = url.slice( 0, off );
-       }
-
-       // If it's a function
-       if ( jQuery.isFunction( params ) ) {
-
-               // We assume that it's the callback
-               callback = params;
-               params = undefined;
-
-       // Otherwise, build a param string
-       } else if ( params && typeof params === "object" ) {
-               type = "POST";
-       }
-
-       // If we have elements to modify, make the request
-       if ( self.length > 0 ) {
-               jQuery.ajax({
-                       url: url,
-
-                       // if "type" variable is undefined, then "GET" method will be used
-                       type: type,
-                       dataType: "html",
-                       data: params
-               }).done(function( responseText ) {
-
-                       // Save response for use in complete callback
-                       response = arguments;
-
-                       self.html( selector ?
-
-                               // If a selector was specified, locate the right elements in a dummy div
-                               // Exclude scripts to avoid IE 'Permission Denied' errors
-                               jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
-
-                               // Otherwise use the full result
-                               responseText );
-
-               }).complete( callback && function( jqXHR, status ) {
-                       self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
-               });
-       }
-
-       return this;
-};
-
-
-
-
-var docElem = window.document.documentElement;
-
-/**
- * Gets a window from an element
- */
-function getWindow( elem ) {
-       return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
-}
-
-jQuery.offset = {
-       setOffset: function( elem, options, i ) {
-               var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
-                       position = jQuery.css( elem, "position" ),
-                       curElem = jQuery( elem ),
-                       props = {};
-
-               // Set position first, in-case top/left are set even on static elem
-               if ( position === "static" ) {
-                       elem.style.position = "relative";
-               }
-
-               curOffset = curElem.offset();
-               curCSSTop = jQuery.css( elem, "top" );
-               curCSSLeft = jQuery.css( elem, "left" );
-               calculatePosition = ( position === "absolute" || position === "fixed" ) &&
-                       ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
-
-               // Need to be able to calculate position if either top or left is auto and position is either absolute or fixed
-               if ( calculatePosition ) {
-                       curPosition = curElem.position();
-                       curTop = curPosition.top;
-                       curLeft = curPosition.left;
-
-               } else {
-                       curTop = parseFloat( curCSSTop ) || 0;
-                       curLeft = parseFloat( curCSSLeft ) || 0;
-               }
-
-               if ( jQuery.isFunction( options ) ) {
-                       options = options.call( elem, i, curOffset );
-               }
-
-               if ( options.top != null ) {
-                       props.top = ( options.top - curOffset.top ) + curTop;
-               }
-               if ( options.left != null ) {
-                       props.left = ( options.left - curOffset.left ) + curLeft;
-               }
-
-               if ( "using" in options ) {
-                       options.using.call( elem, props );
-
-               } else {
-                       curElem.css( props );
-               }
-       }
-};
-
-jQuery.fn.extend({
-       offset: function( options ) {
-               if ( arguments.length ) {
-                       return options === undefined ?
-                               this :
-                               this.each(function( i ) {
-                                       jQuery.offset.setOffset( this, options, i );
-                               });
-               }
-
-               var docElem, win,
-                       elem = this[ 0 ],
-                       box = { top: 0, left: 0 },
-                       doc = elem && elem.ownerDocument;
-
-               if ( !doc ) {
-                       return;
-               }
-
-               docElem = doc.documentElement;
-
-               // Make sure it's not a disconnected DOM node
-               if ( !jQuery.contains( docElem, elem ) ) {
-                       return box;
-               }
-
-               // If we don't have gBCR, just use 0,0 rather than error
-               // BlackBerry 5, iOS 3 (original iPhone)
-               if ( typeof elem.getBoundingClientRect !== strundefined ) {
-                       box = elem.getBoundingClientRect();
-               }
-               win = getWindow( doc );
-               return {
-                       top: box.top + win.pageYOffset - docElem.clientTop,
-                       left: box.left + win.pageXOffset - docElem.clientLeft
-               };
-       },
-
-       position: function() {
-               if ( !this[ 0 ] ) {
-                       return;
-               }
-
-               var offsetParent, offset,
-                       elem = this[ 0 ],
-                       parentOffset = { top: 0, left: 0 };
-
-               // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
-               if ( jQuery.css( elem, "position" ) === "fixed" ) {
-                       // We assume that getBoundingClientRect is available when computed position is fixed
-                       offset = elem.getBoundingClientRect();
-
-               } else {
-                       // Get *real* offsetParent
-                       offsetParent = this.offsetParent();
-
-                       // Get correct offsets
-                       offset = this.offset();
-                       if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
-                               parentOffset = offsetParent.offset();
-                       }
-
-                       // Add offsetParent borders
-                       parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
-                       parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
-               }
-
-               // Subtract parent offsets and element margins
-               return {
-                       top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
-                       left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
-               };
-       },
-
-       offsetParent: function() {
-               return this.map(function() {
-                       var offsetParent = this.offsetParent || docElem;
-
-                       while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
-                               offsetParent = offsetParent.offsetParent;
-                       }
-
-                       return offsetParent || docElem;
-               });
-       }
-});
-
-// Create scrollLeft and scrollTop methods
-jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
-       var top = "pageYOffset" === prop;
-
-       jQuery.fn[ method ] = function( val ) {
-               return access( this, function( elem, method, val ) {
-                       var win = getWindow( elem );
-
-                       if ( val === undefined ) {
-                               return win ? win[ prop ] : elem[ method ];
-                       }
-
-                       if ( win ) {
-                               win.scrollTo(
-                                       !top ? val : window.pageXOffset,
-                                       top ? val : window.pageYOffset
-                               );
-
-                       } else {
-                               elem[ method ] = val;
-                       }
-               }, method, val, arguments.length, null );
-       };
-});
-
-// Add the top/left cssHooks using jQuery.fn.position
-// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
-// getComputedStyle returns percent when specified for top/left/bottom/right
-// rather than make the css module depend on the offset module, we just check for it here
-jQuery.each( [ "top", "left" ], function( i, prop ) {
-       jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
-               function( elem, computed ) {
-                       if ( computed ) {
-                               computed = curCSS( elem, prop );
-                               // if curCSS returns percentage, fallback to offset
-                               return rnumnonpx.test( computed ) ?
-                                       jQuery( elem ).position()[ prop ] + "px" :
-                                       computed;
-                       }
-               }
-       );
-});
-
-
-// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
-jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
-       jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
-               // margin is only for outerHeight, outerWidth
-               jQuery.fn[ funcName ] = function( margin, value ) {
-                       var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
-                               extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
-
-                       return access( this, function( elem, type, value ) {
-                               var doc;
-
-                               if ( jQuery.isWindow( elem ) ) {
-                                       // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
-                                       // isn't a whole lot we can do. See pull request at this URL for discussion:
-                                       // https://github.com/jquery/jquery/pull/764
-                                       return elem.document.documentElement[ "client" + name ];
-                               }
-
-                               // Get document width or height
-                               if ( elem.nodeType === 9 ) {
-                                       doc = elem.documentElement;
-
-                                       // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
-                                       // whichever is greatest
-                                       return Math.max(
-                                               elem.body[ "scroll" + name ], doc[ "scroll" + name ],
-                                               elem.body[ "offset" + name ], doc[ "offset" + name ],
-                                               doc[ "client" + name ]
-                                       );
-                               }
-
-                               return value === undefined ?
-                                       // Get width or height on the element, requesting but not forcing parseFloat
-                                       jQuery.css( elem, type, extra ) :
-
-                                       // Set width or height on the element
-                                       jQuery.style( elem, type, value, extra );
-                       }, type, chainable ? margin : undefined, chainable, null );
-               };
-       });
-});
-
-
-// Register as a named AMD module, since jQuery can be concatenated with other
-// files that may use define, but not via a proper concatenation script that
-// understands anonymous AMD modules. A named AMD is safest and most robust
-// way to register. Lowercase jquery is used because AMD module names are
-// derived from file names, and jQuery is normally delivered in a lowercase
-// file name. Do this after creating the global so that if an AMD module wants
-// to call noConflict to hide this version of jQuery, it will work.
-
-// Note that for maximum portability, libraries that are not jQuery should
-// declare themselves as anonymous modules, and avoid setting a global if an
-// AMD loader is present. jQuery is a special case. For more information, see
-// https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
-
-if ( typeof define === "function" && define.amd ) {
-       define( "jquery", [], function() {
-               return jQuery;
-       });
-}
-
-
-
-
-var
-       // Map over jQuery in case of overwrite
-       _jQuery = window.jQuery,
-
-       // Map over the $ in case of overwrite
-       _$ = window.$;
-
-jQuery.noConflict = function( deep ) {
-       if ( window.$ === jQuery ) {
-               window.$ = _$;
-       }
-
-       if ( deep && window.jQuery === jQuery ) {
-               window.jQuery = _jQuery;
-       }
-
-       return jQuery;
-};
-
-// Expose jQuery and $ identifiers, even in
-// AMD (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
-// and CommonJS for browser emulators (#13566)
-if ( typeof noGlobal === strundefined ) {
-       window.jQuery = window.$ = jQuery;
-}
-
-
-
-
-return jQuery;
-
-}));
diff --git a/www/js/jquery.sparkline.js b/www/js/jquery.sparkline.js
deleted file mode 100644 (file)
index 0758e0d..0000000
+++ /dev/null
@@ -1,1463 +0,0 @@
-/**
-*
-* jquery.sparkline.js
-*
-* v2.1.2
-* (c) Splunk, Inc
-* Contact: Gareth Watts (gareth@splunk.com)
-* http://omnipotent.net/jquery.sparkline/
-*
-* Generates inline sparkline charts from data supplied either to the method
-* or inline in HTML
-*
-* Compatible with Internet Explorer 6.0+ and modern browsers equipped with the canvas tag
-* (Firefox 2.0+, Safari, Opera, etc)
-*
-* License: New BSD License
-*
-* Copyright (c) 2012, Splunk Inc.
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without modification,
-* are permitted provided that the following conditions are met:
-*
-*     * Redistributions of source code must retain the above copyright notice,
-*       this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright notice,
-*       this list of conditions and the following disclaimer in the documentation
-*       and/or other materials provided with the distribution.
-*     * Neither the name of Splunk Inc nor the names of its contributors may
-*       be used to endorse or promote products derived from this software without
-*       specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
-* SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
-* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*
-*
-* Usage:
-*  $(selector).sparkline(values, options)
-*
-* If values is undefined or set to 'html' then the data values are read from the specified tag:
-*   <p>Sparkline: <span class="sparkline">1,4,6,6,8,5,3,5</span></p>
-*   $('.sparkline').sparkline();
-* There must be no spaces in the enclosed data set
-*
-* Otherwise values must be an array of numbers or null values
-*    <p>Sparkline: <span id="sparkline1">This text replaced if the browser is compatible</span></p>
-*    $('#sparkline1').sparkline([1,4,6,6,8,5,3,5])
-*    $('#sparkline2').sparkline([1,4,6,null,null,5,3,5])
-*
-* Values can also be specified in an HTML comment, or as a values attribute:
-*    <p>Sparkline: <span class="sparkline"><!--1,4,6,6,8,5,3,5 --></span></p>
-*    <p>Sparkline: <span class="sparkline" values="1,4,6,6,8,5,3,5"></span></p>
-*    $('.sparkline').sparkline();
-*
-* By default, options should be passed in as teh second argument to the sparkline function:
-*   $('.sparkline').sparkline([1,2,3,4], {type: 'bar'})
-*
-* Supported options:
-*   lineColor - Color of the line used for the chart
-*   fillColor - Color used to fill in the chart - Set to '' or false for a transparent chart
-*   width - Width of the chart - Defaults to 3 times the number of values in pixels
-*   height - Height of the chart - Defaults to the height of the containing element
-*   chartRangeMin - Specify the minimum value to use for the Y range of the chart - Defaults to the minimum value supplied
-*   chartRangeMax - Specify the maximum value to use for the Y range of the chart - Defaults to the maximum value supplied
-*   chartRangeClip - Clip out of range values to the max/min specified by chartRangeMin and chartRangeMax
-*   chartRangeMinX - Specify the minimum value to use for the X range of the chart - Defaults to the minimum value supplied
-*   chartRangeMaxX - Specify the maximum value to use for the X range of the chart - Defaults to the maximum value supplied
-*   tagValuesAttribute - Name of tag attribute to check for data values - Defaults to 'values'
-*   disableInteraction - If set to true then all mouseover/click interaction behaviour will be disabled,
-*       making the plugin perform much like it did in 1.x
-*   disableTooltips - If set to true then tooltips will be disabled - Defaults to false (tooltips enabled)
-*   disableHighlight - If set to true then highlighting of selected chart elements on mouseover will be disabled
-*       defaults to false (highlights enabled)
-*   highlightLighten - Factor to lighten/darken highlighted chart values by - Defaults to 1.4 for a 40% increase
-*   tooltipContainer - Specify which DOM element the tooltip should be rendered into - defaults to document.body
-*   tooltipClassname - Optional CSS classname to apply to tooltips - If not specified then a default style will be applied
-*   tooltipOffsetX - How many pixels away from the mouse pointer to render the tooltip on the X axis
-*   tooltipOffsetY - How many pixels away from the mouse pointer to render the tooltip on the r axis
-*   tooltipFormatter  - Optional callback that allows you to override the HTML displayed in the tooltip
-*       callback is given arguments of (sparkline, options, fields)
-*   tooltipChartTitle - If specified then the tooltip uses the string specified by this setting as a title
-*   tooltipPrefix - A string to prepend to each field displayed in a tooltip
-*   tooltipSuffix - A string to append to each field displayed in a tooltip
-*   tooltipSkipNull - If true then null values will not have a tooltip displayed (defaults to true)
-*   tooltipValueLookups - An object or range map to map field values to tooltip strings
-*       (eg. to map -1 to "Lost", 0 to "Draw", and 1 to "Win")
-*   numberFormatter - Optional callback for formatting numbers in tooltips
-*   numberDigitGroupSep - Character to use for group separator in numbers "1,234" - Defaults to ","
-*   numberDecimalMark - Character to use for the decimal point when formatting numbers - Defaults to "."
-*   numberDigitGroupCount - Number of digits between group separator - Defaults to 3
-*
-* There is 1 type of sparkline, selected by supplying a "type" option of 'bar' (default),
-*
-*   bar - Bar chart.  Options:
-*       barColor - Color of bars for postive values
-*       negBarColor - Color of bars for negative values
-*       zeroColor - Color of bars with zero values
-*       nullColor - Color of bars with null values - Defaults to omitting the bar entirely
-*       barWidth - Width of bars in pixels
-*       barSpacing - Gap between bars in pixels
-*       zeroAxis - Centers the y-axis around zero if true
-*
-*
-*
-*
-*
-*
-*   Examples:
-*   $('#sparkline1').sparkline(myvalues, { lineColor: '#f00', fillColor: false });
-*   $('.barsparks').sparkline('html', { type:'bar', height:'40px', barWidth:5 });
-*/
-
-/*jslint regexp: true, browser: true, jquery: true, white: true, nomen: false, plusplus: false, maxerr: 500, indent: 4 */
-
-(function(document, Math, undefined) { // performance/minified-size optimization
-(function(factory) {
-    if(typeof define === 'function' && define.amd) {
-        define(['jquery'], factory);
-    } else if (jQuery && !jQuery.fn.sparkline) {
-        factory(jQuery);
-    }
-}
-(function($) {
-    'use strict';
-
-    var UNSET_OPTION = {},
-        getDefaults, createClass, clipval, quartile, normalizeValue, normalizeValues,
-        remove, isNumber, all, sum, addCSS, ensureArray, formatNumber,
-        MouseHandler, Tooltip, barHighlightMixin,
-        bar, defaultStyles, initStyles,
-        VShape, VCanvas_base, VCanvas_canvas, pending, shapeCount = 0;
-
-    /**
-     * Default configuration settings
-     */
-    getDefaults = function () {
-        return {
-            // Settings common to most/all chart types
-            common: {
-                type: 'bar',
-                lineColor: '#00f',
-                fillColor: '#cdf',
-                defaultPixelsPerValue: 3,
-                width: 'auto',
-                height: 'auto',
-                tagValuesAttribute: 'values',
-                enableHighlight: true,
-                highlightLighten: 1.4,
-                tooltipSkipNull: true,
-                tooltipPrefix: '',
-                tooltipSuffix: '',
-                numberFormatter: false,
-                numberDigitGroupCount: 3,
-                numberDigitGroupSep: ',',
-                numberDecimalMark: '.',
-                disableTooltips: false,
-                disableInteraction: false
-            },
-            // Defaults for bar charts
-            bar: {
-                barColor: '#3366cc',
-                negBarColor: '#f44',
-                zeroColor: undefined,
-                nullColor: undefined,
-                zeroAxis: true,
-                barWidth: 4,
-                barSpacing: 1,
-                chartRangeMax: undefined,
-                chartRangeMin: undefined,
-                chartRangeClip: false,
-                tooltipFormat: '',
-            },
-        };
-    };
-
-    // You can have tooltips use a css class other than jqstooltip by specifying tooltipClassname
-    defaultStyles = '.jqstooltip { ' +
-            'position: absolute;' +
-            'left: 0px;' +
-            'top: 0px;' +
-            'visibility: hidden;' +
-            'background: rgb(0, 0, 0) transparent;' +
-            'background-color: rgba(0,0,0,0.6);' +
-            'filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000);' +
-            '-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#99000000, endColorstr=#99000000)";' +
-            'color: white;' +
-            'font: 10px arial, san serif;' +
-            'text-align: left;' +
-            'white-space: nowrap;' +
-            'padding: 5px;' +
-            'border: 1px solid white;' +
-            'z-index: 10000;' +
-            '}' +
-            '.jqsfield { ' +
-            'color: white;' +
-            'font: 10px arial, san serif;' +
-            'text-align: left;' +
-            '}';
-
-    /**
-     * Utilities
-     */
-
-    createClass = function (/* [baseclass, [mixin, ...]], definition */) {
-        var Class, args;
-        Class = function () {
-            this.init.apply(this, arguments);
-        };
-        if (arguments.length > 1) {
-            if (arguments[0]) {
-                Class.prototype = $.extend(new arguments[0](), arguments[arguments.length - 1]);
-                Class._super = arguments[0].prototype;
-            } else {
-                Class.prototype = arguments[arguments.length - 1];
-            }
-            if (arguments.length > 2) {
-                args = Array.prototype.slice.call(arguments, 1, -1);
-                args.unshift(Class.prototype);
-                $.extend.apply($, args);
-            }
-        } else {
-            Class.prototype = arguments[0];
-        }
-        Class.prototype.cls = Class;
-        return Class;
-    };
-
-    clipval = function (val, min, max) {
-        if (val < min) {
-            return min;
-        }
-        if (val > max) {
-            return max;
-        }
-        return val;
-    };
-
-    quartile = function (values, q) {
-        var vl;
-        if (q === 2) {
-            vl = Math.floor(values.length / 2);
-            return values.length % 2 ? values[vl] : (values[vl-1] + values[vl]) / 2;
-        } else {
-            if (values.length % 2 ) { // odd
-                vl = (values.length * q + q) / 4;
-                return vl % 1 ? (values[Math.floor(vl)] + values[Math.floor(vl) - 1]) / 2 : values[vl-1];
-            } else { //even
-                vl = (values.length * q + 2) / 4;
-                return vl % 1 ? (values[Math.floor(vl)] + values[Math.floor(vl) - 1]) / 2 :  values[vl-1];
-
-            }
-        }
-    };
-
-    normalizeValue = function (val) {
-        var nf;
-        switch (val) {
-            case 'undefined':
-                val = undefined;
-                break;
-            case 'null':
-                val = null;
-                break;
-            case 'true':
-                val = true;
-                break;
-            case 'false':
-                val = false;
-                break;
-            default:
-                nf = parseFloat(val);
-                if (val == nf) {
-                    val = nf;
-                }
-        }
-        return val;
-    };
-
-    normalizeValues = function (vals) {
-        var i, result = [];
-        for (i = vals.length; i--;) {
-            result[i] = normalizeValue(vals[i]);
-        }
-        return result;
-    };
-
-    remove = function (vals, filter) {
-        var i, vl, result = [];
-        for (i = 0, vl = vals.length; i < vl; i++) {
-            if (vals[i] !== filter) {
-                result.push(vals[i]);
-            }
-        }
-        return result;
-    };
-
-    isNumber = function (num) {
-        return !isNaN(parseFloat(num)) && isFinite(num);
-    };
-
-    formatNumber = function (num, prec, groupsize, groupsep, decsep) {
-        var p, i;
-        num = (prec === false ? parseFloat(num).toString() : num.toFixed(prec)).split('');
-        p = (p = $.inArray('.', num)) < 0 ? num.length : p;
-        if (p < num.length) {
-            num[p] = decsep;
-        }
-        for (i = p - groupsize; i > 0; i -= groupsize) {
-            num.splice(i, 0, groupsep);
-        }
-        return num.join('');
-    };
-
-    // determine if all values of an array match a value
-    // returns true if the array is empty
-    all = function (val, arr, ignoreNull) {
-        var i;
-        for (i = arr.length; i--; ) {
-            if (ignoreNull && arr[i] === null) continue;
-            if (arr[i] !== val) {
-                return false;
-            }
-        }
-        return true;
-    };
-
-    // sums the numeric values in an array, ignoring other values
-    sum = function (vals) {
-        var total = 0, i;
-        for (i = vals.length; i--;) {
-            total += typeof vals[i] === 'number' ? vals[i] : 0;
-        }
-        return total;
-    };
-
-    ensureArray = function (val) {
-        return $.isArray(val) ? val : [val];
-    };
-
-    // http://paulirish.com/2008/bookmarklet-inject-new-css-rules/
-    addCSS = function(css) {
-        var tag;
-        //if ('\v' == 'v') /* ie only */ {
-        if (document.createStyleSheet) {
-            document.createStyleSheet().cssText = css;
-        } else {
-            tag = document.createElement('style');
-            tag.type = 'text/css';
-            document.getElementsByTagName('head')[0].appendChild(tag);
-            tag[(typeof document.body.style.WebkitAppearance == 'string') /* webkit only */ ? 'innerText' : 'innerHTML'] = css;
-        }
-    };
-
-    // Provide a cross-browser interface to a few simple drawing primitives
-    $.fn.simpledraw = function (width, height, useExisting, interact) {
-        var target, mhandler;
-        if (useExisting && (target = this.data('_jqs_vcanvas'))) {
-            return target;
-        }
-
-        if ($.fn.sparkline.canvas === false) {
-            // We've already determined that neither Canvas nor VML are available
-            return false;
-
-        } else if ($.fn.sparkline.canvas === undefined) {
-            // No function defined yet -- need to see if we support Canvas or VML
-            var el = document.createElement('canvas');
-            if (!!(el.getContext && el.getContext('2d'))) {
-                // Canvas is available
-                $.fn.sparkline.canvas = function(width, height, target, interact) {
-                    return new VCanvas_canvas(width, height, target, interact);
-                };
-            } else {
-                // Neither Canvas nor VML are available
-                $.fn.sparkline.canvas = false;
-                return false;
-            }
-        }
-
-        if (width === undefined) {
-            width = $(this).innerWidth();
-        }
-        if (height === undefined) {
-            height = $(this).innerHeight();
-        }
-
-        target = $.fn.sparkline.canvas(width, height, this, interact);
-
-        mhandler = $(this).data('_jqs_mhandler');
-        if (mhandler) {
-            mhandler.registerCanvas(target);
-        }
-        return target;
-    };
-
-    $.fn.cleardraw = function () {
-        var target = this.data('_jqs_vcanvas');
-        if (target) {
-            target.reset();
-        }
-    };
-
-    MouseHandler = createClass({
-        init: function (el, options) {
-            var $el = $(el);
-            this.$el = $el;
-            this.options = options;
-            this.currentPageX = 0;
-            this.currentPageY = 0;
-            this.el = el;
-            this.splist = [];
-            this.tooltip = null;
-            this.over = false;
-            this.displayTooltips = !options.get('disableTooltips');
-            this.highlightEnabled = !options.get('disableHighlight');
-        },
-
-        registerSparkline: function (sp) {
-            this.splist.push(sp);
-            if (this.over) {
-                this.updateDisplay();
-            }
-        },
-
-        registerCanvas: function (canvas) {
-            var $canvas = $(canvas.canvas);
-            this.canvas = canvas;
-            this.$canvas = $canvas;
-            $canvas.mouseenter($.proxy(this.mouseenter, this));
-            $canvas.mouseleave($.proxy(this.mouseleave, this));
-            $canvas.click($.proxy(this.mouseclick, this));
-        },
-
-        reset: function (removeTooltip) {
-            this.splist = [];
-            if (this.tooltip && removeTooltip) {
-                this.tooltip.remove();
-                this.tooltip = undefined;
-            }
-        },
-
-        mouseclick: function (e) {
-            var clickEvent = $.Event('sparklineClick');
-            clickEvent.originalEvent = e;
-            clickEvent.sparklines = this.splist;
-            this.$el.trigger(clickEvent);
-        },
-
-        mouseenter: function (e) {
-            $(document.body).unbind('mousemove.jqs');
-            $(document.body).bind('mousemove.jqs', $.proxy(this.mousemove, this));
-            this.over = true;
-            this.currentPageX = e.pageX;
-            this.currentPageY = e.pageY;
-            this.currentEl = e.target;
-            if (!this.tooltip && this.displayTooltips) {
-                this.tooltip = new Tooltip(this.options);
-                this.tooltip.updatePosition(e.pageX, e.pageY);
-            }
-            this.updateDisplay();
-        },
-
-        mouseleave: function () {
-            $(document.body).unbind('mousemove.jqs');
-            var splist = this.splist,
-                 spcount = splist.length,
-                 needsRefresh = false,
-                 sp, i;
-            this.over = false;
-            this.currentEl = null;
-
-            if (this.tooltip) {
-                this.tooltip.remove();
-                this.tooltip = null;
-            }
-
-            for (i = 0; i < spcount; i++) {
-                sp = splist[i];
-                if (sp.clearRegionHighlight()) {
-                    needsRefresh = true;
-                }
-            }
-
-            if (needsRefresh) {
-                this.canvas.render();
-            }
-        },
-
-        mousemove: function (e) {
-            this.currentPageX = e.pageX;
-            this.currentPageY = e.pageY;
-            this.currentEl = e.target;
-            if (this.tooltip) {
-                this.tooltip.updatePosition(e.pageX, e.pageY);
-            }
-            this.updateDisplay();
-        },
-
-        updateDisplay: function () {
-            var splist = this.splist,
-                 spcount = splist.length,
-                 needsRefresh = false,
-                 offset = this.$canvas.offset(),
-                 localX = this.currentPageX - offset.left,
-                 localY = this.currentPageY - offset.top,
-                 tooltiphtml, sp, i, result, changeEvent;
-            if (!this.over) {
-                return;
-            }
-            for (i = 0; i < spcount; i++) {
-                sp = splist[i];
-                result = sp.setRegionHighlight(this.currentEl, localX, localY);
-                if (result) {
-                    needsRefresh = true;
-                }
-            }
-            if (needsRefresh) {
-                changeEvent = $.Event('sparklineRegionChange');
-                changeEvent.sparklines = this.splist;
-                this.$el.trigger(changeEvent);
-                if (this.tooltip) {
-                    tooltiphtml = '';
-                    for (i = 0; i < spcount; i++) {
-                        sp = splist[i];
-                        tooltiphtml += sp.getCurrentRegionTooltip();
-                    }
-                    this.tooltip.setContent(tooltiphtml);
-                }
-                if (!this.disableHighlight) {
-                    this.canvas.render();
-                }
-            }
-            if (result === null) {
-                this.mouseleave();
-            }
-        }
-    });
-
-
-    Tooltip = createClass({
-        sizeStyle: 'position: static !important;' +
-            'display: block !important;' +
-            'visibility: hidden !important;' +
-            'float: left !important;',
-
-        init: function (options) {
-            var tooltipClassname = options.get('tooltipClassname', 'jqstooltip'),
-                sizetipStyle = this.sizeStyle,
-                offset;
-            this.container = options.get('tooltipContainer') || document.body;
-            this.tooltipOffsetX = options.get('tooltipOffsetX', 10);
-            this.tooltipOffsetY = options.get('tooltipOffsetY', 12);
-            // remove any previous lingering tooltip
-            $('#jqssizetip').remove();
-            $('#jqstooltip').remove();
-            this.sizetip = $('<div/>', {
-                id: 'jqssizetip',
-                style: sizetipStyle,
-                'class': tooltipClassname
-            });
-            this.tooltip = $('<div/>', {
-                id: 'jqstooltip',
-                'class': tooltipClassname
-            }).appendTo(this.container);
-            // account for the container's location
-            offset = this.tooltip.offset();
-            this.offsetLeft = offset.left;
-            this.offsetTop = offset.top;
-            this.hidden = true;
-            $(window).unbind('resize.jqs scroll.jqs');
-            $(window).bind('resize.jqs scroll.jqs', $.proxy(this.updateWindowDims, this));
-            this.updateWindowDims();
-        },
-
-        updateWindowDims: function () {
-            this.scrollTop = $(window).scrollTop();
-            this.scrollLeft = $(window).scrollLeft();
-            this.scrollRight = this.scrollLeft + $(window).width();
-            this.updatePosition();
-        },
-
-        getSize: function (content) {
-            this.sizetip.html(content).appendTo(this.container);
-            this.width = this.sizetip.width() + 1;
-            this.height = this.sizetip.height();
-            this.sizetip.remove();
-        },
-
-        setContent: function (content) {
-            if (!content) {
-                this.tooltip.css('visibility', 'hidden');
-                this.hidden = true;
-                return;
-            }
-            this.getSize(content);
-            this.tooltip.html(content)
-                .css({
-                    'width': this.width,
-                    'height': this.height,
-                    'visibility': 'visible'
-                });
-            if (this.hidden) {
-                this.hidden = false;
-                this.updatePosition();
-            }
-        },
-
-        updatePosition: function (x, y) {
-            if (x === undefined) {
-                if (this.mousex === undefined) {
-                    return;
-                }
-                x = this.mousex - this.offsetLeft;
-                y = this.mousey - this.offsetTop;
-
-            } else {
-                this.mousex = x = x - this.offsetLeft;
-                this.mousey = y = y - this.offsetTop;
-            }
-            if (!this.height || !this.width || this.hidden) {
-                return;
-            }
-
-            y -= this.height + this.tooltipOffsetY;
-            x += this.tooltipOffsetX;
-
-            if (y < this.scrollTop) {
-                y = this.scrollTop;
-            }
-            if (x < this.scrollLeft) {
-                x = this.scrollLeft;
-            } else if (x + this.width > this.scrollRight) {
-                x = this.scrollRight - this.width;
-            }
-
-            this.tooltip.css({
-                'left': x,
-                'top': y
-            });
-        },
-
-        remove: function () {
-            this.tooltip.remove();
-            this.sizetip.remove();
-            this.sizetip = this.tooltip = undefined;
-            $(window).unbind('resize.jqs scroll.jqs');
-        }
-    });
-
-    initStyles = function() {
-        addCSS(defaultStyles);
-    };
-
-    $(initStyles);
-
-    pending = [];
-    $.fn.sparkline = function (userValues, userOptions) {
-        return this.each(function () {
-            var options = new $.fn.sparkline.options(this, userOptions),
-                 $this = $(this),
-                 render, i;
-            render = function () {
-                var values, width, height, tmp, mhandler, sp, vals;
-                if (userValues === 'html' || userValues === undefined) {
-                    vals = this.getAttribute(options.get('tagValuesAttribute'));
-                    if (vals === undefined || vals === null) {
-                        vals = $this.html();
-                    }
-                    values = vals.replace(/(^\s*<!--)|(-->\s*$)|\s+/g, '').split(',');
-                } else {
-                    values = userValues;
-                }
-
-                width = options.get('width') === 'auto' ? values.length * options.get('defaultPixelsPerValue') : options.get('width');
-                if (options.get('height') === 'auto') {
-                        // must be a better way to get the line height
-                        tmp = document.createElement('span');
-                        tmp.innerHTML = 'a';
-                        $this.html(tmp);
-                        height = $(tmp).innerHeight() || $(tmp).height();
-                        $(tmp).remove();
-                        tmp = null;
-                } else {
-                    height = options.get('height');
-                }
-
-                if (!options.get('disableInteraction')) {
-                    mhandler = $.data(this, '_jqs_mhandler');
-                    if (!mhandler) {
-                        mhandler = new MouseHandler(this, options);
-                        $.data(this, '_jqs_mhandler', mhandler);
-                    } else {
-                        mhandler.reset();
-                    }
-                } else {
-                    mhandler = false;
-                }
-
-                sp = new $.fn.sparkline[options.get('type')](this, values, options, width, height);
-
-                sp.render();
-
-                if (mhandler) {
-                    mhandler.registerSparkline(sp);
-                }
-            };
-            render.call(this);
-        });
-    };
-
-    $.fn.sparkline.defaults = getDefaults();
-
-
-    $.sparkline_display_visible = function () {
-        var el, i, pl;
-        var done = [];
-        for (i = 0, pl = pending.length; i < pl; i++) {
-            el = pending[i][0];
-                pending[i][1].call(el);
-                $.data(pending[i][0], '_jqs_pending', false);
-                done.push(i);
-        }
-        for (i = done.length; i; i--) {
-            pending.splice(done[i - 1], 1);
-        }
-    };
-
-
-    /**
-     * User option handler
-     */
-    $.fn.sparkline.options = createClass({
-        init: function (tag, userOptions) {
-            var extendedOptions, defaults, base;
-            this.userOptions = userOptions = userOptions || {};
-            this.tag = tag;
-            this.tagValCache = {};
-            defaults = $.fn.sparkline.defaults;
-            base = defaults.common;
-
-            extendedOptions = defaults[userOptions.type || base.type];
-            this.mergedOptions = $.extend({}, base, extendedOptions, userOptions);
-        },
-
-
-        get: function (key, defaultval) {
-            var result;
-            return (result = this.mergedOptions[key]) === undefined ? defaultval : result;
-        }
-    });
-
-
-    $.fn.sparkline._base = createClass({
-        disabled: false,
-
-        init: function (el, values, options, width, height) {
-            this.el = el;
-            this.$el = $(el);
-            this.values = values;
-            this.options = options;
-            this.width = width;
-            this.height = height;
-            this.currentRegion = undefined;
-        },
-
-        /**
-         * Setup the canvas
-         */
-        initTarget: function () {
-            var interactive = !this.options.get('disableInteraction');
-            if (!(this.target = this.$el.simpledraw(this.width, this.height, false, interactive))) {
-                this.disabled = true;
-            } else {
-                this.canvasWidth = this.target.pixelWidth;
-                this.canvasHeight = this.target.pixelHeight;
-            }
-        },
-
-        /**
-         * Actually render the chart to the canvas
-         */
-        render: function () {
-            if (this.disabled) {
-                this.el.innerHTML = '';
-                return false;
-            }
-            return true;
-        },
-
-        /**
-         * Return a region id for a given x/y co-ordinate
-         */
-        getRegion: function (x, y) {
-        },
-
-        /**
-         * Highlight an item based on the moused-over x,y co-ordinate
-         */
-        setRegionHighlight: function (el, x, y) {
-            var currentRegion = this.currentRegion,
-                highlightEnabled = !this.options.get('disableHighlight'),
-                newRegion;
-            if (x > this.canvasWidth || y > this.canvasHeight || x < 0 || y < 0) {
-                return null;
-            }
-            newRegion = this.getRegion(el, x, y);
-            if (currentRegion !== newRegion) {
-                if (currentRegion !== undefined && highlightEnabled) {
-                    this.removeHighlight();
-                }
-                this.currentRegion = newRegion;
-                if (newRegion !== undefined && highlightEnabled) {
-                    this.renderHighlight();
-                }
-                return true;
-            }
-            return false;
-        },
-
-        /**
-         * Reset any currently highlighted item
-         */
-        clearRegionHighlight: function () {
-            if (this.currentRegion !== undefined) {
-                this.removeHighlight();
-                this.currentRegion = undefined;
-                return true;
-            }
-            return false;
-        },
-
-        renderHighlight: function () {
-            this.changeHighlight(true);
-        },
-
-        removeHighlight: function () {
-            this.changeHighlight(false);
-        },
-
-        changeHighlight: function (highlight)  {},
-
-        /**
-         * Fetch the HTML to display as a tooltip
-         */
-        getCurrentRegionTooltip: function () {
-            var options = this.options,
-                header = '',
-                entries = [],
-                fields, formats, formatlen, fclass, text, i,
-                showFields, showFieldsKey, newFields, fv,
-                formatter, format, fieldlen, j;
-            if (this.currentRegion === undefined) {
-                return '';
-            }
-            fields = this.getCurrentRegionFields();
-            formatter = options.get('tooltipFormatter');
-            if (formatter) {
-                return formatter(this, options, fields);
-            }
-            if (options.get('tooltipChartTitle')) {
-                header += '<div class="jqs jqstitle">' + options.get('tooltipChartTitle') + '</div>\n';
-            }
-            formats = this.options.get('tooltipFormat');
-            if (!formats) {
-                return '';
-            }
-            if (!$.isArray(formats)) {
-                formats = [formats];
-            }
-            if (!$.isArray(fields)) {
-                fields = [fields];
-            }
-            showFields = this.options.get('tooltipFormatFieldlist');
-            showFieldsKey = this.options.get('tooltipFormatFieldlistKey');
-            if (showFields && showFieldsKey) {
-                // user-selected ordering of fields
-                newFields = [];
-                for (i = fields.length; i--;) {
-                    fv = fields[i][showFieldsKey];
-                    if ((j = $.inArray(fv, showFields)) != -1) {
-                        newFields[j] = fields[i];
-                    }
-                }
-                fields = newFields;
-            }
-            formatlen = formats.length;
-            fieldlen = fields.length;
-            for (i = 0; i < formatlen; i++) {
-                format = formats[i];
-                fclass = format.fclass || 'jqsfield';
-                for (j = 0; j < fieldlen; j++) {
-                    if (!fields[j].isNull || !options.get('tooltipSkipNull')) {
-                        $.extend(fields[j], {
-                            prefix: options.get('tooltipPrefix'),
-                            suffix: options.get('tooltipSuffix')
-                        });
-                        text = format.render(fields[j], options.get('tooltipValueLookups'), options);
-                        entries.push('<div class="' + fclass + '">' + text + '</div>');
-                    }
-                }
-            }
-            if (entries.length) {
-                return header + entries.join('\n');
-            }
-            return '';
-        },
-
-        getCurrentRegionFields: function () {},
-
-        calcHighlightColor: function (color, options) {
-            var highlightColor = options.get('highlightColor'),
-                lighten = options.get('highlightLighten'),
-                parse, mult, rgbnew, i;
-            if (highlightColor) {
-                return highlightColor;
-            }
-            if (lighten) {
-                // extract RGB values
-                parse = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(color) || /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(color);
-                if (parse) {
-                    rgbnew = [];
-                    mult = color.length === 4 ? 16 : 1;
-                    for (i = 0; i < 3; i++) {
-                        rgbnew[i] = clipval(Math.round(parseInt(parse[i + 1], 16) * mult * lighten), 0, 255);
-                    }
-                    return 'rgb(' + rgbnew.join(',') + ')';
-                }
-
-            }
-            return color;
-        }
-
-    });
-
-    barHighlightMixin = {
-        changeHighlight: function (highlight) {
-            var currentRegion = this.currentRegion,
-                target = this.target,
-                shapeids = this.regionShapes[currentRegion],
-                newShapes;
-            // will be null if the region value was null
-            if (shapeids) {
-                newShapes = this.renderRegion(currentRegion, highlight);
-                if ($.isArray(newShapes) || $.isArray(shapeids)) {
-                    target.replaceWithShapes(shapeids, newShapes);
-                    this.regionShapes[currentRegion] = $.map(newShapes, function (newShape) {
-                        return newShape.id;
-                    });
-                } else {
-                    target.replaceWithShape(shapeids, newShapes);
-                    this.regionShapes[currentRegion] = newShapes.id;
-                }
-            }
-        },
-
-        render: function () {
-            var values = this.values,
-                target = this.target,
-                regionShapes = this.regionShapes,
-                shapes, ids, i, j;
-
-            if (!this.cls._super.render.call(this)) {
-                return;
-            }
-            for (i = values.length; i--;) {
-                shapes = this.renderRegion(i);
-                if (shapes) {
-                    if ($.isArray(shapes)) {
-                        ids = [];
-                        for (j = shapes.length; j--;) {
-                            shapes[j].append();
-                            ids.push(shapes[j].id);
-                        }
-                        regionShapes[i] = ids;
-                    } else {
-                        shapes.append();
-                        regionShapes[i] = shapes.id; // store just the shapeid
-                    }
-                } else {
-                    // null value
-                    regionShapes[i] = null;
-                }
-            }
-            target.render();
-        }
-    };
-
-    /**
-     * Bar charts
-     */
-    $.fn.sparkline.bar = bar = createClass($.fn.sparkline._base, barHighlightMixin, {
-        type: 'bar',
-
-        init: function (el, values, options, width, height) {
-            var barWidth = parseInt(options.get('barWidth'), 10),
-                barSpacing = parseInt(options.get('barSpacing'), 10),
-                chartRangeMin = options.get('chartRangeMin'),
-                chartRangeMax = options.get('chartRangeMax'),
-                chartRangeClip = options.get('chartRangeClip'),
-                groupMin, groupMax,
-                numValues, i, vlen, range, zeroAxis, xaxisOffset, min, max, clipMin, clipMax,
-                vlist, j, slen, svals, val, yoffset, yMaxCalc, canvasHeightEf;
-            bar._super.init.call(this, el, values, options, width, height);
-
-            this.regionShapes = {};
-            this.barWidth = barWidth;
-            this.barSpacing = barSpacing;
-            this.totalBarWidth = barWidth + barSpacing;
-            this.width = width = (values.length * barWidth) + ((values.length - 1) * barSpacing);
-
-            this.initTarget();
-
-            if (chartRangeClip) {
-                clipMin = chartRangeMin === undefined ? -Infinity : chartRangeMin;
-                clipMax = chartRangeMax === undefined ? Infinity : chartRangeMax;
-            }
-
-            numValues = [];
-            for (i = 0, vlen = values.length; i < vlen; i++) {
-                    val = chartRangeClip ? clipval(values[i], clipMin, clipMax) : values[i];
-                    val = values[i] = normalizeValue(val);
-                    if (val !== null) {
-                        numValues.push(val);
-                    }
-            }
-            this.max = max = Math.max.apply(Math, numValues);
-            this.min = min = Math.min.apply(Math, numValues);
-
-            if (options.get('chartRangeMin') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMin') < min)) {
-                min = options.get('chartRangeMin');
-            }
-            if (options.get('chartRangeMax') !== undefined && (options.get('chartRangeClip') || options.get('chartRangeMax') > max)) {
-                max = options.get('chartRangeMax');
-            }
-
-            this.zeroAxis = zeroAxis = options.get('zeroAxis', true);
-            if (min <= 0 && max >= 0 && zeroAxis) {
-                xaxisOffset = 0;
-            } else if (zeroAxis == false) {
-                xaxisOffset = min;
-            } else if (min > 0) {
-                xaxisOffset = min;
-            } else {
-                xaxisOffset = max;
-            }
-            this.xaxisOffset = xaxisOffset;
-
-            range = max - min;
-
-            // as we plot zero/min values a single pixel line, we add a pixel to all other
-            // values - Reduce the effective canvas size to suit
-            this.canvasHeightEf = (zeroAxis && min < 0) ? this.canvasHeight - 2 : this.canvasHeight - 1;
-
-            if (min < xaxisOffset) {
-                yMaxCalc = max;
-                yoffset = (yMaxCalc - xaxisOffset) / range * this.canvasHeight;
-                if (yoffset !== Math.ceil(yoffset)) {
-                    this.canvasHeightEf -= 2;
-                    yoffset = Math.ceil(yoffset);
-                }
-            } else {
-                yoffset = this.canvasHeight;
-            }
-            this.yoffset = yoffset;
-
-            this.range = range;
-        },
-
-        getRegion: function (el, x, y) {
-            var result = Math.floor(x / this.totalBarWidth);
-            return (result < 0 || result >= this.values.length) ? undefined : result;
-        },
-
-        getCurrentRegionFields: function () {
-            var currentRegion = this.currentRegion,
-                values = ensureArray(this.values[currentRegion]),
-                result = [],
-                value, i;
-            for (i = values.length; i--;) {
-                value = values[i];
-                result.push({
-                    isNull: value === null,
-                    value: value,
-                    color: this.calcColor(i, value, currentRegion),
-                    offset: currentRegion
-                });
-            }
-            return result;
-        },
-
-        calcColor: function (stacknum, value, valuenum) {
-            var color, newColor,
-               options = this.options;
-                color = (value < 0) ? options.get('negBarColor') : options.get('barColor');
-            if (value === 0 && options.get('zeroColor') !== undefined) {
-                color = options.get('zeroColor');
-            }
-            return color;
-        },
-
-        /**
-         * Render bar(s) for a region
-         */
-        renderRegion: function (valuenum, highlight) {
-            var vals = this.values[valuenum],
-                options = this.options,
-                xaxisOffset = this.xaxisOffset,
-                result = [],
-                range = this.range,
-                target = this.target,
-                x = valuenum * this.totalBarWidth,
-                canvasHeightEf = this.canvasHeightEf,
-                yoffset = this.yoffset,
-                y, height, color, isNull, yoffsetNeg, i, valcount, val, minPlotted, allMin;
-
-            vals = $.isArray(vals) ? vals : [vals];
-            valcount = vals.length;
-            val = vals[0];
-            isNull = all(null, vals);
-            allMin = all(xaxisOffset, vals, true);
-
-            if (isNull) {
-                if (options.get('nullColor')) {
-                    color = highlight ? options.get('nullColor') : this.calcHighlightColor(options.get('nullColor'), options);
-                    y = (yoffset > 0) ? yoffset - 1 : yoffset;
-                    return target.drawRect(x, y, this.barWidth - 1, 0, color, color);
-                } else {
-                    return undefined;
-                }
-            }
-            yoffsetNeg = yoffset;
-            for (i = 0; i < valcount; i++) {
-                val = vals[i];
-
-                if (range > 0) {
-                    height = Math.floor(canvasHeightEf * ((Math.abs(val - xaxisOffset) / range))) + 1;
-                } else {
-                    height = 1;
-                }
-                if (val < xaxisOffset || (val === xaxisOffset && yoffset === 0)) {
-                    y = yoffsetNeg;
-                    yoffsetNeg += height;
-                } else {
-                    y = yoffset - height;
-                    yoffset -= height;
-                }
-                color = this.calcColor(i, val, valuenum);
-                if (highlight) {
-                    color = this.calcHighlightColor(color, options);
-                }
-                result.push(target.drawRect(x, y, this.barWidth - 1, height - 1, color, color));
-            }
-            if (result.length === 1) {
-                return result[0];
-            }
-            return result;
-        }
-    });
-
-    // Setup a very simple "virtual canvas" to make drawing the few shapes we need easier
-    // This is accessible as $(foo).simpledraw()
-
-    VShape = createClass({
-        init: function (target, id, type, args) {
-            this.target = target;
-            this.id = id;
-            this.type = type;
-            this.args = args;
-        },
-        append: function () {
-            this.target.appendShape(this);
-            return this;
-        }
-    });
-
-    VCanvas_base = createClass({
-        _pxregex: /(\d+)(px)?\s*$/i,
-
-        init: function (width, height, target) {
-            if (!width) {
-                return;
-            }
-            this.width = width;
-            this.height = height;
-            this.target = target;
-            this.lastShapeId = null;
-            if (target[0]) {
-                target = target[0];
-            }
-            $.data(target, '_jqs_vcanvas', this);
-        },
-
-        drawLine: function (x1, y1, x2, y2, lineColor, lineWidth) {
-            return this.drawShape([[x1, y1], [x2, y2]], lineColor, lineWidth);
-        },
-
-        drawShape: function (path, lineColor, fillColor, lineWidth) {
-            return this._genShape('Shape', [path, lineColor, fillColor, lineWidth]);
-        },
-
-        drawRect: function (x, y, width, height, lineColor, fillColor) {
-            return this._genShape('Rect', [x, y, width, height, lineColor, fillColor]);
-        },
-
-        getElement: function () {
-            return this.canvas;
-        },
-
-        /**
-         * Return the most recently inserted shape id
-         */
-        getLastShapeId: function () {
-            return this.lastShapeId;
-        },
-
-        /**
-         * Clear and reset the canvas
-         */
-        reset: function () {
-            alert('reset not implemented');
-        },
-
-        _insert: function (el, target) {
-            $(target).html(el);
-        },
-
-        /**
-         * Calculate the pixel dimensions of the canvas
-         */
-        _calculatePixelDims: function (width, height, canvas) {
-            // XXX This should probably be a configurable option
-            var match;
-            match = this._pxregex.exec(height);
-            if (match) {
-                this.pixelHeight = match[1];
-            } else {
-                this.pixelHeight = $(canvas).height();
-            }
-            match = this._pxregex.exec(width);
-            if (match) {
-                this.pixelWidth = match[1];
-            } else {
-                this.pixelWidth = $(canvas).width();
-            }
-        },
-
-        /**
-         * Generate a shape object and id for later rendering
-         */
-        _genShape: function (shapetype, shapeargs) {
-            var id = shapeCount++;
-            shapeargs.unshift(id);
-            return new VShape(this, id, shapetype, shapeargs);
-        },
-
-        /**
-         * Add a shape to the end of the render queue
-         */
-        appendShape: function (shape) {
-            alert('appendShape not implemented');
-        },
-
-        /**
-         * Replace one shape with another
-         */
-        replaceWithShape: function (shapeid, shape) {
-            alert('replaceWithShape not implemented');
-        },
-
-        /**
-         * Insert one shape after another in the render queue
-         */
-        insertAfterShape: function (shapeid, shape) {
-            alert('insertAfterShape not implemented');
-        },
-
-        /**
-         * Remove a shape from the queue
-         */
-        removeShapeId: function (shapeid) {
-            alert('removeShapeId not implemented');
-        },
-
-        /**
-         * Find a shape at the specified x/y co-ordinates
-         */
-        getShapeAt: function (el, x, y) {
-            alert('getShapeAt not implemented');
-        },
-
-        /**
-         * Render all queued shapes onto the canvas
-         */
-        render: function () {
-            alert('render not implemented');
-        }
-    });
-
-    VCanvas_canvas = createClass(VCanvas_base, {
-        init: function (width, height, target, interact) {
-            VCanvas_canvas._super.init.call(this, width, height, target);
-            this.canvas = document.createElement('canvas');
-            if (target[0]) {
-                target = target[0];
-            }
-            $.data(target, '_jqs_vcanvas', this);
-            $(this.canvas).css({ display: 'inline-block', width: width, height: height, verticalAlign: 'top' });
-            this._insert(this.canvas, target);
-            this._calculatePixelDims(width, height, this.canvas);
-            this.canvas.width = this.pixelWidth;
-            this.canvas.height = this.pixelHeight;
-            this.interact = interact;
-            this.shapes = {};
-            this.shapeseq = [];
-            this.currentTargetShapeId = undefined;
-            $(this.canvas).css({width: this.pixelWidth, height: this.pixelHeight});
-        },
-
-        _getContext: function (lineColor, fillColor, lineWidth) {
-            var context = this.canvas.getContext('2d');
-            if (lineColor !== undefined) {
-                context.strokeStyle = lineColor;
-            }
-            context.lineWidth = lineWidth === undefined ? 1 : lineWidth;
-            if (fillColor !== undefined) {
-                context.fillStyle = fillColor;
-            }
-            return context;
-        },
-
-        reset: function () {
-            var context = this._getContext();
-            context.clearRect(0, 0, this.pixelWidth, this.pixelHeight);
-            this.shapes = {};
-            this.shapeseq = [];
-            this.currentTargetShapeId = undefined;
-        },
-
-        _drawShape: function (shapeid, path, lineColor, fillColor, lineWidth) {
-            var context = this._getContext(lineColor, fillColor, lineWidth),
-                i, plen;
-            context.beginPath();
-            context.moveTo(path[0][0] + 0.5, path[0][1] + 0.5);
-            for (i = 1, plen = path.length; i < plen; i++) {
-                context.lineTo(path[i][0] + 0.5, path[i][1] + 0.5); // the 0.5 offset gives us crisp pixel-width lines
-            }
-            if (lineColor !== undefined) {
-                context.stroke();
-            }
-            if (fillColor !== undefined) {
-                context.fill();
-            }
-            if (this.targetX !== undefined && this.targetY !== undefined &&
-                context.isPointInPath(this.targetX, this.targetY)) {
-                this.currentTargetShapeId = shapeid;
-            }
-        },
-
-        _drawRect: function (shapeid, x, y, width, height, lineColor, fillColor) {
-            return this._drawShape(shapeid, [[x, y], [x + width, y], [x + width, y + height], [x, y + height], [x, y]], lineColor, fillColor);
-        },
-
-        appendShape: function (shape) {
-            this.shapes[shape.id] = shape;
-            this.shapeseq.push(shape.id);
-            this.lastShapeId = shape.id;
-            return shape.id;
-        },
-
-        replaceWithShape: function (shapeid, shape) {
-            var shapeseq = this.shapeseq,
-                i;
-            this.shapes[shape.id] = shape;
-            for (i = shapeseq.length; i--;) {
-                if (shapeseq[i] == shapeid) {
-                    shapeseq[i] = shape.id;
-                }
-            }
-            delete this.shapes[shapeid];
-        },
-
-        replaceWithShapes: function (shapeids, shapes) {
-            var shapeseq = this.shapeseq,
-                shapemap = {},
-                sid, i, first;
-
-            for (i = shapeids.length; i--;) {
-                shapemap[shapeids[i]] = true;
-            }
-            for (i = shapeseq.length; i--;) {
-                sid = shapeseq[i];
-                if (shapemap[sid]) {
-                    shapeseq.splice(i, 1);
-                    delete this.shapes[sid];
-                    first = i;
-                }
-            }
-            for (i = shapes.length; i--;) {
-                shapeseq.splice(first, 0, shapes[i].id);
-                this.shapes[shapes[i].id] = shapes[i];
-            }
-
-        },
-
-        insertAfterShape: function (shapeid, shape) {
-            var shapeseq = this.shapeseq,
-                i;
-            for (i = shapeseq.length; i--;) {
-                if (shapeseq[i] === shapeid) {
-                    shapeseq.splice(i + 1, 0, shape.id);
-                    this.shapes[shape.id] = shape;
-                    return;
-                }
-            }
-        },
-
-        removeShapeId: function (shapeid) {
-            var shapeseq = this.shapeseq,
-                i;
-            for (i = shapeseq.length; i--;) {
-                if (shapeseq[i] === shapeid) {
-                    shapeseq.splice(i, 1);
-                    break;
-                }
-            }
-            delete this.shapes[shapeid];
-        },
-
-        getShapeAt: function (el, x, y) {
-            this.targetX = x;
-            this.targetY = y;
-            this.render();
-            return this.currentTargetShapeId;
-        },
-
-        render: function () {
-            var shapeseq = this.shapeseq,
-                shapes = this.shapes,
-                shapeCount = shapeseq.length,
-                context = this._getContext(),
-                shapeid, shape, i;
-            context.clearRect(0, 0, this.pixelWidth, this.pixelHeight);
-            for (i = 0; i < shapeCount; i++) {
-                shapeid = shapeseq[i];
-                shape = shapes[shapeid];
-                this['_draw' + shape.type].apply(this, shape.args);
-            }
-            if (!this.interact) {
-                // not interactive so no need to keep the shapes array
-                this.shapes = {};
-                this.shapeseq = [];
-            }
-        }
-
-    });
-}))}(document, Math));
index 91b17e1c11344790a8a9b144a8612780ecb24ae1..f6417df92773b6439f6f8d9640637c9b8146bd75 100644 (file)
@@ -29,7 +29,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 This implementation is based heavily on the original python2 version:
 see http://www.phil-roberts.name/json-delta/ for further
 documentation.  */
-JSON_delta = {
+const JSON_delta = {
     isStrictlyEqual: function (left, right) {
        if (this.isTerminal(left) && this.isTerminal(right)) {
            return (left === right);
@@ -41,7 +41,7 @@ JSON_delta = {
            if (left.length != right.length) {
                return false;
            }
-           for (idx in left) {
+           for (let idx in left) {
                if ( ! this.isStrictlyEqual(left[idx], right[idx])) {
                    return false;
                }
@@ -55,7 +55,7 @@ JSON_delta = {
        if (ks[1].length != 0 || ks[2].length != 0) {
            return false;
        }
-       for (key in ks[0]) {
+       for (let key in ks[0]) {
            key = ks[0][key];
            if ( ! this.isStrictlyEqual(left[key], right[key])) {
                return false
@@ -75,7 +75,7 @@ JSON_delta = {
     splitDeletions: function (diff) {
        if (diff.length == 0) {return [[], diff]}
        diff.sort(function (a,b) {return b.length-a.length});
-       for (idx in diff) {
+       for (var idx in diff) {
            if (diff[idx].length === 1) {break}
        }
        return [diff.slice(0,idx), diff.slice(idx)]
@@ -109,7 +109,7 @@ JSON_delta = {
        var target = overlap;
        var targ_num = (left instanceof Array);
 
-       for (key in left) {
+       for (let key in left) {
            if (targ_num) {
                key = Number(key)
            }
@@ -121,7 +121,7 @@ JSON_delta = {
            }
            target.push(key);
        }
-       for (key in right) {
+       for (let key in right) {
            if (targ_num) {
                key = Number(key)
            }
@@ -135,12 +135,13 @@ JSON_delta = {
     commonality: function (left, right) {
        var com = 0;
        var tot = 0;
+        var elem;
        if (this.isTerminal(left) || this.isTerminal(right)) {
            return 0;
        }
 
        if ((left instanceof Array) && (right instanceof Array)) {
-           for (idx in left) {
+           for (let idx in left) {
                elem = left[idx];
                if (right.indexOf(elem) != -1) {
                    com += 1;
@@ -153,10 +154,10 @@ JSON_delta = {
        }
        else {
             var ks = this.computeKeysets(left, right);
-            o = ks[0]; l = ks[1]; r = ks[2];
+            let o = ks[0]; let l = ks[1]; let r = ks[2];
            com = o.length;
            tot = o.length + l.length + r.length;
-           for (idx in r) {
+           for (let idx in r) {
                elem = r[idx];
                if (l.indexOf(elem) == -1) {
                    tot += 1
@@ -180,18 +181,18 @@ JSON_delta = {
 
        if (common) {
            var ks = this.computeKeysets(left, right);
-           for (idx in ks[0]) {
-               okey = ks[0][idx];
+           for (let idx in ks[0]) {
+               let okey = ks[0][idx];
                if (left[okey] != right[okey]) {
                    out.push([key.concat([okey]), right[okey]]);
                }
            }
-           for (idx in ks[1]) {
-               okey = ks[1][idx];
+           for (let idx in ks[1]) {
+               let okey = ks[1][idx];
                out.push([key.concat([okey])]);
            }
-           for (idx in ks[2]) {
-               okey = ks[2][idx];
+           for (let idx in ks[2]) {
+               let okey = ks[2][idx];
                out.push([key.concat([okey]), right[okey]]);
            }
            return out
@@ -207,13 +208,13 @@ JSON_delta = {
     keysetDiff: function (left, right, key) {
        var out = [];
        var ks = this.computeKeysets(left, right);
-       for (k in ks[1]) {
+       for (let k in ks[1]) {
            out.push([key.concat(ks[1][k])]);
        }
-       for (k in ks[2]) {
+       for (let k in ks[2]) {
            out.push([key.concat(ks[2][k]), right[ks[2][k]]]);
        }
-       for (k in ks[0]) {
+       for (let k in ks[0]) {
            out = out.concat(this.diff(left[ks[0][k]], right[ks[0][k]],
                                       key.concat([ks[0][k]])))
        }
@@ -223,7 +224,7 @@ JSON_delta = {
     patchStanza: function (struc, diff) {
        // Applies the diff stanza diff to the structure struc.  Returns
        // the modified structure.
-       key = diff[0];
+       let key = diff[0];
        switch (key.length) {
        case 0:
            struc = diff[1];
@@ -242,9 +243,9 @@ JSON_delta = {
            }
            break;
        default:
-           pass_key = key.slice(1);
-           pass_struc = struc[key[0]];
-           pass_diff = [pass_key].concat(diff.slice(1));
+           let pass_key = key.slice(1);
+           let pass_struc = struc[key[0]];
+           let pass_diff = [pass_key].concat(diff.slice(1));
            struc[key[0]] = this.patchStanza(pass_struc, pass_diff);
        }
        return struc;
@@ -253,7 +254,7 @@ JSON_delta = {
     patch: function (struc, diff) {
        // Applies the sequence of diff stanzas diff to the structure
        // struc, and returns the patched structure.
-       for (stan_key in diff) {
+       for (let stan_key in diff) {
            struc = this.patchStanza(struc, diff[stan_key]);
        }
        return struc
@@ -265,7 +266,7 @@ JSON_delta = {
        var dumbdiff = [[key, right]]
        var my_diff = [];
 
-       common = this.commonality(left, right);
+       let common = this.commonality(left, right);
        if (common < 0.5) {
            my_diff = this.thisLevelDiff(left, right, key, common);
        }
index bed5a5cdf8ad3d1fdd4de3eb9cff1f8b39d17b4b..d36bf9e5117bed15911ea36263ed5084fc6f0c48 100644 (file)
@@ -1,13 +1,14 @@
 (function() {
+'use strict';
 
 /**
  * Version of this script. If the server returns a version larger than
  * this, it is a sign we should reload to upgrade ourselves.
  *
- * @type {Number}
+ * @type {number}
  * @const
  * @private */
-var SCRIPT_VERSION = 2016113008;
+let SCRIPT_VERSION = 2023122700;
 
 /**
  * The current backend URL.
@@ -15,14 +16,14 @@ var SCRIPT_VERSION = 2016113008;
  * @type {!string}
  * @private
  */
-var backend_url = "/analysis.pl";
-var backend_hash_url = "/hash";
+let backend_url = "/analysis.pl";
+let backend_hash_url = "/hash";
 
 /** @type {window.ChessBoard} @private */
-var board = null;
+let board = null;
 
 /** @type {boolean} @private */
-var board_is_animating = false;
+let board_is_animating = false;
 
 /**
  * The most recent analysis data we have from the server
@@ -30,7 +31,7 @@ var board_is_animating = false;
  *
  * @type {?Object}
  * @private */
-var current_analysis_data = null;
+let current_analysis_data = null;
 
 /**
  * If we are displaying previous analysis or from hash, this is non-null,
@@ -39,7 +40,7 @@ var current_analysis_data = null;
  * @type {?Object}
  * @private
  */
-var displayed_analysis_data = null;
+let displayed_analysis_data = null;
 
 /**
  * Games currently in progress, if any.
@@ -54,7 +55,7 @@ var displayed_analysis_data = null;
  * }>}
  * @private
  */
-var current_games = null;
+let current_games = null;
 
 /** @type {Array.<{
  *      from_col: number,
@@ -67,65 +68,78 @@ var current_games = null;
  * }>}
  * @private
  */
-var arrows = [];
+let arrows = [];
 
 /** @type {Array.<Array.<boolean>>} */
-var occupied_by_arrows = [];
+let occupied_by_arrows = [];
 
 /** Currently displayed refutation lines (on-screen).
  * Can either come from the current_analysis_data, displayed_analysis_data,
- * or hash_refutation_lines.
+ * or hash_refutation_lines (choose_displayed_refutation_lines() chooses which one).
+ *
+ * @typedef {{
+ *     score: Array,
+ *     depth: string,
+ *     pv: Array.<string>,
+ *     move: string
+ * }}
+ * @private
  */
-var refutation_lines = [];
+var RefutationLine;
 
 /** Refutation lines from current hash probe.
- *
  * If non-null, will override refutation lines from the base position.
- * Note that these are relative to display_fen, not base_fen.
+ *
+ * @type {Array.<RefutationLine>}
  */
-var hash_refutation_lines = null;
-
-/** @type {!number} @private */
-var move_num = 1;
+let hash_refutation_lines = null;
 
-/** @type {!string} @private */
-var toplay = 'W';
+/**
+ * What FEN hash_refutation_lines is relative to.
+ */
+let hash_refutation_lines_base_fen = null;
 
 /** @type {number} @private */
-var ims = 0;
+let ims = 0;
 
 /** @type {boolean} @private */
-var truncate_display_history = true;
+let truncate_display_history = true;
 
 /** @type {!string|undefined} @private */
-var highlight_from = undefined;
+let highlight_from = undefined;
 
 /** @type {!string|undefined} @private */
-var highlight_to = undefined;
+let highlight_to = undefined;
 
 /** The HTML object of the move currently being highlighted (in red).
- * @type {?jQuery}
+ * @type {?Element}
  * @private */
-var highlighted_move = null;
+let highlighted_move = null;
 
 /** Currently suggested/recommended move when dragging.
  * @type {?{from: !string, to: !string}}
  * @private
  */
-var recommended_move = null;
+let recommended_move = null;
 
 /** If reverse-dragging (dragging from the destination square to the
  * source square), the destination square.
  * @type {?string}
  * @private
  */
-var reverse_dragging_from = null;
+let reverse_dragging_from = null;
 
 /** @type {?number} @private */
-var unique = null;
+let unique = null;
+
+/** @type {?string} @private */
+let admin_password = null;
 
 /** @type {boolean} @private */
-var enable_sound = false;
+let enable_sound = false;
+
+/** @type {!number} @private */
+let delay_ms = 0;
 
 /**
  * Our best estimate of how many milliseconds we need to add to 
@@ -135,36 +149,40 @@ var enable_sound = false;
  * @type {?number}
  * @private
  */
-var client_clock_offset_ms = null;
+let client_clock_offset_ms = null;
 
-var clock_timer = null;
+let clock_timer = null;
 
 /** The current position being analyzed, represented as a FEN string.
  * Note that this is not necessarily the same as display_fen.
  * @type {?string}
  * @private
  */
-var base_fen = null;
+let base_fen = null;
 
 /** The current position on the board, represented as a FEN string.
  * Note that board.fen() does not contain e.g. who is to play.
  * @type {?string}
  * @private
  */
-var display_fen = null;
+let display_fen = null;
 
 /** @typedef {{
  *    start_fen: string,
  *    pv: Array.<string>,
- *    move_num: number,
- *    toplay: string,
  *    scores: Array<{first_move: number, score: Object}>,
  *    start_display_move_num: number
- * }} DisplayLine
+ * }}
+ *
+ * "start_display_move_num" is the (half-)move number to start displaying the PV at,
+ * i.e., the index into pv.
  *
- * "start_display_move_num" is the (half-)move number to start displaying the PV at.
- * "score" is also evaluated at this point.
+ * "score" is also evaluated at this point. scores can be empty and is frequently
+ * sparse; it's generally only really useful for history (we obviously don't know
+ * much about how the score will * move during e.g. a PV, except that a mate/TB
+ * counter might go down).
  */
+var DisplayLine;
 
 /** All PVs that we currently know of.
  *
@@ -175,61 +193,65 @@ var display_fen = null;
  * @type {Array.<DisplayLine>}
  * @private
  */
-var display_lines = [];
+let display_lines = [];
 
 /** @type {?DisplayLine} @private */
-var current_display_line = null;
+let current_display_line = null;
 
 /** @type {boolean} @private */
-var current_display_line_is_history = false;
+let current_display_line_is_history = false;
 
-/** @type {?number} @private */
-var current_display_move = null;
+/** @type {?number} @private
+ *
+ * The highlighted/used/shown move in current_display_line.pv, in terms of absolute index
+ * (not relative to e.g. the start FEN).
+ */
+let current_display_move = null;
 
 /**
  * The current backend request to get main analysis (not history), if any,
  * so that we can abort it.
  *
- * @type {?jqXHR}
+ * @type {?AbortController}
  * @private
  */
-var current_analysis_xhr = null;
+let current_analysis_xhr = null;
 
 /**
  * The current timer to fire off a request to get main analysis (not history),
  * if any, so that we can abort it.
  *
- * @type {?Number}
+ * @type {?number}
  * @private
  */
-var current_analysis_request_timer = null;
+let current_analysis_request_timer = null;
 
 /**
  * The current backend request to get historic data, if any.
  *
- * @type {?jqXHR}
+ * @type {?AbortController}
  * @private
  */
-var current_historic_xhr = null;
+let current_historic_xhr = null;
 
 /**
  * The current backend request to get hash probes, if any, so that we can abort it.
  *
- * @type {?jqXHR}
+ * @type {?AbortController}
  * @private
  */
-var current_hash_xhr = null;
+let current_hash_xhr = null;
 
 /**
  * The current timer to display hash probe information (it could be waiting on the
  * board to stop animating), if any, so that we can abort it.
  *
- * @type {?Number}
+ * @type {?number}
  * @private
  */
-var current_hash_display_timer = null;
+let current_hash_display_timer = null;
 
-var supports_html5_storage = function() {
+function supports_html5_storage() {
        try {
                return 'localStorage' in window && window['localStorage'] !== null;
        } catch (e) {
@@ -239,92 +261,117 @@ var supports_html5_storage = function() {
 
 // Make the unique token persistent so people refreshing the page won't count twice.
 // Of course, you can never fully protect against people deliberately wanting to spam.
-var get_unique = function() {
-       var use_local_storage = supports_html5_storage();
-       if (use_local_storage && localStorage['unique']) {
-               return localStorage['unique'];
+function get_unique() {
+       let use_local_storage = supports_html5_storage();
+       if (use_local_storage && window['localStorage']['unique']) {
+               return window['localStorage']['unique'];
        }
-       var unique = Math.random();
+       let unique = Math.random();
        if (use_local_storage) {
-               localStorage['unique'] = unique;
+               window['localStorage']['unique'] = unique;
        }
        return unique;
 }
 
-var request_update = function() {
+function request_update() {
        current_analysis_request_timer = null;
 
-       current_analysis_xhr = $.ajax({
-               url: backend_url + "?ims=" + ims + "&unique=" + unique
-       }).done(function(data, textstatus, xhr) {
-               sync_server_clock(xhr.getResponseHeader('Date'));
-               ims = xhr.getResponseHeader('X-RGLM');
-               var num_viewers = xhr.getResponseHeader('X-RGNV');
-               var new_data;
-               if (Array.isArray(data)) {
-                       new_data = JSON.parse(JSON.stringify(current_analysis_data));
-                       JSON_delta.patch(new_data, data);
-               } else {
-                       new_data = data;
-               }
+       let handle_err = () => {
+               // Backend error or similar. Wait ten seconds, then try again.
+               current_analysis_request_timer = setTimeout(function() { request_update(); }, 10000);
+       };
 
-               var minimum_version = xhr.getResponseHeader('X-RGMV');
-               if (minimum_version && minimum_version > SCRIPT_VERSION) {
-                       // Upgrade to latest version with a force-reload.
-                       location.reload(true);
-               }
+       current_analysis_xhr = new AbortController();
+       const signal = current_analysis_xhr.signal;
+       fetch(backend_url + "?ims=" + ims + "&unique=" + unique, { signal })
+               .then((response) => response.json().then(data => ({ok: response.ok, headers: response.headers, json: data})))  // ick
+               .then((obj) => {
+                       if (!obj.ok) {
+                               handle_err();
+                               return;
+                       }
 
-               // Verify that the PV makes sense.
-               var valid = true;
-               if (new_data['pv']) {
-                       var hiddenboard = new Chess(new_data['position']['fen']);
-                       for (var i = 0; i < new_data['pv'].length; ++i) {
-                               if (hiddenboard.move(new_data['pv'][i]) === null) {
-                                       valid = false;
-                                       break;
-                               }
+                       if (delay_ms === 0) {
+                               process_update_response(obj.json, obj.headers);
+                       } else {
+                               setTimeout(function() { process_update_response(obj.json, obj.headers); }, delay_ms);
                        }
-               }
 
-               var timeout = 100;
-               if (valid) {
-                       possibly_play_sound(current_analysis_data, new_data);
-                       current_analysis_data = new_data;
-                       update_board();
-                       update_num_viewers(num_viewers);
-               } else {
-                       console.log("Received invalid update, waiting five seconds and trying again.");
-                       setTimeout(function() { location.reload(true); }, 5000);
-               }
+                       // Next update.
+                       if (!backend_url.match(/history/)) {
+                               let timeout = 100;
+                               current_analysis_request_timer = setTimeout(function() { request_update(); }, timeout);
+                       }
+               })
+               .catch((err) => {
+                       if (err.name === 'AbortError') {
+                               // Aborted because we are switching backends. Abandon and don't retry,
+                               // because another one is already started for us.
+                       } else {
+                               console.log(err);
+                               handle_err(err);
+                       }
+               })
+               .finally(() => {
+                       // Display.
+                       document.body.style.opacity = null;
+               })
 
-               // Next update.
-               if (!backend_url.match(/history/)) {
-                       current_analysis_request_timer = setTimeout(function() { request_update(); }, timeout);
-               }
-       }).fail(function(jqXHR, textStatus, errorThrown) {
-               if (textStatus === "abort") {
-                       // Aborted because we are switching backends. Abandon and don't retry,
-                       // because another one is already started for us.
-               } else {
-                       // Backend error or similar. Wait ten seconds, then try again.
-                       current_analysis_request_timer = setTimeout(function() { request_update(); }, 10000);
+}
+
+function process_update_response(data, headers) {
+       sync_server_clock(headers.get('Date'));
+       ims = headers.get('X-RGLM');
+       let num_viewers = headers.get('X-RGNV');
+       let new_data;
+       if (Array.isArray(data)) {
+               new_data = JSON.parse(JSON.stringify(current_analysis_data));
+               JSON_delta.patch(new_data, data);
+       } else {
+               new_data = data;
+       }
+
+       let minimum_version = headers.get('X-RGMV');
+       if (minimum_version && minimum_version > SCRIPT_VERSION) {
+               // Upgrade to latest version with a force-reload.
+               location.reload(true);
+       }
+
+       // Verify that the PV makes sense.
+       let valid = true;
+       if (new_data['pv']) {
+               let hiddenboard = new Chess(new_data['position']['fen']);
+               for (let i = 0; i < new_data['pv'].length; ++i) {
+                       if (hiddenboard.move(new_data['pv'][i]) === null) {
+                               valid = false;
+                               break;
+                       }
                }
-       });
+       }
+
+       if (valid) {
+               possibly_play_sound(current_analysis_data, new_data);
+               current_analysis_data = new_data;
+               update_board();
+               update_num_viewers(num_viewers);
+       } else {
+               console.log("Received invalid update, waiting five seconds and trying again.");
+               setTimeout(function() { location.reload(true); }, 5000);
+       }
 }
 
-var possibly_play_sound = function(old_data, new_data) {
+function possibly_play_sound(old_data, new_data) {
        if (!enable_sound) {
                return;
        }
        if (old_data === null) {
                return;
        }
-       var ding = document.getElementById('ding');
+       let ding = document.getElementById('ding');
        if (ding && ding.play) {
                if (old_data['position'] && old_data['position']['fen'] &&
                    new_data['position'] && new_data['position']['fen'] &&
-                   (old_data['position']['fen'] !== new_data['position']['fen'] ||
-                    old_data['position']['move_num'] !== new_data['position']['move_num'])) {
+                   old_data['position']['fen'] !== new_data['position']['fen']) {
                        ding.play();
                }
        }
@@ -333,10 +380,10 @@ var possibly_play_sound = function(old_data, new_data) {
 /**
  * @type {!string} server_date_string
  */
-var sync_server_clock = function(server_date_string) {
-       var server_time_ms = new Date(server_date_string).getTime();
-       var client_time_ms = new Date().getTime();
-       var estimated_offset_ms = server_time_ms - client_time_ms;
+function sync_server_clock(server_date_string) {
+       let server_time_ms = new Date(server_date_string).getTime();
+       let client_time_ms = new Date().getTime();
+       let estimated_offset_ms = server_time_ms - client_time_ms;
 
        // In order not to let the noise move us too much back and forth
        // (the server only has one-second resolution anyway), we only
@@ -347,33 +394,60 @@ var sync_server_clock = function(server_date_string) {
        }
 }
 
-var clear_arrows = function() {
-       for (var i = 0; i < arrows.length; ++i) {
+function clear_arrows() {
+       for (let i = 0; i < arrows.length; ++i) {
                if (arrows[i].svg) {
-                       if (arrows[i].svg.parentElement) {
-                               arrows[i].svg.parentElement.removeChild(arrows[i].svg);
-                       }
+                       arrows[i].svg.remove();
                        delete arrows[i].svg;
                }
        }
        arrows = [];
 
        occupied_by_arrows = [];
-       for (var y = 0; y < 8; ++y) {
+       for (let y = 0; y < 8; ++y) {
                occupied_by_arrows.push([false, false, false, false, false, false, false, false]);
        }
 }
 
-var redraw_arrows = function() {
-       for (var i = 0; i < arrows.length; ++i) {
+function redraw_arrows() {
+       for (let i = 0; i < arrows.length; ++i) {
                position_arrow(arrows[i]);
        }
 }
 
+/** @param {!string} fen
+ * @return {!string}
+ *
+ * Return whose side it is to play (w or b), given a FEN.
+ */
+function find_toplay(fen) {
+       return fen.split(' ')[1];
+}
+
+/** @param {!string} fen
+ * @return {!number}
+ *
+ * Return the move clock, starting from 1. See also find_toplay().
+ */
+function find_move_num(fen) {
+       return parseInt(fen.split(' ')[5]);
+}
+
+/** @param {!string} fen
+ * @return {!number}
+ *
+ * Return the half-move clock, starting from 0 (and never resetting).
+ */
+function find_halfmove_num(fen) {
+       let move_num = find_move_num(fen);
+       let toplay = find_toplay(fen);
+       return (move_num - 1) * 2 + (toplay === 'w' ? 0 : 1);
+}
+
 /** @param {!number} x
  * @return {!number}
  */
-var sign = function(x) {
+function sign(x) {
        if (x > 0) {
                return 1;
        } else if (x < 0) {
@@ -388,11 +462,11 @@ var sign = function(x) {
  * @param {!string} to The square the arrow is to (e.g. e4).
  * @return {boolean}
  */
-var interfering_arrow = function(from, to) {
-       var from_col = from.charCodeAt(0) - "a1".charCodeAt(0);
-       var from_row = from.charCodeAt(1) - "a1".charCodeAt(1);
-       var to_col   = to.charCodeAt(0) - "a1".charCodeAt(0);
-       var to_row   = to.charCodeAt(1) - "a1".charCodeAt(1);
+function interfering_arrow(from, to) {
+       let from_col = from.charCodeAt(0) - "a1".charCodeAt(0);
+       let from_row = from.charCodeAt(1) - "a1".charCodeAt(1);
+       let to_col   = to.charCodeAt(0) - "a1".charCodeAt(0);
+       let to_row   = to.charCodeAt(1) - "a1".charCodeAt(1);
 
        occupied_by_arrows[from_row][from_col] = true;
 
@@ -403,10 +477,10 @@ var interfering_arrow = function(from, to) {
        }
 
        // Sliding piece: Check if anything except the from-square is seen before.
-       var dx = sign(to_col - from_col);
-       var dy = sign(to_row - from_row);
-       var x = from_col;
-       var y = from_row;
+       let dx = sign(to_col - from_col);
+       let dy = sign(to_row - from_row);
+       let x = from_col;
+       let y = from_row;
        do {
                x += dx;
                y += dy;
@@ -429,16 +503,16 @@ var interfering_arrow = function(from, to) {
  * @param {!number} u
  * @return {!string} The point in "x y" form, suitable for SVG paths.
  */
-var point_from_start = function(x1, y1, x2, y2, t, u) {
-       var dx = x2 - x1;
-       var dy = y2 - y1;
+function point_from_start(x1, y1, x2, y2, t, u) {
+       let dx = x2 - x1;
+       let dy = y2 - y1;
 
-       var norm = 1.0 / Math.sqrt(dx * dx + dy * dy);
+       let norm = 1.0 / Math.sqrt(dx * dx + dy * dy);
        dx *= norm;
        dy *= norm;
 
-       var x = x1 + dx * t + dy * u;
-       var y = y1 + dy * t - dx * u;
+       let x = x1 + dx * t + dy * u;
+       let y = y1 + dy * t - dx * u;
        return x + " " + y;
 }
 
@@ -452,20 +526,20 @@ var point_from_start = function(x1, y1, x2, y2, t, u) {
  * @param {!number} u
  * @return {!string} The point in "x y" form, suitable for SVG paths.
  */
-var point_from_end = function(x1, y1, x2, y2, t, u) {
-       var dx = x2 - x1;
-       var dy = y2 - y1;
+function point_from_end(x1, y1, x2, y2, t, u) {
+       let dx = x2 - x1;
+       let dy = y2 - y1;
 
-       var norm = 1.0 / Math.sqrt(dx * dx + dy * dy);
+       let norm = 1.0 / Math.sqrt(dx * dx + dy * dy);
        dx *= norm;
        dy *= norm;
 
-       var x = x2 + dx * t + dy * u;
-       var y = y2 + dy * t - dx * u;
+       let x = x2 + dx * t + dy * u;
+       let y = y2 + dy * t - dx * u;
        return x + " " + y;
 }
 
-var position_arrow = function(arrow) {
+function position_arrow(arrow) {
        if (arrow.svg) {
                if (arrow.svg.parentElement) {
                        arrow.svg.parentElement.removeChild(arrow.svg);
@@ -476,44 +550,41 @@ var position_arrow = function(arrow) {
                return;
        }
 
-       var zoom_factor = $("#board").width() / 400.0;
-       var line_width = arrow.line_width * zoom_factor;
-       var arrow_size = arrow.arrow_size * zoom_factor;
+       // We always draw as if the board is 400x400, the viewBox will adjust that for us
+       let line_width = arrow.line_width;
+       let arrow_size = arrow.arrow_size;
 
-       var square_width = $(".square-a8").width();
-       var pos, from_y, to_y, from_x, to_x;
+       let square_width = 400 / 8;
+       let from_y, to_y, from_x, to_x;
        if (board.orientation() === 'black') {
-               pos = $(".square-h1").position();
                from_y = (arrow.from_row + 0.5)*square_width;
                to_y = (arrow.to_row + 0.5)*square_width;
                from_x = (7 - arrow.from_col + 0.5)*square_width;
                to_x = (7 - arrow.to_col + 0.5)*square_width;
        } else {
-               pos = $(".square-a8").position();
                from_y = (7 - arrow.from_row + 0.5)*square_width;
                to_y = (7 - arrow.to_row + 0.5)*square_width;
                from_x = (arrow.from_col + 0.5)*square_width;
                to_x = (arrow.to_col + 0.5)*square_width;
        }
 
-       var SVG_NS = "http://www.w3.org/2000/svg";
-       var XHTML_NS = "http://www.w3.org/1999/xhtml";
-       var svg = document.createElementNS(SVG_NS, "svg");
-       svg.setAttribute("width", /** @type{number} */ ($("#board").width()));
-       svg.setAttribute("height", /** @type{number} */ ($("#board").height()));
-       svg.setAttribute("style", "position: absolute");
-       svg.setAttribute("position", "absolute");
+       let SVG_NS = "http://www.w3.org/2000/svg";
+       let XHTML_NS = "http://www.w3.org/1999/xhtml";
+       let svg = document.createElementNS(SVG_NS, "svg");
+       svg.setAttribute("width", "100%");
+       svg.setAttribute("height", "100%");
+       svg.setAttribute("viewBox", "0 0 400 400");
        svg.setAttribute("version", "1.1");
        svg.setAttribute("class", "c1");
        svg.setAttribute("xmlns", XHTML_NS);
 
-       var x1 = from_x;
-       var y1 = from_y;
-       var x2 = to_x;
-       var y2 = to_y;
+       let x1 = from_x;
+       let y1 = from_y;
+       let x2 = to_x;
+       let y2 = to_y;
 
        // Draw the line.
-       var outline = document.createElementNS(SVG_NS, "path");
+       let outline = document.createElementNS(SVG_NS, "path");
        outline.setAttribute("d", "M " + point_from_start(x1, y1, x2, y2, arrow_size / 2, 0) + " L " + point_from_end(x1, y1, x2, y2, -arrow_size / 2, 0));
        outline.setAttribute("xmlns", XHTML_NS);
        outline.setAttribute("stroke", "#666");
@@ -521,7 +592,7 @@ var position_arrow = function(arrow) {
        outline.setAttribute("fill", "none");
        svg.appendChild(outline);
 
-       var path = document.createElementNS(SVG_NS, "path");
+       let path = document.createElementNS(SVG_NS, "path");
        path.setAttribute("d", "M " + point_from_start(x1, y1, x2, y2, arrow_size / 2, 0) + " L " + point_from_end(x1, y1, x2, y2, -arrow_size / 2, 0));
        path.setAttribute("xmlns", XHTML_NS);
        path.setAttribute("stroke", arrow.fg_color);
@@ -530,7 +601,7 @@ var position_arrow = function(arrow) {
        svg.appendChild(path);
 
        // Then the arrow head.
-       var head = document.createElementNS(SVG_NS, "path");
+       let head = document.createElementNS(SVG_NS, "path");
        head.setAttribute("d",
                "M " +  point_from_end(x1, y1, x2, y2, 0, 0) +
                " L " + point_from_end(x1, y1, x2, y2, -arrow_size, -arrow_size / 2) +
@@ -543,8 +614,11 @@ var position_arrow = function(arrow) {
        head.setAttribute("fill", arrow.fg_color);
        svg.appendChild(head);
 
-       $(svg).css({ top: pos.top, left: pos.left, 'pointer-events': 'none' });
-       document.body.appendChild(svg);
+       svg.style.position = 'absolute';
+       svg.style.top = '0px';  /* Border for .board-b72b1. */
+       svg.style.left = '0px';
+       svg.style.pointerEvents = 'none';
+       document.getElementById('board').appendChild(svg);
        arrow.svg = svg;
 }
 
@@ -555,14 +629,14 @@ var position_arrow = function(arrow) {
  * @param {number} line_width
  * @param {number} arrow_size
  */
-var create_arrow = function(from_square, to_square, fg_color, line_width, arrow_size) {
-       var from_col = from_square.charCodeAt(0) - "a1".charCodeAt(0);
-       var from_row = from_square.charCodeAt(1) - "a1".charCodeAt(1);
-       var to_col   = to_square.charCodeAt(0) - "a1".charCodeAt(0);
-       var to_row   = to_square.charCodeAt(1) - "a1".charCodeAt(1);
+function create_arrow(from_square, to_square, fg_color, line_width, arrow_size) {
+       let from_col = from_square.charCodeAt(0) - "a1".charCodeAt(0);
+       let from_row = from_square.charCodeAt(1) - "a1".charCodeAt(1);
+       let to_col   = to_square.charCodeAt(0) - "a1".charCodeAt(0);
+       let to_row   = to_square.charCodeAt(1) - "a1".charCodeAt(1);
 
        // Create arrow.
-       var arrow = {
+       let arrow = {
                from_col: from_col,
                from_row: from_row,
                to_col: to_col,
@@ -576,9 +650,9 @@ var create_arrow = function(from_square, to_square, fg_color, line_width, arrow_
        arrows.push(arrow);
 }
 
-var compare_by_score = function(refutation_lines, invert, a, b) {
-       var sa = compute_score_sort_key(refutation_lines[b]['score'], refutation_lines[b]['depth'], invert);
-       var sb = compute_score_sort_key(refutation_lines[a]['score'], refutation_lines[a]['depth'], invert);
+function compare_by_score(refutation_lines, invert, a, b) {
+       let sa = compute_score_sort_key(refutation_lines[b]['score'], refutation_lines[b]['depth'], invert);
+       let sb = compute_score_sort_key(refutation_lines[a]['score'], refutation_lines[a]['depth'], invert);
        return sa - sb;
 }
 
@@ -593,15 +667,15 @@ var compare_by_score = function(refutation_lines, invert, a, b) {
  * @return {Array.<string>} The FEN representation (e.g. Ne4) of all
  *     moves, in score order.
  */
-var find_nonstupid_moves = function(data, margin, invert) {
+function find_nonstupid_moves(data, margin, invert) {
        // First of all, if there are any moves that are more than 0.5 ahead of
        // the primary move, the refutation lines are probably bunk, so just
        // kill them all. 
-       var best_score = undefined;
-       var pv_score = undefined;
-       for (var move in data['refutation_lines']) {
-               var line = data['refutation_lines'][move];
-               var score = compute_score_sort_key(line['score'], line['depth'], invert, false);
+       let best_score = undefined;
+       let pv_score = undefined;
+       for (let move in data['refutation_lines']) {
+               let line = data['refutation_lines'][move];
+               let score = compute_score_sort_key(line['score'], line['depth'], invert);
                if (move == data['pv'][0]) {
                        pv_score = score;
                }
@@ -619,15 +693,16 @@ var find_nonstupid_moves = function(data, margin, invert) {
 
        // Now find all moves that are within “margin” of the best score.
        // The PV move will always be first.
-       var moves = [];
-       for (var move in data['refutation_lines']) {
-               var line = data['refutation_lines'][move];
-               var score = compute_score_sort_key(line['score'], line['depth'], invert);
+       let moves = [];
+       for (let move in data['refutation_lines']) {
+               let line = data['refutation_lines'][move];
+               let score = compute_score_sort_key(line['score'], line['depth'], invert);
                if (move != data['pv'][0] && best_score - score <= margin) {
                        moves.push(move);
                }
        }
-       moves = moves.sort(function(a, b) { return compare_by_score(data['refutation_lines'], data['position']['toplay'] === 'B', a, b) });
+       let toplay = find_toplay(data['position']['fen']);
+       moves = moves.sort(function(a, b) { return compare_by_score(data['refutation_lines'], toplay, a, b) });
        moves.unshift(data['pv'][0]);
 
        return moves;
@@ -637,229 +712,271 @@ var find_nonstupid_moves = function(data, margin, invert) {
  * @param {number} x
  * @return {!string}
  */
-var thousands = function(x) {
+function thousands(x) {
        return String(x).split('').reverse().join('').replace(/(\d{3}\B)/g, '$1,').split('').reverse().join('');
 }
 
 /**
  * @param {!string} start_fen
  * @param {Array.<string>} pv
- * @param {number} move_num
- * @param {!string} toplay
- * @param {Array<{ first_move: integer, score: Object }>} scores
+ * @param {Array<{ first_move: number, score: Object }>} scores
  * @param {number} start_display_move_num
  * @param {number=} opt_limit
  * @param {boolean=} opt_showlast
  */
-var add_pv = function(start_fen, pv, move_num, toplay, scores, start_display_move_num, opt_limit, opt_showlast) {
+function add_pv(start_fen, pv, scores, start_display_move_num, opt_limit, opt_showlast) {
        display_lines.push({
                start_fen: start_fen,
                pv: pv,
-               move_num: parseInt(move_num),
-               toplay: toplay,
                scores: scores,
                start_display_move_num: start_display_move_num
        });
-       return print_pv(display_lines.length - 1, opt_limit, opt_showlast);
+       let splicepos = null;
+       if (scores !== null && scores.length >= 1 &&
+           scores[scores.length - 1].score !== undefined &&
+           scores[scores.length - 1].score !== null &&
+           (scores[scores.length - 1].score[0] === 'T' ||
+            scores[scores.length - 1].score[0] === 't')) {
+               splicepos = scores[scores.length - 1].score[1];
+       }
+       return print_pv(display_lines.length - 1, splicepos, opt_limit, opt_showlast);
 }
 
 /**
  * @param {number} line_num
+ * @param {?number} splicepos If non-null, where the tablebase-spliced portion of the TB starts.
  * @param {number=} opt_limit If set, show at most this number of moves.
  * @param {boolean=} opt_showlast If limit is set, show the last moves instead of the first ones.
  */
-var print_pv = function(line_num, opt_limit, opt_showlast) {
-       var display_line = display_lines[line_num];
-       var pv = display_line.pv;
-       var move_num = display_line.move_num;
-       var toplay = display_line.toplay;
+function print_pv(line_num, splicepos, opt_limit, opt_showlast) {
+       let display_line = display_lines[line_num];
+       let pv = display_line.pv;
+       let halfmove_num = find_halfmove_num(display_line.start_fen) + 2;  // From two, for simplicity.
+       let start_halfmove_num = halfmove_num;
+
+       let ret = document.createDocumentFragment();
 
        // Truncate PV at the start if needed.
-       var start_display_move_num = display_line.start_display_move_num;
-       if (start_display_move_num > 0) {
-               pv = pv.slice(start_display_move_num);
-               var to_add = start_display_move_num;
-               if (toplay === 'B') {
-                       ++move_num;
-                       toplay = 'W';
-                       --to_add;
-               }
-               if (to_add % 2 == 1) {
-                       toplay = 'B';
-                       --to_add;
-               }
-               move_num += to_add / 2;
-       }
-
-       var ret = '';
-       var i = 0;
-       if (opt_limit && opt_showlast && pv.length > opt_limit) {
-               // Truncate the PV at the beginning (instead of at the end).
-               // We assume here that toplay is 'W'. We also assume that if
-               // opt_showlast is set, then it is the history, and thus,
-               // the UI should be to expand the history.
-               ret = '(<a class="move" href="javascript:collapse_history(false)">…</a>) ';
-               i = pv.length - opt_limit;
-               if (i % 2 == 1) {
-                       ++i;
-               }
-               move_num += i / 2;
-       } else if (toplay == 'B' && pv.length > 0) {
-               var move = "<a class=\"move\" id=\"automove" + line_num + "-0\" href=\"javascript:show_line(" + line_num + ", " + 0 + ");\">" + pv[0] + "</a>";
-               ret = move_num + '. … ' + move;
-               toplay = 'W';
-               ++i;
-               ++move_num;
-       }
-       for ( ; i < pv.length; ++i) {
-               var move = "<a class=\"move\" id=\"automove" + line_num + "-" + i + "\" href=\"javascript:show_line(" + line_num + ", " + i + ");\">" + pv[i] + "</a>";
-
-               if (toplay == 'W') {
-                       if (i > opt_limit && !opt_showlast) {
-                               return ret + ' (…)';
+       let to_skip = display_line.start_display_move_num;
+       if (opt_limit && opt_showlast && pv.length - to_skip > opt_limit) {
+               // Explicit (UI-visible) truncation from the start, for the history.
+               ret.appendChild(document.createTextNode('('));
+               let link = document.createElement('a');
+               link.className = 'move';
+               link.href = 'javascript:collapse_history(false)';
+               link.textContent = '…';
+               ret.appendChild(link);
+               ret.appendChild(document.createTextNode(') '));
+               to_skip = pv.length - opt_limit;
+               to_skip += to_skip % 2;  // Make sure it starts on a white move.
+       }
+       if (to_skip > 0) {
+               pv = pv.slice(to_skip);
+               halfmove_num += to_skip;
+               if (splicepos !== null) {
+                       splicepos -= to_skip;
+                       if (splicepos < 0) {
+                               splicepos = 0;
                        }
-                       if (ret != '') {
-                               ret += ' ';
+               }
+       }
+
+       // The initial move number needs to go before any (TB: …) marker.
+       if (halfmove_num % 2 == 1) {
+               // Black move.
+               ret.appendChild(document.createTextNode((halfmove_num - 1) / 2 + '. … '));
+       } else {
+               // White move.
+               ret.appendChild(document.createTextNode(halfmove_num / 2 + '. '));
+       }
+       let in_tb = false;
+       for (let i = 0; i < pv.length; ++i, ++halfmove_num) {
+               let prefix = '';
+               if (splicepos === i) {
+                       prefix = '(TB:';
+                       in_tb = true;
+               }
+
+               if (halfmove_num % 2 == 0 && i != 0) {
+                       if (i > opt_limit && !opt_showlast) {
+                               if (in_tb) {
+                                       prefix += ')';
+                               }
+                               ret.appendChild(document.createTextNode(prefix + ' (…)'));
+                               return ret;
                        }
-                       ret += move_num + '. ' + move;
-                       ++move_num;
-                       toplay = 'B';
+                       prefix += ' ' + (halfmove_num / 2) + '. ';
                } else {
-                       ret += ' ' + move;
-                       toplay = 'W';
+                       prefix += ' ';
                }
+               ret.appendChild(document.createTextNode(prefix));
+
+               let link = document.createElement('a');
+               link.className = 'move';
+               link.setAttribute('id', 'automove' + line_num + '-' + (halfmove_num - start_halfmove_num));
+               link.textContent = pv[i];
+               link.href = 'javascript:show_line(' + line_num + ', ' + (halfmove_num - start_halfmove_num) + ');';
+               ret.appendChild(link);
+       }
+       if (in_tb) {
+               ret.appendChild(document.createTextNode(')'));
        }
        return ret;
 }
 
 /** Update the highlighted to/from squares on the board.
- * Based on the global "highlight_from" and "highlight_to" variables.
+ * Based on the global "highlight_from" and "highlight_to" letiables.
  */
-var update_board_highlight = function() {
-       $("#board").find('.square-55d63').removeClass('nonuglyhighlight');
+function update_board_highlight() {
+       document.getElementById("board").querySelectorAll('.square-55d63').forEach((square) => square.classList.remove('nonuglyhighlight'));
        if ((current_display_line === null || current_display_line_is_history) &&
            highlight_from !== undefined && highlight_to !== undefined) {
-               $("#board").find('.square-' + highlight_from).addClass('nonuglyhighlight');
-               $("#board").find('.square-' + highlight_to).addClass('nonuglyhighlight');
+               document.getElementById("board").querySelector('.square-' + highlight_from).classList.add('nonuglyhighlight');
+               document.getElementById("board").querySelector('.square-' + highlight_to).classList.add('nonuglyhighlight');
        }
 }
 
-var update_history = function() {
+function update_history() {
+       let history = document.getElementById('history');
        if (display_lines[0] === null || display_lines[0].pv.length == 0) {
-               $("#history").html("No history");
+               history.textContent = 'No history';
        } else if (truncate_display_history) {
-               $("#history").html(print_pv(0, 8, true));
+               history.replaceChildren(print_pv(0, null, 8, true));
        } else {
-               $("#history").html(
-                       '(<a class="move" href="javascript:collapse_history(true)">collapse</a>) ' +
-                       print_pv(0));
+               history.textContent = '(';
+               let link = document.createElement('a');
+               link.className = 'move';
+               link.href = 'javascript:collapse_history(true)';
+               link.textContent = 'collapse';
+               history.appendChild(link);
+               history.appendChild(document.createTextNode(') '));
+               history.append(print_pv(0, null));
        }
 }
 
 /**
  * @param {!boolean} truncate_history
  */
-var collapse_history = function(truncate_history) {
+function collapse_history(truncate_history) {
        truncate_display_history = truncate_history;
        update_history();
 }
 window['collapse_history'] = collapse_history;
 
-/** Update the HTML display of multi-PV from the global "refutation_lines".
+function choose_displayed_refutation_lines() {
+       if (hash_refutation_lines) {
+               // If we're in hash exploration, that takes precedence.
+               return [hash_refutation_lines, hash_refutation_lines_base_fen];
+       } else {
+               let data = displayed_analysis_data || current_analysis_data;
+               return [data['refutation_lines'], data['position']['fen']];
+       }
+}
+
+/** Update the HTML display of multi-PV.
  *
  * Also recreates the global "display_lines".
  */
-var update_refutation_lines = function() {
-       if (base_fen === null) {
+function update_refutation_lines() {
+       const [refutation_lines, refutation_lines_base_fen] = choose_displayed_refutation_lines();
+       if (!refutation_lines) {
                return;
        }
        if (display_lines.length > 2) {
                // Truncate so that only the history and PV is left.
                display_lines = [ display_lines[0], display_lines[1] ];
        }
-       var tbl = $("#refutationlines");
-       tbl.empty();
+       let tbl = document.getElementById("refutationlines");
+       tbl.replaceChildren();
 
        if (display_lines.length < 2) {
+               // Update the move highlight, as we've rewritten all the HTML.
+               update_move_highlight();
                return;
        }
 
        // Find out where the lines start from.
-       var base_line = [];
-       var base_scores = display_lines[1].scores;
-       var start_display_move_num = 0;
+       let base_line = [];
+       let base_scores = display_lines[1].scores;
+       let start_display_move_num = 0;
        if (hash_refutation_lines) {
                base_line = current_display_line.pv.slice(0, current_display_move + 1);
                base_scores = current_display_line.scores;
                start_display_move_num = base_line.length;
        }
 
-       var moves = [];
-       for (var move in refutation_lines) {
+       let moves = [];
+       for (let move in refutation_lines) {
                moves.push(move);
        }
 
-       var invert = (toplay === 'B');
+       let invert = (find_toplay(refutation_lines_base_fen) === 'b');
        if (current_display_line && current_display_move % 2 == 0 && !current_display_line_is_history) {
                invert = !invert;
        }
        moves = moves.sort(function(a, b) { return compare_by_score(refutation_lines, invert, a, b) });
-       for (var i = 0; i < moves.length; ++i) {
-               var line = refutation_lines[moves[i]];
+       for (let i = 0; i < moves.length; ++i) {
+               let line = refutation_lines[moves[i]];
 
-               var tr = document.createElement("tr");
+               let tr = document.createElement("tr");
 
-               var move_td = document.createElement("td");
+               let move_td = document.createElement("td");
                tr.appendChild(move_td);
-               $(move_td).addClass("move");
+               move_td.classList.add("move");
 
-               var scores = base_scores.concat([{ first_move: start_display_move_num, score: line['score'] }]);
+               let scores = base_scores.concat([{ first_move: start_display_move_num, score: line['score'] }]);
 
                if (line['pv'].length == 0) {
                        // Not found, so just make a one-move PV.
-                       var move = "<a class=\"move\" href=\"javascript:show_line(" + display_lines.length + ", " + 0 + ");\">" + line['move'] + "</a>";
-                       $(move_td).html(move);
-                       var score_td = document.createElement("td");
-
-                       $(score_td).addClass("score");
-                       $(score_td).text("—");
+                       let link = document.createElement('a');
+                       link.className = 'move';
+                       link.href = 'javascript:show_line(' + display_lines.length + ', ' + 0 + ')';
+                       link.textContent = line['move'];
+                       move_td.replaceChildren(link);
+
+                       let score_td = document.createElement("td");
+                       score_td.classList.add("score");
+                       score_td.textContent = "—";
                        tr.appendChild(score_td);
 
-                       var depth_td = document.createElement("td");
+                       let depth_td = document.createElement("td");
                        tr.appendChild(depth_td);
-                       $(depth_td).addClass("depth");
-                       $(depth_td).text("—");
+                       depth_td.classList.add("depth");
+                       depth_td.textContent = "—";
 
-                       var pv_td = document.createElement("td");
+                       let pv_td = document.createElement("td");
                        tr.appendChild(pv_td);
-                       $(pv_td).addClass("pv");
-                       $(pv_td).html(add_pv(base_fen, base_line.concat([ line['move'] ]), move_num, toplay, scores, start_display_move_num));
+                       pv_td.classList.add("pv");
+                       pv_td.append(add_pv(refutation_lines_base_fen, base_line.concat([ line['move'] ]), scores, start_display_move_num));
 
                        tbl.append(tr);
                        continue;
                }
 
-               var move = "<a class=\"move\" href=\"javascript:show_line(" + display_lines.length + ", " + 0 + ");\">" + line['move'] + "</a>";
-               $(move_td).html(move);
+               let move_link = document.createElement("a");
+               move_link.classList.add("move");
+               move_link.setAttribute("href", "javascript:show_line(" + display_lines.length + ", 0)");
+               move_link.textContent = line['move'];
+               move_td.appendChild(move_link);
 
-               var score_td = document.createElement("td");
+               let score_td = document.createElement("td");
                tr.appendChild(score_td);
-               $(score_td).addClass("score");
-               $(score_td).text(format_short_score(line['score']));
+               score_td.classList.add("score");
+               score_td.textContent = format_short_score(line['score']);
 
-               var depth_td = document.createElement("td");
+               let depth_td = document.createElement("td");
                tr.appendChild(depth_td);
-               $(depth_td).addClass("depth");
+               depth_td.classList.add("depth");
                if (line['depth'] && line['depth'] >= 0) {
-                       $(depth_td).text("d" + line['depth']);
+                       depth_td.textContent = "d" + line['depth'];
                } else {
-                       $(depth_td).text("—");
+                       depth_td.textContent = "—";
                }
 
-               var pv_td = document.createElement("td");
+               let pv_td = document.createElement("td");
                tr.appendChild(pv_td);
-               $(pv_td).addClass("pv");
-               $(pv_td).html(add_pv(base_fen, base_line.concat(line['pv']), move_num, toplay, scores, start_display_move_num, 10));
+               pv_td.classList.add("pv");
+               pv_td.append(add_pv(refutation_lines_base_fen, base_line.concat(line['pv']), scores, start_display_move_num, 10));
 
                tbl.append(tr);
        }
@@ -876,12 +993,12 @@ var update_refutation_lines = function() {
  * @param {Array.<string>} moves
  * @param {number} last_move
  */
-var chess_from = function(fen, moves, last_move) {
-       var hiddenboard = new Chess();
+function chess_from(fen, moves, last_move) {
+       let hiddenboard = new Chess();
        if (fen !== null && fen !== undefined) {
                hiddenboard.load(fen);
        }
-       for (var i = 0; i <= last_move; ++i) {
+       for (let i = 0; i <= last_move; ++i) {
                if (moves[i] === '0-0') {
                        hiddenboard.move('O-O');
                } else if (moves[i] === '0-0-0') {
@@ -893,25 +1010,25 @@ var chess_from = function(fen, moves, last_move) {
        return hiddenboard;
 }
 
-var update_game_list = function(games) {
-       $("#games").text("");
+function update_game_list(games) {
+       document.getElementById("games").textContent = "";
        if (games === null) {
                return;
        }
 
-       var games_div = document.getElementById('games');
-       for (var game_num = 0; game_num < games.length; ++game_num) {
-               var game = games[game_num];
-               var game_span = document.createElement("span");
+       let games_div = document.getElementById('games');
+       for (let game_num = 0; game_num < games.length; ++game_num) {
+               let game = games[game_num];
+               let game_span = document.createElement("span");
                game_span.setAttribute("class", "game");
 
-               var game_name = document.createTextNode(game['name']);
+               let game_name = document.createTextNode(game['name']);
                if (game['url'] === backend_url) {
                        // This game.
                        game_span.appendChild(game_name);
 
                        if (current_analysis_data && current_analysis_data['position']) {
-                               var score;
+                               let score;
                                if (current_analysis_data['position']['result']) {
                                        score = " (" + current_analysis_data['position']['result'] + ")";
                                } else {
@@ -921,12 +1038,12 @@ var update_game_list = function(games) {
                        }
                } else {
                        // Some other game.
-                       var game_a = document.createElement("a");
+                       let game_a = document.createElement("a");
                        game_a.setAttribute("href", "#" + game['id']);
                        game_a.appendChild(game_name);
                        game_span.appendChild(game_a);
 
-                       var score;
+                       let score;
                        if (game['result']) {
                                score = " (" + game['result'] + ")";
                        } else {
@@ -943,11 +1060,11 @@ var update_game_list = function(games) {
  * Try to find a running game that matches with the current hash,
  * and switch to it if we're not already displaying it.
  */
-var possibly_switch_game_from_hash = function() {
-       var history_match = window.location.hash.match(/^#history=([a-zA-Z0-9_-]+)/);
+function possibly_switch_game_from_hash() {
+       let history_match = window.location.hash.match(/^#history=([a-zA-Z0-9_-]+)/);
        if (history_match !== null) {
-               var game_id = history_match[1];
-               var fake_game = {
+               let game_id = history_match[1];
+               let fake_game = {
                        url: '/history/' + game_id + '.json',
                        hashurl: '',
                        id: 'history=' + game_id
@@ -960,8 +1077,8 @@ var possibly_switch_game_from_hash = function() {
                return;
        }
 
-       var hash = window.location.hash.replace(/^#/,'');
-       for (var i = 0; i < current_games.length; ++i) {
+       let hash = window.location.hash.replace(/^#/,'');
+       for (let i = 0; i < current_games.length; ++i) {
                if (current_games[i]['id'] === hash) {
                        if (backend_url !== current_games[i]['url']) {
                                switch_backend(current_games[i]);
@@ -975,14 +1092,14 @@ var possibly_switch_game_from_hash = function() {
  * If this is a Chess960 castling which doesn't move the king,
  * move the rook instead.
 */
-var patch_move = function(move) {
+function patch_move(move) {
        if (move === null) return null;
        if (move.from !== move.to) return move;
 
-       var f = move.rook_sq & 15;
-       var r = move.rook_sq >> 4;
-       var from = ('abcdefgh'.substring(f,f+1) + '87654321'.substring(r,r+1));
-       var to = move.to;
+       let f = move.rook_sq & 15;
+       let r = move.rook_sq >> 4;
+       let from = ('abcdefgh'.substring(f,f+1) + '87654321'.substring(r,r+1));
+       let to = move.to;
 
        if (move.to === 'g1') {
                to = 'f1';
@@ -999,9 +1116,11 @@ var patch_move = function(move) {
 
 /** Update all the HTML on the page, based on current global state.
  */
-var update_board = function() {
-       var data = displayed_analysis_data || current_analysis_data;
-       var current_data = current_analysis_data;  // Convenience alias.
+function update_board() {
+       document.body.style.opacity = null;
+
+       let data = displayed_analysis_data || current_analysis_data;
+       let current_data = current_analysis_data;  // Convenience alias.
 
        display_lines = [];
 
@@ -1009,8 +1128,8 @@ var update_board = function() {
        // unconditionally taken from current_data (we're not interested in
        // historic history).
        if (current_data['position']['history']) {
-               var start = (current_data['position'] && current_data['position']['start_fen']) ? current_data['position']['start_fen'] : 'start';
-               add_pv(start, current_data['position']['history'], 1, 'W', null, 0, 8, true);
+               let start = (current_data['position'] && current_data['position']['start_fen']) ? current_data['position']['start_fen'] : 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1';
+               add_pv(start, current_data['position']['history'], null, 0, 8, true);
        } else {
                display_lines.push(null);
        }
@@ -1027,7 +1146,7 @@ var update_board = function() {
 
        // The headline. Names are always fetched from current_data;
        // the rest can depend a bit.
-       var headline;
+       let headline;
        if (current_data &&
            current_data['position']['player_w'] && current_data['position']['player_b']) {
                headline = current_data['position']['player_w'] + '–' +
@@ -1036,51 +1155,42 @@ var update_board = function() {
                headline = 'Analysis';
        }
 
-       // Credits, where applicable. Note that we don't want the footer to change a lot
-       // when e.g. viewing history, so if any of these changed during the game,
-       // use the current one still.
-       if (current_data['using_lomonosov']) {
-               $("#lomonosov").show();
-       } else {
-               $("#lomonosov").hide();
-       }
-
        // Credits: The engine name/version.
        if (current_data['engine'] && current_data['engine']['name'] !== null) {
-               $("#engineid").text(current_data['engine']['name']);
+               document.getElementById("engineid").textContent = current_data['engine']['name'];
        }
 
        // Credits: The engine URL.
        if (current_data['engine'] && current_data['engine']['url']) {
-               $("#engineid").attr("href", current_data['engine']['url']);
+               document.getElementById("engineid").setAttribute("href", current_data['engine']['url']);
        } else {
-               $("#engineid").removeAttr("href");
+               document.getElementById("engineid").removeAttribute("href");
        }
 
        // Credits: Engine details.
        if (current_data['engine'] && current_data['engine']['details']) {
-               $("#enginedetails").text(" (" + current_data['engine']['details'] + ")");
+               document.getElementById("enginedetails").textContent = " (" + current_data['engine']['details'] + ")";
        } else {
-               $("#enginedetails").text("");
+               document.getElementById("enginedetails").textContent = "";
        }
 
        // Credits: Move source, possibly with URL.
        if (current_data['move_source'] && current_data['move_source_url']) {
-               $("#movesource").text("Moves provided by ");
-               var movesource_a = document.createElement("a");
+               document.getElementById("movesource").textContent = "Moves provided by ";
+               let movesource_a = document.createElement("a");
                movesource_a.setAttribute("href", current_data['move_source_url']);
-               var movesource_text = document.createTextNode(current_data['move_source']);
+               let movesource_text = document.createTextNode(current_data['move_source']);
                movesource_a.appendChild(movesource_text);
-               var movesource_period = document.createTextNode(".");
+               let movesource_period = document.createTextNode(".");
                document.getElementById("movesource").appendChild(movesource_a);
                document.getElementById("movesource").appendChild(movesource_period);
        } else if (current_data['move_source']) {
-               $("#movesource").text("Moves provided by " + current_data['move_source'] + ".");
+               document.getElementById("movesource").textContent = "Moves provided by " + current_data['move_source'] + ".";
        } else {
-               $("#movesource").text("");
+               document.getElementById("movesource").textContent = "";
        }
 
-       var last_move;
+       let last_move;
        if (displayed_analysis_data) {
                // Displaying some non-current position, pick out the last move
                // from the history. This will work even if the fetch failed.
@@ -1092,27 +1202,28 @@ var update_board = function() {
                }
        } else if (data['position']['last_move'] !== 'none') {
                // Find the previous move.
-               var previous_move_num, previous_toplay;
-               if (data['position']['toplay'] == 'B') {
-                       previous_move_num = data['position']['move_num'];
-                       previous_toplay = 'W';
+               let previous_move_num, previous_toplay;
+               let fen = data['position']['fen'];
+               if (find_toplay(fen) === 'b') {
+                       previous_move_num = find_move_num(fen);
+                       previous_toplay = 'w';
                } else {
-                       previous_move_num = data['position']['move_num'] - 1;
-                       previous_toplay = 'B';
+                       previous_move_num = find_move_num(fen) - 1;
+                       previous_toplay = 'b';
                }
 
                last_move = format_move_with_number(
                        data['position']['last_move'],
                        previous_move_num,
-                       previous_toplay == 'W');
+                       previous_toplay == 'w');
                headline += ' after ' + last_move;
        } else {
                last_move = null;
        }
-       $("#headline").text(headline);
+       document.getElementById("headline").textContent = headline;
 
        // The <title> contains a very brief headline.
-       var title_elems = [];
+       let title_elems = [];
        if (data['position'] && data['position']['result']) {
                title_elems.push(data['position']['result']);
        } else if (data['score']) {
@@ -1136,9 +1247,9 @@ var update_board = function() {
                // We don't have historic analysis for this position, but we
                // can reconstruct what the last move was by just replaying
                // from the start.
-               var position = (data['position'] && data['position']['start_fen']) ? data['position']['start_fen'] : null;
-               var hiddenboard = chess_from(position, current_display_line.pv, current_display_move);
-               var moves = hiddenboard.history({ verbose: true });
+               let position = (data['position'] && data['position']['start_fen']) ? data['position']['start_fen'] : null;
+               let hiddenboard = chess_from(position, current_display_line.pv, current_display_move);
+               let moves = hiddenboard.history({ verbose: true });
                last_move = moves.pop();
                highlight_from = last_move.from;
                highlight_to = last_move.to;
@@ -1148,14 +1259,13 @@ var update_board = function() {
        update_board_highlight();
 
        if (data['failed']) {
-               $("#score").text("No analysis for this move");
-               $("#pvtitle").text("PV:");
-               $("#pv").empty();
-               $("#searchstats").html("&nbsp;");
-               $("#refutationlines").empty();
-               $("#whiteclock").empty();
-               $("#blackclock").empty();
-               refutation_lines = [];
+               document.getElementById("score").textContent = "No analysis for this move";
+               document.getElementById("pvtitle").textContent = "PV:";
+               document.getElementById("pv").replaceChildren();
+               document.getElementById("searchstats").innerHTML = "&nbsp;";
+               document.getElementById("refutationlines").replaceChildren();
+               document.getElementById("whiteclock").replaceChildren();
+               document.getElementById("blackclock").replaceChildren();
                update_refutation_lines();
                clear_arrows();
                update_displayed_line();
@@ -1163,13 +1273,16 @@ var update_board = function() {
                return;
        }
 
+       if (clock_timer !== null) {
+               clearTimeout(clock_timer);
+       }
        update_clock();
 
        // The score.
        if (current_display_line && !current_display_line_is_history) {
-               var score;
+               let score;
                if (current_display_line.scores && current_display_line.scores.length > 0) {
-                       for (var i = 0; i < current_display_line.scores.length; ++i) {
+                       for (let i = 0; i < current_display_line.scores.length; ++i) {
                                if (current_display_move < current_display_line.scores[i].first_move) {
                                        break;
                                }
@@ -1177,21 +1290,19 @@ var update_board = function() {
                        }
                }
                if (score) {
-                       $("#score").text(format_long_score(score));
+                       document.getElementById("score").textContent = format_long_score(score);
                } else {
-                       $("#score").text("No score for this line");
+                       document.getElementById("score").textContent = "No score for this line";
                }
        } else if (data['score']) {
-               $("#score").text(format_long_score(data['score']));
+               document.getElementById("score").textContent = format_long_score(data['score']);
        }
 
        // The search stats.
        if (data['searchstats']) {
-               $("#searchstats").html(data['searchstats']);
-       } else if (data['tablebase'] == 1) {
-               $("#searchstats").text("Tablebase result");
+               document.getElementById("searchstats").textContent = data['searchstats'];
        } else if (data['nodes'] && data['nps'] && data['depth']) {
-               var stats = thousands(data['nodes']) + ' nodes, ' + thousands(data['nps']) + ' nodes/sec, depth ' + data['depth'] + ' ply';
+               let stats = thousands(data['nodes']) + ' nodes, ' + thousands(data['nps']) + ' nodes/sec, depth ' + data['depth'] + ' ply';
                if (data['seldepth']) {
                        stats += ' (' + data['seldepth'] + ' selective)';
                }
@@ -1203,9 +1314,12 @@ var update_board = function() {
                        }
                }
 
-               $("#searchstats").text(stats);
+               document.getElementById("searchstats").textContent = stats;
        } else {
-               $("#searchstats").text("");
+               document.getElementById("searchstats").textContent = "";
+       }
+       if (admin_password !== null) {
+               document.getElementById("searchstats").innerHTML += " | <span style=\"color: red;\">ADMIN MODE (if password is right) | <a href=\"javascript:undo_move()\">Undo move</a></span>";
        }
 
        // Update the board itself.
@@ -1213,20 +1327,21 @@ var update_board = function() {
        update_displayed_line();
 
        // Print the PV.
-       $("#pvtitle").text("PV:");
+       document.getElementById("pvtitle").textContent = "PV:";
 
-       var scores = [{ first_move: -1, score: data['score'] }];
-       $("#pv").html(add_pv(data['position']['fen'], data['pv'], data['position']['move_num'], data['position']['toplay'], scores, 0));
+       let scores = [{ first_move: -1, score: data['score'] }];
+       document.getElementById("pv").replaceChildren(add_pv(data['position']['fen'], data['pv'], scores, 0));
 
        // Update the PV arrow.
        clear_arrows();
+       let toplay = find_toplay(data['position']['fen']);
        if (data['pv'].length >= 1) {
-               var hiddenboard = new Chess(base_fen);
+               let hiddenboard = new Chess(base_fen);
 
                // draw a continuation arrow as long as it's the same piece
-               var last_to;
-               for (var i = 0; i < data['pv'].length; i += 2) {
-                       var move = patch_move(hiddenboard.move(data['pv'][i]));
+               let last_to;
+               for (let i = 0; i < data['pv'].length; i += 2) {
+                       let move = patch_move(hiddenboard.move(data['pv'][i]));
 
                        if ((i >= 2 && move.from != last_to) ||
                             interfering_arrow(move.from, move.to)) {
@@ -1237,10 +1352,10 @@ var update_board = function() {
                        hiddenboard.move(data['pv'][i + 1]);  // To keep continuity.
                }
 
-               var alt_moves = find_nonstupid_moves(data, 30, data['position']['toplay'] === 'B');
-               for (var i = 1; i < alt_moves.length && i < 3; ++i) {
+               let alt_moves = find_nonstupid_moves(data, 30, toplay === 'b');
+               for (let i = 1; i < alt_moves.length && i < 3; ++i) {
                        hiddenboard = new Chess(base_fen);
-                       var move = patch_move(hiddenboard.move(alt_moves[i]));
+                       let move = patch_move(hiddenboard.move(alt_moves[i]));
                        if (move !== null) {
                                create_arrow(move.from, move.to, '#f66', 1, 10);
                        }
@@ -1249,14 +1364,11 @@ var update_board = function() {
 
        // See if all semi-reasonable moves have only one possible response.
        if (data['pv'].length >= 2) {
-               var nonstupid_moves = find_nonstupid_moves(data, 300, data['position']['toplay'] === 'B');
-               var response;
-               {
-                       var hiddenboard = new Chess(base_fen);
-                       hiddenboard.move(data['pv'][0]);
-                       response = hiddenboard.move(data['pv'][1]);
-               }
-               for (var i = 0; i < nonstupid_moves.length; ++i) {
+               let nonstupid_moves = find_nonstupid_moves(data, 300, toplay === 'b');
+               let hiddenboard = new Chess(base_fen);
+               hiddenboard.move(data['pv'][0]);
+               let response = hiddenboard.move(data['pv'][1]);
+               for (let i = 0; i < nonstupid_moves.length; ++i) {
                        if (nonstupid_moves[i] == data['pv'][0]) {
                                // ignore the PV move for refutation lines.
                                continue;
@@ -1269,10 +1381,15 @@ var update_board = function() {
                                response = undefined;
                                break;
                        }
-                       var line = data['refutation_lines'][nonstupid_moves[i]];
+                       let line = data['refutation_lines'][nonstupid_moves[i]];
                        hiddenboard = new Chess(base_fen);
                        hiddenboard.move(line['pv'][0]);
-                       var this_response = hiddenboard.move(line['pv'][1]);
+                       let this_response = hiddenboard.move(line['pv'][1]);
+                       if (this_response === null) {
+                               console.log("BUG: ", i);
+                               console.log(data);
+                               console.log(line['pv']);
+                       }
                        if (response.from !== this_response.from || response.to !== this_response.to) {
                                // Different response depending on lines, abort.
                                response = undefined;
@@ -1285,49 +1402,44 @@ var update_board = function() {
                }
        }
 
-       // Update the refutation lines.
        base_fen = data['position']['fen'];
-       move_num = parseInt(data['position']['move_num']);
-       toplay = data['position']['toplay'];
-       refutation_lines = hash_refutation_lines || data['refutation_lines'];
        update_refutation_lines();
 
        // Update the sparkline last, since its size depends on how everything else reflowed.
        update_sparkline(data);
 }
 
-var update_sparkline = function(data) {
+function update_sparkline(data) {
+       let scorespark = document.getElementById('scoresparkcontainer');
+       scorespark.textContent = '';
        if (data && data['score_history']) {
-               var first_move_num = undefined;
-               for (var halfmove_num in data['score_history']) {
+               let first_move_num = undefined;
+               for (let halfmove_num in data['score_history']) {
                        halfmove_num = parseInt(halfmove_num);
                        if (first_move_num === undefined || halfmove_num < first_move_num) {
                                first_move_num = halfmove_num;
                        }
                }
                if (first_move_num !== undefined) {
-                       var last_move_num = data['position']['move_num'] * 2 - 3;
-                       if (data['position']['toplay'] === 'B') {
+                       let fen = data['position']['fen'];
+                       let last_move_num = find_move_num(fen) * 2 - 3;
+                       if (find_toplay(fen) === 'b') {
                                ++last_move_num;
                        }
 
                        // Possibly truncate some moves if we don't have enough width.
-                       // FIXME: Sometimes width() for #scorecontainer (and by extent,
-                       // #scoresparkcontainer) on Chrome for mobile seems to start off
-                       // at something very small, and then suddenly snap back into place.
-                       // Figure out why.
-                       var max_moves = Math.floor($("#scoresparkcontainer").width() / 5) - 5;
+                       let max_moves = Math.floor(scorespark.getBoundingClientRect().width / 5) - 3;
                        if (last_move_num - first_move_num > max_moves) {
                                first_move_num = last_move_num - max_moves;
                        }
 
-                       var min_score = -100;
-                       var max_score = 100;
-                       var last_score = null;
-                       var scores = [];
-                       for (var halfmove_num = first_move_num; halfmove_num <= last_move_num; ++halfmove_num) {
+                       let min_score = -1;
+                       let max_score = 1;
+                       let last_score = null;
+                       let scores = [];
+                       for (let halfmove_num = first_move_num; halfmove_num <= last_move_num; ++halfmove_num) {
                                if (data['score_history'][halfmove_num]) {
-                                       var score = compute_plot_score(data['score_history'][halfmove_num]);
+                                       let score = compute_plot_score(data['score_history'][halfmove_num]);
                                        last_score = score;
                                        if (score < min_score) min_score = score;
                                        if (score > max_score) max_score = score;
@@ -1335,82 +1447,144 @@ var update_sparkline = function(data) {
                                scores.push(last_score);
                        }
                        if (data['score']) {
-                               scores.push(compute_plot_score(data['score']));
+                               let score = compute_plot_score(data['score']);
+                               scores.push(score);
+                               if (score < min_score) min_score = score;
+                               if (score > max_score) max_score = score;
                        }
-                       // FIXME: at some widths, calling sparkline() seems to push
-                       // #scorecontainer under the board.
-                       $("#scorespark").sparkline(scores, {
-                               type: 'bar',
-                               zeroColor: 'gray',
-                               chartRangeMin: min_score,
-                               chartRangeMax: max_score,
-                               tooltipFormatter: function(sparkline, options, fields) {
-                                       // score_history contains the Nth _position_, but format_tooltip
-                                       // wants to format the Nth _move_; thus the -1.
-                                       return format_tooltip(data, fields[0].offset + first_move_num - 1);
+                       if (max_score - min_score < 100) {
+                               if (Math.abs(max_score) >= Math.abs(min_score)) {
+                                       max_score = min_score + 100;
+                               } else {
+                                       min_score = max_score - 100;
                                }
-                       });
-                       $('#scorespark').bind('sparklineClick', function(event) {
-                               var sparkline = event.sparklines[0];
-                               var region = sparkline.getCurrentRegionFields();
-                               if (region[0].offset !== undefined) {
-                                       show_line(0, first_move_num + region[0].offset - 1);
+                       }
+
+                       const h = scorespark.getBoundingClientRect().height;
+
+                       let base_y = h - h * min_score / (min_score - max_score);
+                       for (let i = 0; i < scores.length; ++i) {
+                               let rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
+                               //rect.setAttributeNS(null, 'stroke', "#000000");
+                               rect.setAttributeNS(null, 'x', i * 5)
+                               rect.setAttributeNS(null, 'width', 4);
+                               let extent = scores[i] * h / (max_score - min_score);
+                               if (extent > 0 && extent < 1) {
+                                       extent = 1;
+                               } else if (extent < 0 && extent > -1) {
+                                       extent = -1;
                                }
-                       });
-               } else {
-                       $("#scorespark").text("");
+
+                               let color;
+                               if (scores[i] === 0) {
+                                       color = [0.5, 0.5, 0.5];
+                                       rect.setAttributeNS(null, 'y', base_y);
+                                       rect.setAttributeNS(null, 'height', 1);
+                               } else if (scores[i] > 0) {
+                                       color = [0.2, 0.4, 0.8];
+                                       rect.setAttributeNS(null, 'y', base_y - extent);
+                                       rect.setAttributeNS(null, 'height', extent + 1);
+                               } else {
+                                       color = [1.0, 0.267, 0.267];
+                                       rect.setAttributeNS(null, 'y', base_y);
+                                       rect.setAttributeNS(null, 'height', -extent + 1);
+                               }
+                               let hlcolor = [color[0], color[1], color[2]];
+                               if (scores[i] !== 0) { 
+                                       hlcolor[0] = Math.min(hlcolor[0] * 1.4, 1.0);
+                                       hlcolor[1] = Math.min(hlcolor[1] * 1.4, 1.0);
+                                       hlcolor[2] = Math.min(hlcolor[2] * 1.4, 1.0);
+                               }
+                               rect.style.fill = 'rgb(' + color[0]*100.0 + '%, ' + color[1]*100.0 + '%, ' + color[2]*100.0 + '%)';
+
+                               // score_history contains the Nth _position_, but format_tooltip
+                               // wants to format the Nth _move_; thus the -1.
+                               const tooltip = format_tooltip(data, i + first_move_num - 1);
+                               rect.addEventListener('mouseenter', (e) => draw_hover(e, hlcolor, tooltip));
+                               rect.addEventListener('mousemove', (e) => draw_hover(e, hlcolor, tooltip));
+                               rect.addEventListener('mouseleave', (e) => hide_hover(e, color));
+                               rect.addEventListener('click', (e) => { hide_hover(e, color); show_line(0, i + first_move_num - 1) });
+                               scorespark.appendChild(rect);
+                       }
                }
-       } else {
-               $("#scorespark").text("");
        }
 }
 
+function draw_hover(e, color, tooltip) {
+       e.target.style.fill = 'rgb(' + color[0]*100.0 + '%, ' + color[1]*100.0 + '%, ' + color[2]*100.0 + '%)';
+
+       let hover = document.getElementById('sparklinehover');
+       hover.textContent = tooltip;
+       hover.style.display = 'initial';
+
+       let left = Math.max(e.pageX + 10, window.pageXOffset);
+       let top = Math.max(e.pageY - hover.getBoundingClientRect().height, window.pageYOffset);
+       left = Math.min(left, window.pageXOffset + document.documentElement.clientWidth - hover.getBoundingClientRect().width);
+
+       hover.style.left = left + 'px';
+       hover.style.top = top + 'px';
+
+}
+function hide_hover(e, color) {
+       e.target.style.fill = 'rgb(' + color[0]*100.0 + '%, ' + color[1]*100.0 + '%, ' + color[2]*100.0 + '%)';
+       document.getElementById('sparklinehover').style.display = 'none';
+}
+
 /**
  * @param {number} num_viewers
  */
-var update_num_viewers = function(num_viewers) {
+function update_num_viewers(num_viewers) {
+       let text = "";
        if (num_viewers === null) {
-               $("#numviewers").text("");
+               text = "";
        } else if (num_viewers == 1) {
-               $("#numviewers").text("You are the only current viewer");
+               text = "You are the only current viewer";
        } else {
-               $("#numviewers").text(num_viewers + " current viewers");
+               text = num_viewers + " current viewers";
        }
+       if (display_fen !== null) {
+               let counter = Math.floor(display_fen.split(" ")[4] / 2);
+               if (counter >= 20) {
+                       text = text.replace("current ", "");
+                       text += " | 50-move rule: " + counter;
+               }
+       }
+       document.getElementById("numviewers").textContent = text;
 }
 
-var update_clock = function() {
-       clearTimeout(clock_timer);
+function update_clock() {
+       clock_timer = null;
 
-       var data = displayed_analysis_data || current_analysis_data;
+       let data = displayed_analysis_data || current_analysis_data;
        if (!data) return;
 
        if (data['position']) {
-               var result = data['position']['result'];
+               let result = data['position']['result'];
                if (result === '1-0') {
-                       $("#whiteclock").text("1");
-                       $("#blackclock").text("0");
-                       $("#whiteclock").removeClass("running-clock");
-                       $("#blackclock").removeClass("running-clock");
+                       document.getElementById("whiteclock").textContent = "1";
+                       document.getElementById("blackclock").textContent = "0";
+                       document.getElementById("whiteclock").classList.remove("running-clock");
+                       document.getElementById("blackclock").classList.remove("running-clock");
                        return;
                }
                if (result === '1/2-1/2') {
-                       $("#whiteclock").text("1/2");
-                       $("#blackclock").text("1/2");
-                       $("#whiteclock").removeClass("running-clock");
-                       $("#blackclock").removeClass("running-clock");
+                       document.getElementById("whiteclock").textContent = "1/2";
+                       document.getElementById("blackclock").textContent = "1/2";
+                       document.getElementById("whiteclock").classList.remove("running-clock");
+                       document.getElementById("blackclock").classList.remove("running-clock");
                        return;
                }       
                if (result === '0-1') {
-                       $("#whiteclock").text("0");
-                       $("#blackclock").text("1");
-                       $("#whiteclock").removeClass("running-clock");
-                       $("#blackclock").removeClass("running-clock");
+                       document.getElementById("whiteclock").textContent = "0";
+                       document.getElementById("blackclock").textContent = "1";
+                       document.getElementById("whiteclock").classList.remove("running-clock");
+                       document.getElementById("blackclock").classList.remove("running-clock");
                        return;
                }
        }
 
-       var white_clock_ms = null;
-       var black_clock_ms = null;
+       let white_clock_ms = null;
+       let black_clock_ms = null;
 
        // Static clocks.
        if (data['position'] &&
@@ -1421,22 +1595,22 @@ var update_clock = function() {
        }
 
        // Dynamic clock (only one, obviously).
-       var color;
+       let color;
        if (data['position']['white_clock_target']) {
                color = "white";
-               $("#whiteclock").addClass("running-clock");
-               $("#blackclock").removeClass("running-clock");
+               document.getElementById("whiteclock").classList.add("running-clock");
+               document.getElementById("blackclock").classList.remove("running-clock");
        } else if (data['position']['black_clock_target']) {
                color = "black";
-               $("#whiteclock").removeClass("running-clock");
-               $("#blackclock").addClass("running-clock");
+               document.getElementById("whiteclock").classList.remove("running-clock");
+               document.getElementById("blackclock").classList.add("running-clock");
        } else {
-               $("#whiteclock").removeClass("running-clock");
-               $("#blackclock").removeClass("running-clock");
+               document.getElementById("whiteclock").classList.remove("running-clock");
+               document.getElementById("blackclock").classList.remove("running-clock");
        }
-       var remaining_ms;
+       let remaining_ms;
        if (color) {
-               var now = new Date().getTime() + client_clock_offset_ms;
+               let now = new Date().getTime() + client_clock_offset_ms;
                remaining_ms = data['position'][color + '_clock_target'] * 1000 - now;
                if (color === "white") {
                        white_clock_ms = remaining_ms;
@@ -1446,18 +1620,18 @@ var update_clock = function() {
        }
 
        if (white_clock_ms === null || black_clock_ms === null) {
-               $("#whiteclock").empty();
-               $("#blackclock").empty();
+               document.getElementById("whiteclock").replaceChildren();
+               document.getElementById("blackclock").replaceChildren();
                return;
        }
 
        // If either player has twenty minutes or less left, add the second counters.
        // This matches what DGT clocks do.
-       var show_seconds = (white_clock_ms < 60 * 20 * 1000 || black_clock_ms < 60 * 20 * 1000);
+       let show_seconds = (white_clock_ms < 60 * 20 * 1000 || black_clock_ms < 60 * 20 * 1000);
 
-       if (color) {
+       if (color && remaining_ms > 0) {
                // See when the clock will change next, and update right after that.
-               var next_update_ms;
+               let next_update_ms;
                if (show_seconds) {
                        next_update_ms = remaining_ms % 1000 + 100;
                } else {
@@ -1466,15 +1640,15 @@ var update_clock = function() {
                clock_timer = setTimeout(update_clock, next_update_ms);
        }
 
-       $("#whiteclock").text(format_clock(white_clock_ms, show_seconds));
-       $("#blackclock").text(format_clock(black_clock_ms, show_seconds));
+       document.getElementById("whiteclock").textContent = format_clock(white_clock_ms, show_seconds);
+       document.getElementById("blackclock").textContent = format_clock(black_clock_ms, show_seconds);
 }
 
 /**
- * @param {Number} remaining_ms
+ * @param {number} remaining_ms
  * @param {boolean} show_seconds
  */
-var format_clock = function(remaining_ms, show_seconds) {
+function format_clock(remaining_ms, show_seconds) {
        if (remaining_ms <= 0) {
                if (show_seconds) {
                        return "00:00:00";
@@ -1483,12 +1657,12 @@ var format_clock = function(remaining_ms, show_seconds) {
                }
        }
 
-       var remaining = Math.floor(remaining_ms / 1000);
-       var seconds = remaining % 60;
+       let remaining = Math.floor(remaining_ms / 1000);
+       let seconds = remaining % 60;
        remaining = (remaining - seconds) / 60;
-       var minutes = remaining % 60;
+       let minutes = remaining % 60;
        remaining = (remaining - minutes) / 60;
-       var hours = remaining;
+       let hours = remaining;
        if (show_seconds) {
                return format_2d(hours) + ":" + format_2d(minutes) + ":" + format_2d(seconds);
        } else {
@@ -1497,9 +1671,9 @@ var format_clock = function(remaining_ms, show_seconds) {
 }
 
 /**
- * @param {Number} x
+ * @param {number} x
  */
-var format_2d = function(x) {
+function format_2d(x) {
        if (x >= 10) {
                return x;
        } else {
@@ -1509,11 +1683,11 @@ var format_2d = function(x) {
 
 /**
  * @param {string} move
- * @param {Number} move_num Move number of this move.
+ * @param {number} move_num Move number of this move.
  * @param {boolean} white_to_play Whether white is to play this move.
  */
-var format_move_with_number = function(move, move_num, white_to_play) {
-       var ret;
+function format_move_with_number(move, move_num, white_to_play) {
+       let ret;
        if (white_to_play) {
                ret = move_num + '. ';
        } else {
@@ -1525,10 +1699,10 @@ var format_move_with_number = function(move, move_num, white_to_play) {
 
 /**
  * @param {string} move
- * @param {Number} halfmove_num Half-move number that is to be played,
+ * @param {number} halfmove_num Half-move number that is to be played,
  *   starting from 0.
  */
-var format_halfmove_with_number = function(move, halfmove_num) {
+function format_halfmove_with_number(move, halfmove_num) {
        return format_move_with_number(
                move,
                Math.floor(halfmove_num / 2) + 1,
@@ -1537,15 +1711,15 @@ var format_halfmove_with_number = function(move, halfmove_num) {
 
 /**
  * @param {Object} data
- * @param {Number} halfmove_num
+ * @param {number} halfmove_num
  */
-var format_tooltip = function(data, halfmove_num) {
+function format_tooltip(data, halfmove_num) {
        if (data['score_history'][halfmove_num + 1] ||
            (halfmove_num + 1) === data['position']['history'].length) {
                // Position is in the history, or it is the current position
                // (which is implicitly tacked onto the history).
-               var move;
-               var short_score;
+               let move;
+               let short_score;
                if ((halfmove_num + 1) === data['position']['history'].length) {
                        move = data['position']['last_move'];
                        short_score = format_short_score(data['score']);
@@ -1556,13 +1730,13 @@ var format_tooltip = function(data, halfmove_num) {
                if (halfmove_num === -1) {
                        return "Start position: " + short_score;
                } else {
-                       var move_with_number = format_halfmove_with_number(move, halfmove_num);
+                       let move_with_number = format_halfmove_with_number(move, halfmove_num);
                        return "After " + move_with_number + ": " + short_score;
                }
        } else {
-               for (var i = halfmove_num; i --> -1; ) {
+               for (let i = halfmove_num; i --> -1; ) {
                        if (data['score_history'][i]) {
-                               var move = data['position']['history'][i];
+                               let move = data['position']['history'][i];
                                if (i === -1) {
                                        return "[Analysis kept from start position]";
                                } else {
@@ -1573,20 +1747,11 @@ var format_tooltip = function(data, halfmove_num) {
        }
 }
 
-/**
- * @param {boolean} truncate_history
- */
-var set_truncate_history = function(truncate_history) {
-       truncate_display_history = truncate_history;
-       update_refutation_lines();
-}
-window['set_truncate_history'] = set_truncate_history;
-
 /**
  * @param {number} line_num
  * @param {number} move_num
  */
-var show_line = function(line_num, move_num) {
+function show_line(line_num, move_num) {
        if (line_num == -1) {
                current_display_line = null;
                current_display_move = null;
@@ -1599,8 +1764,8 @@ var show_line = function(line_num, move_num) {
                update_board();
                return;
        } else {
-               current_display_line = jQuery.extend({}, display_lines[line_num]);  // Shallow clone.
-               current_display_move = move_num + current_display_line.start_display_move_num;
+               current_display_line = {...display_lines[line_num]};  // Shallow clone.
+               current_display_move = move_num;
        }
        current_display_line_is_history = (line_num == 0);
 
@@ -1612,7 +1777,7 @@ var show_line = function(line_num, move_num) {
 }
 window['show_line'] = show_line;
 
-var prev_move = function() {
+function prev_move() {
        if (current_display_line &&
            current_display_move >= current_display_line.start_display_move_num) {
                --current_display_move;
@@ -1623,7 +1788,7 @@ var prev_move = function() {
 }
 window['prev_move'] = prev_move;
 
-var next_move = function() {
+function next_move() {
        if (current_display_line &&
            current_display_move < current_display_line.pv.length - 1) {
                ++current_display_move;
@@ -1634,16 +1799,16 @@ var next_move = function() {
 }
 window['next_move'] = next_move;
 
-var next_game = function() {
+function next_game() {
        if (current_games === null) {
                return;
        }
 
        // Try to find the game we are currently looking at.
-       for (var game_num = 0; game_num < current_games.length; ++game_num) {
-               var game = current_games[game_num];
+       for (let game_num = 0; game_num < current_games.length; ++game_num) {
+               let game = current_games[game_num];
                if (game['url'] === backend_url) {
-                       var next_game_num = (game_num + 1) % current_games.length;
+                       let next_game_num = (game_num + 1) % current_games.length;
                        switch_backend(current_games[next_game_num]);
                        return;
                }
@@ -1652,7 +1817,7 @@ var next_game = function() {
        // Couldn't find it; give up.
 }
 
-var update_historic_analysis = function() {
+function update_historic_analysis() {
        if (!current_display_line_is_history) {
                return;
        }
@@ -1662,85 +1827,115 @@ var update_historic_analysis = function() {
        }
 
        // Fetch old analysis for this line if it exists.
-       var hiddenboard = chess_from(current_display_line.start_fen, current_display_line.pv, current_display_move);
-       var filename = "/history/move" + (current_display_move + 1) + "-" +
+       let hiddenboard = chess_from(current_display_line.start_fen, current_display_line.pv, current_display_move);
+       let filename = "/history/move" + (current_display_move + 1) + "-" +
                hiddenboard.fen().replace(/ /g, '_').replace(/\//g, '-') + ".json";
 
-       current_historic_xhr = $.ajax({
-               url: filename
-       }).done(function(data, textstatus, xhr) {
-               displayed_analysis_data = data;
+       let handle_err = () => {
+               displayed_analysis_data = {'failed': true};
                update_board();
-       }).fail(function(jqXHR, textStatus, errorThrown) {
-               if (textStatus === "abort") {
-                       // Aborted because we are switching backends. Don't do anything;
-                       // we will already have been cleared.
-               } else {
-                       displayed_analysis_data = {'failed': true};
+       };
+
+       current_historic_xhr = new AbortController();
+       const signal = current_analysis_xhr.signal;
+       fetch(filename, { signal })
+               .then((response) => response.json().then(data => ({ok: response.ok, json: data})))  // ick
+               .then((obj) => {
+                       if (!obj.ok) {
+                               handle_err();
+                               return;
+                       }
+                       displayed_analysis_data = obj.json;
                        update_board();
-               }
-       });
+               })
+               .catch((err) => {
+                       if (err.name === 'AbortError') {
+                               // Aborted because we are switching backends. Abandon and don't retry,
+                               // because another one is already started for us.
+                       } else {
+                               console.log(err);
+                               handle_err();
+                       }
+               });
 }
 
 /**
  * @param {string} fen
  */
-var update_imbalance = function(fen) {
-       var hiddenboard = new Chess(fen);
-       var imbalance = {'k': 0, 'q': 0, 'r': 0, 'b': 0, 'n': 0, 'p': 0};
-       for (var row = 0; row < 8; ++row) {
-               for (var col = 0; col < 8; ++col) {
-                       var col_text = String.fromCharCode('a1'.charCodeAt(0) + col);
-                       var row_text = String.fromCharCode('a1'.charCodeAt(1) + row);
-                       var square = col_text + row_text;
-                       var contents = hiddenboard.get(square);
-                       if (contents !== null) {
-                               if (contents.color === 'w') {
-                                       ++imbalance[contents.type];
-                               } else {
-                                       --imbalance[contents.type];
-                               }
-                       }
+function update_imbalance(fen) {
+       let imbalance = {'k': 0, 'q': 0, 'r': 0, 'b': 0, 'n': 0, 'p': 0};
+       for (const c of fen) {
+               if (c === ' ') {
+                       // End of board
+                       break;
+               }
+               if (c != c.toUpperCase()) {
+                       --imbalance[c];
+               } else if (c != c.toLowerCase()) {
+                       ++imbalance[c.toLowerCase()];
+               }
+       }
+
+       let white_imbalance = document.getElementById('whiteimbalance');
+       let black_imbalance = document.getElementById('blackimbalance');
+       white_imbalance.textContent = '';
+       black_imbalance.textContent = '';
+       for (let piece in imbalance) {
+               for (let i = 0; i < imbalance[piece]; ++i) {
+                       let i1 = document.createElement('img');
+                       i1.src = svg_pieces['w' + piece.toUpperCase()];
+                       i1.setAttribute('alt', piece.toUpperCase());
+                       i1.classList.add('imbalance-piece');
+                       white_imbalance.appendChild(i1);
+
+                       let i2 = document.createElement('img');
+                       i2.src = svg_pieces['b' + piece.toUpperCase()];
+                       i2.setAttribute('alt', piece.toUpperCase());
+                       i2.classList.add('imbalance-inverted-piece');
+                       white_imbalance.appendChild(i2);
+               }
+               for (let i = 0; i < -imbalance[piece]; ++i) {
+                       let i1 = document.createElement('img');
+                       i1.src = svg_pieces['b' + piece.toUpperCase()];
+                       i1.setAttribute('alt', piece.toUpperCase());
+                       i1.classList.add('imbalance-piece');
+                       black_imbalance.appendChild(i1);
+
+                       let i2 = document.createElement('img');
+                       i2.src = svg_pieces['w' + piece.toUpperCase()];
+                       i2.setAttribute('alt', piece.toUpperCase());
+                       i2.classList.add('imbalance-inverted-piece');
+                       black_imbalance.appendChild(i2);
                }
        }
-       var white_imbalance = '';
-       var black_imbalance = '';
-       for (var piece in imbalance) {
-               for (var i = 0; i < imbalance[piece]; ++i) {
-                       white_imbalance += '<img src="img/chesspieces/wikipedia/w' + piece.toUpperCase() + '.png" alt="" style="width: 15px;height: 15px;">';
-               }
-               for (var i = 0; i < -imbalance[piece]; ++i) {
-                       black_imbalance += '<img src="img/chesspieces/wikipedia/b' + piece.toUpperCase() + '.png" alt="" style="width: 15px;height: 15px;">';
-               }
-       }
-       $('#whiteimbalance').html(white_imbalance);
-       $('#blackimbalance').html(black_imbalance);
 }
 
 /** Mark the currently selected move in red.
  * Also replaces the PV with the current displayed line if it's not shown
  * anywhere else on the screen.
  */
-var update_move_highlight = function() {
+function update_move_highlight() {
        if (highlighted_move !== null) {
-               highlighted_move.removeClass('highlight'); 
+               highlighted_move.classList.remove('highlight'); 
        }
        if (current_display_line) {
-               var display_line_num = find_display_line_matching_num();
+               let display_line_num = find_display_line_matching_num();
                if (display_line_num === null) {
                        // Replace the PV with the (complete) line.
-                       $("#pvtitle").text("Exploring:");
+                       document.getElementById("pvtitle").textContent = "Exploring:";
                        current_display_line.start_display_move_num = 0;
                        display_lines.push(current_display_line);
-                       $("#pv").html(print_pv(display_lines.length - 1));
+                       document.getElementById("pv").replaceChildren(print_pv(display_lines.length - 1, null));  // FIXME
                        display_line_num = display_lines.length - 1;
 
                        // Clear out the PV, so it's not selected by anything later.
                        display_lines[1].pv = [];
                }
 
-               highlighted_move = $("#automove" + display_line_num + "-" + (current_display_move - current_display_line.start_display_move_num));
-               highlighted_move.addClass('highlight');
+               highlighted_move = document.getElementById("automove" + display_line_num + "-" + current_display_move);
+               if (highlighted_move !== null) {
+                       highlighted_move.classList.add('highlight');
+               }
        }
 }
 
@@ -1751,14 +1946,14 @@ var update_move_highlight = function() {
  *
  * @return {?number}
  */
-var find_display_line_matching_num = function() {
-       for (var i = 0; i < display_lines.length; ++i) {
-               var line = display_lines[i];
+function find_display_line_matching_num() {
+       for (let i = 0; i < display_lines.length; ++i) {
+               let line = display_lines[i];
                if (line.start_display_move_num > 0) continue;
                if (current_display_line.start_fen !== line.start_fen) continue;
                if (current_display_line.pv.length !== line.pv.length) continue;
-               var ok = true;
-               for (var j = 0; j < line.pv.length; ++j) {
+               let ok = true;
+               for (let j = 0; j < line.pv.length; ++j) {
                        if (current_display_line.pv[j] !== line.pv[j]) {
                                ok = false;
                                break;
@@ -1776,31 +1971,31 @@ var find_display_line_matching_num = function() {
  * TODO: This should really be called only whenever something changes,
  * instead of all the time.
  */
-var update_displayed_line = function() {
+function update_displayed_line() {
        if (current_display_line === null) {
-               $("#linenav").hide();
-               $("#linemsg").show();
+               document.getElementById("linenav").style.display = 'none';
+               document.getElementById("linemsg").style.display = 'revert';
                display_fen = base_fen;
                set_board_position(base_fen);
                update_imbalance(base_fen);
                return;
        }
 
-       $("#linenav").show();
-       $("#linemsg").hide();
+       document.getElementById("linenav").style.display = 'revert';
+       document.getElementById("linemsg").style.display = 'none';
 
        if (current_display_move <= 0) {
-               $("#prevmove").html("Previous");
+               document.getElementById("prevmove").textContent = "Previous";
        } else {
-               $("#prevmove").html("<a href=\"javascript:prev_move();\">Previous</a></span>");
+               document.getElementById("prevmove").innerHTML = "<a href=\"javascript:prev_move();\">Previous</a></span>";
        }
        if (current_display_move == current_display_line.pv.length - 1) {
-               $("#nextmove").html("Next");
+               document.getElementById("nextmove").textContent = "Next";
        } else {
-               $("#nextmove").html("<a href=\"javascript:next_move();\">Next</a></span>");
+               document.getElementById("nextmove").innerHTML = "<a href=\"javascript:next_move();\">Next</a></span>";
        }
 
-       var hiddenboard = chess_from(current_display_line.start_fen, current_display_line.pv, current_display_move);
+       let hiddenboard = chess_from(current_display_line.start_fen, current_display_line.pv, current_display_move);
        set_board_position(hiddenboard.fen());
        if (display_fen !== hiddenboard.fen() && !current_display_line_is_history) {
                // Fire off a hash request, since we're now off the main position
@@ -1811,10 +2006,11 @@ var update_displayed_line = function() {
        update_imbalance(hiddenboard.fen());
 }
 
-var set_board_position = function(new_fen) {
+function set_board_position(new_fen) {
        board_is_animating = true;
-       var old_fen = board.fen();
-       board.position(new_fen);
+       let old_fen = board.fen();
+       let animate = old_fen !== '8/8/8/8/8/8/8/';
+       board.position(new_fen, animate);
        if (board.fen() === old_fen) {
                board_is_animating = false;
        }
@@ -1823,25 +2019,25 @@ var set_board_position = function(new_fen) {
 /**
  * @param {boolean} param_enable_sound
  */
-var set_sound = function(param_enable_sound) {
+function set_sound(param_enable_sound) {
        enable_sound = param_enable_sound;
        if (enable_sound) {
-               $("#soundon").html("<strong>On</strong>");
-               $("#soundoff").html("<a href=\"javascript:set_sound(false)\">Off</a>");
+               document.getElementById("soundon").innerHTML = "<strong>On</strong>";
+               document.getElementById("soundoff").innerHTML = "<a href=\"javascript:set_sound(false)\">Off</a>";
 
                // Seemingly at least Firefox prefers MP3 over Opus; tell it otherwise,
                // and also preload the file since the user has selected audio.
-               var ding = document.getElementById('ding');
+               let ding = document.getElementById('ding');
                if (ding && ding.canPlayType && ding.canPlayType('audio/ogg; codecs="opus"') === 'probably') {
                        ding.src = 'ding.opus';
                        ding.load();
                }
        } else {
-               $("#soundon").html("<a href=\"javascript:set_sound(true)\">On</a>");
-               $("#soundoff").html("<strong>Off</strong>");
+               document.getElementById("soundon").innerHTML = "<a href=\"javascript:set_sound(true)\">On</a>";
+               document.getElementById("soundoff").innerHTML = "<strong>Off</strong>";
        }
        if (supports_html5_storage()) {
-               localStorage['enable_sound'] = enable_sound ? 1 : 0;
+               window['localStorage']['enable_sound'] = enable_sound ? 1 : 0;
        }
 }
 window['set_sound'] = set_sound;
@@ -1849,7 +2045,7 @@ window['set_sound'] = set_sound;
 /** Send off a hash probe request to the backend.
  * @param {string} fen
  */
-var explore_hash = function(fen) {
+function explore_hash(fen) {
        // If we already have a backend response going, abort it.
        if (current_hash_xhr) {
                current_hash_xhr.abort();
@@ -1858,19 +2054,25 @@ var explore_hash = function(fen) {
                clearTimeout(current_hash_display_timer);
                current_hash_display_timer = null;
        }
-       $("#refutationlines").empty();
-       current_hash_xhr = $.ajax({
-               url: backend_hash_url + "?fen=" + fen
-       }).done(function(data, textstatus, xhr) {
-               show_explore_hash_results(data, fen);
-       });
+       document.getElementById("refutationlines").replaceChildren();
+
+       current_hash_xhr = new AbortController();
+       const signal = current_analysis_xhr.signal;
+       fetch(backend_hash_url + "?fen=" + fen, { signal })
+               .then((response) => response.json())
+               .then((data) => { show_explore_hash_results(data, fen); })
+               .catch((err) => {
+                       // Truncate the lines, since we already cleared the display.
+                       display_lines = [ display_lines[0], display_lines[1] ];
+                       update_move_highlight();
+               });
 }
 
 /** Process the JSON response from a hash probe request.
  * @param {!Object} data
  * @param {string} fen
  */
-var show_explore_hash_results = function(data, fen) {
+function show_explore_hash_results(data, fen) {
        if (board_is_animating) {
                // Updating while the animation is still going causes
                // the animation to jerk. This is pretty crude, but it will do.
@@ -1879,12 +2081,13 @@ var show_explore_hash_results = function(data, fen) {
        }
        current_hash_display_timer = null;
        hash_refutation_lines = data['lines'];
+       hash_refutation_lines_base_fen = fen;
        update_board();
 }
 
 // almost all of this stuff comes from the chessboard.js example page
-var onDragStart = function(source, piece, position, orientation) {
-       var pseudogame = new Chess(display_fen);
+function onDragStart(source, piece, position, orientation) {
+       let pseudogame = new Chess(display_fen);
        if (pseudogame.game_over() === true ||
            (pseudogame.turn() === 'w' && piece.search(/^b/) !== -1) ||
            (pseudogame.turn() === 'b' && piece.search(/^w/) !== -1)) {
@@ -1893,53 +2096,62 @@ var onDragStart = function(source, piece, position, orientation) {
 
        recommended_move = get_best_move(pseudogame, source, null, pseudogame.turn() === 'b');
        if (recommended_move) {
-               var squareEl = $('#board .square-' + recommended_move.to);
-               squareEl.addClass('highlight1-32417');
+               let squareEl = document.querySelector('#board .square-' + recommended_move.to);
+               squareEl.classList.add('highlight1-32417');
        }
        return true;
 }
 
-var mousedownSquare = function(e) {
+function mousedownSquare(e) {
+       if (!e.target || !e.target.getAttribute('data-square')) {
+               return;
+       }
+
        reverse_dragging_from = null;
-       var square = $(this).attr('data-square');
+       let square = e.target.getAttribute('data-square');
 
-       var pseudogame = new Chess(display_fen);
+       let pseudogame = new Chess(display_fen);
        if (pseudogame.game_over() === true) {
                return;
        }
 
        // If the square is empty, or has a piece of the side not to move,
        // we handle it. If not, normal piece dragging will take it.
-       var position = board.position();
+       let position = board.position();
        if (!position.hasOwnProperty(square) ||
            (pseudogame.turn() === 'w' && position[square].search(/^b/) !== -1) ||
            (pseudogame.turn() === 'b' && position[square].search(/^w/) !== -1)) {
                reverse_dragging_from = square;
                recommended_move = get_best_move(pseudogame, null, square, pseudogame.turn() === 'b');
                if (recommended_move) {
-                       var squareEl = $('#board .square-' + recommended_move.from);
-                       squareEl.addClass('highlight1-32417');
-                       squareEl = $('#board .square-' + recommended_move.to);
-                       squareEl.addClass('highlight1-32417');
+                       let squareEl = document.querySelector('#board .square-' + recommended_move.from);
+                       squareEl.classList.add('highlight1-32417');
+                       squareEl = document.querySelector('#board .square-' + recommended_move.to);
+                       squareEl.classList.add('highlight1-32417');
                }
        }
 }
 
-var mouseupSquare = function(e) {
+function mouseupSquare(e) {
+       if (!e.target || !e.target.getAttribute('data-square')) {
+               return;
+       }
        if (reverse_dragging_from === null) {
                return;
        }
-       var source = $(this).attr('data-square');
-       var target = reverse_dragging_from;
+       let source = e.target.getAttribute('data-square');
+       let target = reverse_dragging_from;
        reverse_dragging_from = null;
        if (onDrop(source, target) !== 'snapback') {
                onSnapEnd(source, target);
        }
-       $("#board").find('.square-55d63').removeClass('highlight1-32417');
+       document.getElementById("board").querySelectorAll('.square-55d63.highlight1-32417').forEach((square) => {
+               square.classList.remove('highlight1-32417');
+       });
 }
 
-var get_best_move = function(game, source, target, invert) {
-       var moves = game.moves({ verbose: true });
+function get_best_move(game, source, target, invert) {
+       let moves = game.moves({ verbose: true });
        if (source !== null) {
                moves = moves.filter(function(move) { return move.from == source; });
        }
@@ -1955,40 +2167,41 @@ var get_best_move = function(game, source, target, invert) {
 
        // More than one move. Use the display lines (if we have them)
        // to disambiguate; otherwise, we have no information.
-       var move_hash = {};
-       for (var i = 0; i < moves.length; ++i) {
+       let move_hash = {};
+       for (let i = 0; i < moves.length; ++i) {
                move_hash[moves[i].san] = moves[i];
        }
 
        // See if we're already exploring some line.
        if (current_display_line &&
            current_display_move < current_display_line.pv.length - 1) {
-               var first_move = current_display_line.pv[current_display_move + 1];
+               let first_move = current_display_line.pv[current_display_move + 1];
                if (move_hash[first_move]) {
                        return move_hash[first_move];
                }
        }
 
        // History and PV take priority over the display lines.
-       for (var i = 0; i < 2; ++i) {
-               var line = display_lines[i];
-               var first_move = line.pv[line.start_display_move_num];
+       for (let i = 0; i < 2; ++i) {
+               let line = display_lines[i];
+               let first_move = line.pv[line.start_display_move_num];
                if (move_hash[first_move]) {
                        return move_hash[first_move];
                }
        }
 
-       var best_move = null;
-       var best_move_score = null;
+       let best_move = null;
+       let best_move_score = null;
 
-       for (var move in refutation_lines) {
-               var line = refutation_lines[move];
+       let refutation_lines = choose_displayed_refutation_lines()[0];
+       for (let move in refutation_lines) {
+               let line = refutation_lines[move];
                if (!line['score']) {
                        continue;
                }
-               var first_move = line['pv'][0];
+               let first_move = line['pv'][0];
                if (move_hash[first_move]) {
-                       var score = compute_score_sort_key(line['score'], line['depth'], invert);
+                       let score = compute_score_sort_key(line['score'], line['depth'], invert);
                        if (best_move_score === null || score > best_move_score) {
                                best_move = move_hash[first_move];
                                best_move_score = score;
@@ -1998,7 +2211,7 @@ var get_best_move = function(game, source, target, invert) {
        return best_move;
 }
 
-var onDrop = function(source, target) {
+function onDrop(source, target) {
        if (source === target) {
                if (recommended_move === null) {
                        return 'snapback';
@@ -2012,8 +2225,8 @@ var onDrop = function(source, target) {
        }
 
        // see if the move is legal
-       var pseudogame = new Chess(display_fen);
-       var move = pseudogame.move({
+       let pseudogame = new Chess(display_fen);
+       let move = pseudogame.move({
                from: source,
                to: target,
                promotion: 'q' // NOTE: always promote to a queen for example simplicity
@@ -2023,19 +2236,71 @@ var onDrop = function(source, target) {
        if (move === null) return 'snapback';
 }
 
-var onSnapEnd = function(source, target) {
+/**
+ * If we are in admin mode, send this move to the backend.
+ *
+ * @param {string} fen
+ * @param {string} move
+ */
+function send_chosen_move(fen, move) {
+       if (admin_password !== null) {
+               let history = current_analysis_data['position']['history'];
+               let url = '/manual-override.pl';
+               url += '?fen=' + encodeURIComponent(fen);
+               url += '&history=' + encodeURIComponent(JSON.stringify(history));
+               url += '&move=' + encodeURIComponent(move);
+               url += '&player_w=' + encodeURIComponent(current_analysis_data['position']['player_w']);
+               url += '&player_b=' + encodeURIComponent(current_analysis_data['position']['player_b']);
+               url += '&password=' + encodeURIComponent(admin_password);
+
+               console.log(fen, history);
+               fetch(url);  // Ignore the result.
+       }
+}
+
+function undo_move() {
+       if (admin_password !== null) {
+               let history = current_analysis_data['position']['history'];
+               history = history.slice(0, history.length - 1);
+
+               let position = current_analysis_data['position']['start_fen'];
+               let hiddenboard = chess_from(position, history, history.length);
+               let fen = hiddenboard.fen();
+
+               let url = '/manual-override.pl';
+               url += '?fen=' + encodeURIComponent(fen);
+               url += '&history=' + encodeURIComponent(JSON.stringify(history));
+               url += '&move=null';
+               url += '&player_w=' + encodeURIComponent(current_analysis_data['position']['player_w']);
+               url += '&player_b=' + encodeURIComponent(current_analysis_data['position']['player_b']);
+               url += '&password=' + encodeURIComponent(admin_password);
+
+               console.log(fen, history);
+               fetch(url);  // Ignore the result.
+       }
+}
+window['undo_move'] = undo_move;
+
+function onSnapEnd(source, target) {
        if (source === target && recommended_move !== null) {
                source = recommended_move.from;
                target = recommended_move.to;
        }
        recommended_move = null;
-       var pseudogame = new Chess(display_fen);
-       var move = pseudogame.move({
+       let pseudogame = new Chess(display_fen);
+       let move = pseudogame.move({
                from: source,
                to: target,
                promotion: 'q' // NOTE: always promote to a queen for example simplicity
        });
 
+       if (admin_password !== null) {
+               send_chosen_move(display_fen, move.san);
+               return;
+       }
+
+       // Move ahead on the line we're on -- this includes history if we've
+       // gone backwards.
        if (current_display_line &&
            current_display_move < current_display_line.pv.length - 1 &&
            current_display_line.pv[current_display_move + 1] === move.san) {
@@ -2045,25 +2310,29 @@ var onSnapEnd = function(source, target) {
 
        // Walk down the displayed lines until we find one that starts with
        // this move, then select that. Note that this gives us a good priority
-       // order (history first, then PV, then multi-PV lines).
-       for (var i = 0; i < display_lines.length; ++i) {
+       // order (PV, then multi-PV lines; history was already dealt with above,
+       // as it's the only line that originates backwards).
+       for (let i = 1; i < display_lines.length; ++i) {
                if (i == 1 && current_display_line) {
                        // Do not choose PV if not on it.
                        continue;
                }
-               var line = display_lines[i];
+               let line = display_lines[i];
                if (line.pv[line.start_display_move_num] === move.san) {
-                       show_line(i, 0);
+                       show_line(i, line.start_display_move_num);
                        return;
                }
        }
 
        // Shouldn't really be here if we have hash probes, but there's really
        // nothing we can do.
+       // FIXME: Just make a new line, probably (even if we don't have hash moves).
+       // As it is, we can actually drag (but not click) such a move in the UI,
+       // but it has no effect on what we're probing.
 }
 // End of dragging-related code.
 
-var fmt_cp = function(v) {
+function fmt_cp(v) {
        if (v === 0) {
                return "0.00";
        } else if (v > 0) {
@@ -2074,18 +2343,29 @@ var fmt_cp = function(v) {
        }
 }
 
-var format_short_score = function(score) {
+function format_short_score(score) {
        if (!score) {
                return "???";
        }
-       if (score[0] === 'm') {
+       if (score[0] === 'T' || score[0] === 't') {
+               let ret = "TB\u00a0";
                if (score[2]) {  // Is a bound.
-                       return score[2] + "\u00a0M " + score[1];
+                       ret = score[2] + "\u00a0TB\u00a0";
+               }
+               if (score[0] === 'T') {
+                       return ret + Math.ceil(score[1] / 2);
                } else {
-                       return "M " + score[1];
+                       return ret + "-" + Math.ceil(score[1] / 2);
+               }
+       } else if (score[0] === 'M' || score[0] === 'm') {
+               let sign = (score[0] === 'm') ? '-' : '';
+               if (score[2]) {  // Is a bound.
+                       return score[2] + "\u00a0M " + sign + score[1];
+               } else {
+                       return "M " + sign + score[1];
                }
        } else if (score[0] === 'd') {
-               return "TB draw";
+               return "TB =0";
        } else if (score[0] === 'cp') {
                if (score[2]) {  // Is a bound.
                        return score[2] + "\u00a0" + fmt_cp(score[1]);
@@ -2096,15 +2376,33 @@ var format_short_score = function(score) {
        return null;
 }
 
-var format_long_score = function(score) {
+function format_long_score(score) {
        if (!score) {
                return "???";
        }
-       if (score[0] === 'm') {
-               if (score[1] > 0) {
+       if (score[0] === 'T') {
+               if (score[1] == 0) {
+                       return "Won for white (tablebase)";
+               } else {
+                       return "White wins in " + Math.ceil(score[1] / 2);
+               }
+       } else if (score[0] === 't') {
+               if (score[1] == -1) {
+                       return "Won for black (tablebase)";
+               } else {
+                       return "Black wins in " + Math.ceil(score[1] / 2);
+               }
+       } else if (score[0] === 'M') {
+               if (score[1] == 0) {
+                       return "White wins by checkmate";
+               } else {
                        return "White mates in " + score[1];
+               }
+       } else if (score[0] === 'm') {
+               if (score[1] == 0) {
+                       return "Black wins by checkmate";
                } else {
-                       return "Black mates in " + (-score[1]);
+                       return "Black mates in " + score[1];
                }
        } else if (score[0] === 'd') {
                return "Theoretical draw";
@@ -2114,13 +2412,11 @@ var format_long_score = function(score) {
        return null;
 }
 
-var compute_plot_score = function(score) {
-       if (score[0] === 'm') {
-               if (score[1] > 0) {
-                       return 500;
-               } else {
-                       return -500;
-               }
+function compute_plot_score(score) {
+       if (score[0] === 'M' || score[0] === 'T') {
+               return 500;
+       } else if (score[0] === 'm' || score[0] === 't') {
+               return -500;
        } else if (score[0] === 'd') {
                return 0;
        } else if (score[0] === 'cp') {
@@ -2139,22 +2435,25 @@ var compute_plot_score = function(score) {
  * @param score The score digest tuple.
  * @param {?number} depth Depth the move has been computed to, or null.
  * @param {boolean} invert Whether black is to play.
- * @param {boolean=} depth_secondary_key
  * @return {number}
  */
-var compute_score_sort_key = function(score, depth, invert, depth_secondary_key) {
-       var s;
+function compute_score_sort_key(score, depth, invert) {
+       let s;
        if (!score) {
                return -10000000;
        }
-       if (score[0] === 'm') {
-               if (score[1] > 0) {
-                       // White mates.
-                       s = 99999 - score[1];
-               } else {
-                       // Black mates (note the double negative for score[1]).
-                       s = -99999 - score[1];
-               }
+       if (score[0] === 'T') {
+               // White reaches TB win.
+               s = 89999 - score[1];
+       } else if (score[0] === 't') {
+               // Black reaches TB win.
+               s = -(89999 - score[1]);
+       } else if (score[0] === 'M') {
+               // White mates.
+               s = 99999 - score[1];
+       } else if (score[0] === 'm') {
+               // Black mates.
+               s = -(99999 - score[1]);
        } else if (score[0] === 'd') {
                s = 0;
        } else if (score[0] === 'cp') {
@@ -2162,11 +2461,7 @@ var compute_score_sort_key = function(score, depth, invert, depth_secondary_key)
        }
        if (s) {
                if (invert) s = -s;
-               if (depth_secondary_key) {
-                       return s * 200 + (depth || 0);
-               } else {
-                       return s;
-               }
+               return s;
        } else {
                return null;
        }
@@ -2175,7 +2470,7 @@ var compute_score_sort_key = function(score, depth, invert, depth_secondary_key)
 /**
  * @param {Object} game
  */
-var switch_backend = function(game) {
+function switch_backend(game) {
        // Stop looking at historic data.
        current_display_line = null;
        current_display_move = null;
@@ -2214,43 +2509,79 @@ var switch_backend = function(game) {
 window['switch_backend'] = switch_backend;
 
 window['flip'] = function() { board.flip(); redraw_arrows(); };
+window['set_delay_ms'] = function(ms) { delay_ms = ms; console.log('Delay is now ' + ms + ' ms.'); };
+
+// Mostly from Wikipedia's chess set as of October 2022, but some pieces are from
+// the 2013 version, as I like those better (and it matches the 2014 PNGs; nobody
+// really likes change, do they?). That is wK, bK, bQ. wQ is also slightly different,
+// but not enough to notice.
+const svg_pieces = {
+       'wK': 'data:image/svg+xml,<?xml version=%221.0%22 encoding=%22UTF-8%22 standalone=%22no%22?>%0A<!DOCTYPE svg PUBLIC %22-//W3C//DTD SVG 1.1//EN%22 %22http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd%22>%0A<svg xmlns=%22http://www.w3.org/2000/svg%22 version=%221.1%22 width=%2245%22 height=%2245%22><g style=%22fill:none;fill-opacity:1;fill-rule:evenodd;stroke:%23000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22><path d=%22M 22.5,11.63 L 22.5,6%22 style=%22fill:none;stroke:%23000000;stroke-linejoin:miter%22/><path d=%22M 20,8 L 25,8%22 style=%22fill:none;stroke:%23000000;stroke-linejoin:miter%22/><path d=%22M 22.5,25 C 22.5,25 27,17.5 25.5,14.5 C 25.5,14.5 24.5,12 22.5,12 C 20.5,12 19.5,14.5 19.5,14.5 C 18,17.5 22.5,25 22.5,25%22 style=%22fill:%23ffffff;stroke:%23000000;stroke-linecap:butt;stroke-linejoin:miter%22/><path d=%22M 11.5,37 C 17,40.5 27,40.5 32.5,37 L 32.5,30 C 32.5,30 41.5,25.5 38.5,19.5 C 34.5,13 25,16 22.5,23.5 L 22.5,27 L 22.5,23.5 C 19,16 9.5,13 6.5,19.5 C 3.5,25.5 11.5,29.5 11.5,29.5 L 11.5,37 z %22 style=%22fill:%23ffffff;stroke:%23000000%22/><path d=%22M 11.5,30 C 17,27 27,27 32.5,30%22 style=%22fill:none;stroke:%23000000%22/><path d=%22M 11.5,33.5 C 17,30.5 27,30.5 32.5,33.5%22 style=%22fill:none;stroke:%23000000%22/><path d=%22M 11.5,37 C 17,34 27,34 32.5,37%22 style=%22fill:none;stroke:%23000000%22/></g></svg>',
+       'wQ': 'data:image/svg+xml,<?xml version=%221.0%22 encoding=%22UTF-8%22 standalone=%22no%22?>%0A<!DOCTYPE svg PUBLIC %22-//W3C//DTD SVG 1.1//EN%22 %22http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd%22>%0A<svg xmlns=%22http://www.w3.org/2000/svg%22 version=%221.1%22 width=%2245%22 height=%2245%22><g style=%22fill:%23ffffff;stroke:%23000000;stroke-width:1.5;stroke-linejoin:round%22><path d=%22M 9,26 C 17.5,24.5 30,24.5 36,26 L 38.5,13.5 L 31,25 L 30.7,10.9 L 25.5,24.5 L 22.5,10 L 19.5,24.5 L 14.3,10.9 L 14,25 L 6.5,13.5 L 9,26 z%22/><path d=%22M 9,26 C 9,28 10.5,28 11.5,30 C 12.5,31.5 12.5,31 12,33.5 C 10.5,34.5 11,36 11,36 C 9.5,37.5 11,38.5 11,38.5 C 17.5,39.5 27.5,39.5 34,38.5 C 34,38.5 35.5,37.5 34,36 C 34,36 34.5,34.5 33,33.5 C 32.5,31 32.5,31.5 33.5,30 C 34.5,28 36,28 36,26 C 27.5,24.5 17.5,24.5 9,26 z%22/><path d=%22M 11.5,30 C 15,29 30,29 33.5,30%22 style=%22fill:none%22/><path d=%22M 12,33.5 C 18,32.5 27,32.5 33,33.5%22 style=%22fill:none%22/><circle cx=%226%22 cy=%2212%22 r=%222%22/><circle cx=%2214%22 cy=%229%22 r=%222%22/><circle cx=%2222.5%22 cy=%228%22 r=%222%22/><circle cx=%2231%22 cy=%229%22 r=%222%22/><circle cx=%2239%22 cy=%2212%22 r=%222%22/></g></svg>',
+       'wR': 'data:image/svg+xml,<?xml version=%221.0%22 encoding=%22UTF-8%22 standalone=%22no%22?>%0A<!DOCTYPE svg PUBLIC %22-//W3C//DTD SVG 1.1//EN%22 %22http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd%22>%0A<svg xmlns=%22http://www.w3.org/2000/svg%22 version=%221.1%22 width=%2245%22 height=%2245%22><g style=%22opacity:1;fill:%23ffffff;fill-opacity:1;fill-rule:evenodd;stroke:%23000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22 transform=%22translate(0,0.3)%22><path d=%22M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z %22 style=%22stroke-linecap:butt%22/><path d=%22M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z %22 style=%22stroke-linecap:butt%22/><path d=%22M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14%22 style=%22stroke-linecap:butt%22/><path d=%22M 34,14 L 31,17 L 14,17 L 11,14%22/><path d=%22M 31,17 L 31,29.5 L 14,29.5 L 14,17%22 style=%22stroke-linecap:butt;stroke-linejoin:miter%22/><path d=%22M 31,29.5 L 32.5,32 L 12.5,32 L 14,29.5%22/><path d=%22M 11,14 L 34,14%22 style=%22fill:none;stroke:%23000000;stroke-linejoin:miter%22/></g></svg>',
+       'wB': 'data:image/svg+xml,<?xml version=%221.0%22 encoding=%22UTF-8%22 standalone=%22no%22?>%0A<!DOCTYPE svg PUBLIC %22-//W3C//DTD SVG 1.1//EN%22 %22http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd%22>%0A<svg xmlns=%22http://www.w3.org/2000/svg%22 version=%221.1%22 width=%2245%22 height=%2245%22><g style=%22opacity:1;fill:none;fill-rule:evenodd;fill-opacity:1;stroke:%23000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22 transform=%22translate(0,0.6)%22><g style=%22fill:%23ffffff;stroke:%23000000;stroke-linecap:butt%22><path d=%22M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.65,38.99 6.68,38.97 6,38 C 7.35,36.54 9,36 9,36 z%22/><path d=%22M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z%22/><path d=%22M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z%22/></g><path d=%22M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18%22 style=%22fill:none;stroke:%23000000;stroke-linejoin:miter%22/></g></svg>',
+       'wN': 'data:image/svg+xml,<?xml version=%221.0%22 encoding=%22UTF-8%22 standalone=%22no%22?>%0A<!DOCTYPE svg PUBLIC %22-//W3C//DTD SVG 1.1//EN%22 %22http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd%22>%0A<svg xmlns=%22http://www.w3.org/2000/svg%22 version=%221.1%22 width=%2245%22 height=%2245%22><g style=%22opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:%23000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22 transform=%22translate(0,0.3)%22><path d=%22M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18%22 style=%22fill:%23ffffff;stroke:%23000000%22/><path d=%22M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10%22 style=%22fill:%23ffffff;stroke:%23000000%22/><path d=%22M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z%22 style=%22fill:%23000000;stroke:%23000000%22/><path d=%22M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z%22 transform=%22matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)%22 style=%22fill:%23000000;stroke:%23000000%22/></g></svg>',
+       'wP': 'data:image/svg+xml,<?xml version=%221.0%22 encoding=%22UTF-8%22 standalone=%22no%22?>%0A<!DOCTYPE svg PUBLIC %22-//W3C//DTD SVG 1.1//EN%22 %22http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd%22>%0A<svg xmlns=%22http://www.w3.org/2000/svg%22 version=%221.1%22 width=%2245%22 height=%2245%22><path d=%22m 22.5,9 c -2.21,0 -4,1.79 -4,4 0,0.89 0.29,1.71 0.78,2.38 C 17.33,16.5 16,18.59 16,21 c 0,2.03 0.94,3.84 2.41,5.03 C 15.41,27.09 11,31.58 11,39.5 H 34 C 34,31.58 29.59,27.09 26.59,26.03 28.06,24.84 29,23.03 29,21 29,18.59 27.67,16.5 25.72,15.38 26.21,14.71 26.5,13.89 26.5,13 c 0,-2.21 -1.79,-4 -4,-4 z%22 style=%22opacity:1;fill:%23ffffff;fill-opacity:1;fill-rule:nonzero;stroke:%23000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22/></svg>',
+       'bK': 'data:image/svg+xml,<?xml version=%221.0%22 encoding=%22UTF-8%22 standalone=%22no%22?>%0A<!DOCTYPE svg PUBLIC %22-//W3C//DTD SVG 1.1//EN%22 %22http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd%22>%0A<svg xmlns=%22http://www.w3.org/2000/svg%22 version=%221.1%22 width=%2245%22 height=%2245%22><g style=%22fill:none;fill-opacity:1;fill-rule:evenodd;stroke:%23000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22><path d=%22M 22.5,11.63 L 22.5,6%22 style=%22fill:none;stroke:%23000000;stroke-linejoin:miter%22 id=%22path6570%22/><path d=%22M 22.5,25 C 22.5,25 27,17.5 25.5,14.5 C 25.5,14.5 24.5,12 22.5,12 C 20.5,12 19.5,14.5 19.5,14.5 C 18,17.5 22.5,25 22.5,25%22 style=%22fill:%23000000;fill-opacity:1;stroke-linecap:butt;stroke-linejoin:miter%22/><path d=%22M 11.5,37 C 17,40.5 27,40.5 32.5,37 L 32.5,30 C 32.5,30 41.5,25.5 38.5,19.5 C 34.5,13 25,16 22.5,23.5 L 22.5,27 L 22.5,23.5 C 19,16 9.5,13 6.5,19.5 C 3.5,25.5 11.5,29.5 11.5,29.5 L 11.5,37 z %22 style=%22fill:%23000000;stroke:%23000000%22/><path d=%22M 20,8 L 25,8%22 style=%22fill:none;stroke:%23000000;stroke-linejoin:miter%22/><path d=%22M 32,29.5 C 32,29.5 40.5,25.5 38.03,19.85 C 34.15,14 25,18 22.5,24.5 L 22.51,26.6 L 22.5,24.5 C 20,18 9.906,14 6.997,19.85 C 4.5,25.5 11.85,28.85 11.85,28.85%22 style=%22fill:none;stroke:%23ffffff%22/><path d=%22M 11.5,30 C 17,27 27,27 32.5,30 M 11.5,33.5 C 17,30.5 27,30.5 32.5,33.5 M 11.5,37 C 17,34 27,34 32.5,37%22 style=%22fill:none;stroke:%23ffffff%22/></g></svg>',
+        'bQ': 'data:image/svg+xml,<?xml version=%221.0%22 encoding=%22UTF-8%22 standalone=%22no%22?>%0A<!DOCTYPE svg PUBLIC %22-//W3C//DTD SVG 1.1//EN%22 %22http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd%22>%0A<svg xmlns:svg=%22http://www.w3.org/2000/svg%22 xmlns=%22http://www.w3.org/2000/svg%22 version=%221.1%22 width=%2245%22 height=%2245%22 id=%22svg3128%22><defs/><g id=%22layer1%22><path d=%22M 8 12 A 2 2 0 1 1 4,12 A 2 2 0 1 1 8 12 z%22 style=%22opacity:1;fill:%23000000;fill-opacity:1;stroke:%23000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22 id=%22path5571%22/><path d=%22M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z%22 transform=%22translate(15.5,-5.5)%22 style=%22opacity:1;fill:%23000000;fill-opacity:1;stroke:%23000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22 id=%22path5573%22/><path d=%22M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z%22 transform=%22translate(32,-1)%22 style=%22opacity:1;fill:%23000000;fill-opacity:1;stroke:%23000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22 id=%22path5575%22/><path d=%22M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z%22 transform=%22translate(7,-4.5)%22 style=%22opacity:1;fill:%23000000;fill-opacity:1;stroke:%23000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22 id=%22path5577%22/><path d=%22M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z%22 transform=%22translate(24,-4)%22 style=%22opacity:1;fill:%23000000;fill-opacity:1;stroke:%23000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22 id=%22path5579%22/><path d=%22M 9,26 C 17.5,24.5 30,24.5 36,26 L 38,14 L 31,25 L 31,11 L 25.5,24.5 L 22.5,9.5 L 19.5,24.5 L 14,10.5 L 14,25 L 7,14 L 9,26 z %22 style=%22fill:%23000000;fill-opacity:1;fill-rule:evenodd;stroke:%23000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:round;stroke-opacity:1%22 id=%22path5581%22/><path d=%22M 9,26 C 9,28 10.5,28 11.5,30 C 12.5,31.5 12.5,31 12,33.5 C 10.5,34.5 10.5,36 10.5,36 C 9,37.5 11,38.5 11,38.5 C 17.5,39.5 27.5,39.5 34,38.5 C 34,38.5 35.5,37.5 34,36 C 34,36 34.5,34.5 33,33.5 C 32.5,31 32.5,31.5 33.5,30 C 34.5,28 36,28 36,26 C 27.5,24.5 17.5,24.5 9,26 z %22 style=%22fill:%23000000;fill-opacity:1;fill-rule:evenodd;stroke:%23000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:round;stroke-opacity:1%22 id=%22path5583%22/><path d=%22M 11.5,30 C 15,29 30,29 33.5,30%22 style=%22fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:%23ffffff;stroke-width:1px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1%22 id=%22path5585%22/><path d=%22M 12,33.5 C 18,32.5 27,32.5 33,33.5%22 style=%22fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:%23ffffff;stroke-width:1px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1%22 id=%22path5587%22/><path d=%22M 10.5,36 C 15.5,35 29,35 34,36%22 style=%22fill:none;fill-opacity:0.75;fill-rule:evenodd;stroke:%23ffffff;stroke-width:1px;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1%22 id=%22path5589%22/></g></svg>',
+       'bR': 'data:image/svg+xml,<?xml version=%221.0%22 encoding=%22UTF-8%22 standalone=%22no%22?>%0A<!DOCTYPE svg PUBLIC %22-//W3C//DTD SVG 1.1//EN%22 %22http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd%22>%0A<svg xmlns=%22http://www.w3.org/2000/svg%22 version=%221.1%22 width=%2245%22 height=%2245%22><g style=%22opacity:1;fill:%23000000;fill-opacity:1;fill-rule:evenodd;stroke:%23000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22 transform=%22translate(0,0.3)%22><path d=%22M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z %22 style=%22stroke-linecap:butt%22/><path d=%22M 12.5,32 L 14,29.5 L 31,29.5 L 32.5,32 L 12.5,32 z %22 style=%22stroke-linecap:butt%22/><path d=%22M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z %22 style=%22stroke-linecap:butt%22/><path d=%22M 14,29.5 L 14,16.5 L 31,16.5 L 31,29.5 L 14,29.5 z %22 style=%22stroke-linecap:butt;stroke-linejoin:miter%22/><path d=%22M 14,16.5 L 11,14 L 34,14 L 31,16.5 L 14,16.5 z %22 style=%22stroke-linecap:butt%22/><path d=%22M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14 L 11,14 z %22 style=%22stroke-linecap:butt%22/><path d=%22M 12,35.5 L 33,35.5 L 33,35.5%22 style=%22fill:none;stroke:%23ffffff;stroke-width:1;stroke-linejoin:miter%22/><path d=%22M 13,31.5 L 32,31.5%22 style=%22fill:none;stroke:%23ffffff;stroke-width:1;stroke-linejoin:miter%22/><path d=%22M 14,29.5 L 31,29.5%22 style=%22fill:none;stroke:%23ffffff;stroke-width:1;stroke-linejoin:miter%22/><path d=%22M 14,16.5 L 31,16.5%22 style=%22fill:none;stroke:%23ffffff;stroke-width:1;stroke-linejoin:miter%22/><path d=%22M 11,14 L 34,14%22 style=%22fill:none;stroke:%23ffffff;stroke-width:1;stroke-linejoin:miter%22/></g></svg>',
+       'bB': 'data:image/svg+xml,<?xml version=%221.0%22 encoding=%22UTF-8%22 standalone=%22no%22?>%0A<!DOCTYPE svg PUBLIC %22-//W3C//DTD SVG 1.1//EN%22 %22http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd%22>%0A<svg xmlns=%22http://www.w3.org/2000/svg%22 version=%221.1%22 width=%2245%22 height=%2245%22><g style=%22opacity:1;fill:none;fill-rule:evenodd;fill-opacity:1;stroke:%23000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22 transform=%22translate(0,0.6)%22><g style=%22fill:%23000000;stroke:%23000000;stroke-linecap:butt%22><path d=%22M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.65,38.99 6.68,38.97 6,38 C 7.35,36.54 9,36 9,36 z%22/><path d=%22M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z%22/><path d=%22M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z%22/></g><path d=%22M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18%22 style=%22fill:none;stroke:%23ffffff;stroke-linejoin:miter%22/></g></svg>',
+       'bN': 'data:image/svg+xml,<?xml version=%221.0%22 encoding=%22UTF-8%22 standalone=%22no%22?>%0A<!DOCTYPE svg PUBLIC %22-//W3C//DTD SVG 1.1//EN%22 %22http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd%22>%0A<svg xmlns=%22http://www.w3.org/2000/svg%22 version=%221.1%22 width=%2245%22 height=%2245%22><g style=%22opacity:1;fill:none;fill-opacity:1;fill-rule:evenodd;stroke:%23000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22 transform=%22translate(0,0.3)%22><path d=%22M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18%22 style=%22fill:%23000000;stroke:%23000000%22/><path d=%22M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10%22 style=%22fill:%23000000;stroke:%23000000%22/><path d=%22M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z%22 style=%22fill:%23ffffff;stroke:%23ffffff%22/><path d=%22M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z%22 transform=%22matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)%22 style=%22fill:%23ffffff;stroke:%23ffffff%22/><path d=%22M 24.55,10.4 L 24.1,11.85 L 24.6,12 C 27.75,13 30.25,14.49 32.5,18.75 C 34.75,23.01 35.75,29.06 35.25,39 L 35.2,39.5 L 37.45,39.5 L 37.5,39 C 38,28.94 36.62,22.15 34.25,17.66 C 31.88,13.17 28.46,11.02 25.06,10.5 L 24.55,10.4 z %22 style=%22fill:%23ffffff;stroke:none%22/></g></svg>',
+       'bP': 'data:image/svg+xml,<?xml version=%221.0%22 encoding=%22UTF-8%22 standalone=%22no%22?>%0A<!DOCTYPE svg PUBLIC %22-//W3C//DTD SVG 1.1//EN%22 %22http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd%22>%0A<svg xmlns=%22http://www.w3.org/2000/svg%22 version=%221.1%22 width=%2245%22 height=%2245%22><path d=%22m 22.5,9 c -2.21,0 -4,1.79 -4,4 0,0.89 0.29,1.71 0.78,2.38 C 17.33,16.5 16,18.59 16,21 c 0,2.03 0.94,3.84 2.41,5.03 C 15.41,27.09 11,31.58 11,39.5 H 34 C 34,31.58 29.59,27.09 26.59,26.03 28.06,24.84 29,23.03 29,21 29,18.59 27.67,16.5 25.72,15.38 26.21,14.71 26.5,13.89 26.5,13 c 0,-2.21 -1.79,-4 -4,-4 z%22 style=%22opacity:1;fill:%23000000;fill-opacity:1;fill-rule:nonzero;stroke:%23000000;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1%22/></svg>',
+};
 
-var init = function() {
+function svg_piece_theme(piece) {
+       return svg_pieces[piece];
+}
+
+function init() {
        unique = get_unique();
 
        // Load settings from HTML5 local storage if available.
-       if (supports_html5_storage() && localStorage['enable_sound']) {
-               set_sound(parseInt(localStorage['enable_sound']));
+       if (supports_html5_storage() && window['localStorage']['enable_sound']) {
+               set_sound(parseInt(window['localStorage']['enable_sound']));
        } else {
                set_sound(false);
        }
 
+       let admin_match = window.location.href.match(/\?password=([a-zA-Z0-9_-]+)/);
+       if (admin_match !== null) {
+               admin_password = admin_match[1];
+       }
+
        // Create board.
        board = new window.ChessBoard('board', {
                onMoveEnd: function() { board_is_animating = false; },
 
                draggable: true,
+               pieceTheme: svg_piece_theme,
                onDragStart: onDragStart,
                onDrop: onDrop,
                onSnapEnd: onSnapEnd
        });
-       $("#board").on('mousedown', '.square-55d63', mousedownSquare);
-       $("#board").on('mouseup', '.square-55d63', mouseupSquare);
+       document.getElementById("board").addEventListener('mousedown', mousedownSquare);
+       document.getElementById("board").addEventListener('mouseup', mouseupSquare);
 
+       if (window['inline_json']) {
+               let j = window['inline_json'];
+               process_update_response(j['data'], { 'get': (h) => j['headers'][h] });
+               delete window['inline_json'];
+       }
        request_update();
-       $(window).resize(function() {
+       window.addEventListener('resize', function() {
                board.resize();
                update_sparkline(displayed_analysis_data || current_analysis_data);
                update_board_highlight();
                redraw_arrows();
        });
-       $(window).keyup(function(event) {
+       new ResizeObserver(() => update_sparkline(displayed_analysis_data || current_analysis_data)).observe(document.getElementById('scoresparkcontainer'));
+       window.addEventListener('keyup', function(event) {
                if (event.which == 39) {  // Left arrow.
                        next_move();
                } else if (event.which == 37) {  // Right arrow.
                        prev_move();
                } else if (event.which >= 49 && event.which <= 57) {  // 1-9.
-                       var num = event.which - 49;
+                       let num = event.which - 49;
                        if (current_games && current_games.length >= num) {
                                switch_backend(current_games[num]);
                        }
@@ -2261,6 +2592,6 @@ var init = function() {
        window.addEventListener('hashchange', possibly_switch_game_from_hash, false);
        possibly_switch_game_from_hash();
 };
-$(document).ready(init);
+document.addEventListener('DOMContentLoaded', init);
 
 })();
diff --git a/www/manual-override.pl b/www/manual-override.pl
new file mode 100755 (executable)
index 0000000..23f571f
--- /dev/null
@@ -0,0 +1,42 @@
+#! /usr/bin/perl
+use strict;
+use warnings;
+use DBI;
+use DBD::Pg;
+use CGI;
+use Encode;
+use lib qw(..);
+require 'config.pm';
+
+my $dbh = DBI->connect($remoteglotconf::dbistr, $remoteglotconf::dbiuser, $remoteglotconf::dbipass)
+        or die DBI->errstr;
+$dbh->{RaiseError} = 1;
+
+my $cgi = CGI->new;
+my $password = Encode::decode_utf8($cgi->param('password'));
+if (!defined($password) || $password ne $remoteglotconf::adminpass) {
+       print CGI->header(-type=>'text/plain; charset=utf-8', -status=>'403 Denied');
+       print "Nope.\n";
+       exit;
+}
+
+if ($cgi->param('move') eq 'null') {
+       $dbh->do('DELETE FROM game_extensions WHERE fen=? AND history=? AND player_w=? AND player_b=?',
+               undef,
+               Encode::decode_utf8($cgi->param('fen')),
+               Encode::decode_utf8($cgi->param('history')),
+               Encode::decode_utf8($cgi->param('player_w')),
+               Encode::decode_utf8($cgi->param('player_b')));
+} else {
+       $dbh->do('INSERT INTO game_extensions ( fen, history, player_w, player_b, ts, next_move ) VALUES ( ?, ?, ?, ?, CURRENT_TIMESTAMP, ? )',
+               undef,
+               Encode::decode_utf8($cgi->param('fen')),
+               Encode::decode_utf8($cgi->param('history')),
+               Encode::decode_utf8($cgi->param('player_w')),
+               Encode::decode_utf8($cgi->param('player_b')),
+               Encode::decode_utf8($cgi->param('move')));
+}
+system("sudo", "/usr/bin/touch", $remoteglotconf::target);
+
+print CGI->header(-type=>'text/plain; charset=utf-8');
+print "OK\n";