Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigigraph / vigigraph / public / js / libs / mootools.js @ 2832ea2b

History | View | Annotate | Download (101 KB)

1
/*
2
---
3

4
script: Core.js
5

6
description: The core of MooTools, contains all the base functions and the Native and Hash implementations. Required by all the other scripts.
7

8
license: MIT-style license.
9

10
copyright: Copyright (c) 2006-2008 [Valerio Proietti](http://mad4milk.net/).
11

12
authors: The MooTools production team (http://mootools.net/developers/)
13

14
inspiration:
15
- Class implementation inspired by [Base.js](http://dean.edwards.name/weblog/2006/03/base/) Copyright (c) 2006 Dean Edwards, [GNU Lesser General Public License](http://opensource.org/licenses/lgpl-license.php)
16
- Some functionality inspired by [Prototype.js](http://prototypejs.org) Copyright (c) 2005-2007 Sam Stephenson, [MIT License](http://opensource.org/licenses/mit-license.php)
17

18
provides: [Mootools, Native, Hash.base, Array.each, $util]
19

20
...
21
*/
22

    
23
var MooTools = {
24
        'version': '1.2.4',
25
        'build': '0d9113241a90b9cd5643b926795852a2026710d4'
26
};
27

    
28
var Native = function(options){
29
        options = options || {};
30
        var name = options.name;
31
        var legacy = options.legacy;
32
        var protect = options.protect;
33
        var methods = options.implement;
34
        var generics = options.generics;
35
        var initialize = options.initialize;
36
        var afterImplement = options.afterImplement || function(){};
37
        var object = initialize || legacy;
38
        generics = generics !== false;
39

    
40
        object.constructor = Native;
41
        object.$family = {name: 'native'};
42
        if (legacy && initialize) object.prototype = legacy.prototype;
43
        object.prototype.constructor = object;
44

    
45
        if (name){
46
                var family = name.toLowerCase();
47
                object.prototype.$family = {name: family};
48
                Native.typize(object, family);
49
        }
50

    
51
        var add = function(obj, name, method, force){
52
                if (!protect || force || !obj.prototype[name]) obj.prototype[name] = method;
53
                if (generics) Native.genericize(obj, name, protect);
54
                afterImplement.call(obj, name, method);
55
                return obj;
56
        };
57

    
58
        object.alias = function(a1, a2, a3){
59
                if (typeof a1 == 'string'){
60
                        var pa1 = this.prototype[a1];
61
                        if ((a1 = pa1)) return add(this, a2, a1, a3);
62
                }
63
                for (var a in a1) this.alias(a, a1[a], a2);
64
                return this;
65
        };
66

    
67
        object.implement = function(a1, a2, a3){
68
                if (typeof a1 == 'string') return add(this, a1, a2, a3);
69
                for (var p in a1) add(this, p, a1[p], a2);
70
                return this;
71
        };
72

    
73
        if (methods) object.implement(methods);
74

    
75
        return object;
76
};
77

    
78
Native.genericize = function(object, property, check){
79
        if ((!check || !object[property]) && typeof object.prototype[property] == 'function') object[property] = function(){
80
                var args = Array.prototype.slice.call(arguments);
81
                return object.prototype[property].apply(args.shift(), args);
82
        };
83
};
84

    
85
Native.implement = function(objects, properties){
86
        for (var i = 0, l = objects.length; i < l; i++) objects[i].implement(properties);
87
};
88

    
89
Native.typize = function(object, family){
90
        if (!object.type) object.type = function(item){
91
                return ($type(item) === family);
92
        };
93
};
94

    
95
(function(){
96
        var natives = {'Array': Array, 'Date': Date, 'Function': Function, 'Number': Number, 'RegExp': RegExp, 'String': String};
97
        for (var n in natives) new Native({name: n, initialize: natives[n], protect: true});
98

    
99
        var types = {'boolean': Boolean, 'native': Native, 'object': Object};
100
        for (var t in types) Native.typize(types[t], t);
101

    
102
        var generics = {
103
                'Array': ["concat", "indexOf", "join", "lastIndexOf", "pop", "push", "reverse", "shift", "slice", "sort", "splice", "toString", "unshift", "valueOf"],
104
                'String': ["charAt", "charCodeAt", "concat", "indexOf", "lastIndexOf", "match", "replace", "search", "slice", "split", "substr", "substring", "toLowerCase", "toUpperCase", "valueOf"]
105
        };
106
        for (var g in generics){
107
                for (var i = generics[g].length; i--;) Native.genericize(natives[g], generics[g][i], true);
108
        }
109
})();
110

    
111
var Hash = new Native({
112

    
113
        name: 'Hash',
114

    
115
        initialize: function(object){
116
                if ($type(object) == 'hash') object = $unlink(object.getClean());
117
                for (var key in object) this[key] = object[key];
118
                return this;
119
        }
120

    
121
});
122

    
123
Hash.implement({
124

    
125
        forEach: function(fn, bind){
126
                for (var key in this){
127
                        if (this.hasOwnProperty(key)) fn.call(bind, this[key], key, this);
128
                }
129
        },
130

    
131
        getClean: function(){
132
                var clean = {};
133
                for (var key in this){
134
                        if (this.hasOwnProperty(key)) clean[key] = this[key];
135
                }
136
                return clean;
137
        },
138

    
139
        getLength: function(){
140
                var length = 0;
141
                for (var key in this){
142
                        if (this.hasOwnProperty(key)) length++;
143
                }
144
                return length;
145
        }
146

    
147
});
148

    
149
Hash.alias('forEach', 'each');
150

    
151
Array.implement({
152

    
153
        forEach: function(fn, bind){
154
                for (var i = 0, l = this.length; i < l; i++) fn.call(bind, this[i], i, this);
155
        }
156

    
157
});
158

    
159
Array.alias('forEach', 'each');
160

    
161
function $A(iterable){
162
        if (iterable.item){
163
                var l = iterable.length, array = new Array(l);
164
                while (l--) array[l] = iterable[l];
165
                return array;
166
        }
167
        return Array.prototype.slice.call(iterable);
168
};
169

    
170
function $arguments(i){
171
        return function(){
172
                return arguments[i];
173
        };
174
};
175

    
176
function $chk(obj){
177
        return !!(obj || obj === 0);
178
};
179

    
180
function $clear(timer){
181
        clearTimeout(timer);
182
        clearInterval(timer);
183
        return null;
184
};
185

    
186
function $defined(obj){
187
        return (obj != undefined);
188
};
189

    
190
function $each(iterable, fn, bind){
191
        var type = $type(iterable);
192
        ((type == 'arguments' || type == 'collection' || type == 'array') ? Array : Hash).each(iterable, fn, bind);
193
};
194

    
195
function $empty(){};
196

    
197
function $extend(original, extended){
198
        for (var key in (extended || {})) original[key] = extended[key];
199
        return original;
200
};
201

    
202
function $H(object){
203
        return new Hash(object);
204
};
205

    
206
function $lambda(value){
207
        return ($type(value) == 'function') ? value : function(){
208
                return value;
209
        };
210
};
211

    
212
function $merge(){
213
        var args = Array.slice(arguments);
214
        args.unshift({});
215
        return $mixin.apply(null, args);
216
};
217

    
218
function $mixin(mix){
219
        for (var i = 1, l = arguments.length; i < l; i++){
220
                var object = arguments[i];
221
                if ($type(object) != 'object') continue;
222
                for (var key in object){
223
                        var op = object[key], mp = mix[key];
224
                        mix[key] = (mp && $type(op) == 'object' && $type(mp) == 'object') ? $mixin(mp, op) : $unlink(op);
225
                }
226
        }
227
        return mix;
228
};
229

    
230
function $pick(){
231
        for (var i = 0, l = arguments.length; i < l; i++){
232
                if (arguments[i] != undefined) return arguments[i];
233
        }
234
        return null;
235
};
236

    
237
function $random(min, max){
238
        return Math.floor(Math.random() * (max - min + 1) + min);
239
};
240

    
241
function $splat(obj){
242
        var type = $type(obj);
243
        return (type) ? ((type != 'array' && type != 'arguments') ? [obj] : obj) : [];
244
};
245

    
246
var $time = Date.now || function(){
247
        return +new Date;
248
};
249

    
250
function $try(){
251
        for (var i = 0, l = arguments.length; i < l; i++){
252
                try {
253
                        return arguments[i]();
254
                } catch(e){}
255
        }
256
        return null;
257
};
258

    
259
function $type(obj){
260
        if (obj == undefined) return false;
261
        if (obj.$family) return (obj.$family.name == 'number' && !isFinite(obj)) ? false : obj.$family.name;
262
        if (obj.nodeName){
263
                switch (obj.nodeType){
264
                        case 1: return 'element';
265
                        case 3: return (/\S/).test(obj.nodeValue) ? 'textnode' : 'whitespace';
266
                }
267
        } else if (typeof obj.length == 'number'){
268
                if (obj.callee) return 'arguments';
269
                else if (obj.item) return 'collection';
270
        }
271
        return typeof obj;
272
};
273

    
274
function $unlink(object){
275
        var unlinked;
276
        switch ($type(object)){
277
                case 'object':
278
                        unlinked = {};
279
                        for (var p in object) unlinked[p] = $unlink(object[p]);
280
                break;
281
                case 'hash':
282
                        unlinked = new Hash(object);
283
                break;
284
                case 'array':
285
                        unlinked = [];
286
                        for (var i = 0, l = object.length; i < l; i++) unlinked[i] = $unlink(object[i]);
287
                break;
288
                default: return object;
289
        }
290
        return unlinked;
291
};
292

    
293

    
294
/*
295
---
296

297
script: Browser.js
298

299
description: The Browser Core. Contains Browser initialization, Window and Document, and the Browser Hash.
300

301
license: MIT-style license.
302

303
requires: 
304
- /Native
305
- /$util
306

307
provides: [Browser, Window, Document, $exec]
308

309
...
310
*/
311

    
312
var Browser = $merge({
313

    
314
        Engine: {name: 'unknown', version: 0},
315

    
316
        Platform: {name: (window.orientation != undefined) ? 'ipod' : (navigator.platform.match(/mac|win|linux/i) || ['other'])[0].toLowerCase()},
317

    
318
        Features: {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)},
319

    
320
        Plugins: {},
321

    
322
        Engines: {
323

    
324
                presto: function(){
325
                        return (!window.opera) ? false : ((arguments.callee.caller) ? 960 : ((document.getElementsByClassName) ? 950 : 925));
326
                },
327

    
328
                trident: function(){
329
                        return (!window.ActiveXObject) ? false : ((window.XMLHttpRequest) ? ((document.querySelectorAll) ? 6 : 5) : 4);
330
                },
331

    
332
                webkit: function(){
333
                        return (navigator.taintEnabled) ? false : ((Browser.Features.xpath) ? ((Browser.Features.query) ? 525 : 420) : 419);
334
                },
335

    
336
                gecko: function(){
337
                        return (!document.getBoxObjectFor && window.mozInnerScreenX == null) ? false : ((document.getElementsByClassName) ? 19 : 18);
338
                }
339

    
340
        }
341

    
342
}, Browser || {});
343

    
344
Browser.Platform[Browser.Platform.name] = true;
345

    
346
Browser.detect = function(){
347

    
348
        for (var engine in this.Engines){
349
                var version = this.Engines[engine]();
350
                if (version){
351
                        this.Engine = {name: engine, version: version};
352
                        this.Engine[engine] = this.Engine[engine + version] = true;
353
                        break;
354
                }
355
        }
356

    
357
        return {name: engine, version: version};
358

    
359
};
360

    
361
Browser.detect();
362

    
363
Browser.Request = function(){
364
        return $try(function(){
365
                return new XMLHttpRequest();
366
        }, function(){
367
                return new ActiveXObject('MSXML2.XMLHTTP');
368
        }, function(){
369
                return new ActiveXObject('Microsoft.XMLHTTP');
370
        });
371
};
372

    
373
Browser.Features.xhr = !!(Browser.Request());
374

    
375
Browser.Plugins.Flash = (function(){
376
        var version = ($try(function(){
377
                return navigator.plugins['Shockwave Flash'].description;
378
        }, function(){
379
                return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
380
        }) || '0 r0').match(/\d+/g);
381
        return {version: parseInt(version[0] || 0 + '.' + version[1], 10) || 0, build: parseInt(version[2], 10) || 0};
382
})();
383

    
384
function $exec(text){
385
        if (!text) return text;
386
        if (window.execScript){
387
                window.execScript(text);
388
        } else {
389
                var script = document.createElement('script');
390
                script.setAttribute('type', 'text/javascript');
391
                script[(Browser.Engine.webkit && Browser.Engine.version < 420) ? 'innerText' : 'text'] = text;
392
                document.head.appendChild(script);
393
                document.head.removeChild(script);
394
        }
395
        return text;
396
};
397

    
398
Native.UID = 1;
399

    
400
var $uid = (Browser.Engine.trident) ? function(item){
401
        return (item.uid || (item.uid = [Native.UID++]))[0];
402
} : function(item){
403
        return item.uid || (item.uid = Native.UID++);
404
};
405

    
406
var Window = new Native({
407

    
408
        name: 'Window',
409

    
410
        legacy: (Browser.Engine.trident) ? null: window.Window,
411

    
412
        initialize: function(win){
413
                $uid(win);
414
                if (!win.Element){
415
                        win.Element = $empty;
416
                        if (Browser.Engine.webkit) win.document.createElement("iframe"); //fixes safari 2
417
                        win.Element.prototype = (Browser.Engine.webkit) ? window["[[DOMElement.prototype]]"] : {};
418
                }
419
                win.document.window = win;
420
                return $extend(win, Window.Prototype);
421
        },
422

    
423
        afterImplement: function(property, value){
424
                window[property] = Window.Prototype[property] = value;
425
        }
426

    
427
});
428

    
429
Window.Prototype = {$family: {name: 'window'}};
430

    
431
new Window(window);
432

    
433
var Document = new Native({
434

    
435
        name: 'Document',
436

    
437
        legacy: (Browser.Engine.trident) ? null: window.Document,
438

    
439
        initialize: function(doc){
440
                $uid(doc);
441
                doc.head = doc.getElementsByTagName('head')[0];
442
                doc.html = doc.getElementsByTagName('html')[0];
443
                if (Browser.Engine.trident && Browser.Engine.version <= 4) $try(function(){
444
                        doc.execCommand("BackgroundImageCache", false, true);
445
                });
446
                if (Browser.Engine.trident) doc.window.attachEvent('onunload', function(){
447
                        doc.window.detachEvent('onunload', arguments.callee);
448
                        doc.head = doc.html = doc.window = null;
449
                });
450
                return $extend(doc, Document.Prototype);
451
        },
452

    
453
        afterImplement: function(property, value){
454
                document[property] = Document.Prototype[property] = value;
455
        }
456

    
457
});
458

    
459
Document.Prototype = {$family: {name: 'document'}};
460

    
461
new Document(document);
462

    
463

    
464
/*
465
---
466

467
script: Array.js
468

469
description: Contains Array Prototypes like each, contains, and erase.
470

471
license: MIT-style license.
472

473
requires:
474
- /$util
475
- /Array.each
476

477
provides: [Array]
478

479
...
480
*/
481

    
482
Array.implement({
483

    
484
        every: function(fn, bind){
485
                for (var i = 0, l = this.length; i < l; i++){
486
                        if (!fn.call(bind, this[i], i, this)) return false;
487
                }
488
                return true;
489
        },
490

    
491
        filter: function(fn, bind){
492
                var results = [];
493
                for (var i = 0, l = this.length; i < l; i++){
494
                        if (fn.call(bind, this[i], i, this)) results.push(this[i]);
495
                }
496
                return results;
497
        },
498

    
499
        clean: function(){
500
                return this.filter($defined);
501
        },
502

    
503
        indexOf: function(item, from){
504
                var len = this.length;
505
                for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){
506
                        if (this[i] === item) return i;
507
                }
508
                return -1;
509
        },
510

    
511
        map: function(fn, bind){
512
                var results = [];
513
                for (var i = 0, l = this.length; i < l; i++) results[i] = fn.call(bind, this[i], i, this);
514
                return results;
515
        },
516

    
517
        some: function(fn, bind){
518
                for (var i = 0, l = this.length; i < l; i++){
519
                        if (fn.call(bind, this[i], i, this)) return true;
520
                }
521
                return false;
522
        },
523

    
524
        associate: function(keys){
525
                var obj = {}, length = Math.min(this.length, keys.length);
526
                for (var i = 0; i < length; i++) obj[keys[i]] = this[i];
527
                return obj;
528
        },
529

    
530
        link: function(object){
531
                var result = {};
532
                for (var i = 0, l = this.length; i < l; i++){
533
                        for (var key in object){
534
                                if (object[key](this[i])){
535
                                        result[key] = this[i];
536
                                        delete object[key];
537
                                        break;
538
                                }
539
                        }
540
                }
541
                return result;
542
        },
543

    
544
        contains: function(item, from){
545
                return this.indexOf(item, from) != -1;
546
        },
547

    
548
        extend: function(array){
549
                for (var i = 0, j = array.length; i < j; i++) this.push(array[i]);
550
                return this;
551
        },
552
        
553
        getLast: function(){
554
                return (this.length) ? this[this.length - 1] : null;
555
        },
556

    
557
        getRandom: function(){
558
                return (this.length) ? this[$random(0, this.length - 1)] : null;
559
        },
560

    
561
        include: function(item){
562
                if (!this.contains(item)) this.push(item);
563
                return this;
564
        },
565

    
566
        combine: function(array){
567
                for (var i = 0, l = array.length; i < l; i++) this.include(array[i]);
568
                return this;
569
        },
570

    
571
        erase: function(item){
572
                for (var i = this.length; i--; i){
573
                        if (this[i] === item) this.splice(i, 1);
574
                }
575
                return this;
576
        },
577

    
578
        empty: function(){
579
                this.length = 0;
580
                return this;
581
        },
582

    
583
        flatten: function(){
584
                var array = [];
585
                for (var i = 0, l = this.length; i < l; i++){
586
                        var type = $type(this[i]);
587
                        if (!type) continue;
588
                        array = array.concat((type == 'array' || type == 'collection' || type == 'arguments') ? Array.flatten(this[i]) : this[i]);
589
                }
590
                return array;
591
        },
592

    
593
        hexToRgb: function(array){
594
                if (this.length != 3) return null;
595
                var rgb = this.map(function(value){
596
                        if (value.length == 1) value += value;
597
                        return value.toInt(16);
598
                });
599
                return (array) ? rgb : 'rgb(' + rgb + ')';
600
        },
601

    
602
        rgbToHex: function(array){
603
                if (this.length < 3) return null;
604
                if (this.length == 4 && this[3] == 0 && !array) return 'transparent';
605
                var hex = [];
606
                for (var i = 0; i < 3; i++){
607
                        var bit = (this[i] - 0).toString(16);
608
                        hex.push((bit.length == 1) ? '0' + bit : bit);
609
                }
610
                return (array) ? hex : '#' + hex.join('');
611
        }
612

    
613
});
614

    
615

    
616
/*
617
---
618

619
script: Function.js
620

621
description: Contains Function Prototypes like create, bind, pass, and delay.
622

623
license: MIT-style license.
624

625
requires:
626
- /Native
627
- /$util
628

629
provides: [Function]
630

631
...
632
*/
633

    
634
Function.implement({
635

    
636
        extend: function(properties){
637
                for (var property in properties) this[property] = properties[property];
638
                return this;
639
        },
640

    
641
        create: function(options){
642
                var self = this;
643
                options = options || {};
644
                return function(event){
645
                        var args = options.arguments;
646
                        args = (args != undefined) ? $splat(args) : Array.slice(arguments, (options.event) ? 1 : 0);
647
                        if (options.event) args = [event || window.event].extend(args);
648
                        var returns = function(){
649
                                return self.apply(options.bind || null, args);
650
                        };
651
                        if (options.delay) return setTimeout(returns, options.delay);
652
                        if (options.periodical) return setInterval(returns, options.periodical);
653
                        if (options.attempt) return $try(returns);
654
                        return returns();
655
                };
656
        },
657

    
658
        run: function(args, bind){
659
                return this.apply(bind, $splat(args));
660
        },
661

    
662
        pass: function(args, bind){
663
                return this.create({bind: bind, arguments: args});
664
        },
665

    
666
        bind: function(bind, args){
667
                return this.create({bind: bind, arguments: args});
668
        },
669

    
670
        bindWithEvent: function(bind, args){
671
                return this.create({bind: bind, arguments: args, event: true});
672
        },
673

    
674
        attempt: function(args, bind){
675
                return this.create({bind: bind, arguments: args, attempt: true})();
676
        },
677

    
678
        delay: function(delay, bind, args){
679
                return this.create({bind: bind, arguments: args, delay: delay})();
680
        },
681

    
682
        periodical: function(periodical, bind, args){
683
                return this.create({bind: bind, arguments: args, periodical: periodical})();
684
        }
685

    
686
});
687

    
688

    
689
/*
690
---
691

692
script: Number.js
693

694
description: Contains Number Prototypes like limit, round, times, and ceil.
695

696
license: MIT-style license.
697

698
requires:
699
- /Native
700
- /$util
701

702
provides: [Number]
703

704
...
705
*/
706

    
707
Number.implement({
708

    
709
        limit: function(min, max){
710
                return Math.min(max, Math.max(min, this));
711
        },
712

    
713
        round: function(precision){
714
                precision = Math.pow(10, precision || 0);
715
                return Math.round(this * precision) / precision;
716
        },
717

    
718
        times: function(fn, bind){
719
                for (var i = 0; i < this; i++) fn.call(bind, i, this);
720
        },
721

    
722
        toFloat: function(){
723
                return parseFloat(this);
724
        },
725

    
726
        toInt: function(base){
727
                return parseInt(this, base || 10);
728
        }
729

    
730
});
731

    
732
Number.alias('times', 'each');
733

    
734
(function(math){
735
        var methods = {};
736
        math.each(function(name){
737
                if (!Number[name]) methods[name] = function(){
738
                        return Math[name].apply(null, [this].concat($A(arguments)));
739
                };
740
        });
741
        Number.implement(methods);
742
})(['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'sin', 'sqrt', 'tan']);
743

    
744

    
745
/*
746
---
747

748
script: String.js
749

750
description: Contains String Prototypes like camelCase, capitalize, test, and toInt.
751

752
license: MIT-style license.
753

754
requires:
755
- /Native
756

757
provides: [String]
758

759
...
760
*/
761

    
762
String.implement({
763

    
764
        test: function(regex, params){
765
                return ((typeof regex == 'string') ? new RegExp(regex, params) : regex).test(this);
766
        },
767

    
768
        contains: function(string, separator){
769
                return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : this.indexOf(string) > -1;
770
        },
771

    
772
        trim: function(){
773
                return this.replace(/^\s+|\s+$/g, '');
774
        },
775

    
776
        clean: function(){
777
                return this.replace(/\s+/g, ' ').trim();
778
        },
779

    
780
        camelCase: function(){
781
                return this.replace(/-\D/g, function(match){
782
                        return match.charAt(1).toUpperCase();
783
                });
784
        },
785

    
786
        hyphenate: function(){
787
                return this.replace(/[A-Z]/g, function(match){
788
                        return ('-' + match.charAt(0).toLowerCase());
789
                });
790
        },
791

    
792
        capitalize: function(){
793
                return this.replace(/\b[a-z]/g, function(match){
794
                        return match.toUpperCase();
795
                });
796
        },
797

    
798
        escapeRegExp: function(){
799
                return this.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
800
        },
801

    
802
        toInt: function(base){
803
                return parseInt(this, base || 10);
804
        },
805

    
806
        toFloat: function(){
807
                return parseFloat(this);
808
        },
809

    
810
        hexToRgb: function(array){
811
                var hex = this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
812
                return (hex) ? hex.slice(1).hexToRgb(array) : null;
813
        },
814

    
815
        rgbToHex: function(array){
816
                var rgb = this.match(/\d{1,3}/g);
817
                return (rgb) ? rgb.rgbToHex(array) : null;
818
        },
819

    
820
        stripScripts: function(option){
821
                var scripts = '';
822
                var text = this.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){
823
                        scripts += arguments[1] + '\n';
824
                        return '';
825
                });
826
                if (option === true) $exec(scripts);
827
                else if ($type(option) == 'function') option(scripts, text);
828
                return text;
829
        },
830

    
831
        substitute: function(object, regexp){
832
                return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
833
                        if (match.charAt(0) == '\\') return match.slice(1);
834
                        return (object[name] != undefined) ? object[name] : '';
835
                });
836
        }
837

    
838
});
839

    
840

    
841
/*
842
---
843

844
script: Hash.js
845

846
description: Contains Hash Prototypes. Provides a means for overcoming the JavaScript practical impossibility of extending native Objects.
847

848
license: MIT-style license.
849

850
requires:
851
- /Hash.base
852

853
provides: [Hash]
854

855
...
856
*/
857

    
858
Hash.implement({
859

    
860
        has: Object.prototype.hasOwnProperty,
861

    
862
        keyOf: function(value){
863
                for (var key in this){
864
                        if (this.hasOwnProperty(key) && this[key] === value) return key;
865
                }
866
                return null;
867
        },
868

    
869
        hasValue: function(value){
870
                return (Hash.keyOf(this, value) !== null);
871
        },
872

    
873
        extend: function(properties){
874
                Hash.each(properties || {}, function(value, key){
875
                        Hash.set(this, key, value);
876
                }, this);
877
                return this;
878
        },
879

    
880
        combine: function(properties){
881
                Hash.each(properties || {}, function(value, key){
882
                        Hash.include(this, key, value);
883
                }, this);
884
                return this;
885
        },
886

    
887
        erase: function(key){
888
                if (this.hasOwnProperty(key)) delete this[key];
889
                return this;
890
        },
891

    
892
        get: function(key){
893
                return (this.hasOwnProperty(key)) ? this[key] : null;
894
        },
895

    
896
        set: function(key, value){
897
                if (!this[key] || this.hasOwnProperty(key)) this[key] = value;
898
                return this;
899
        },
900

    
901
        empty: function(){
902
                Hash.each(this, function(value, key){
903
                        delete this[key];
904
                }, this);
905
                return this;
906
        },
907

    
908
        include: function(key, value){
909
                if (this[key] == undefined) this[key] = value;
910
                return this;
911
        },
912

    
913
        map: function(fn, bind){
914
                var results = new Hash;
915
                Hash.each(this, function(value, key){
916
                        results.set(key, fn.call(bind, value, key, this));
917
                }, this);
918
                return results;
919
        },
920

    
921
        filter: function(fn, bind){
922
                var results = new Hash;
923
                Hash.each(this, function(value, key){
924
                        if (fn.call(bind, value, key, this)) results.set(key, value);
925
                }, this);
926
                return results;
927
        },
928

    
929
        every: function(fn, bind){
930
                for (var key in this){
931
                        if (this.hasOwnProperty(key) && !fn.call(bind, this[key], key)) return false;
932
                }
933
                return true;
934
        },
935

    
936
        some: function(fn, bind){
937
                for (var key in this){
938
                        if (this.hasOwnProperty(key) && fn.call(bind, this[key], key)) return true;
939
                }
940
                return false;
941
        },
942

    
943
        getKeys: function(){
944
                var keys = [];
945
                Hash.each(this, function(value, key){
946
                        keys.push(key);
947
                });
948
                return keys;
949
        },
950

    
951
        getValues: function(){
952
                var values = [];
953
                Hash.each(this, function(value){
954
                        values.push(value);
955
                });
956
                return values;
957
        },
958

    
959
        toQueryString: function(base){
960
                var queryString = [];
961
                Hash.each(this, function(value, key){
962
                        if (base) key = base + '[' + key + ']';
963
                        var result;
964
                        switch ($type(value)){
965
                                case 'object': result = Hash.toQueryString(value, key); break;
966
                                case 'array':
967
                                        var qs = {};
968
                                        value.each(function(val, i){
969
                                                qs[i] = val;
970
                                        });
971
                                        result = Hash.toQueryString(qs, key);
972
                                break;
973
                                default: result = key + '=' + encodeURIComponent(value);
974
                        }
975
                        if (value != undefined) queryString.push(result);
976
                });
977

    
978
                return queryString.join('&');
979
        }
980

    
981
});
982

    
983
Hash.alias({keyOf: 'indexOf', hasValue: 'contains'});
984

    
985

    
986
/*
987
---
988

989
script: Event.js
990

991
description: Contains the Event Class, to make the event object cross-browser.
992

993
license: MIT-style license.
994

995
requires:
996
- /Window
997
- /Document
998
- /Hash
999
- /Array
1000
- /Function
1001
- /String
1002

1003
provides: [Event]
1004

1005
...
1006
*/
1007

    
1008
var Event = new Native({
1009

    
1010
        name: 'Event',
1011

    
1012
        initialize: function(event, win){
1013
                win = win || window;
1014
                var doc = win.document;
1015
                event = event || win.event;
1016
                if (event.$extended) return event;
1017
                this.$extended = true;
1018
                var type = event.type;
1019
                var target = event.target || event.srcElement;
1020
                while (target && target.nodeType == 3) target = target.parentNode;
1021

    
1022
                if (type.test(/key/)){
1023
                        var code = event.which || event.keyCode;
1024
                        var key = Event.Keys.keyOf(code);
1025
                        if (type == 'keydown'){
1026
                                var fKey = code - 111;
1027
                                if (fKey > 0 && fKey < 13) key = 'f' + fKey;
1028
                        }
1029
                        key = key || String.fromCharCode(code).toLowerCase();
1030
                } else if (type.match(/(click|mouse|menu)/i)){
1031
                        doc = (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body;
1032
                        var page = {
1033
                                x: event.pageX || event.clientX + doc.scrollLeft,
1034
                                y: event.pageY || event.clientY + doc.scrollTop
1035
                        };
1036
                        var client = {
1037
                                x: (event.pageX) ? event.pageX - win.pageXOffset : event.clientX,
1038
                                y: (event.pageY) ? event.pageY - win.pageYOffset : event.clientY
1039
                        };
1040
                        if (type.match(/DOMMouseScroll|mousewheel/)){
1041
                                var wheel = (event.wheelDelta) ? event.wheelDelta / 120 : -(event.detail || 0) / 3;
1042
                        }
1043
                        var rightClick = (event.which == 3) || (event.button == 2);
1044
                        var related = null;
1045
                        if (type.match(/over|out/)){
1046
                                switch (type){
1047
                                        case 'mouseover': related = event.relatedTarget || event.fromElement; break;
1048
                                        case 'mouseout': related = event.relatedTarget || event.toElement;
1049
                                }
1050
                                if (!(function(){
1051
                                        while (related && related.nodeType == 3) related = related.parentNode;
1052
                                        return true;
1053
                                }).create({attempt: Browser.Engine.gecko})()) related = false;
1054
                        }
1055
                }
1056

    
1057
                return $extend(this, {
1058
                        event: event,
1059
                        type: type,
1060

    
1061
                        page: page,
1062
                        client: client,
1063
                        rightClick: rightClick,
1064

    
1065
                        wheel: wheel,
1066

    
1067
                        relatedTarget: related,
1068
                        target: target,
1069

    
1070
                        code: code,
1071
                        key: key,
1072

    
1073
                        shift: event.shiftKey,
1074
                        control: event.ctrlKey,
1075
                        alt: event.altKey,
1076
                        meta: event.metaKey
1077
                });
1078
        }
1079

    
1080
});
1081

    
1082
Event.Keys = new Hash({
1083
        'enter': 13,
1084
        'up': 38,
1085
        'down': 40,
1086
        'left': 37,
1087
        'right': 39,
1088
        'esc': 27,
1089
        'space': 32,
1090
        'backspace': 8,
1091
        'tab': 9,
1092
        'delete': 46
1093
});
1094

    
1095
Event.implement({
1096

    
1097
        stop: function(){
1098
                return this.stopPropagation().preventDefault();
1099
        },
1100

    
1101
        stopPropagation: function(){
1102
                if (this.event.stopPropagation) this.event.stopPropagation();
1103
                else this.event.cancelBubble = true;
1104
                return this;
1105
        },
1106

    
1107
        preventDefault: function(){
1108
                if (this.event.preventDefault) this.event.preventDefault();
1109
                else this.event.returnValue = false;
1110
                return this;
1111
        }
1112

    
1113
});
1114

    
1115

    
1116
/*
1117
---
1118

1119
script: Class.js
1120

1121
description: Contains the Class Function for easily creating, extending, and implementing reusable Classes.
1122

1123
license: MIT-style license.
1124

1125
requires:
1126
- /$util
1127
- /Native
1128
- /Array
1129
- /String
1130
- /Function
1131
- /Number
1132
- /Hash
1133

1134
provides: [Class]
1135

1136
...
1137
*/
1138

    
1139
function Class(params){
1140
        
1141
        if (params instanceof Function) params = {initialize: params};
1142
        
1143
        var newClass = function(){
1144
                Object.reset(this);
1145
                if (newClass._prototyping) return this;
1146
                this._current = $empty;
1147
                var value = (this.initialize) ? this.initialize.apply(this, arguments) : this;
1148
                delete this._current; delete this.caller;
1149
                return value;
1150
        }.extend(this);
1151
        
1152
        newClass.implement(params);
1153
        
1154
        newClass.constructor = Class;
1155
        newClass.prototype.constructor = newClass;
1156

    
1157
        return newClass;
1158

    
1159
};
1160

    
1161
Function.prototype.protect = function(){
1162
        this._protected = true;
1163
        return this;
1164
};
1165

    
1166
Object.reset = function(object, key){
1167
                
1168
        if (key == null){
1169
                for (var p in object) Object.reset(object, p);
1170
                return object;
1171
        }
1172
        
1173
        delete object[key];
1174
        
1175
        switch ($type(object[key])){
1176
                case 'object':
1177
                        var F = function(){};
1178
                        F.prototype = object[key];
1179
                        var i = new F;
1180
                        object[key] = Object.reset(i);
1181
                break;
1182
                case 'array': object[key] = $unlink(object[key]); break;
1183
        }
1184
        
1185
        return object;
1186
        
1187
};
1188

    
1189
new Native({name: 'Class', initialize: Class}).extend({
1190

    
1191
        instantiate: function(F){
1192
                F._prototyping = true;
1193
                var proto = new F;
1194
                delete F._prototyping;
1195
                return proto;
1196
        },
1197
        
1198
        wrap: function(self, key, method){
1199
                if (method._origin) method = method._origin;
1200
                
1201
                return function(){
1202
                        if (method._protected && this._current == null) throw new Error('The method "' + key + '" cannot be called.');
1203
                        var caller = this.caller, current = this._current;
1204
                        this.caller = current; this._current = arguments.callee;
1205
                        var result = method.apply(this, arguments);
1206
                        this._current = current; this.caller = caller;
1207
                        return result;
1208
                }.extend({_owner: self, _origin: method, _name: key});
1209

    
1210
        }
1211
        
1212
});
1213

    
1214
Class.implement({
1215
        
1216
        implement: function(key, value){
1217
                
1218
                if ($type(key) == 'object'){
1219
                        for (var p in key) this.implement(p, key[p]);
1220
                        return this;
1221
                }
1222
                
1223
                var mutator = Class.Mutators[key];
1224
                
1225
                if (mutator){
1226
                        value = mutator.call(this, value);
1227
                        if (value == null) return this;
1228
                }
1229
                
1230
                var proto = this.prototype;
1231

    
1232
                switch ($type(value)){
1233
                        
1234
                        case 'function':
1235
                                if (value._hidden) return this;
1236
                                proto[key] = Class.wrap(this, key, value);
1237
                        break;
1238
                        
1239
                        case 'object':
1240
                                var previous = proto[key];
1241
                                if ($type(previous) == 'object') $mixin(previous, value);
1242
                                else proto[key] = $unlink(value);
1243
                        break;
1244
                        
1245
                        case 'array':
1246
                                proto[key] = $unlink(value);
1247
                        break;
1248
                        
1249
                        default: proto[key] = value;
1250

    
1251
                }
1252
                
1253
                return this;
1254

    
1255
        }
1256
        
1257
});
1258

    
1259
Class.Mutators = {
1260
        
1261
        Extends: function(parent){
1262

    
1263
                this.parent = parent;
1264
                this.prototype = Class.instantiate(parent);
1265

    
1266
                this.implement('parent', function(){
1267
                        var name = this.caller._name, previous = this.caller._owner.parent.prototype[name];
1268
                        if (!previous) throw new Error('The method "' + name + '" has no parent.');
1269
                        return previous.apply(this, arguments);
1270
                }.protect());
1271

    
1272
        },
1273

    
1274
        Implements: function(items){
1275
                $splat(items).each(function(item){
1276
                        if (item instanceof Function) item = Class.instantiate(item);
1277
                        this.implement(item);
1278
                }, this);
1279

    
1280
        }
1281
        
1282
};
1283

    
1284

    
1285
/*
1286
---
1287

1288
script: Class.Extras.js
1289

1290
description: Contains Utility Classes that can be implemented into your own Classes to ease the execution of many common tasks.
1291

1292
license: MIT-style license.
1293

1294
requires:
1295
- /Class
1296

1297
provides: [Chain, Events, Options]
1298

1299
...
1300
*/
1301

    
1302
var Chain = new Class({
1303

    
1304
        $chain: [],
1305

    
1306
        chain: function(){
1307
                this.$chain.extend(Array.flatten(arguments));
1308
                return this;
1309
        },
1310

    
1311
        callChain: function(){
1312
                return (this.$chain.length) ? this.$chain.shift().apply(this, arguments) : false;
1313
        },
1314

    
1315
        clearChain: function(){
1316
                this.$chain.empty();
1317
                return this;
1318
        }
1319

    
1320
});
1321

    
1322
var Events = new Class({
1323

    
1324
        $events: {},
1325

    
1326
        addEvent: function(type, fn, internal){
1327
                type = Events.removeOn(type);
1328
                if (fn != $empty){
1329
                        this.$events[type] = this.$events[type] || [];
1330
                        this.$events[type].include(fn);
1331
                        if (internal) fn.internal = true;
1332
                }
1333
                return this;
1334
        },
1335

    
1336
        addEvents: function(events){
1337
                for (var type in events) this.addEvent(type, events[type]);
1338
                return this;
1339
        },
1340

    
1341
        fireEvent: function(type, args, delay){
1342
                type = Events.removeOn(type);
1343
                if (!this.$events || !this.$events[type]) return this;
1344
                this.$events[type].each(function(fn){
1345
                        fn.create({'bind': this, 'delay': delay, 'arguments': args})();
1346
                }, this);
1347
                return this;
1348
        },
1349

    
1350
        removeEvent: function(type, fn){
1351
                type = Events.removeOn(type);
1352
                if (!this.$events[type]) return this;
1353
                if (!fn.internal) this.$events[type].erase(fn);
1354
                return this;
1355
        },
1356

    
1357
        removeEvents: function(events){
1358
                var type;
1359
                if ($type(events) == 'object'){
1360
                        for (type in events) this.removeEvent(type, events[type]);
1361
                        return this;
1362
                }
1363
                if (events) events = Events.removeOn(events);
1364
                for (type in this.$events){
1365
                        if (events && events != type) continue;
1366
                        var fns = this.$events[type];
1367
                        for (var i = fns.length; i--; i) this.removeEvent(type, fns[i]);
1368
                }
1369
                return this;
1370
        }
1371

    
1372
});
1373

    
1374
Events.removeOn = function(string){
1375
        return string.replace(/^on([A-Z])/, function(full, first){
1376
                return first.toLowerCase();
1377
        });
1378
};
1379

    
1380
var Options = new Class({
1381

    
1382
        setOptions: function(){
1383
                this.options = $merge.run([this.options].extend(arguments));
1384
                if (!this.addEvent) return this;
1385
                for (var option in this.options){
1386
                        if ($type(this.options[option]) != 'function' || !(/^on[A-Z]/).test(option)) continue;
1387
                        this.addEvent(option, this.options[option]);
1388
                        delete this.options[option];
1389
                }
1390
                return this;
1391
        }
1392

    
1393
});
1394

    
1395

    
1396
/*
1397
---
1398

1399
script: Element.js
1400

1401
description: One of the most important items in MooTools. Contains the dollar function, the dollars function, and an handful of cross-browser, time-saver methods to let you easily work with HTML Elements.
1402

1403
license: MIT-style license.
1404

1405
requires:
1406
- /Window
1407
- /Document
1408
- /Array
1409
- /String
1410
- /Function
1411
- /Number
1412
- /Hash
1413

1414
provides: [Element, Elements, $, $$, Iframe]
1415

1416
...
1417
*/
1418

    
1419
var Element = new Native({
1420

    
1421
        name: 'Element',
1422

    
1423
        legacy: window.Element,
1424

    
1425
        initialize: function(tag, props){
1426
                var konstructor = Element.Constructors.get(tag);
1427
                if (konstructor) return konstructor(props);
1428
                if (typeof tag == 'string') return document.newElement(tag, props);
1429
                return document.id(tag).set(props);
1430
        },
1431

    
1432
        afterImplement: function(key, value){
1433
                Element.Prototype[key] = value;
1434
                if (Array[key]) return;
1435
                Elements.implement(key, function(){
1436
                        var items = [], elements = true;
1437
                        for (var i = 0, j = this.length; i < j; i++){
1438
                                var returns = this[i][key].apply(this[i], arguments);
1439
                                items.push(returns);
1440
                                if (elements) elements = ($type(returns) == 'element');
1441
                        }
1442
                        return (elements) ? new Elements(items) : items;
1443
                });
1444
        }
1445

    
1446
});
1447

    
1448
Element.Prototype = {$family: {name: 'element'}};
1449

    
1450
Element.Constructors = new Hash;
1451

    
1452
var IFrame = new Native({
1453

    
1454
        name: 'IFrame',
1455

    
1456
        generics: false,
1457

    
1458
        initialize: function(){
1459
                var params = Array.link(arguments, {properties: Object.type, iframe: $defined});
1460
                var props = params.properties || {};
1461
                var iframe = document.id(params.iframe);
1462
                var onload = props.onload || $empty;
1463
                delete props.onload;
1464
                props.id = props.name = $pick(props.id, props.name, iframe ? (iframe.id || iframe.name) : 'IFrame_' + $time());
1465
                iframe = new Element(iframe || 'iframe', props);
1466
                var onFrameLoad = function(){
1467
                        var host = $try(function(){
1468
                                return iframe.contentWindow.location.host;
1469
                        });
1470
                        if (!host || host == window.location.host){
1471
                                var win = new Window(iframe.contentWindow);
1472
                                new Document(iframe.contentWindow.document);
1473
                                $extend(win.Element.prototype, Element.Prototype);
1474
                        }
1475
                        onload.call(iframe.contentWindow, iframe.contentWindow.document);
1476
                };
1477
                var contentWindow = $try(function(){
1478
                        return iframe.contentWindow;
1479
                });
1480
                ((contentWindow && contentWindow.document.body) || window.frames[props.id]) ? onFrameLoad() : iframe.addListener('load', onFrameLoad);
1481
                return iframe;
1482
        }
1483

    
1484
});
1485

    
1486
var Elements = new Native({
1487

    
1488
        initialize: function(elements, options){
1489
                options = $extend({ddup: true, cash: true}, options);
1490
                elements = elements || [];
1491
                if (options.ddup || options.cash){
1492
                        var uniques = {}, returned = [];
1493
                        for (var i = 0, l = elements.length; i < l; i++){
1494
                                var el = document.id(elements[i], !options.cash);
1495
                                if (options.ddup){
1496
                                        if (uniques[el.uid]) continue;
1497
                                        uniques[el.uid] = true;
1498
                                }
1499
                                if (el) returned.push(el);
1500
                        }
1501
                        elements = returned;
1502
                }
1503
                return (options.cash) ? $extend(elements, this) : elements;
1504
        }
1505

    
1506
});
1507

    
1508
Elements.implement({
1509

    
1510
        filter: function(filter, bind){
1511
                if (!filter) return this;
1512
                return new Elements(Array.filter(this, (typeof filter == 'string') ? function(item){
1513
                        return item.match(filter);
1514
                } : filter, bind));
1515
        }
1516

    
1517
});
1518

    
1519
Document.implement({
1520

    
1521
        newElement: function(tag, props){
1522
                if (Browser.Engine.trident && props){
1523
                        ['name', 'type', 'checked'].each(function(attribute){
1524
                                if (!props[attribute]) return;
1525
                                tag += ' ' + attribute + '="' + props[attribute] + '"';
1526
                                if (attribute != 'checked') delete props[attribute];
1527
                        });
1528
                        tag = '<' + tag + '>';
1529
                }
1530
                return document.id(this.createElement(tag)).set(props);
1531
        },
1532

    
1533
        newTextNode: function(text){
1534
                return this.createTextNode(text);
1535
        },
1536

    
1537
        getDocument: function(){
1538
                return this;
1539
        },
1540

    
1541
        getWindow: function(){
1542
                return this.window;
1543
        },
1544
        
1545
        id: (function(){
1546
                
1547
                var types = {
1548

    
1549
                        string: function(id, nocash, doc){
1550
                                id = doc.getElementById(id);
1551
                                return (id) ? types.element(id, nocash) : null;
1552
                        },
1553
                        
1554
                        element: function(el, nocash){
1555
                                $uid(el);
1556
                                if (!nocash && !el.$family && !(/^object|embed$/i).test(el.tagName)){
1557
                                        var proto = Element.Prototype;
1558
                                        for (var p in proto) el[p] = proto[p];
1559
                                };
1560
                                return el;
1561
                        },
1562
                        
1563
                        object: function(obj, nocash, doc){
1564
                                if (obj.toElement) return types.element(obj.toElement(doc), nocash);
1565
                                return null;
1566
                        }
1567
                        
1568
                };
1569

    
1570
                types.textnode = types.whitespace = types.window = types.document = $arguments(0);
1571
                
1572
                return function(el, nocash, doc){
1573
                        if (el && el.$family && el.uid) return el;
1574
                        var type = $type(el);
1575
                        return (types[type]) ? types[type](el, nocash, doc || document) : null;
1576
                };
1577

    
1578
        })()
1579

    
1580
});
1581

    
1582
if (window.$ == null) Window.implement({
1583
        $: function(el, nc){
1584
                return document.id(el, nc, this.document);
1585
        }
1586
});
1587

    
1588
Window.implement({
1589

    
1590
        $$: function(selector){
1591
                if (arguments.length == 1 && typeof selector == 'string') return this.document.getElements(selector);
1592
                var elements = [];
1593
                var args = Array.flatten(arguments);
1594
                for (var i = 0, l = args.length; i < l; i++){
1595
                        var item = args[i];
1596
                        switch ($type(item)){
1597
                                case 'element': elements.push(item); break;
1598
                                case 'string': elements.extend(this.document.getElements(item, true));
1599
                        }
1600
                }
1601
                return new Elements(elements);
1602
        },
1603

    
1604
        getDocument: function(){
1605
                return this.document;
1606
        },
1607

    
1608
        getWindow: function(){
1609
                return this;
1610
        }
1611

    
1612
});
1613

    
1614
Native.implement([Element, Document], {
1615

    
1616
        getElement: function(selector, nocash){
1617
                return document.id(this.getElements(selector, true)[0] || null, nocash);
1618
        },
1619

    
1620
        getElements: function(tags, nocash){
1621
                tags = tags.split(',');
1622
                var elements = [];
1623
                var ddup = (tags.length > 1);
1624
                tags.each(function(tag){
1625
                        var partial = this.getElementsByTagName(tag.trim());
1626
                        (ddup) ? elements.extend(partial) : elements = partial;
1627
                }, this);
1628
                return new Elements(elements, {ddup: ddup, cash: !nocash});
1629
        }
1630

    
1631
});
1632

    
1633
(function(){
1634

    
1635
var collected = {}, storage = {};
1636
var props = {input: 'checked', option: 'selected', textarea: (Browser.Engine.webkit && Browser.Engine.version < 420) ? 'innerHTML' : 'value'};
1637

    
1638
var get = function(uid){
1639
        return (storage[uid] || (storage[uid] = {}));
1640
};
1641

    
1642
var clean = function(item, retain){
1643
        if (!item) return;
1644
        var uid = item.uid;
1645
        if (Browser.Engine.trident){
1646
                if (item.clearAttributes){
1647
                        var clone = retain && item.cloneNode(false);
1648
                        item.clearAttributes();
1649
                        if (clone) item.mergeAttributes(clone);
1650
                } else if (item.removeEvents){
1651
                        item.removeEvents();
1652
                }
1653
                if ((/object/i).test(item.tagName)){
1654
                        for (var p in item){
1655
                                if (typeof item[p] == 'function') item[p] = $empty;
1656
                        }
1657
                        Element.dispose(item);
1658
                }
1659
        }        
1660
        if (!uid) return;
1661
        collected[uid] = storage[uid] = null;
1662
};
1663

    
1664
var purge = function(){
1665
        Hash.each(collected, clean);
1666
        if (Browser.Engine.trident) $A(document.getElementsByTagName('object')).each(clean);
1667
        if (window.CollectGarbage) CollectGarbage();
1668
        collected = storage = null;
1669
};
1670

    
1671
var walk = function(element, walk, start, match, all, nocash){
1672
        var el = element[start || walk];
1673
        var elements = [];
1674
        while (el){
1675
                if (el.nodeType == 1 && (!match || Element.match(el, match))){
1676
                        if (!all) return document.id(el, nocash);
1677
                        elements.push(el);
1678
                }
1679
                el = el[walk];
1680
        }
1681
        return (all) ? new Elements(elements, {ddup: false, cash: !nocash}) : null;
1682
};
1683

    
1684
var attributes = {
1685
        'html': 'innerHTML',
1686
        'class': 'className',
1687
        'for': 'htmlFor',
1688
        'defaultValue': 'defaultValue',
1689
        'text': (Browser.Engine.trident || (Browser.Engine.webkit && Browser.Engine.version < 420)) ? 'innerText' : 'textContent'
1690
};
1691
var bools = ['compact', 'nowrap', 'ismap', 'declare', 'noshade', 'checked', 'disabled', 'readonly', 'multiple', 'selected', 'noresize', 'defer'];
1692
var camels = ['value', 'type', 'defaultValue', 'accessKey', 'cellPadding', 'cellSpacing', 'colSpan', 'frameBorder', 'maxLength', 'readOnly', 'rowSpan', 'tabIndex', 'useMap'];
1693

    
1694
bools = bools.associate(bools);
1695

    
1696
Hash.extend(attributes, bools);
1697
Hash.extend(attributes, camels.associate(camels.map(String.toLowerCase)));
1698

    
1699
var inserters = {
1700

    
1701
        before: function(context, element){
1702
                if (element.parentNode) element.parentNode.insertBefore(context, element);
1703
        },
1704

    
1705
        after: function(context, element){
1706
                if (!element.parentNode) return;
1707
                var next = element.nextSibling;
1708
                (next) ? element.parentNode.insertBefore(context, next) : element.parentNode.appendChild(context);
1709
        },
1710

    
1711
        bottom: function(context, element){
1712
                element.appendChild(context);
1713
        },
1714

    
1715
        top: function(context, element){
1716
                var first = element.firstChild;
1717
                (first) ? element.insertBefore(context, first) : element.appendChild(context);
1718
        }
1719

    
1720
};
1721

    
1722
inserters.inside = inserters.bottom;
1723

    
1724
Hash.each(inserters, function(inserter, where){
1725

    
1726
        where = where.capitalize();
1727

    
1728
        Element.implement('inject' + where, function(el){
1729
                inserter(this, document.id(el, true));
1730
                return this;
1731
        });
1732

    
1733
        Element.implement('grab' + where, function(el){
1734
                inserter(document.id(el, true), this);
1735
                return this;
1736
        });
1737

    
1738
});
1739

    
1740
Element.implement({
1741

    
1742
        set: function(prop, value){
1743
                switch ($type(prop)){
1744
                        case 'object':
1745
                                for (var p in prop) this.set(p, prop[p]);
1746
                                break;
1747
                        case 'string':
1748
                                var property = Element.Properties.get(prop);
1749
                                (property && property.set) ? property.set.apply(this, Array.slice(arguments, 1)) : this.setProperty(prop, value);
1750
                }
1751
                return this;
1752
        },
1753

    
1754
        get: function(prop){
1755
                var property = Element.Properties.get(prop);
1756
                return (property && property.get) ? property.get.apply(this, Array.slice(arguments, 1)) : this.getProperty(prop);
1757
        },
1758

    
1759
        erase: function(prop){
1760
                var property = Element.Properties.get(prop);
1761
                (property && property.erase) ? property.erase.apply(this) : this.removeProperty(prop);
1762
                return this;
1763
        },
1764

    
1765
        setProperty: function(attribute, value){
1766
                var key = attributes[attribute];
1767
                if (value == undefined) return this.removeProperty(attribute);
1768
                if (key && bools[attribute]) value = !!value;
1769
                (key) ? this[key] = value : this.setAttribute(attribute, '' + value);
1770
                return this;
1771
        },
1772

    
1773
        setProperties: function(attributes){
1774
                for (var attribute in attributes) this.setProperty(attribute, attributes[attribute]);
1775
                return this;
1776
        },
1777

    
1778
        getProperty: function(attribute){
1779
                var key = attributes[attribute];
1780
                var value = (key) ? this[key] : this.getAttribute(attribute, 2);
1781
                return (bools[attribute]) ? !!value : (key) ? value : value || null;
1782
        },
1783

    
1784
        getProperties: function(){
1785
                var args = $A(arguments);
1786
                return args.map(this.getProperty, this).associate(args);
1787
        },
1788

    
1789
        removeProperty: function(attribute){
1790
                var key = attributes[attribute];
1791
                (key) ? this[key] = (key && bools[attribute]) ? false : '' : this.removeAttribute(attribute);
1792
                return this;
1793
        },
1794

    
1795
        removeProperties: function(){
1796
                Array.each(arguments, this.removeProperty, this);
1797
                return this;
1798
        },
1799

    
1800
        hasClass: function(className){
1801
                return this.className.contains(className, ' ');
1802
        },
1803

    
1804
        addClass: function(className){
1805
                if (!this.hasClass(className)) this.className = (this.className + ' ' + className).clean();
1806
                return this;
1807
        },
1808

    
1809
        removeClass: function(className){
1810
                this.className = this.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1');
1811
                return this;
1812
        },
1813

    
1814
        toggleClass: function(className){
1815
                return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
1816
        },
1817

    
1818
        adopt: function(){
1819
                Array.flatten(arguments).each(function(element){
1820
                        element = document.id(element, true);
1821
                        if (element) this.appendChild(element);
1822
                }, this);
1823
                return this;
1824
        },
1825

    
1826
        appendText: function(text, where){
1827
                return this.grab(this.getDocument().newTextNode(text), where);
1828
        },
1829

    
1830
        grab: function(el, where){
1831
                inserters[where || 'bottom'](document.id(el, true), this);
1832
                return this;
1833
        },
1834

    
1835
        inject: function(el, where){
1836
                inserters[where || 'bottom'](this, document.id(el, true));
1837
                return this;
1838
        },
1839

    
1840
        replaces: function(el){
1841
                el = document.id(el, true);
1842
                el.parentNode.replaceChild(this, el);
1843
                return this;
1844
        },
1845

    
1846
        wraps: function(el, where){
1847
                el = document.id(el, true);
1848
                return this.replaces(el).grab(el, where);
1849
        },
1850

    
1851
        getPrevious: function(match, nocash){
1852
                return walk(this, 'previousSibling', null, match, false, nocash);
1853
        },
1854

    
1855
        getAllPrevious: function(match, nocash){
1856
                return walk(this, 'previousSibling', null, match, true, nocash);
1857
        },
1858

    
1859
        getNext: function(match, nocash){
1860
                return walk(this, 'nextSibling', null, match, false, nocash);
1861
        },
1862

    
1863
        getAllNext: function(match, nocash){
1864
                return walk(this, 'nextSibling', null, match, true, nocash);
1865
        },
1866

    
1867
        getFirst: function(match, nocash){
1868
                return walk(this, 'nextSibling', 'firstChild', match, false, nocash);
1869
        },
1870

    
1871
        getLast: function(match, nocash){
1872
                return walk(this, 'previousSibling', 'lastChild', match, false, nocash);
1873
        },
1874

    
1875
        getParent: function(match, nocash){
1876
                return walk(this, 'parentNode', null, match, false, nocash);
1877
        },
1878

    
1879
        getParents: function(match, nocash){
1880
                return walk(this, 'parentNode', null, match, true, nocash);
1881
        },
1882
        
1883
        getSiblings: function(match, nocash){
1884
                return this.getParent().getChildren(match, nocash).erase(this);
1885
        },
1886

    
1887
        getChildren: function(match, nocash){
1888
                return walk(this, 'nextSibling', 'firstChild', match, true, nocash);
1889
        },
1890

    
1891
        getWindow: function(){
1892
                return this.ownerDocument.window;
1893
        },
1894

    
1895
        getDocument: function(){
1896
                return this.ownerDocument;
1897
        },
1898

    
1899
        getElementById: function(id, nocash){
1900
                var el = this.ownerDocument.getElementById(id);
1901
                if (!el) return null;
1902
                for (var parent = el.parentNode; parent != this; parent = parent.parentNode){
1903
                        if (!parent) return null;
1904
                }
1905
                return document.id(el, nocash);
1906
        },
1907

    
1908
        getSelected: function(){
1909
                return new Elements($A(this.options).filter(function(option){
1910
                        return option.selected;
1911
                }));
1912
        },
1913

    
1914
        getComputedStyle: function(property){
1915
                if (this.currentStyle) return this.currentStyle[property.camelCase()];
1916
                var computed = this.getDocument().defaultView.getComputedStyle(this, null);
1917
                return (computed) ? computed.getPropertyValue([property.hyphenate()]) : null;
1918
        },
1919

    
1920
        toQueryString: function(){
1921
                var queryString = [];
1922
                this.getElements('input, select, textarea', true).each(function(el){
1923
                        if (!el.name || el.disabled || el.type == 'submit' || el.type == 'reset' || el.type == 'file') return;
1924
                        var value = (el.tagName.toLowerCase() == 'select') ? Element.getSelected(el).map(function(opt){
1925
                                return opt.value;
1926
                        }) : ((el.type == 'radio' || el.type == 'checkbox') && !el.checked) ? null : el.value;
1927
                        $splat(value).each(function(val){
1928
                                if (typeof val != 'undefined') queryString.push(el.name + '=' + encodeURIComponent(val));
1929
                        });
1930
                });
1931
                return queryString.join('&');
1932
        },
1933

    
1934
        clone: function(contents, keepid){
1935
                contents = contents !== false;
1936
                var clone = this.cloneNode(contents);
1937
                var clean = function(node, element){
1938
                        if (!keepid) node.removeAttribute('id');
1939
                        if (Browser.Engine.trident){
1940
                                node.clearAttributes();
1941
                                node.mergeAttributes(element);
1942
                                node.removeAttribute('uid');
1943
                                if (node.options){
1944
                                        var no = node.options, eo = element.options;
1945
                                        for (var j = no.length; j--;) no[j].selected = eo[j].selected;
1946
                                }
1947
                        }
1948
                        var prop = props[element.tagName.toLowerCase()];
1949
                        if (prop && element[prop]) node[prop] = element[prop];
1950
                };
1951

    
1952
                if (contents){
1953
                        var ce = clone.getElementsByTagName('*'), te = this.getElementsByTagName('*');
1954
                        for (var i = ce.length; i--;) clean(ce[i], te[i]);
1955
                }
1956

    
1957
                clean(clone, this);
1958
                return document.id(clone);
1959
        },
1960

    
1961
        destroy: function(){
1962
                Element.empty(this);
1963
                Element.dispose(this);
1964
                clean(this, true);
1965
                return null;
1966
        },
1967

    
1968
        empty: function(){
1969
                $A(this.childNodes).each(function(node){
1970
                        Element.destroy(node);
1971
                });
1972
                return this;
1973
        },
1974

    
1975
        dispose: function(){
1976
                return (this.parentNode) ? this.parentNode.removeChild(this) : this;
1977
        },
1978

    
1979
        hasChild: function(el){
1980
                el = document.id(el, true);
1981
                if (!el) return false;
1982
                if (Browser.Engine.webkit && Browser.Engine.version < 420) return $A(this.getElementsByTagName(el.tagName)).contains(el);
1983
                return (this.contains) ? (this != el && this.contains(el)) : !!(this.compareDocumentPosition(el) & 16);
1984
        },
1985

    
1986
        match: function(tag){
1987
                return (!tag || (tag == this) || (Element.get(this, 'tag') == tag));
1988
        }
1989

    
1990
});
1991

    
1992
Native.implement([Element, Window, Document], {
1993

    
1994
        addListener: function(type, fn){
1995
                if (type == 'unload'){
1996
                        var old = fn, self = this;
1997
                        fn = function(){
1998
                                self.removeListener('unload', fn);
1999
                                old();
2000
                        };
2001
                } else {
2002
                        collected[this.uid] = this;
2003
                }
2004
                if (this.addEventListener) this.addEventListener(type, fn, false);
2005
                else this.attachEvent('on' + type, fn);
2006
                return this;
2007
        },
2008

    
2009
        removeListener: function(type, fn){
2010
                if (this.removeEventListener) this.removeEventListener(type, fn, false);
2011
                else this.detachEvent('on' + type, fn);
2012
                return this;
2013
        },
2014

    
2015
        retrieve: function(property, dflt){
2016
                var storage = get(this.uid), prop = storage[property];
2017
                if (dflt != undefined && prop == undefined) prop = storage[property] = dflt;
2018
                return $pick(prop);
2019
        },
2020

    
2021
        store: function(property, value){
2022
                var storage = get(this.uid);
2023
                storage[property] = value;
2024
                return this;
2025
        },
2026

    
2027
        eliminate: function(property){
2028
                var storage = get(this.uid);
2029
                delete storage[property];
2030
                return this;
2031
        }
2032

    
2033
});
2034

    
2035
window.addListener('unload', purge);
2036

    
2037
})();
2038

    
2039
Element.Properties = new Hash;
2040

    
2041
Element.Properties.style = {
2042

    
2043
        set: function(style){
2044
                this.style.cssText = style;
2045
        },
2046

    
2047
        get: function(){
2048
                return this.style.cssText;
2049
        },
2050

    
2051
        erase: function(){
2052
                this.style.cssText = '';
2053
        }
2054

    
2055
};
2056

    
2057
Element.Properties.tag = {
2058

    
2059
        get: function(){
2060
                return this.tagName.toLowerCase();
2061
        }
2062

    
2063
};
2064

    
2065
Element.Properties.html = (function(){
2066
        var wrapper = document.createElement('div');
2067

    
2068
        var translations = {
2069
                table: [1, '<table>', '</table>'],
2070
                select: [1, '<select>', '</select>'],
2071
                tbody: [2, '<table><tbody>', '</tbody></table>'],
2072
                tr: [3, '<table><tbody><tr>', '</tr></tbody></table>']
2073
        };
2074
        translations.thead = translations.tfoot = translations.tbody;
2075

    
2076
        var html = {
2077
                set: function(){
2078
                        var html = Array.flatten(arguments).join('');
2079
                        var wrap = Browser.Engine.trident && translations[this.get('tag')];
2080
                        if (wrap){
2081
                                var first = wrapper;
2082
                                first.innerHTML = wrap[1] + html + wrap[2];
2083
                                for (var i = wrap[0]; i--;) first = first.firstChild;
2084
                                this.empty().adopt(first.childNodes);
2085
                        } else {
2086
                                this.innerHTML = html;
2087
                        }
2088
                }
2089
        };
2090

    
2091
        html.erase = html.set;
2092

    
2093
        return html;
2094
})();
2095

    
2096
if (Browser.Engine.webkit && Browser.Engine.version < 420) Element.Properties.text = {
2097
        get: function(){
2098
                if (this.innerText) return this.innerText;
2099
                var temp = this.ownerDocument.newElement('div', {html: this.innerHTML}).inject(this.ownerDocument.body);
2100
                var text = temp.innerText;
2101
                temp.destroy();
2102
                return text;
2103
        }
2104
};
2105

    
2106

    
2107
/*
2108
---
2109

2110
script: Element.Event.js
2111

2112
description: Contains Element methods for dealing with events. This file also includes mouseenter and mouseleave custom Element Events.
2113

2114
license: MIT-style license.
2115

2116
requires: 
2117
- /Element
2118
- /Event
2119

2120
provides: [Element.Event]
2121

2122
...
2123
*/
2124

    
2125
Element.Properties.events = {set: function(events){
2126
        this.addEvents(events);
2127
}};
2128

    
2129
Native.implement([Element, Window, Document], {
2130

    
2131
        addEvent: function(type, fn){
2132
                var events = this.retrieve('events', {});
2133
                events[type] = events[type] || {'keys': [], 'values': []};
2134
                if (events[type].keys.contains(fn)) return this;
2135
                events[type].keys.push(fn);
2136
                var realType = type, custom = Element.Events.get(type), condition = fn, self = this;
2137
                if (custom){
2138
                        if (custom.onAdd) custom.onAdd.call(this, fn);
2139
                        if (custom.condition){
2140
                                condition = function(event){
2141
                                        if (custom.condition.call(this, event)) return fn.call(this, event);
2142
                                        return true;
2143
                                };
2144
                        }
2145
                        realType = custom.base || realType;
2146
                }
2147
                var defn = function(){
2148
                        return fn.call(self);
2149
                };
2150
                var nativeEvent = Element.NativeEvents[realType];
2151
                if (nativeEvent){
2152
                        if (nativeEvent == 2){
2153
                                defn = function(event){
2154
                                        event = new Event(event, self.getWindow());
2155
                                        if (condition.call(self, event) === false) event.stop();
2156
                                };
2157
                        }
2158
                        this.addListener(realType, defn);
2159
                }
2160
                events[type].values.push(defn);
2161
                return this;
2162
        },
2163

    
2164
        removeEvent: function(type, fn){
2165
                var events = this.retrieve('events');
2166
                if (!events || !events[type]) return this;
2167
                var pos = events[type].keys.indexOf(fn);
2168
                if (pos == -1) return this;
2169
                events[type].keys.splice(pos, 1);
2170
                var value = events[type].values.splice(pos, 1)[0];
2171
                var custom = Element.Events.get(type);
2172
                if (custom){
2173
                        if (custom.onRemove) custom.onRemove.call(this, fn);
2174
                        type = custom.base || type;
2175
                }
2176
                return (Element.NativeEvents[type]) ? this.removeListener(type, value) : this;
2177
        },
2178

    
2179
        addEvents: function(events){
2180
                for (var event in events) this.addEvent(event, events[event]);
2181
                return this;
2182
        },
2183

    
2184
        removeEvents: function(events){
2185
                var type;
2186
                if ($type(events) == 'object'){
2187
                        for (type in events) this.removeEvent(type, events[type]);
2188
                        return this;
2189
                }
2190
                var attached = this.retrieve('events');
2191
                if (!attached) return this;
2192
                if (!events){
2193
                        for (type in attached) this.removeEvents(type);
2194
                        this.eliminate('events');
2195
                } else if (attached[events]){
2196
                        while (attached[events].keys[0]) this.removeEvent(events, attached[events].keys[0]);
2197
                        attached[events] = null;
2198
                }
2199
                return this;
2200
        },
2201

    
2202
        fireEvent: function(type, args, delay){
2203
                var events = this.retrieve('events');
2204
                if (!events || !events[type]) return this;
2205
                events[type].keys.each(function(fn){
2206
                        fn.create({'bind': this, 'delay': delay, 'arguments': args})();
2207
                }, this);
2208
                return this;
2209
        },
2210

    
2211
        cloneEvents: function(from, type){
2212
                from = document.id(from);
2213
                var fevents = from.retrieve('events');
2214
                if (!fevents) return this;
2215
                if (!type){
2216
                        for (var evType in fevents) this.cloneEvents(from, evType);
2217
                } else if (fevents[type]){
2218
                        fevents[type].keys.each(function(fn){
2219
                                this.addEvent(type, fn);
2220
                        }, this);
2221
                }
2222
                return this;
2223
        }
2224

    
2225
});
2226

    
2227
Element.NativeEvents = {
2228
        click: 2, dblclick: 2, mouseup: 2, mousedown: 2, contextmenu: 2, //mouse buttons
2229
        mousewheel: 2, DOMMouseScroll: 2, //mouse wheel
2230
        mouseover: 2, mouseout: 2, mousemove: 2, selectstart: 2, selectend: 2, //mouse movement
2231
        keydown: 2, keypress: 2, keyup: 2, //keyboard
2232
        focus: 2, blur: 2, change: 2, reset: 2, select: 2, submit: 2, //form elements
2233
        load: 1, unload: 1, beforeunload: 2, resize: 1, move: 1, DOMContentLoaded: 1, readystatechange: 1, //window
2234
        error: 1, abort: 1, scroll: 1 //misc
2235
};
2236

    
2237
(function(){
2238

    
2239
var $check = function(event){
2240
        var related = event.relatedTarget;
2241
        if (related == undefined) return true;
2242
        if (related === false) return false;
2243
        return ($type(this) != 'document' && related != this && related.prefix != 'xul' && !this.hasChild(related));
2244
};
2245

    
2246
Element.Events = new Hash({
2247

    
2248
        mouseenter: {
2249
                base: 'mouseover',
2250
                condition: $check
2251
        },
2252

    
2253
        mouseleave: {
2254
                base: 'mouseout',
2255
                condition: $check
2256
        },
2257

    
2258
        mousewheel: {
2259
                base: (Browser.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel'
2260
        }
2261

    
2262
});
2263

    
2264
})();
2265

    
2266

    
2267
/*
2268
---
2269

2270
script: Element.Style.js
2271

2272
description: Contains methods for interacting with the styles of Elements in a fashionable way.
2273

2274
license: MIT-style license.
2275

2276
requires:
2277
- /Element
2278

2279
provides: [Element.Style]
2280

2281
...
2282
*/
2283

    
2284
Element.Properties.styles = {set: function(styles){
2285
        this.setStyles(styles);
2286
}};
2287

    
2288
Element.Properties.opacity = {
2289

    
2290
        set: function(opacity, novisibility){
2291
                if (!novisibility){
2292
                        if (opacity == 0){
2293
                                if (this.style.visibility != 'hidden') this.style.visibility = 'hidden';
2294
                        } else {
2295
                                if (this.style.visibility != 'visible') this.style.visibility = 'visible';
2296
                        }
2297
                }
2298
                if (!this.currentStyle || !this.currentStyle.hasLayout) this.style.zoom = 1;
2299
                if (Browser.Engine.trident) this.style.filter = (opacity == 1) ? '' : 'alpha(opacity=' + opacity * 100 + ')';
2300
                this.style.opacity = opacity;
2301
                this.store('opacity', opacity);
2302
        },
2303

    
2304
        get: function(){
2305
                return this.retrieve('opacity', 1);
2306
        }
2307

    
2308
};
2309

    
2310
Element.implement({
2311

    
2312
        setOpacity: function(value){
2313
                return this.set('opacity', value, true);
2314
        },
2315

    
2316
        getOpacity: function(){
2317
                return this.get('opacity');
2318
        },
2319

    
2320
        setStyle: function(property, value){
2321
                switch (property){
2322
                        case 'opacity': return this.set('opacity', parseFloat(value));
2323
                        case 'float': property = (Browser.Engine.trident) ? 'styleFloat' : 'cssFloat';
2324
                }
2325
                property = property.camelCase();
2326
                if ($type(value) != 'string'){
2327
                        var map = (Element.Styles.get(property) || '@').split(' ');
2328
                        value = $splat(value).map(function(val, i){
2329
                                if (!map[i]) return '';
2330
                                return ($type(val) == 'number') ? map[i].replace('@', Math.round(val)) : val;
2331
                        }).join(' ');
2332
                } else if (value == String(Number(value))){
2333
                        value = Math.round(value);
2334
                }
2335
                this.style[property] = value;
2336
                return this;
2337
        },
2338

    
2339
        getStyle: function(property){
2340
                switch (property){
2341
                        case 'opacity': return this.get('opacity');
2342
                        case 'float': property = (Browser.Engine.trident) ? 'styleFloat' : 'cssFloat';
2343
                }
2344
                property = property.camelCase();
2345
                var result = this.style[property];
2346
                if (!$chk(result)){
2347
                        result = [];
2348
                        for (var style in Element.ShortStyles){
2349
                                if (property != style) continue;
2350
                                for (var s in Element.ShortStyles[style]) result.push(this.getStyle(s));
2351
                                return result.join(' ');
2352
                        }
2353
                        result = this.getComputedStyle(property);
2354
                }
2355
                if (result){
2356
                        result = String(result);
2357
                        var color = result.match(/rgba?\([\d\s,]+\)/);
2358
                        if (color) result = result.replace(color[0], color[0].rgbToHex());
2359
                }
2360
                if (Browser.Engine.presto || (Browser.Engine.trident && !$chk(parseInt(result, 10)))){
2361
                        if (property.test(/^(height|width)$/)){
2362
                                var values = (property == 'width') ? ['left', 'right'] : ['top', 'bottom'], size = 0;
2363
                                values.each(function(value){
2364
                                        size += this.getStyle('border-' + value + '-width').toInt() + this.getStyle('padding-' + value).toInt();
2365
                                }, this);
2366
                                return this['offset' + property.capitalize()] - size + 'px';
2367
                        }
2368
                        if ((Browser.Engine.presto) && String(result).test('px')) return result;
2369
                        if (property.test(/(border(.+)Width|margin|padding)/)) return '0px';
2370
                }
2371
                return result;
2372
        },
2373

    
2374
        setStyles: function(styles){
2375
                for (var style in styles) this.setStyle(style, styles[style]);
2376
                return this;
2377
        },
2378

    
2379
        getStyles: function(){
2380
                var result = {};
2381
                Array.flatten(arguments).each(function(key){
2382
                        result[key] = this.getStyle(key);
2383
                }, this);
2384
                return result;
2385
        }
2386

    
2387
});
2388

    
2389
Element.Styles = new Hash({
2390
        left: '@px', top: '@px', bottom: '@px', right: '@px',
2391
        width: '@px', height: '@px', maxWidth: '@px', maxHeight: '@px', minWidth: '@px', minHeight: '@px',
2392
        backgroundColor: 'rgb(@, @, @)', backgroundPosition: '@px @px', color: 'rgb(@, @, @)',
2393
        fontSize: '@px', letterSpacing: '@px', lineHeight: '@px', clip: 'rect(@px @px @px @px)',
2394
        margin: '@px @px @px @px', padding: '@px @px @px @px', border: '@px @ rgb(@, @, @) @px @ rgb(@, @, @) @px @ rgb(@, @, @)',
2395
        borderWidth: '@px @px @px @px', borderStyle: '@ @ @ @', borderColor: 'rgb(@, @, @) rgb(@, @, @) rgb(@, @, @) rgb(@, @, @)',
2396
        zIndex: '@', 'zoom': '@', fontWeight: '@', textIndent: '@px', opacity: '@'
2397
});
2398

    
2399
Element.ShortStyles = {margin: {}, padding: {}, border: {}, borderWidth: {}, borderStyle: {}, borderColor: {}};
2400

    
2401
['Top', 'Right', 'Bottom', 'Left'].each(function(direction){
2402
        var Short = Element.ShortStyles;
2403
        var All = Element.Styles;
2404
        ['margin', 'padding'].each(function(style){
2405
                var sd = style + direction;
2406
                Short[style][sd] = All[sd] = '@px';
2407
        });
2408
        var bd = 'border' + direction;
2409
        Short.border[bd] = All[bd] = '@px @ rgb(@, @, @)';
2410
        var bdw = bd + 'Width', bds = bd + 'Style', bdc = bd + 'Color';
2411
        Short[bd] = {};
2412
        Short.borderWidth[bdw] = Short[bd][bdw] = All[bdw] = '@px';
2413
        Short.borderStyle[bds] = Short[bd][bds] = All[bds] = '@';
2414
        Short.borderColor[bdc] = Short[bd][bdc] = All[bdc] = 'rgb(@, @, @)';
2415
});
2416

    
2417

    
2418
/*
2419
---
2420

2421
script: Element.Dimensions.js
2422

2423
description: Contains methods to work with size, scroll, or positioning of Elements and the window object.
2424

2425
license: MIT-style license.
2426

2427
credits:
2428
- Element positioning based on the [qooxdoo](http://qooxdoo.org/) code and smart browser fixes, [LGPL License](http://www.gnu.org/licenses/lgpl.html).
2429
- Viewport dimensions based on [YUI](http://developer.yahoo.com/yui/) code, [BSD License](http://developer.yahoo.com/yui/license.html).
2430

2431
requires:
2432
- /Element
2433

2434
provides: [Element.Dimensions]
2435

2436
...
2437
*/
2438

    
2439
(function(){
2440

    
2441
Element.implement({
2442

    
2443
        scrollTo: function(x, y){
2444
                if (isBody(this)){
2445
                        this.getWindow().scrollTo(x, y);
2446
                } else {
2447
                        this.scrollLeft = x;
2448
                        this.scrollTop = y;
2449
                }
2450
                return this;
2451
        },
2452

    
2453
        getSize: function(){
2454
                if (isBody(this)) return this.getWindow().getSize();
2455
                return {x: this.offsetWidth, y: this.offsetHeight};
2456
        },
2457

    
2458
        getScrollSize: function(){
2459
                if (isBody(this)) return this.getWindow().getScrollSize();
2460
                return {x: this.scrollWidth, y: this.scrollHeight};
2461
        },
2462

    
2463
        getScroll: function(){
2464
                if (isBody(this)) return this.getWindow().getScroll();
2465
                return {x: this.scrollLeft, y: this.scrollTop};
2466
        },
2467

    
2468
        getScrolls: function(){
2469
                var element = this, position = {x: 0, y: 0};
2470
                while (element && !isBody(element)){
2471
                        position.x += element.scrollLeft;
2472
                        position.y += element.scrollTop;
2473
                        element = element.parentNode;
2474
                }
2475
                return position;
2476
        },
2477

    
2478
        getOffsetParent: function(){
2479
                var element = this;
2480
                if (isBody(element)) return null;
2481
                if (!Browser.Engine.trident) return element.offsetParent;
2482
                while ((element = element.parentNode) && !isBody(element)){
2483
                        if (styleString(element, 'position') != 'static') return element;
2484
                }
2485
                return null;
2486
        },
2487

    
2488
        getOffsets: function(){
2489
                if (this.getBoundingClientRect){
2490
                        var bound = this.getBoundingClientRect(),
2491
                                html = document.id(this.getDocument().documentElement),
2492
                                htmlScroll = html.getScroll(),
2493
                                elemScrolls = this.getScrolls(),
2494
                                elemScroll = this.getScroll(),
2495
                                isFixed = (styleString(this, 'position') == 'fixed');
2496

    
2497
                        return {
2498
                                x: bound.left.toInt() + elemScrolls.x - elemScroll.x + ((isFixed) ? 0 : htmlScroll.x) - html.clientLeft,
2499
                                y: bound.top.toInt()  + elemScrolls.y - elemScroll.y + ((isFixed) ? 0 : htmlScroll.y) - html.clientTop
2500
                        };
2501
                }
2502

    
2503
                var element = this, position = {x: 0, y: 0};
2504
                if (isBody(this)) return position;
2505

    
2506
                while (element && !isBody(element)){
2507
                        position.x += element.offsetLeft;
2508
                        position.y += element.offsetTop;
2509

    
2510
                        if (Browser.Engine.gecko){
2511
                                if (!borderBox(element)){
2512
                                        position.x += leftBorder(element);
2513
                                        position.y += topBorder(element);
2514
                                }
2515
                                var parent = element.parentNode;
2516
                                if (parent && styleString(parent, 'overflow') != 'visible'){
2517
                                        position.x += leftBorder(parent);
2518
                                        position.y += topBorder(parent);
2519
                                }
2520
                        } else if (element != this && Browser.Engine.webkit){
2521
                                position.x += leftBorder(element);
2522
                                position.y += topBorder(element);
2523
                        }
2524

    
2525
                        element = element.offsetParent;
2526
                }
2527
                if (Browser.Engine.gecko && !borderBox(this)){
2528
                        position.x -= leftBorder(this);
2529
                        position.y -= topBorder(this);
2530
                }
2531
                return position;
2532
        },
2533

    
2534
        getPosition: function(relative){
2535
                if (isBody(this)) return {x: 0, y: 0};
2536
                var offset = this.getOffsets(),
2537
                                scroll = this.getScrolls();
2538
                var position = {
2539
                        x: offset.x - scroll.x,
2540
                        y: offset.y - scroll.y
2541
                };
2542
                var relativePosition = (relative && (relative = document.id(relative))) ? relative.getPosition() : {x: 0, y: 0};
2543
                return {x: position.x - relativePosition.x, y: position.y - relativePosition.y};
2544
        },
2545

    
2546
        getCoordinates: function(element){
2547
                if (isBody(this)) return this.getWindow().getCoordinates();
2548
                var position = this.getPosition(element),
2549
                                size = this.getSize();
2550
                var obj = {
2551
                        left: position.x,
2552
                        top: position.y,
2553
                        width: size.x,
2554
                        height: size.y
2555
                };
2556
                obj.right = obj.left + obj.width;
2557
                obj.bottom = obj.top + obj.height;
2558
                return obj;
2559
        },
2560

    
2561
        computePosition: function(obj){
2562
                return {
2563
                        left: obj.x - styleNumber(this, 'margin-left'),
2564
                        top: obj.y - styleNumber(this, 'margin-top')
2565
                };
2566
        },
2567

    
2568
        setPosition: function(obj){
2569
                return this.setStyles(this.computePosition(obj));
2570
        }
2571

    
2572
});
2573

    
2574

    
2575
Native.implement([Document, Window], {
2576

    
2577
        getSize: function(){
2578
                if (Browser.Engine.presto || Browser.Engine.webkit){
2579
                        var win = this.getWindow();
2580
                        return {x: win.innerWidth, y: win.innerHeight};
2581
                }
2582
                var doc = getCompatElement(this);
2583
                return {x: doc.clientWidth, y: doc.clientHeight};
2584
        },
2585

    
2586
        getScroll: function(){
2587
                var win = this.getWindow(), doc = getCompatElement(this);
2588
                return {x: win.pageXOffset || doc.scrollLeft, y: win.pageYOffset || doc.scrollTop};
2589
        },
2590

    
2591
        getScrollSize: function(){
2592
                var doc = getCompatElement(this), min = this.getSize();
2593
                return {x: Math.max(doc.scrollWidth, min.x), y: Math.max(doc.scrollHeight, min.y)};
2594
        },
2595

    
2596
        getPosition: function(){
2597
                return {x: 0, y: 0};
2598
        },
2599

    
2600
        getCoordinates: function(){
2601
                var size = this.getSize();
2602
                return {top: 0, left: 0, bottom: size.y, right: size.x, height: size.y, width: size.x};
2603
        }
2604

    
2605
});
2606

    
2607
// private methods
2608

    
2609
var styleString = Element.getComputedStyle;
2610

    
2611
function styleNumber(element, style){
2612
        return styleString(element, style).toInt() || 0;
2613
};
2614

    
2615
function borderBox(element){
2616
        return styleString(element, '-moz-box-sizing') == 'border-box';
2617
};
2618

    
2619
function topBorder(element){
2620
        return styleNumber(element, 'border-top-width');
2621
};
2622

    
2623
function leftBorder(element){
2624
        return styleNumber(element, 'border-left-width');
2625
};
2626

    
2627
function isBody(element){
2628
        return (/^(?:body|html)$/i).test(element.tagName);
2629
};
2630

    
2631
function getCompatElement(element){
2632
        var doc = element.getDocument();
2633
        return (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body;
2634
};
2635

    
2636
})();
2637

    
2638
//aliases
2639
Element.alias('setPosition', 'position'); //compatability
2640

    
2641
Native.implement([Window, Document, Element], {
2642

    
2643
        getHeight: function(){
2644
                return this.getSize().y;
2645
        },
2646

    
2647
        getWidth: function(){
2648
                return this.getSize().x;
2649
        },
2650

    
2651
        getScrollTop: function(){
2652
                return this.getScroll().y;
2653
        },
2654

    
2655
        getScrollLeft: function(){
2656
                return this.getScroll().x;
2657
        },
2658

    
2659
        getScrollHeight: function(){
2660
                return this.getScrollSize().y;
2661
        },
2662

    
2663
        getScrollWidth: function(){
2664
                return this.getScrollSize().x;
2665
        },
2666

    
2667
        getTop: function(){
2668
                return this.getPosition().y;
2669
        },
2670

    
2671
        getLeft: function(){
2672
                return this.getPosition().x;
2673
        }
2674

    
2675
});
2676

    
2677

    
2678
/*
2679
---
2680

2681
script: Selectors.js
2682

2683
description: Adds advanced CSS-style querying capabilities for targeting HTML Elements. Includes pseudo selectors.
2684

2685
license: MIT-style license.
2686

2687
requires:
2688
- /Element
2689

2690
provides: [Selectors]
2691

2692
...
2693
*/
2694

    
2695
Native.implement([Document, Element], {
2696

    
2697
        getElements: function(expression, nocash){
2698
                expression = expression.split(',');
2699
                var items, local = {};
2700
                for (var i = 0, l = expression.length; i < l; i++){
2701
                        var selector = expression[i], elements = Selectors.Utils.search(this, selector, local);
2702
                        if (i != 0 && elements.item) elements = $A(elements);
2703
                        items = (i == 0) ? elements : (items.item) ? $A(items).concat(elements) : items.concat(elements);
2704
                }
2705
                return new Elements(items, {ddup: (expression.length > 1), cash: !nocash});
2706
        }
2707

    
2708
});
2709

    
2710
Element.implement({
2711

    
2712
        match: function(selector){
2713
                if (!selector || (selector == this)) return true;
2714
                var tagid = Selectors.Utils.parseTagAndID(selector);
2715
                var tag = tagid[0], id = tagid[1];
2716
                if (!Selectors.Filters.byID(this, id) || !Selectors.Filters.byTag(this, tag)) return false;
2717
                var parsed = Selectors.Utils.parseSelector(selector);
2718
                return (parsed) ? Selectors.Utils.filter(this, parsed, {}) : true;
2719
        }
2720

    
2721
});
2722

    
2723
var Selectors = {Cache: {nth: {}, parsed: {}}};
2724

    
2725
Selectors.RegExps = {
2726
        // FIXME: fpo: Restriction de l'id pour que la recherche sur un attribut avec un '#' fonctionne.
2727
        id: (/#([a-zA-Z_][\w-]+)/),
2728
        tag: (/^(\w+|\*)/),
2729
        quick: (/^(\w+|\*)$/),
2730
        splitter: (/\s*([+>~\s])\s*([a-zA-Z#.*:\[])/g),
2731
        combined: (/\.([\w-]+)|\[(\w+)(?:([!*^$~|]?=)(["']?)([^\4]*?)\4)?\]|:([\w-]+)(?:\(["']?(.*?)?["']?\)|$)/g)
2732
};
2733

    
2734
Selectors.Utils = {
2735

    
2736
        chk: function(item, uniques){
2737
                if (!uniques) return true;
2738
                var uid = $uid(item);
2739
                if (!uniques[uid]) return uniques[uid] = true;
2740
                return false;
2741
        },
2742

    
2743
        parseNthArgument: function(argument){
2744
                if (Selectors.Cache.nth[argument]) return Selectors.Cache.nth[argument];
2745
                var parsed = argument.match(/^([+-]?\d*)?([a-z]+)?([+-]?\d*)?$/);
2746
                if (!parsed) return false;
2747
                var inta = parseInt(parsed[1], 10);
2748
                var a = (inta || inta === 0) ? inta : 1;
2749
                var special = parsed[2] || false;
2750
                var b = parseInt(parsed[3], 10) || 0;
2751
                if (a != 0){
2752
                        b--;
2753
                        while (b < 1) b += a;
2754
                        while (b >= a) b -= a;
2755
                } else {
2756
                        a = b;
2757
                        special = 'index';
2758
                }
2759
                switch (special){
2760
                        case 'n': parsed = {a: a, b: b, special: 'n'}; break;
2761
                        case 'odd': parsed = {a: 2, b: 0, special: 'n'}; break;
2762
                        case 'even': parsed = {a: 2, b: 1, special: 'n'}; break;
2763
                        case 'first': parsed = {a: 0, special: 'index'}; break;
2764
                        case 'last': parsed = {special: 'last-child'}; break;
2765
                        case 'only': parsed = {special: 'only-child'}; break;
2766
                        default: parsed = {a: (a - 1), special: 'index'};
2767
                }
2768

    
2769
                return Selectors.Cache.nth[argument] = parsed;
2770
        },
2771

    
2772
        parseSelector: function(selector){
2773
                if (Selectors.Cache.parsed[selector]) return Selectors.Cache.parsed[selector];
2774
                var m, parsed = {classes: [], pseudos: [], attributes: []};
2775
                while ((m = Selectors.RegExps.combined.exec(selector))){
2776
                        var cn = m[1], an = m[2], ao = m[3], av = m[5], pn = m[6], pa = m[7];
2777
                        if (cn){
2778
                                parsed.classes.push(cn);
2779
                        } else if (pn){
2780
                                var parser = Selectors.Pseudo.get(pn);
2781
                                if (parser) parsed.pseudos.push({parser: parser, argument: pa});
2782
                                else parsed.attributes.push({name: pn, operator: '=', value: pa});
2783
                        } else if (an){
2784
                                parsed.attributes.push({name: an, operator: ao, value: av});
2785
                        }
2786
                }
2787
                if (!parsed.classes.length) delete parsed.classes;
2788
                if (!parsed.attributes.length) delete parsed.attributes;
2789
                if (!parsed.pseudos.length) delete parsed.pseudos;
2790
                if (!parsed.classes && !parsed.attributes && !parsed.pseudos) parsed = null;
2791
                return Selectors.Cache.parsed[selector] = parsed;
2792
        },
2793

    
2794
        parseTagAndID: function(selector){
2795
                var tag = selector.match(Selectors.RegExps.tag);
2796
                var id = selector.match(Selectors.RegExps.id);
2797
                return [(tag) ? tag[1] : '*', (id) ? id[1] : false];
2798
        },
2799

    
2800
        filter: function(item, parsed, local){
2801
                var i;
2802
                if (parsed.classes){
2803
                        for (i = parsed.classes.length; i--; i){
2804
                                var cn = parsed.classes[i];
2805
                                if (!Selectors.Filters.byClass(item, cn)) return false;
2806
                        }
2807
                }
2808
                if (parsed.attributes){
2809
                        for (i = parsed.attributes.length; i--; i){
2810
                                var att = parsed.attributes[i];
2811
                                if (!Selectors.Filters.byAttribute(item, att.name, att.operator, att.value)) return false;
2812
                        }
2813
                }
2814
                if (parsed.pseudos){
2815
                        for (i = parsed.pseudos.length; i--; i){
2816
                                var psd = parsed.pseudos[i];
2817
                                if (!Selectors.Filters.byPseudo(item, psd.parser, psd.argument, local)) return false;
2818
                        }
2819
                }
2820
                return true;
2821
        },
2822

    
2823
        getByTagAndID: function(ctx, tag, id){
2824
                if (id){
2825
                        var item = (ctx.getElementById) ? ctx.getElementById(id, true) : Element.getElementById(ctx, id, true);
2826
                        return (item && Selectors.Filters.byTag(item, tag)) ? [item] : [];
2827
                } else {
2828
                        return ctx.getElementsByTagName(tag);
2829
                }
2830
        },
2831

    
2832
        search: function(self, expression, local){
2833
                var splitters = [];
2834

    
2835
                var selectors = expression.trim().replace(Selectors.RegExps.splitter, function(m0, m1, m2){
2836
                        splitters.push(m1);
2837
                        return ':)' + m2;
2838
                }).split(':)');
2839

    
2840
                var items, filtered, item;
2841

    
2842
                for (var i = 0, l = selectors.length; i < l; i++){
2843

    
2844
                        var selector = selectors[i];
2845

    
2846
                        if (i == 0 && Selectors.RegExps.quick.test(selector)){
2847
                                items = self.getElementsByTagName(selector);
2848
                                continue;
2849
                        }
2850

    
2851
                        var splitter = splitters[i - 1];
2852

    
2853
                        var tagid = Selectors.Utils.parseTagAndID(selector);
2854
                        var tag = tagid[0], id = tagid[1];
2855

    
2856
                        if (i == 0){
2857
                                items = Selectors.Utils.getByTagAndID(self, tag, id);
2858
                        } else {
2859
                                var uniques = {}, found = [];
2860
                                for (var j = 0, k = items.length; j < k; j++) found = Selectors.Getters[splitter](found, items[j], tag, id, uniques);
2861
                                items = found;
2862
                        }
2863

    
2864
                        var parsed = Selectors.Utils.parseSelector(selector);
2865

    
2866
                        if (parsed){
2867
                                filtered = [];
2868
                                for (var m = 0, n = items.length; m < n; m++){
2869
                                        item = items[m];
2870
                                        if (Selectors.Utils.filter(item, parsed, local)) filtered.push(item);
2871
                                }
2872
                                items = filtered;
2873
                        }
2874

    
2875
                }
2876

    
2877
                return items;
2878

    
2879
        }
2880

    
2881
};
2882

    
2883
Selectors.Getters = {
2884

    
2885
        ' ': function(found, self, tag, id, uniques){
2886
                var items = Selectors.Utils.getByTagAndID(self, tag, id);
2887
                for (var i = 0, l = items.length; i < l; i++){
2888
                        var item = items[i];
2889
                        if (Selectors.Utils.chk(item, uniques)) found.push(item);
2890
                }
2891
                return found;
2892
        },
2893

    
2894
        '>': function(found, self, tag, id, uniques){
2895
                var children = Selectors.Utils.getByTagAndID(self, tag, id);
2896
                for (var i = 0, l = children.length; i < l; i++){
2897
                        var child = children[i];
2898
                        if (child.parentNode == self && Selectors.Utils.chk(child, uniques)) found.push(child);
2899
                }
2900
                return found;
2901
        },
2902

    
2903
        '+': function(found, self, tag, id, uniques){
2904
                while ((self = self.nextSibling)){
2905
                        if (self.nodeType == 1){
2906
                                if (Selectors.Utils.chk(self, uniques) && Selectors.Filters.byTag(self, tag) && Selectors.Filters.byID(self, id)) found.push(self);
2907
                                break;
2908
                        }
2909
                }
2910
                return found;
2911
        },
2912

    
2913
        '~': function(found, self, tag, id, uniques){
2914
                while ((self = self.nextSibling)){
2915
                        if (self.nodeType == 1){
2916
                                if (!Selectors.Utils.chk(self, uniques)) break;
2917
                                if (Selectors.Filters.byTag(self, tag) && Selectors.Filters.byID(self, id)) found.push(self);
2918
                        }
2919
                }
2920
                return found;
2921
        }
2922

    
2923
};
2924

    
2925
Selectors.Filters = {
2926

    
2927
        byTag: function(self, tag){
2928
                return (tag == '*' || (self.tagName && self.tagName.toLowerCase() == tag));
2929
        },
2930

    
2931
        byID: function(self, id){
2932
                return (!id || (self.id && self.id == id));
2933
        },
2934

    
2935
        byClass: function(self, klass){
2936
                return (self.className && self.className.contains && self.className.contains(klass, ' '));
2937
        },
2938

    
2939
        byPseudo: function(self, parser, argument, local){
2940
                return parser.call(self, argument, local);
2941
        },
2942

    
2943
        byAttribute: function(self, name, operator, value){
2944
                var result = Element.prototype.getProperty.call(self, name);
2945
                if (!result) return (operator == '!=');
2946
                if (!operator || value == undefined) return true;
2947
                switch (operator){
2948
                        case '=': return (result == value);
2949
                        case '*=': return (result.contains(value));
2950
                        case '^=': return (result.substr(0, value.length) == value);
2951
                        case '$=': return (result.substr(result.length - value.length) == value);
2952
                        case '!=': return (result != value);
2953
                        case '~=': return result.contains(value, ' ');
2954
                        case '|=': return result.contains(value, '-');
2955
                }
2956
                return false;
2957
        }
2958

    
2959
};
2960

    
2961
Selectors.Pseudo = new Hash({
2962

    
2963
        // w3c pseudo selectors
2964

    
2965
        checked: function(){
2966
                return this.checked;
2967
        },
2968
        
2969
        empty: function(){
2970
                return !(this.innerText || this.textContent || '').length;
2971
        },
2972

    
2973
        not: function(selector){
2974
                return !Element.match(this, selector);
2975
        },
2976

    
2977
        contains: function(text){
2978
                return (this.innerText || this.textContent || '').contains(text);
2979
        },
2980

    
2981
        'first-child': function(){
2982
                return Selectors.Pseudo.index.call(this, 0);
2983
        },
2984

    
2985
        'last-child': function(){
2986
                var element = this;
2987
                while ((element = element.nextSibling)){
2988
                        if (element.nodeType == 1) return false;
2989
                }
2990
                return true;
2991
        },
2992

    
2993
        'only-child': function(){
2994
                var prev = this;
2995
                while ((prev = prev.previousSibling)){
2996
                        if (prev.nodeType == 1) return false;
2997
                }
2998
                var next = this;
2999
                while ((next = next.nextSibling)){
3000
                        if (next.nodeType == 1) return false;
3001
                }
3002
                return true;
3003
        },
3004

    
3005
        'nth-child': function(argument, local){
3006
                argument = (argument == undefined) ? 'n' : argument;
3007
                var parsed = Selectors.Utils.parseNthArgument(argument);
3008
                if (parsed.special != 'n') return Selectors.Pseudo[parsed.special].call(this, parsed.a, local);
3009
                var count = 0;
3010
                local.positions = local.positions || {};
3011
                var uid = $uid(this);
3012
                if (!local.positions[uid]){
3013
                        var self = this;
3014
                        while ((self = self.previousSibling)){
3015
                                if (self.nodeType != 1) continue;
3016
                                count ++;
3017
                                var position = local.positions[$uid(self)];
3018
                                if (position != undefined){
3019
                                        count = position + count;
3020
                                        break;
3021
                                }
3022
                        }
3023
                        local.positions[uid] = count;
3024
                }
3025
                return (local.positions[uid] % parsed.a == parsed.b);
3026
        },
3027

    
3028
        // custom pseudo selectors
3029

    
3030
        index: function(index){
3031
                var element = this, count = 0;
3032
                while ((element = element.previousSibling)){
3033
                        if (element.nodeType == 1 && ++count > index) return false;
3034
                }
3035
                return (count == index);
3036
        },
3037

    
3038
        even: function(argument, local){
3039
                return Selectors.Pseudo['nth-child'].call(this, '2n+1', local);
3040
        },
3041

    
3042
        odd: function(argument, local){
3043
                return Selectors.Pseudo['nth-child'].call(this, '2n', local);
3044
        },
3045
        
3046
        selected: function(){
3047
                return this.selected;
3048
        },
3049
        
3050
        enabled: function(){
3051
                return (this.disabled === false);
3052
        }
3053

    
3054
});
3055

    
3056

    
3057
/*
3058
---
3059

3060
script: DomReady.js
3061

3062
description: Contains the custom event domready.
3063

3064
license: MIT-style license.
3065

3066
requires:
3067
- /Element.Event
3068

3069
provides: [DomReady]
3070

3071
...
3072
*/
3073

    
3074
Element.Events.domready = {
3075

    
3076
        onAdd: function(fn){
3077
                if (Browser.loaded) fn.call(this);
3078
        }
3079

    
3080
};
3081

    
3082
(function(){
3083

    
3084
        var domready = function(){
3085
                if (Browser.loaded) return;
3086
                Browser.loaded = true;
3087
                window.fireEvent('domready');
3088
                document.fireEvent('domready');
3089
        };
3090
        
3091
        window.addEvent('load', domready);
3092

    
3093
        if (Browser.Engine.trident){
3094
                var temp = document.createElement('div');
3095
                (function(){
3096
                        ($try(function(){
3097
                                temp.doScroll(); // Technique by Diego Perini
3098
                                return document.id(temp).inject(document.body).set('html', 'temp').dispose();
3099
                        })) ? domready() : arguments.callee.delay(50);
3100
                })();
3101
        } else if (Browser.Engine.webkit && Browser.Engine.version < 525){
3102
                (function(){
3103
                        (['loaded', 'complete'].contains(document.readyState)) ? domready() : arguments.callee.delay(50);
3104
                })();
3105
        } else {
3106
                document.addEvent('DOMContentLoaded', domready);
3107
        }
3108

    
3109
})();
3110

    
3111

    
3112
/*
3113
---
3114

3115
script: JSON.js
3116

3117
description: JSON encoder and decoder.
3118

3119
license: MIT-style license.
3120

3121
See Also: <http://www.json.org/>
3122

3123
requires:
3124
- /Array
3125
- /String
3126
- /Number
3127
- /Function
3128
- /Hash
3129

3130
provides: [JSON]
3131

3132
...
3133
*/
3134

    
3135
var JSON = new Hash(this.JSON && {
3136
        stringify: JSON.stringify,
3137
        parse: JSON.parse
3138
}).extend({
3139
        
3140
        $specialChars: {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'},
3141

    
3142
        $replaceChars: function(chr){
3143
                return JSON.$specialChars[chr] || '\\u00' + Math.floor(chr.charCodeAt() / 16).toString(16) + (chr.charCodeAt() % 16).toString(16);
3144
        },
3145

    
3146
        encode: function(obj){
3147
                switch ($type(obj)){
3148
                        case 'string':
3149
                                return '"' + obj.replace(/[\x00-\x1f\\"]/g, JSON.$replaceChars) + '"';
3150
                        case 'array':
3151
                                return '[' + String(obj.map(JSON.encode).clean()) + ']';
3152
                        case 'object': case 'hash':
3153
                                var string = [];
3154
                                Hash.each(obj, function(value, key){
3155
                                        var json = JSON.encode(value);
3156
                                        if (json) string.push(JSON.encode(key) + ':' + json);
3157
                                });
3158
                                return '{' + string + '}';
3159
                        case 'number': case 'boolean': return String(obj);
3160
                        case false: return 'null';
3161
                }
3162
                return null;
3163
        },
3164

    
3165
        decode: function(string, secure){
3166
                if ($type(string) != 'string' || !string.length) return null;
3167
                if (secure && !(/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(string.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''))) return null;
3168
                return eval('(' + string + ')');
3169
        }
3170

    
3171
});
3172

    
3173
Native.implement([Hash, Array, String, Number], {
3174

    
3175
        toJSON: function(){
3176
                return JSON.encode(this);
3177
        }
3178

    
3179
});
3180

    
3181

    
3182
/*
3183
---
3184

3185
script: Cookie.js
3186

3187
description: Class for creating, reading, and deleting browser Cookies.
3188

3189
license: MIT-style license.
3190

3191
credits:
3192
- Based on the functions by Peter-Paul Koch (http://quirksmode.org).
3193

3194
requires:
3195
- /Options
3196

3197
provides: [Cookie]
3198

3199
...
3200
*/
3201

    
3202
var Cookie = new Class({
3203

    
3204
        Implements: Options,
3205

    
3206
        options: {
3207
                path: false,
3208
                domain: false,
3209
                duration: false,
3210
                secure: false,
3211
                document: document
3212
        },
3213

    
3214
        initialize: function(key, options){
3215
                this.key = key;
3216
                this.setOptions(options);
3217
        },
3218

    
3219
        write: function(value){
3220
                value = encodeURIComponent(value);
3221
                if (this.options.domain) value += '; domain=' + this.options.domain;
3222
                if (this.options.path) value += '; path=' + this.options.path;
3223
                if (this.options.duration){
3224
                        var date = new Date();
3225
                        date.setTime(date.getTime() + this.options.duration * 24 * 60 * 60 * 1000);
3226
                        value += '; expires=' + date.toGMTString();
3227
                }
3228
                if (this.options.secure) value += '; secure';
3229
                this.options.document.cookie = this.key + '=' + value;
3230
                return this;
3231
        },
3232

    
3233
        read: function(){
3234
                var value = this.options.document.cookie.match('(?:^|;)\\s*' + this.key.escapeRegExp() + '=([^;]*)');
3235
                return (value) ? decodeURIComponent(value[1]) : null;
3236
        },
3237

    
3238
        dispose: function(){
3239
                new Cookie(this.key, $merge(this.options, {duration: -1})).write('');
3240
                return this;
3241
        }
3242

    
3243
});
3244

    
3245
Cookie.write = function(key, value, options){
3246
        return new Cookie(key, options).write(value);
3247
};
3248

    
3249
Cookie.read = function(key){
3250
        return new Cookie(key).read();
3251
};
3252

    
3253
Cookie.dispose = function(key, options){
3254
        return new Cookie(key, options).dispose();
3255
};
3256

    
3257

    
3258
/*
3259
---
3260

3261
script: Swiff.js
3262

3263
description: Wrapper for embedding SWF movies. Supports External Interface Communication.
3264

3265
license: MIT-style license.
3266

3267
credits: 
3268
- Flash detection & Internet Explorer + Flash Player 9 fix inspired by SWFObject.
3269

3270
requires:
3271
- /Options
3272
- /$util
3273

3274
provides: [Swiff]
3275

3276
...
3277
*/
3278

    
3279
var Swiff = new Class({
3280

    
3281
        Implements: [Options],
3282

    
3283
        options: {
3284
                id: null,
3285
                height: 1,
3286
                width: 1,
3287
                container: null,
3288
                properties: {},
3289
                params: {
3290
                        quality: 'high',
3291
                        allowScriptAccess: 'always',
3292
                        wMode: 'transparent',
3293
                        swLiveConnect: true
3294
                },
3295
                callBacks: {},
3296
                vars: {}
3297
        },
3298

    
3299
        toElement: function(){
3300
                return this.object;
3301
        },
3302

    
3303
        initialize: function(path, options){
3304
                this.instance = 'Swiff_' + $time();
3305

    
3306
                this.setOptions(options);
3307
                options = this.options;
3308
                var id = this.id = options.id || this.instance;
3309
                var container = document.id(options.container);
3310

    
3311
                Swiff.CallBacks[this.instance] = {};
3312

    
3313
                var params = options.params, vars = options.vars, callBacks = options.callBacks;
3314
                var properties = $extend({height: options.height, width: options.width}, options.properties);
3315

    
3316
                var self = this;
3317

    
3318
                for (var callBack in callBacks){
3319
                        Swiff.CallBacks[this.instance][callBack] = (function(option){
3320
                                return function(){
3321
                                        return option.apply(self.object, arguments);
3322
                                };
3323
                        })(callBacks[callBack]);
3324
                        vars[callBack] = 'Swiff.CallBacks.' + this.instance + '.' + callBack;
3325
                }
3326

    
3327
                params.flashVars = Hash.toQueryString(vars);
3328
                if (Browser.Engine.trident){
3329
                        properties.classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
3330
                        params.movie = path;
3331
                } else {
3332
                        properties.type = 'application/x-shockwave-flash';
3333
                        properties.data = path;
3334
                }
3335
                var build = '<object id="' + id + '"';
3336
                for (var property in properties) build += ' ' + property + '="' + properties[property] + '"';
3337
                build += '>';
3338
                for (var param in params){
3339
                        if (params[param]) build += '<param name="' + param + '" value="' + params[param] + '" />';
3340
                }
3341
                build += '</object>';
3342
                this.object = ((container) ? container.empty() : new Element('div')).set('html', build).firstChild;
3343
        },
3344

    
3345
        replaces: function(element){
3346
                element = document.id(element, true);
3347
                element.parentNode.replaceChild(this.toElement(), element);
3348
                return this;
3349
        },
3350

    
3351
        inject: function(element){
3352
                document.id(element, true).appendChild(this.toElement());
3353
                return this;
3354
        },
3355

    
3356
        remote: function(){
3357
                return Swiff.remote.apply(Swiff, [this.toElement()].extend(arguments));
3358
        }
3359

    
3360
});
3361

    
3362
Swiff.CallBacks = {};
3363

    
3364
Swiff.remote = function(obj, fn){
3365
        var rs = obj.CallFunction('<invoke name="' + fn + '" returntype="javascript">' + __flash__argumentsToXML(arguments, 2) + '</invoke>');
3366
        return eval(rs);
3367
};
3368

    
3369

    
3370
/*
3371
---
3372

3373
script: Fx.js
3374

3375
description: Contains the basic animation logic to be extended by all other Fx Classes.
3376

3377
license: MIT-style license.
3378

3379
requires:
3380
- /Chain
3381
- /Events
3382
- /Options
3383

3384
provides: [Fx]
3385

3386
...
3387
*/
3388

    
3389
var Fx = new Class({
3390

    
3391
        Implements: [Chain, Events, Options],
3392

    
3393
        options: {
3394
                /*
3395
                onStart: $empty,
3396
                onCancel: $empty,
3397
                onComplete: $empty,
3398
                */
3399
                fps: 50,
3400
                unit: false,
3401
                duration: 500,
3402
                link: 'ignore'
3403
        },
3404

    
3405
        initialize: function(options){
3406
                this.subject = this.subject || this;
3407
                this.setOptions(options);
3408
                this.options.duration = Fx.Durations[this.options.duration] || this.options.duration.toInt();
3409
                var wait = this.options.wait;
3410
                if (wait === false) this.options.link = 'cancel';
3411
        },
3412

    
3413
        getTransition: function(){
3414
                return function(p){
3415
                        return -(Math.cos(Math.PI * p) - 1) / 2;
3416
                };
3417
        },
3418

    
3419
        step: function(){
3420
                var time = $time();
3421
                if (time < this.time + this.options.duration){
3422
                        var delta = this.transition((time - this.time) / this.options.duration);
3423
                        this.set(this.compute(this.from, this.to, delta));
3424
                } else {
3425
                        this.set(this.compute(this.from, this.to, 1));
3426
                        this.complete();
3427
                }
3428
        },
3429

    
3430
        set: function(now){
3431
                return now;
3432
        },
3433

    
3434
        compute: function(from, to, delta){
3435
                return Fx.compute(from, to, delta);
3436
        },
3437

    
3438
        check: function(){
3439
                if (!this.timer) return true;
3440
                switch (this.options.link){
3441
                        case 'cancel': this.cancel(); return true;
3442
                        case 'chain': this.chain(this.caller.bind(this, arguments)); return false;
3443
                }
3444
                return false;
3445
        },
3446

    
3447
        start: function(from, to){
3448
                if (!this.check(from, to)) return this;
3449
                this.from = from;
3450
                this.to = to;
3451
                this.time = 0;
3452
                this.transition = this.getTransition();
3453
                this.startTimer();
3454
                this.onStart();
3455
                return this;
3456
        },
3457

    
3458
        complete: function(){
3459
                if (this.stopTimer()) this.onComplete();
3460
                return this;
3461
        },
3462

    
3463
        cancel: function(){
3464
                if (this.stopTimer()) this.onCancel();
3465
                return this;
3466
        },
3467

    
3468
        onStart: function(){
3469
                this.fireEvent('start', this.subject);
3470
        },
3471

    
3472
        onComplete: function(){
3473
                this.fireEvent('complete', this.subject);
3474
                if (!this.callChain()) this.fireEvent('chainComplete', this.subject);
3475
        },
3476

    
3477
        onCancel: function(){
3478
                this.fireEvent('cancel', this.subject).clearChain();
3479
        },
3480

    
3481
        pause: function(){
3482
                this.stopTimer();
3483
                return this;
3484
        },
3485

    
3486
        resume: function(){
3487
                this.startTimer();
3488
                return this;
3489
        },
3490

    
3491
        stopTimer: function(){
3492
                if (!this.timer) return false;
3493
                this.time = $time() - this.time;
3494
                this.timer = $clear(this.timer);
3495
                return true;
3496
        },
3497

    
3498
        startTimer: function(){
3499
                if (this.timer) return false;
3500
                this.time = $time() - this.time;
3501
                this.timer = this.step.periodical(Math.round(1000 / this.options.fps), this);
3502
                return true;
3503
        }
3504

    
3505
});
3506

    
3507
Fx.compute = function(from, to, delta){
3508
        return (to - from) * delta + from;
3509
};
3510

    
3511
Fx.Durations = {'short': 250, 'normal': 500, 'long': 1000};
3512

    
3513

    
3514
/*
3515
---
3516

3517
script: Fx.CSS.js
3518

3519
description: Contains the CSS animation logic. Used by Fx.Tween, Fx.Morph, Fx.Elements.
3520

3521
license: MIT-style license.
3522

3523
requires:
3524
- /Fx
3525
- /Element.Style
3526

3527
provides: [Fx.CSS]
3528

3529
...
3530
*/
3531

    
3532
Fx.CSS = new Class({
3533

    
3534
        Extends: Fx,
3535

    
3536
        //prepares the base from/to object
3537

    
3538
        prepare: function(element, property, values){
3539
                values = $splat(values);
3540
                var values1 = values[1];
3541
                if (!$chk(values1)){
3542
                        values[1] = values[0];
3543
                        values[0] = element.getStyle(property);
3544
                }
3545
                var parsed = values.map(this.parse);
3546
                return {from: parsed[0], to: parsed[1]};
3547
        },
3548

    
3549
        //parses a value into an array
3550

    
3551
        parse: function(value){
3552
                value = $lambda(value)();
3553
                value = (typeof value == 'string') ? value.split(' ') : $splat(value);
3554
                return value.map(function(val){
3555
                        val = String(val);
3556
                        var found = false;
3557
                        Fx.CSS.Parsers.each(function(parser, key){
3558
                                if (found) return;
3559
                                var parsed = parser.parse(val);
3560
                                if ($chk(parsed)) found = {value: parsed, parser: parser};
3561
                        });
3562
                        found = found || {value: val, parser: Fx.CSS.Parsers.String};
3563
                        return found;
3564
                });
3565
        },
3566

    
3567
        //computes by a from and to prepared objects, using their parsers.
3568

    
3569
        compute: function(from, to, delta){
3570
                var computed = [];
3571
                (Math.min(from.length, to.length)).times(function(i){
3572
                        computed.push({value: from[i].parser.compute(from[i].value, to[i].value, delta), parser: from[i].parser});
3573
                });
3574
                computed.$family = {name: 'fx:css:value'};
3575
                return computed;
3576
        },
3577

    
3578
        //serves the value as settable
3579

    
3580
        serve: function(value, unit){
3581
                if ($type(value) != 'fx:css:value') value = this.parse(value);
3582
                var returned = [];
3583
                value.each(function(bit){
3584
                        returned = returned.concat(bit.parser.serve(bit.value, unit));
3585
                });
3586
                return returned;
3587
        },
3588

    
3589
        //renders the change to an element
3590

    
3591
        render: function(element, property, value, unit){
3592
                element.setStyle(property, this.serve(value, unit));
3593
        },
3594

    
3595
        //searches inside the page css to find the values for a selector
3596

    
3597
        search: function(selector){
3598
                if (Fx.CSS.Cache[selector]) return Fx.CSS.Cache[selector];
3599
                var to = {};
3600
                Array.each(document.styleSheets, function(sheet, j){
3601
                        var href = sheet.href;
3602
                        if (href && href.contains('://') && !href.contains(document.domain)) return;
3603
                        var rules = sheet.rules || sheet.cssRules;
3604
                        Array.each(rules, function(rule, i){
3605
                                if (!rule.style) return;
3606
                                var selectorText = (rule.selectorText) ? rule.selectorText.replace(/^\w+/, function(m){
3607
                                        return m.toLowerCase();
3608
                                }) : null;
3609
                                if (!selectorText || !selectorText.test('^' + selector + '$')) return;
3610
                                Element.Styles.each(function(value, style){
3611
                                        if (!rule.style[style] || Element.ShortStyles[style]) return;
3612
                                        value = String(rule.style[style]);
3613
                                        to[style] = (value.test(/^rgb/)) ? value.rgbToHex() : value;
3614
                                });
3615
                        });
3616
                });
3617
                return Fx.CSS.Cache[selector] = to;
3618
        }
3619

    
3620
});
3621

    
3622
Fx.CSS.Cache = {};
3623

    
3624
Fx.CSS.Parsers = new Hash({
3625

    
3626
        Color: {
3627
                parse: function(value){
3628
                        if (value.match(/^#[0-9a-f]{3,6}$/i)) return value.hexToRgb(true);
3629
                        return ((value = value.match(/(\d+),\s*(\d+),\s*(\d+)/))) ? [value[1], value[2], value[3]] : false;
3630
                },
3631
                compute: function(from, to, delta){
3632
                        return from.map(function(value, i){
3633
                                return Math.round(Fx.compute(from[i], to[i], delta));
3634
                        });
3635
                },
3636
                serve: function(value){
3637
                        return value.map(Number);
3638
                }
3639
        },
3640

    
3641
        Number: {
3642
                parse: parseFloat,
3643
                compute: Fx.compute,
3644
                serve: function(value, unit){
3645
                        return (unit) ? value + unit : value;
3646
                }
3647
        },
3648

    
3649
        String: {
3650
                parse: $lambda(false),
3651
                compute: $arguments(1),
3652
                serve: $arguments(0)
3653
        }
3654

    
3655
});
3656

    
3657

    
3658
/*
3659
---
3660

3661
script: Fx.Tween.js
3662

3663
description: Formerly Fx.Style, effect to transition any CSS property for an element.
3664

3665
license: MIT-style license.
3666

3667
requires: 
3668
- /Fx.CSS
3669

3670
provides: [Fx.Tween, Element.fade, Element.highlight]
3671

3672
...
3673
*/
3674

    
3675
Fx.Tween = new Class({
3676

    
3677
        Extends: Fx.CSS,
3678

    
3679
        initialize: function(element, options){
3680
                this.element = this.subject = document.id(element);
3681
                this.parent(options);
3682
        },
3683

    
3684
        set: function(property, now){
3685
                if (arguments.length == 1){
3686
                        now = property;
3687
                        property = this.property || this.options.property;
3688
                }
3689
                this.render(this.element, property, now, this.options.unit);
3690
                return this;
3691
        },
3692

    
3693
        start: function(property, from, to){
3694
                if (!this.check(property, from, to)) return this;
3695
                var args = Array.flatten(arguments);
3696
                this.property = this.options.property || args.shift();
3697
                var parsed = this.prepare(this.element, this.property, args);
3698
                return this.parent(parsed.from, parsed.to);
3699
        }
3700

    
3701
});
3702

    
3703
Element.Properties.tween = {
3704

    
3705
        set: function(options){
3706
                var tween = this.retrieve('tween');
3707
                if (tween) tween.cancel();
3708
                return this.eliminate('tween').store('tween:options', $extend({link: 'cancel'}, options));
3709
        },
3710

    
3711
        get: function(options){
3712
                if (options || !this.retrieve('tween')){
3713
                        if (options || !this.retrieve('tween:options')) this.set('tween', options);
3714
                        this.store('tween', new Fx.Tween(this, this.retrieve('tween:options')));
3715
                }
3716
                return this.retrieve('tween');
3717
        }
3718

    
3719
};
3720

    
3721
Element.implement({
3722

    
3723
        tween: function(property, from, to){
3724
                this.get('tween').start(arguments);
3725
                return this;
3726
        },
3727

    
3728
        fade: function(how){
3729
                var fade = this.get('tween'), o = 'opacity', toggle;
3730
                how = $pick(how, 'toggle');
3731
                switch (how){
3732
                        case 'in': fade.start(o, 1); break;
3733
                        case 'out': fade.start(o, 0); break;
3734
                        case 'show': fade.set(o, 1); break;
3735
                        case 'hide': fade.set(o, 0); break;
3736
                        case 'toggle':
3737
                                var flag = this.retrieve('fade:flag', this.get('opacity') == 1);
3738
                                fade.start(o, (flag) ? 0 : 1);
3739
                                this.store('fade:flag', !flag);
3740
                                toggle = true;
3741
                        break;
3742
                        default: fade.start(o, arguments);
3743
                }
3744
                if (!toggle) this.eliminate('fade:flag');
3745
                return this;
3746
        },
3747

    
3748
        highlight: function(start, end){
3749
                if (!end){
3750
                        end = this.retrieve('highlight:original', this.getStyle('background-color'));
3751
                        end = (end == 'transparent') ? '#fff' : end;
3752
                }
3753
                var tween = this.get('tween');
3754
                tween.start('background-color', start || '#ffff88', end).chain(function(){
3755
                        this.setStyle('background-color', this.retrieve('highlight:original'));
3756
                        tween.callChain();
3757
                }.bind(this));
3758
                return this;
3759
        }
3760

    
3761
});
3762

    
3763

    
3764
/*
3765
---
3766

3767
script: Fx.Morph.js
3768

3769
description: Formerly Fx.Styles, effect to transition any number of CSS properties for an element using an object of rules, or CSS based selector rules.
3770

3771
license: MIT-style license.
3772

3773
requires:
3774
- /Fx.CSS
3775

3776
provides: [Fx.Morph]
3777

3778
...
3779
*/
3780

    
3781
Fx.Morph = new Class({
3782

    
3783
        Extends: Fx.CSS,
3784

    
3785
        initialize: function(element, options){
3786
                this.element = this.subject = document.id(element);
3787
                this.parent(options);
3788
        },
3789

    
3790
        set: function(now){
3791
                if (typeof now == 'string') now = this.search(now);
3792
                for (var p in now) this.render(this.element, p, now[p], this.options.unit);
3793
                return this;
3794
        },
3795

    
3796
        compute: function(from, to, delta){
3797
                var now = {};
3798
                for (var p in from) now[p] = this.parent(from[p], to[p], delta);
3799
                return now;
3800
        },
3801

    
3802
        start: function(properties){
3803
                if (!this.check(properties)) return this;
3804
                if (typeof properties == 'string') properties = this.search(properties);
3805
                var from = {}, to = {};
3806
                for (var p in properties){
3807
                        var parsed = this.prepare(this.element, p, properties[p]);
3808
                        from[p] = parsed.from;
3809
                        to[p] = parsed.to;
3810
                }
3811
                return this.parent(from, to);
3812
        }
3813

    
3814
});
3815

    
3816
Element.Properties.morph = {
3817

    
3818
        set: function(options){
3819
                var morph = this.retrieve('morph');
3820
                if (morph) morph.cancel();
3821
                return this.eliminate('morph').store('morph:options', $extend({link: 'cancel'}, options));
3822
        },
3823

    
3824
        get: function(options){
3825
                if (options || !this.retrieve('morph')){
3826
                        if (options || !this.retrieve('morph:options')) this.set('morph', options);
3827
                        this.store('morph', new Fx.Morph(this, this.retrieve('morph:options')));
3828
                }
3829
                return this.retrieve('morph');
3830
        }
3831

    
3832
};
3833

    
3834
Element.implement({
3835

    
3836
        morph: function(props){
3837
                this.get('morph').start(props);
3838
                return this;
3839
        }
3840

    
3841
});
3842

    
3843

    
3844
/*
3845
---
3846

3847
script: Fx.Transitions.js
3848

3849
description: Contains a set of advanced transitions to be used with any of the Fx Classes.
3850

3851
license: MIT-style license.
3852

3853
credits:
3854
- Easing Equations by Robert Penner, <http://www.robertpenner.com/easing/>, modified and optimized to be used with MooTools.
3855

3856
requires:
3857
- /Fx
3858

3859
provides: [Fx.Transitions]
3860

3861
...
3862
*/
3863

    
3864
Fx.implement({
3865

    
3866
        getTransition: function(){
3867
                var trans = this.options.transition || Fx.Transitions.Sine.easeInOut;
3868
                if (typeof trans == 'string'){
3869
                        var data = trans.split(':');
3870
                        trans = Fx.Transitions;
3871
                        trans = trans[data[0]] || trans[data[0].capitalize()];
3872
                        if (data[1]) trans = trans['ease' + data[1].capitalize() + (data[2] ? data[2].capitalize() : '')];
3873
                }
3874
                return trans;
3875
        }
3876

    
3877
});
3878

    
3879
Fx.Transition = function(transition, params){
3880
        params = $splat(params);
3881
        return $extend(transition, {
3882
                easeIn: function(pos){
3883
                        return transition(pos, params);
3884
                },
3885
                easeOut: function(pos){
3886
                        return 1 - transition(1 - pos, params);
3887
                },
3888
                easeInOut: function(pos){
3889
                        return (pos <= 0.5) ? transition(2 * pos, params) / 2 : (2 - transition(2 * (1 - pos), params)) / 2;
3890
                }
3891
        });
3892
};
3893

    
3894
Fx.Transitions = new Hash({
3895

    
3896
        linear: $arguments(0)
3897

    
3898
});
3899

    
3900
Fx.Transitions.extend = function(transitions){
3901
        for (var transition in transitions) Fx.Transitions[transition] = new Fx.Transition(transitions[transition]);
3902
};
3903

    
3904
Fx.Transitions.extend({
3905

    
3906
        Pow: function(p, x){
3907
                return Math.pow(p, x[0] || 6);
3908
        },
3909

    
3910
        Expo: function(p){
3911
                return Math.pow(2, 8 * (p - 1));
3912
        },
3913

    
3914
        Circ: function(p){
3915
                return 1 - Math.sin(Math.acos(p));
3916
        },
3917

    
3918
        Sine: function(p){
3919
                return 1 - Math.sin((1 - p) * Math.PI / 2);
3920
        },
3921

    
3922
        Back: function(p, x){
3923
                x = x[0] || 1.618;
3924
                return Math.pow(p, 2) * ((x + 1) * p - x);
3925
        },
3926

    
3927
        Bounce: function(p){
3928
                var value;
3929
                for (var a = 0, b = 1; 1; a += b, b /= 2){
3930
                        if (p >= (7 - 4 * a) / 11){
3931
                                value = b * b - Math.pow((11 - 6 * a - 11 * p) / 4, 2);
3932
                                break;
3933
                        }
3934
                }
3935
                return value;
3936
        },
3937

    
3938
        Elastic: function(p, x){
3939
                return Math.pow(2, 10 * --p) * Math.cos(20 * p * Math.PI * (x[0] || 1) / 3);
3940
        }
3941

    
3942
});
3943

    
3944
['Quad', 'Cubic', 'Quart', 'Quint'].each(function(transition, i){
3945
        Fx.Transitions[transition] = new Fx.Transition(function(p){
3946
                return Math.pow(p, [i + 2]);
3947
        });
3948
});
3949

    
3950

    
3951
/*
3952
---
3953

3954
script: Request.js
3955

3956
description: Powerful all purpose Request Class. Uses XMLHTTPRequest.
3957

3958
license: MIT-style license.
3959

3960
requires:
3961
- /Element
3962
- /Chain
3963
- /Events
3964
- /Options
3965
- /Browser
3966

3967
provides: [Request]
3968

3969
...
3970
*/
3971

    
3972
var Request = new Class({
3973

    
3974
        Implements: [Chain, Events, Options],
3975

    
3976
        options: {/*
3977
                onRequest: $empty,
3978
                onComplete: $empty,
3979
                onCancel: $empty,
3980
                onSuccess: $empty,
3981
                onFailure: $empty,
3982
                onException: $empty,*/
3983
                url: '',
3984
                data: '',
3985
                headers: {
3986
                        'X-Requested-With': 'XMLHttpRequest',
3987
                        'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
3988
                },
3989
                async: true,
3990
                format: false,
3991
                method: 'post',
3992
                link: 'ignore',
3993
                isSuccess: null,
3994
                emulation: true,
3995
                urlEncoded: true,
3996
                encoding: 'utf-8',
3997
                evalScripts: false,
3998
                evalResponse: false,
3999
                noCache: false
4000
        },
4001

    
4002
        initialize: function(options){
4003
                this.xhr = new Browser.Request();
4004
                this.setOptions(options);
4005
                this.options.isSuccess = this.options.isSuccess || this.isSuccess;
4006
                this.headers = new Hash(this.options.headers);
4007
        },
4008

    
4009
        onStateChange: function(){
4010
                if (this.xhr.readyState != 4 || !this.running) return;
4011
                this.running = false;
4012
                this.status = 0;
4013
                $try(function(){
4014
                        this.status = this.xhr.status;
4015
                }.bind(this));
4016
                this.xhr.onreadystatechange = $empty;
4017
                if (this.options.isSuccess.call(this, this.status)){
4018
                        this.response = {text: this.xhr.responseText, xml: this.xhr.responseXML};
4019
                        this.success(this.response.text, this.response.xml);
4020
                } else {
4021
                        this.response = {text: null, xml: null};
4022
                        this.failure();
4023
                }
4024
        },
4025

    
4026
        isSuccess: function(){
4027
                return ((this.status >= 200) && (this.status < 300));
4028
        },
4029

    
4030
        processScripts: function(text){
4031
                if (this.options.evalResponse || (/(ecma|java)script/).test(this.getHeader('Content-type'))) return $exec(text);
4032
                return text.stripScripts(this.options.evalScripts);
4033
        },
4034

    
4035
        success: function(text, xml){
4036
                this.onSuccess(this.processScripts(text), xml);
4037
        },
4038

    
4039
        onSuccess: function(){
4040
                this.fireEvent('complete', arguments).fireEvent('success', arguments).callChain();
4041
        },
4042

    
4043
        failure: function(){
4044
                this.onFailure();
4045
        },
4046

    
4047
        onFailure: function(){
4048
                this.fireEvent('complete').fireEvent('failure', this.xhr);
4049
        },
4050

    
4051
        setHeader: function(name, value){
4052
                this.headers.set(name, value);
4053
                return this;
4054
        },
4055

    
4056
        getHeader: function(name){
4057
                return $try(function(){
4058
                        return this.xhr.getResponseHeader(name);
4059
                }.bind(this));
4060
        },
4061

    
4062
        check: function(){
4063
                if (!this.running) return true;
4064
                switch (this.options.link){
4065
                        case 'cancel': this.cancel(); return true;
4066
                        case 'chain': this.chain(this.caller.bind(this, arguments)); return false;
4067
                }
4068
                return false;
4069
        },
4070

    
4071
        send: function(options){
4072
                if (!this.check(options)) return this;
4073
                this.running = true;
4074

    
4075
                var type = $type(options);
4076
                if (type == 'string' || type == 'element') options = {data: options};
4077

    
4078
                var old = this.options;
4079
                options = $extend({data: old.data, url: old.url, method: old.method}, options);
4080
                var data = options.data, url = String(options.url), method = options.method.toLowerCase();
4081

    
4082
                switch ($type(data)){
4083
                        case 'element': data = document.id(data).toQueryString(); break;
4084
                        case 'object': case 'hash': data = Hash.toQueryString(data);
4085
                }
4086

    
4087
                if (this.options.format){
4088
                        var format = 'format=' + this.options.format;
4089
                        data = (data) ? format + '&' + data : format;
4090
                }
4091

    
4092
                if (this.options.emulation && !['get', 'post'].contains(method)){
4093
                        var _method = '_method=' + method;
4094
                        data = (data) ? _method + '&' + data : _method;
4095
                        method = 'post';
4096
                }
4097

    
4098
                if (this.options.urlEncoded && method == 'post'){
4099
                        var encoding = (this.options.encoding) ? '; charset=' + this.options.encoding : '';
4100
                        this.headers.set('Content-type', 'application/x-www-form-urlencoded' + encoding);
4101
                }
4102

    
4103
                if (this.options.noCache){
4104
                        var noCache = 'noCache=' + new Date().getTime();
4105
                        data = (data) ? noCache + '&' + data : noCache;
4106
                }
4107

    
4108
                var trimPosition = url.lastIndexOf('/');
4109
                if (trimPosition > -1 && (trimPosition = url.indexOf('#')) > -1) url = url.substr(0, trimPosition);
4110

    
4111
                if (data && method == 'get'){
4112
                        url = url + (url.contains('?') ? '&' : '?') + data;
4113
                        data = null;
4114
                }
4115

    
4116
                this.xhr.open(method.toUpperCase(), url, this.options.async);
4117

    
4118
                this.xhr.onreadystatechange = this.onStateChange.bind(this);
4119

    
4120
                this.headers.each(function(value, key){
4121
                        try {
4122
                                this.xhr.setRequestHeader(key, value);
4123
                        } catch (e){
4124
                                this.fireEvent('exception', [key, value]);
4125
                        }
4126
                }, this);
4127

    
4128
                this.fireEvent('request');
4129
                this.xhr.send(data);
4130
                if (!this.options.async) this.onStateChange();
4131
                return this;
4132
        },
4133

    
4134
        cancel: function(){
4135
                if (!this.running) return this;
4136
                this.running = false;
4137
                this.xhr.abort();
4138
                this.xhr.onreadystatechange = $empty;
4139
                this.xhr = new Browser.Request();
4140
                this.fireEvent('cancel');
4141
                return this;
4142
        }
4143

    
4144
});
4145

    
4146
(function(){
4147

    
4148
var methods = {};
4149
['get', 'post', 'put', 'delete', 'GET', 'POST', 'PUT', 'DELETE'].each(function(method){
4150
        methods[method] = function(){
4151
                var params = Array.link(arguments, {url: String.type, data: $defined});
4152
                return this.send($extend(params, {method: method}));
4153
        };
4154
});
4155

    
4156
Request.implement(methods);
4157

    
4158
})();
4159

    
4160
Element.Properties.send = {
4161

    
4162
        set: function(options){
4163
                var send = this.retrieve('send');
4164
                if (send) send.cancel();
4165
                return this.eliminate('send').store('send:options', $extend({
4166
                        data: this, link: 'cancel', method: this.get('method') || 'post', url: this.get('action')
4167
                }, options));
4168
        },
4169

    
4170
        get: function(options){
4171
                if (options || !this.retrieve('send')){
4172
                        if (options || !this.retrieve('send:options')) this.set('send', options);
4173
                        this.store('send', new Request(this.retrieve('send:options')));
4174
                }
4175
                return this.retrieve('send');
4176
        }
4177

    
4178
};
4179

    
4180
Element.implement({
4181

    
4182
        send: function(url){
4183
                var sender = this.get('send');
4184
                sender.send({data: this, url: url || sender.options.url});
4185
                return this;
4186
        }
4187

    
4188
});
4189

    
4190

    
4191
/*
4192
---
4193

4194
script: Request.HTML.js
4195

4196
description: Extends the basic Request Class with additional methods for interacting with HTML responses.
4197

4198
license: MIT-style license.
4199

4200
requires:
4201
- /Request
4202
- /Element
4203

4204
provides: [Request.HTML]
4205

4206
...
4207
*/
4208

    
4209
Request.HTML = new Class({
4210

    
4211
        Extends: Request,
4212

    
4213
        options: {
4214
                update: false,
4215
                append: false,
4216
                evalScripts: true,
4217
                filter: false
4218
        },
4219

    
4220
        processHTML: function(text){
4221
                var match = text.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
4222
                text = (match) ? match[1] : text;
4223

    
4224
                var container = new Element('div');
4225

    
4226
                return $try(function(){
4227
                        var root = '<root>' + text + '</root>', doc;
4228
                        if (Browser.Engine.trident){
4229
                                doc = new ActiveXObject('Microsoft.XMLDOM');
4230
                                doc.async = false;
4231
                                doc.loadXML(root);
4232
                        } else {
4233
                                doc = new DOMParser().parseFromString(root, 'text/xml');
4234
                        }
4235
                        root = doc.getElementsByTagName('root')[0];
4236
                        if (!root) return null;
4237
                        for (var i = 0, k = root.childNodes.length; i < k; i++){
4238
                                var child = Element.clone(root.childNodes[i], true, true);
4239
                                if (child) container.grab(child);
4240
                        }
4241
                        return container;
4242
                }) || container.set('html', text);
4243
        },
4244

    
4245
        success: function(text){
4246
                var options = this.options, response = this.response;
4247

    
4248
                response.html = text.stripScripts(function(script){
4249
                        response.javascript = script;
4250
                });
4251

    
4252
                var temp = this.processHTML(response.html);
4253

    
4254
                response.tree = temp.childNodes;
4255
                response.elements = temp.getElements('*');
4256

    
4257
                if (options.filter) response.tree = response.elements.filter(options.filter);
4258
                if (options.update) document.id(options.update).empty().set('html', response.html);
4259
                else if (options.append) document.id(options.append).adopt(temp.getChildren());
4260
                if (options.evalScripts) $exec(response.javascript);
4261

    
4262
                this.onSuccess(response.tree, response.elements, response.html, response.javascript);
4263
        }
4264

    
4265
});
4266

    
4267
Element.Properties.load = {
4268

    
4269
        set: function(options){
4270
                var load = this.retrieve('load');
4271
                if (load) load.cancel();
4272
                return this.eliminate('load').store('load:options', $extend({data: this, link: 'cancel', update: this, method: 'get'}, options));
4273
        },
4274

    
4275
        get: function(options){
4276
                if (options || ! this.retrieve('load')){
4277
                        if (options || !this.retrieve('load:options')) this.set('load', options);
4278
                        this.store('load', new Request.HTML(this.retrieve('load:options')));
4279
                }
4280
                return this.retrieve('load');
4281
        }
4282

    
4283
};
4284

    
4285
Element.implement({
4286

    
4287
        load: function(){
4288
                this.get('load').send(Array.link(arguments, {data: Object.type, url: String.type}));
4289
                return this;
4290
        }
4291

    
4292
});
4293

    
4294

    
4295
/*
4296
---
4297

4298
script: Request.JSON.js
4299

4300
description: Extends the basic Request Class with additional methods for sending and receiving JSON data.
4301

4302
license: MIT-style license.
4303

4304
requires:
4305
- /Request JSON
4306

4307
provides: [Request.HTML]
4308

4309
...
4310
*/
4311

    
4312
Request.JSON = new Class({
4313

    
4314
        Extends: Request,
4315

    
4316
        options: {
4317
                secure: true
4318
        },
4319

    
4320
        initialize: function(options){
4321
                this.parent(options);
4322
                this.headers.extend({'Accept': 'application/json', 'X-Request': 'JSON'});
4323
        },
4324

    
4325
        success: function(text){
4326
                this.response.json = JSON.decode(text, this.options.secure);
4327
                this.onSuccess(this.response.json, text);
4328
        }
4329

    
4330
});