.
[hacks/simpleWebSlides.git] / fds / anim / cartes-jq.js
1 var cards = new Array ();
2 cards[0] = 1;
3 cards[1] = 1;
4 cards[2] = 1;
5 cards[3] = 1;
6 cards[4] = 1;
7
8 function flip(n, cont)
9 {
10
11     var img = "img#c" + n;
12     var width = $(img).width();
13     var height = $(img).height();
14     $(img).animate ({
15         'width': "0px",
16         'left': (width >> 1) + "px",
17         'height': height + "px"}, 150);
18
19     $(img).queue (function(next) {
20         if (cards[n] == 0) {
21             $(img).attr("src", "carte" + n + ".png");
22         } else {
23             $(img).attr("src", "dos.png");
24         };
25         next();
26     });
27
28     $(img).animate ({
29         'width': width + "px",
30         'left': "0px",
31         'height': height + "px"}, 150);
32
33     $(img).queue (function(next) {
34         cards[n] = 1 - cards[n];
35         $("div#d" + n).html(cards[n]);
36         next();
37     });
38
39     if (cont !== undefined){
40         $(img).queue (function(next) {
41             cont();
42             next();
43         });
44     };
45 }
46
47 function update_res() {
48     var acc = 0;
49     for(i = 4; i >= 0; i--){
50         acc = 2*acc + cards[i];
51     };
52     $("div#rescontent").html("= " + acc);
53 }
54
55 function set_to_int(n)
56 {
57     var i;
58     var a = n;
59     var tmp = new Array();
60     for (i = 0; i < 5; i++) {
61         tmp[i] = a & 1;
62         a = a >> 1;
63     };
64     $("div#rescontent").queue(function() {
65         $(this).dequeue();
66     });
67
68     for(i = 0; i < 5; i++) {
69         $("div#rescontent").queue(new Function("next", "if(" + tmp[i] + " != cards[" + i +"]) {flip(" + i + ");}; next();" ));
70     };
71
72     $("div#rescontent").queue(function (next) {
73         $("img").promise().done(function(){
74             update_res();
75             next();
76         });
77     });
78
79     $("div#rescontent").delay(1000);
80
81 }
82 function count(from, to){
83     var i;
84     for (i = from; i <= to; i++){
85         set_to_int(i);
86     }
87
88 }
89 function hide_hints() {
90     $("div#all_digits").toggle();
91     $("div#result").toggle();
92
93 }
94
95 hide_hints();