decembre

GM - Flickr - Number of Favs on Photostream - FIX by Hacker09 2025 - STAY to ViolentMonkey v.2.32.0

Sep 19th, 2024 (edited)
785
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 155.27 KB | None | 0 0
  1. // ==UserScript==
  2. // @name           Flickr - Number of Favs on Photostream - FIX by Hacker09 2025 - STAY to ViolentMonkey v.2.32.0
  3. // @namespace      http://www.flickr.com/alesadam
  4. // @description    v.0.5.11 - STAY to ViolentMonkey v.2.32.0 - LAST UPADTE BROKE (v.2.40.0) this SCRIPT ? -  Fix 2025 for Pool SM other URL - (Seem work ONLY with Violentmonkey?) - GRANT + Match - Shows the number of favs on the photos in a photostream, next to #views, #notes, #comments
  5. // @icon           https://external-content.duckduckgo.com/ip3/blog.flickr.net.ico
  6. // @version        0.5.11
  7. // @include        http://www.flickr.com/photos/*
  8. // @include        http://www.flickr.com/photos/*/*
  9.  
  10.  
  11. // @include    http://www.flickr.com/groups/*/pool*
  12.  
  13. // NEW TEST for: https://www.flickr.com/groups_pool.gne?path=portrait-faces-master-view&nsid=&page=&jump_to=&thumb=1
  14. // BEFORE was: https://www.flickr.com/groups/portrait-faces-master-view/pool/?thumb=1
  15. // @include    https://www.flickr.com/groups_pool.gne?*
  16. // @match      https://www.flickr.com/groups_pool.gne?*
  17.  
  18. // @exclude    http://www.flickr.com/photos/*/stats*
  19. // @exclude    http://www.flickr.com/photos/*/popular-interesting
  20. // @exclude    http://www.flickr.com/groups/*/discuss/*
  21. // @exclude    http://www.flickr.com/photos/*/map*
  22.  
  23. // @include     http*://*flickr.com/photos/*
  24. // @include     http*://*flickr.com/photos/*/*
  25. // @include     http*://*flickr.com/groups/*/
  26. // @include     http*://*flickr.com/groups/*/pool*
  27. // @include     http*://*flickr.com/*/tags/*
  28.  
  29.  
  30. // @exclude       https://www.flickr.com/photos/*
  31.  
  32. // @exclude    http*://*flickr.com/photos/*/stats*
  33. // @exclude    http*://*flickr.com/photos/*/popular-interesting
  34. // @exclude    http*://*flickr.com/groups/*/discuss/*
  35. // @exclude    http*://*flickr.com/photos/*/map*
  36.  
  37. // @grant       GM_log
  38. // @grant       GM_getUserNsid
  39. // @grant       GM_getAuthToken
  40. // @grant       GM_getAuthHash
  41. // @grant       GM_getMagisterLudi
  42.  
  43. // @grant       GM_setValue
  44. // @grant       GM_getValue
  45. // @grant       GM_deleteValue
  46. // @grant       GM_addStyle
  47.  
  48. // @updateURL      https://userscripts.org/scripts/source/78638.meta.js
  49. // @downloadURL    https://userscripts.org/scripts/source/78638.user.js
  50. // @run-at        document-end
  51. // ==/UserScript==
  52. //
  53. (function () {
  54.  
  55. // in Google Chrome, the numbers may be hidden by the thumbnail in the next row
  56. // alter POOL_ITEM_HEIGHT to make some extra room between the thumbnail rows (default: 145)
  57. var POOL_ITEM_HEIGHT = 165;
  58. // in Google Chrome, the numbers may be hidden by the thumbnail in the next row
  59. // alter TAGS_ITEM_HEIGHT to make some extra room between the thumbnail rows (default: 110)
  60. var TAGS_ITEM_HEIGHT = 130;
  61. // use the standard Flickr icons for views, notes, .. on pool pages
  62. var ICON_NOTATION = false;
  63.  
  64. // replace the count indication with its first letter:
  65. // 'views' -> 'v'
  66. // 'comments' -> 'c'
  67. // 'galleries' -> 'g'
  68. // 'notes' -> 'n'
  69. // 'favorites' -> 'f'
  70. // is not taken into account if ICON_NOTATION is set to true
  71. var SHORT_NOTATION = true;
  72.  
  73. // use the SHOW_STREAM_xxx_COUNT booleans to specify what numbers you want to see on Photo Stream pages
  74. // on the Photo Stream pages, comments and favorites are provided by Flickr itself
  75. var SHOW_STREAM_VIEWS_COUNT     = true;
  76. var SHOW_STREAM_NOTES_COUNT     = false; // there is no icon for notes!
  77. var SHOW_STREAM_GALLERIES_COUNT = false;
  78.  
  79. // use the SHOW_PHOTOPAGE_xxx_COUNT booleans to specify what numbers you want to see on Photo pages
  80. var SHOW_PHOTOPAGE_VIEWS_COUNT     = true;
  81. var SHOW_PHOTOPAGE_NOTES_COUNT     = false; // there is no icon for notes!
  82. var SHOW_PHOTOPAGE_GALLERIES_COUNT = false;
  83.  
  84. // use the SHOW_POOL_xxx_COUNT booleans to specify what numbers you want to see on Group Pool pages
  85. var SHOW_POOL_VIEWS_COUNT       = true;
  86. var SHOW_POOL_COMMENTS_COUNT    = false;
  87. var SHOW_POOL_NOTES_COUNT       = false;
  88. var SHOW_POOL_FAVORITES_COUNT   = true;
  89. var SHOW_POOL_GALLERIES_COUNT   = false;
  90.  
  91. // use the SHOW_TAGS_xxx_COUNT booleans to specify what numbers you want to see on 'tags' pages
  92. var SHOW_TAGS_VIEWS_COUNT       = true;
  93. var SHOW_TAGS_COMMENTS_COUNT    = true;
  94. var SHOW_TAGS_NOTES_COUNT       = false;
  95. var SHOW_TAGS_FAVORITES_COUNT   = true;
  96. var SHOW_TAGS_GALLERIES_COUNT   = false;
  97.  
  98. // use the SHOW_SET_xxx_COUNT booleans to specify what numbers you want to see on 'set' pages
  99. var SHOW_SET_VIEWS_COUNT       = true;
  100. var SHOW_SET_COMMENTS_COUNT    = true;
  101. var SHOW_SET_NOTES_COUNT       = false;
  102. var SHOW_SET_FAVORITES_COUNT   = true;
  103. var SHOW_SET_GALLERIES_COUNT   = false;
  104.  
  105. // use the SHOW_CONTRIBUTION_COLOR booleans to specify when to color the icons' background color
  106. var SHOW_COMMENT_CONTRIBUTION_COLOR = false;
  107. var SHOW_NOTE_CONTRIBUTION_COLOR    = false;
  108. var SHOW_FAVORITE_CONTRIBUTION_COLOR    = true;
  109. var SHOW_GALLERY_CONTRIBUTION_COLOR = false;
  110.  
  111. // specify your own colors :-)
  112. var COMMENT_CONTRIBUTION_COLOR  = 'pink';
  113. var NOTE_CONTRIBUTION_COLOR = 'pink';
  114. var FAVORITE_CONTRIBUTION_COLOR = 'pink';
  115. var GALLERY_CONTRIBUTION_COLOR  = 'pink';
  116.  
  117. var NOFOPversion = "0.5.11";
  118.  
  119. var localStoragePrefix = "NumberOfFavsOnPhotostream.";
  120.  
  121.  
  122. // use styles
  123. if (ICON_NOTATION) {
  124.     GM_addStyle('a.nof_pool_icon { display: inline-block; position: relative; text-decoration: none; text-align: center; padding: 0 10px 0 22px; margin-left: 10px; height: 14px; }');
  125.     GM_addStyle('a span.nof_pool_count { text-decoration: none; background: url("http://l.yimg.com/g/images/photo-sprite.png.v8") no-repeat scroll 0 0 transparent; display: block; height: 10px; left: 5px; position: absolute; width: 11px;');
  126.     GM_addStyle('a span.nof_pool_count_views { background-position: -15px -15px; }');
  127.     GM_addStyle('a span.nof_pool_count_comments { background-position: -55px -15px; }');
  128.     GM_addStyle('a span.nof_pool_count_notes { background-position: -1895px -15px; }');
  129.     GM_addStyle('a span.nof_pool_count_favs { background-position: -95px -15px; }');
  130.     GM_addStyle('a span.nof_pool_count_galleries { background-position: -135px -15px; }');
  131.     GM_addStyle('a span.nof_pool_label { position: absolute; left: 2px; padding-left: 16px; padding-right: 8px; padding-top: 5px;');
  132. } else {
  133.     GM_addStyle('.nof_stats { position: relative; top: 7px; }');
  134. }
  135.  
  136. GM_addStyle('.nof_comment_contributed { background-color: ' + COMMENT_CONTRIBUTION_COLOR + '; }');
  137. GM_addStyle('.nof_note_contributed { background-color: ' + NOTE_CONTRIBUTION_COLOR + '; }');
  138. GM_addStyle('.nof_fave_contributed { background-color: ' + FAVORITE_CONTRIBUTION_COLOR + '; }');
  139. GM_addStyle('.nof_gallery_contributed { background-color: ' + GALLERY_CONTRIBUTION_COLOR + '; }');
  140.  
  141. //
  142. // Greased MooTools inline for lack of @require support in Chrome
  143.  
  144. /*
  145. ---
  146.  
  147. script: Core.js
  148.  
  149. description: The core of MooTools, contains all the base functions and the Native and Hash implementations. Required by all the other scripts.
  150.  
  151. license: MIT-style license.
  152.  
  153. copyright: Copyright (c) 2006-2008 [Valerio Proietti](http://mad4milk.net/).
  154.  
  155. authors: The MooTools production team (http://mootools.net/developers/)
  156.  
  157. inspiration:
  158. - 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)
  159. - Some functionality inspired by [Prototype.js](http://prototypejs.org) Copyright (c) 2005-2007 Sam Stephenson, [MIT License](http://opensource.org/licenses/mit-license.php)
  160.  
  161. provides: [MooTools, Native, Hash.base, Array.each, $util]
  162.  
  163. ...
  164. */
  165.  
  166. var MooTools = {
  167.     'version': '1.2.5dev',
  168.     'build': '168759f5904bfdaeafd6b1c0d1be16cd78b5d5c6'
  169. };
  170.  
  171. var Native = function(options){
  172.     options = options || {};
  173.     var name = options.name;
  174.     var legacy = options.legacy;
  175.     var protect = options.protect;
  176.     var methods = options.implement;
  177.     var generics = options.generics;
  178.     var initialize = options.initialize;
  179.     var afterImplement = options.afterImplement || function(){};
  180.     var object = initialize || legacy;
  181.     generics = generics !== false;
  182.  
  183.     object.constructor = Native;
  184.     object.$family = {name: 'native'};
  185.     if (legacy && initialize) object.prototype = legacy.prototype;
  186.     if (!object.prototype) object.prototype = {};
  187.     object.prototype.constructor = object;
  188.  
  189.     if (name){
  190.         var family = name.toLowerCase();
  191.         object.prototype.$family = {name: family};
  192.         Native.typize(object, family);
  193.     }
  194.  
  195.     var add = function(obj, name, method, force){
  196.         if (!protect || force || !obj.prototype[name]) obj.prototype[name] = method;
  197.         if (generics) Native.genericize(obj, name, protect);
  198.         afterImplement.call(obj, name, method);
  199.         return obj;
  200.     };
  201.  
  202.     object.alias = function(a1, a2, a3){
  203.         if (typeof a1 == 'string'){
  204.             var pa1 = this.prototype[a1];
  205.             if ((a1 = pa1)) return add(this, a2, a1, a3);
  206.         }
  207.         for (var a in a1) this.alias(a, a1[a], a2);
  208.         return this;
  209.     };
  210.  
  211.     object.implement = function(a1, a2, a3){
  212.         if (typeof a1 == 'string') return add(this, a1, a2, a3);
  213.         for (var p in a1) add(this, p, a1[p], a2);
  214.         return this;
  215.     };
  216.  
  217.     if (methods) object.implement(methods);
  218.  
  219.     return object;
  220. };
  221.  
  222. Native.genericize = function(object, property, check){
  223.     if ((!check || !object[property]) && typeof object.prototype[property] == 'function') object[property] = function(){
  224.         var args = Array.prototype.slice.call(arguments);
  225.         return object.prototype[property].apply(args.shift(), args);
  226.     };
  227. };
  228.  
  229. Native.implement = function(objects, properties){
  230.     for (var i = 0, l = objects.length; i < l; i++) objects[i].implement(properties);
  231. };
  232.  
  233. Native.typize = function(object, family){
  234.     if (!object.type) object.type = function(item){
  235.         return ($type(item) === family);
  236.     };
  237. };
  238.  
  239. (function(){
  240.     var natives = {'Array': Array, 'Date': Date, 'Function': Function, 'Number': Number, 'RegExp': RegExp, 'String': String};
  241.     for (var n in natives) new Native({name: n, initialize: natives[n], protect: true});
  242.  
  243.     var types = {'boolean': Boolean, 'native': Native, 'object': Object};
  244.     for (var t in types) Native.typize(types[t], t);
  245.  
  246.     var generics = {
  247.         'Array': ["concat", "indexOf", "join", "lastIndexOf", "pop", "push", "reverse", "shift", "slice", "sort", "splice", "toString", "unshift", "valueOf"],
  248.         'String': ["charAt", "charCodeAt", "concat", "indexOf", "lastIndexOf", "match", "replace", "search", "slice", "split", "substr", "substring", "toLowerCase", "toUpperCase", "valueOf"]
  249.     };
  250.     for (var g in generics){
  251.         for (var i = generics[g].length; i--;) Native.genericize(natives[g], generics[g][i], true);
  252.     }
  253. })();
  254.  
  255. var Hash = new Native({
  256.  
  257.     name: 'Hash',
  258.  
  259.     initialize: function(object){
  260.         if ($type(object) == 'hash') object = $unlink(object.getClean());
  261.         for (var key in object) this[key] = object[key];
  262.         return this;
  263.     }
  264.  
  265. });
  266.  
  267. Hash.implement({
  268.  
  269.     forEach: function(fn, bind){
  270.         for (var key in this){
  271.             if (this.hasOwnProperty(key)) fn.call(bind, this[key], key, this);
  272.         }
  273.     },
  274.  
  275.     getClean: function(){
  276.         var clean = {};
  277.         for (var key in this){
  278.             if (this.hasOwnProperty(key)) clean[key] = this[key];
  279.         }
  280.         return clean;
  281.     },
  282.  
  283.     getLength: function(){
  284.         var length = 0;
  285.         for (var key in this){
  286.             if (this.hasOwnProperty(key)) length++;
  287.         }
  288.         return length;
  289.     }
  290.  
  291. });
  292.  
  293. Hash.alias('forEach', 'each');
  294.  
  295. Array.implement({
  296.  
  297.     forEach: function(fn, bind){
  298.         for (var i = 0, l = this.length; i < l; i++) fn.call(bind, this[i], i, this);
  299.     }
  300.  
  301. });
  302.  
  303. Array.alias('forEach', 'each');
  304.  
  305. function $A(iterable){
  306.     if (iterable.item){
  307.         var l = iterable.length, array = new Array(l);
  308.         while (l--) array[l] = iterable[l];
  309.         return array;
  310.     }
  311.     return Array.prototype.slice.call(iterable);
  312. };
  313.  
  314. function $arguments(i){
  315.     return function(){
  316.         return arguments[i];
  317.     };
  318. };
  319.  
  320. function $chk(obj){
  321.     return !!(obj || obj === 0);
  322. };
  323.  
  324. function $clear(timer){
  325.     clearTimeout(timer);
  326.     clearInterval(timer);
  327.     return null;
  328. };
  329.  
  330. function $defined(obj){
  331.     return (obj != undefined);
  332. };
  333.  
  334. function $each(iterable, fn, bind){
  335.     var type = $type(iterable);
  336.     ((type == 'arguments' || type == 'collection' || type == 'array') ? Array : Hash).each(iterable, fn, bind);
  337. };
  338.  
  339. function $empty(){};
  340.  
  341. function $extend(original, extended){
  342.     for (var key in (extended || {})) original[key] = extended[key];
  343.     return original;
  344. };
  345.  
  346. function $H(object){
  347.     return new Hash(object);
  348. };
  349.  
  350. function $lambda(value){
  351.     return ($type(value) == 'function') ? value : function(){
  352.         return value;
  353.     };
  354. };
  355.  
  356. function $merge(){
  357.     var args = Array.slice(arguments);
  358.     args.unshift({});
  359.     return $mixin.apply(null, args);
  360. };
  361.  
  362. function $mixin(mix){
  363.     for (var i = 1, l = arguments.length; i < l; i++){
  364.         var object = arguments[i];
  365.         if ($type(object) != 'object') continue;
  366.         for (var key in object){
  367.             var op = object[key], mp = mix[key];
  368.             mix[key] = (mp && $type(op) == 'object' && $type(mp) == 'object') ? $mixin(mp, op) : $unlink(op);
  369.         }
  370.     }
  371.     return mix;
  372. };
  373.  
  374. function $pick(){
  375.     for (var i = 0, l = arguments.length; i < l; i++){
  376.         if (arguments[i] != undefined) return arguments[i];
  377.     }
  378.     return null;
  379. };
  380.  
  381. function $random(min, max){
  382.     return Math.floor(Math.random() * (max - min + 1) + min);
  383. };
  384.  
  385. function $splat(obj){
  386.     var type = $type(obj);
  387.     return (type) ? ((type != 'array' && type != 'arguments') ? [obj] : obj) : [];
  388. };
  389.  
  390. var $time = Date.now || function(){
  391.     return +new Date;
  392. };
  393.  
  394. function $try(){
  395.     for (var i = 0, l = arguments.length; i < l; i++){
  396.         try {
  397.             return arguments[i]();
  398.         } catch(e){}
  399.     }
  400.     return null;
  401. };
  402.  
  403. function $type(obj){
  404.     if (obj == undefined) return false;
  405.     if (obj.$family) return (obj.$family.name == 'number' && !isFinite(obj)) ? false : obj.$family.name;
  406.     if (obj.nodeName){
  407.         switch (obj.nodeType){
  408.             case 1: return 'element';
  409.             case 3: return (/\S/).test(obj.nodeValue) ? 'textnode' : 'whitespace';
  410.         }
  411.     } else if (typeof obj.length == 'number'){
  412.         if (obj.callee) return 'arguments';
  413.         else if (obj.item) return 'collection';
  414.     }
  415.     return typeof obj;
  416. };
  417.  
  418. function $unlink(object){
  419.     var unlinked;
  420.     switch ($type(object)){
  421.         case 'object':
  422.             unlinked = {};
  423.             for (var p in object) unlinked[p] = $unlink(object[p]);
  424.         break;
  425.         case 'hash':
  426.             unlinked = new Hash(object);
  427.         break;
  428.         case 'array':
  429.             unlinked = [];
  430.             for (var i = 0, l = object.length; i < l; i++) unlinked[i] = $unlink(object[i]);
  431.         break;
  432.         default: return object;
  433.     }
  434.     return unlinked;
  435. };
  436.  
  437. /*
  438. ---
  439.  
  440. script: Browser.js
  441.  
  442. description: The Browser Core. Contains Browser initialization, Window and Document, and the Browser Hash.
  443.  
  444. license: MIT-style license.
  445.  
  446. requires:
  447. - /Native
  448. - /$util
  449.  
  450. provides: [Browser, Window, Document, $exec]
  451.  
  452. ...
  453. */
  454.  
  455. var Browser = $merge({
  456.  
  457.     Engine: {name: 'unknown', version: 0},
  458.  
  459.     Platform: {name: (window.orientation != undefined) ? 'ipod' : (navigator.platform.match(/mac|win|linux/i) || ['other'])[0].toLowerCase()},
  460.  
  461.     Features: {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)},
  462.  
  463.     Plugins: {},
  464.  
  465.     Engines: {
  466.  
  467.         presto: function(){
  468.             return (!window.opera) ? false : ((arguments.callee.caller) ? 960 : ((document.getElementsByClassName) ? 950 : 925));
  469.         },
  470.  
  471.         trident: function(){
  472.             return (!window.ActiveXObject) ? false : ((window.XMLHttpRequest) ? ((document.querySelectorAll) ? 6 : 5) : 4);
  473.         },
  474.  
  475.         webkit: function(){
  476.             return (navigator.taintEnabled) ? false : ((Browser.Features.xpath) ? ((Browser.Features.query) ? 525 : 420) : 419);
  477.         },
  478.  
  479.         gecko: function(){
  480.             return (!document.getBoxObjectFor && window.mozInnerScreenX == null) ? false : ((document.getElementsByClassName) ? 19 : 18);
  481.         }
  482.  
  483.     }
  484.  
  485. }, Browser || {});
  486.  
  487. Browser.Platform[Browser.Platform.name] = true;
  488.  
  489. Browser.detect = function(){
  490.  
  491.     for (var engine in this.Engines){
  492.         var version = this.Engines[engine]();
  493.         if (version){
  494.             this.Engine = {name: engine, version: version};
  495.             this.Engine[engine] = this.Engine[engine + version] = true;
  496.             break;
  497.         }
  498.     }
  499.  
  500.     return {name: engine, version: version};
  501.  
  502. };
  503.  
  504. Browser.detect();
  505.  
  506. Browser.Request = function(){
  507.     return $try(function(){
  508.         return new XMLHttpRequest();
  509.     }, function(){
  510.         return new ActiveXObject('MSXML2.XMLHTTP');
  511.     }, function(){
  512.         return new ActiveXObject('Microsoft.XMLHTTP');
  513.     });
  514. };
  515.  
  516. Browser.Features.xhr = !!(Browser.Request());
  517.  
  518. Browser.Plugins.Flash = (function(){
  519.     var version = ($try(function(){
  520.         return navigator.plugins['Shockwave Flash'].description;
  521.     }, function(){
  522.         return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
  523.     }) || '0 r0').match(/\d+/g);
  524.     return {version: parseInt(version[0] || 0 + '.' + version[1], 10) || 0, build: parseInt(version[2], 10) || 0};
  525. })();
  526.  
  527. function $exec(text){
  528.     if (!text) return text;
  529.     if (window.execScript){
  530.         window.execScript(text);
  531.     } else {
  532.         var script = document.createElement('script');
  533.         script.setAttribute('type', 'text/javascript');
  534.         script[(Browser.Engine.webkit && Browser.Engine.version < 420) ? 'innerText' : 'text'] = text;
  535.         document.head.appendChild(script);
  536.         document.head.removeChild(script);
  537.     }
  538.     return text;
  539. };
  540.  
  541. Native.UID = 1;
  542.  
  543. var $uid = (Browser.Engine.trident) ? function(item){
  544.     return (item.uid || (item.uid = [Native.UID++]))[0];
  545. } : function(item){
  546.     return item.uid || (item.uid = Native.UID++);
  547. };
  548.  
  549. var Window = new Native({
  550.  
  551.     name: 'Window',
  552.  
  553.     legacy: (Browser.Engine.trident) ? null: window.Window,
  554.  
  555.     initialize: function(win){
  556.         $uid(win);
  557.         if (!win.Element){
  558.             win.Element = $empty;
  559.             if (Browser.Engine.webkit) win.document.createElement("iframe"); //fixes safari 2
  560.             win.Element.prototype = (Browser.Engine.webkit) ? window["[[DOMElement.prototype]]"] : {};
  561.         }
  562.         win.document.window = win;
  563.         return $extend(win, Window.Prototype);
  564.     },
  565.  
  566.     afterImplement: function(property, value){
  567.         window[property] = Window.Prototype[property] = value;
  568.     }
  569.  
  570. });
  571.  
  572. Window.Prototype = {$family: {name: 'window'}};
  573.  
  574. new Window(window);
  575.  
  576. var Document = new Native({
  577.  
  578.     name: 'Document',
  579.  
  580.     legacy: (Browser.Engine.trident) ? null: window.Document,
  581.  
  582.     initialize: function(doc){
  583.         $uid(doc);
  584.         doc.head = doc.getElementsByTagName('head')[0];
  585.         doc.html = doc.getElementsByTagName('html')[0];
  586.         if (Browser.Engine.trident && Browser.Engine.version <= 4) $try(function(){
  587.             doc.execCommand("BackgroundImageCache", false, true);
  588.         });
  589.         if (Browser.Engine.trident) doc.window.attachEvent('onunload', function(){
  590.             doc.window.detachEvent('onunload', arguments.callee);
  591.             doc.head = doc.html = doc.window = null;
  592.         });
  593.         return $extend(doc, Document.Prototype);
  594.     },
  595.  
  596.     afterImplement: function(property, value){
  597.         document[property] = Document.Prototype[property] = value;
  598.     }
  599.  
  600. });
  601.  
  602. Document.Prototype = {$family: {name: 'document'}};
  603.  
  604. new Document(document);
  605.  
  606. /*
  607. ---
  608.  
  609. script: Array.js
  610.  
  611. description: Contains Array Prototypes like each, contains, and erase.
  612.  
  613. license: MIT-style license.
  614.  
  615. requires:
  616. - /$util
  617. - /Array.each
  618.  
  619. provides: [Array]
  620.  
  621. ...
  622. */
  623.  
  624. Array.implement({
  625.  
  626.     every: function(fn, bind){
  627.         for (var i = 0, l = this.length; i < l; i++){
  628.             if (!fn.call(bind, this[i], i, this)) return false;
  629.         }
  630.         return true;
  631.     },
  632.  
  633.     filter: function(fn, bind){
  634.         var results = [];
  635.         for (var i = 0, l = this.length; i < l; i++){
  636.             if (fn.call(bind, this[i], i, this)) results.push(this[i]);
  637.         }
  638.         return results;
  639.     },
  640.  
  641.     clean: function(){
  642.         return this.filter($defined);
  643.     },
  644.  
  645.     indexOf: function(item, from){
  646.         var len = this.length;
  647.         for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++){
  648.             if (this[i] === item) return i;
  649.         }
  650.         return -1;
  651.     },
  652.  
  653.     map: function(fn, bind){
  654.         var results = [];
  655.         for (var i = 0, l = this.length; i < l; i++) results[i] = fn.call(bind, this[i], i, this);
  656.         return results;
  657.     },
  658.  
  659.     some: function(fn, bind){
  660.         for (var i = 0, l = this.length; i < l; i++){
  661.             if (fn.call(bind, this[i], i, this)) return true;
  662.         }
  663.         return false;
  664.     },
  665.  
  666.     associate: function(keys){
  667.         var obj = {}, length = Math.min(this.length, keys.length);
  668.         for (var i = 0; i < length; i++) obj[keys[i]] = this[i];
  669.         return obj;
  670.     },
  671.  
  672.     link: function(object){
  673.         var result = {};
  674.         for (var i = 0, l = this.length; i < l; i++){
  675.             for (var key in object){
  676.                 if (object[key](this[i])){
  677.                     result[key] = this[i];
  678.                     delete object[key];
  679.                     break;
  680.                 }
  681.             }
  682.         }
  683.         return result;
  684.     },
  685.  
  686.     contains: function(item, from){
  687.         return this.indexOf(item, from) != -1;
  688.     },
  689.  
  690.     extend: function(array){
  691.         for (var i = 0, j = array.length; i < j; i++) this.push(array[i]);
  692.         return this;
  693.     },
  694.  
  695.     getLast: function(){
  696.         return (this.length) ? this[this.length - 1] : null;
  697.     },
  698.  
  699.     getRandom: function(){
  700.         return (this.length) ? this[$random(0, this.length - 1)] : null;
  701.     },
  702.  
  703.     include: function(item){
  704.         if (!this.contains(item)) this.push(item);
  705.         return this;
  706.     },
  707.  
  708.     combine: function(array){
  709.         for (var i = 0, l = array.length; i < l; i++) this.include(array[i]);
  710.         return this;
  711.     },
  712.  
  713.     erase: function(item){
  714.         for (var i = this.length; i--; i){
  715.             if (this[i] === item) this.splice(i, 1);
  716.         }
  717.         return this;
  718.     },
  719.  
  720.     empty: function(){
  721.         this.length = 0;
  722.         return this;
  723.     },
  724.  
  725.     flatten: function(){
  726.         var array = [];
  727.         for (var i = 0, l = this.length; i < l; i++){
  728.             var type = $type(this[i]);
  729.             if (!type) continue;
  730.             array = array.concat((type == 'array' || type == 'collection' || type == 'arguments') ? Array.flatten(this[i]) : this[i]);
  731.         }
  732.         return array;
  733.     },
  734.  
  735.     hexToRgb: function(array){
  736.         if (this.length != 3) return null;
  737.         var rgb = this.map(function(value){
  738.             if (value.length == 1) value += value;
  739.             return value.toInt(16);
  740.         });
  741.         return (array) ? rgb : 'rgb(' + rgb + ')';
  742.     },
  743.  
  744.     rgbToHex: function(array){
  745.         if (this.length < 3) return null;
  746.         if (this.length == 4 && this[3] == 0 && !array) return 'transparent';
  747.         var hex = [];
  748.         for (var i = 0; i < 3; i++){
  749.             var bit = (this[i] - 0).toString(16);
  750.             hex.push((bit.length == 1) ? '0' + bit : bit);
  751.         }
  752.         return (array) ? hex : '#' + hex.join('');
  753.     }
  754.  
  755. });
  756.  
  757. /*
  758. ---
  759.  
  760. script: String.js
  761.  
  762. description: Contains String Prototypes like camelCase, capitalize, test, and toInt.
  763.  
  764. license: MIT-style license.
  765.  
  766. requires:
  767. - /Native
  768.  
  769. provides: [String]
  770.  
  771. ...
  772. */
  773.  
  774. String.implement({
  775.  
  776.     test: function(regex, params){
  777.         return ((typeof regex == 'string') ? new RegExp(regex, params) : regex).test(this);
  778.     },
  779.  
  780.     contains: function(string, separator){
  781.         return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : this.indexOf(string) > -1;
  782.     },
  783.  
  784.     trim: function(){
  785.         return this.replace(/^\s+|\s+$/g, '');
  786.     },
  787.  
  788.     clean: function(){
  789.         return this.replace(/\s+/g, ' ').trim();
  790.     },
  791.  
  792.     camelCase: function(){
  793.         return this.replace(/-\D/g, function(match){
  794.             return match.charAt(1).toUpperCase();
  795.         });
  796.     },
  797.  
  798.     hyphenate: function(){
  799.         return this.replace(/[A-Z]/g, function(match){
  800.             return ('-' + match.charAt(0).toLowerCase());
  801.         });
  802.     },
  803.  
  804.     capitalize: function(){
  805.         return this.replace(/\b[a-z]/g, function(match){
  806.             return match.toUpperCase();
  807.         });
  808.     },
  809.  
  810.     escapeRegExp: function(){
  811.         return this.replace(/([-.*+?^${}()|[\]\/\\])/g, '\\$1');
  812.     },
  813.  
  814.     toInt: function(base){
  815.         return parseInt(this, base || 10);
  816.     },
  817.  
  818.     toFloat: function(){
  819.         return parseFloat(this);
  820.     },
  821.  
  822.     hexToRgb: function(array){
  823.         var hex = this.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);
  824.         return (hex) ? hex.slice(1).hexToRgb(array) : null;
  825.     },
  826.  
  827.     rgbToHex: function(array){
  828.         var rgb = this.match(/\d{1,3}/g);
  829.         return (rgb) ? rgb.rgbToHex(array) : null;
  830.     },
  831.  
  832.     stripScripts: function(option){
  833.         var scripts = '';
  834.         var text = this.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){
  835.             scripts += arguments[1] + '\n';
  836.             return '';
  837.         });
  838.         if (option === true) $exec(scripts);
  839.         else if ($type(option) == 'function') option(scripts, text);
  840.         return text;
  841.     },
  842.  
  843.     substitute: function(object, regexp){
  844.         return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
  845.             if (match.charAt(0) == '\\') return match.slice(1);
  846.             return (object[name] != undefined) ? object[name] : '';
  847.         });
  848.     }
  849.  
  850. });
  851.  
  852. /*
  853. ---
  854.  
  855. script: Function.js
  856.  
  857. description: Contains Function Prototypes like create, bind, pass, and delay.
  858.  
  859. license: MIT-style license.
  860.  
  861. requires:
  862. - /Native
  863. - /$util
  864.  
  865. provides: [Function]
  866.  
  867. ...
  868. */
  869.  
  870. Function.implement({
  871.  
  872.     extend: function(properties){
  873.         for (var property in properties) this[property] = properties[property];
  874.         return this;
  875.     },
  876.  
  877.     create: function(options){
  878.         var self = this;
  879.         options = options || {};
  880.         return function(event){
  881.             var args = options.arguments;
  882.             args = (args != undefined) ? $splat(args) : Array.slice(arguments, (options.event) ? 1 : 0);
  883.             if (options.event) args = [event || window.event].extend(args);
  884.             var returns = function(){
  885.                 return self.apply(options.bind || null, args);
  886.             };
  887.             if (options.delay) return setTimeout(returns, options.delay);
  888.             if (options.periodical) return setInterval(returns, options.periodical);
  889.             if (options.attempt) return $try(returns);
  890.             return returns();
  891.         };
  892.     },
  893.  
  894.     run: function(args, bind){
  895.         return this.apply(bind, $splat(args));
  896.     },
  897.  
  898.     pass: function(args, bind){
  899.         return this.create({bind: bind, arguments: args});
  900.     },
  901.  
  902.     bind: function(bind, args){
  903.         return this.create({bind: bind, arguments: args});
  904.     },
  905.  
  906.     bindWithEvent: function(bind, args){
  907.         return this.create({bind: bind, arguments: args, event: true});
  908.     },
  909.  
  910.     attempt: function(args, bind){
  911.         return this.create({bind: bind, arguments: args, attempt: true})();
  912.     },
  913.  
  914.     delay: function(delay, bind, args){
  915.         return this.create({bind: bind, arguments: args, delay: delay})();
  916.     },
  917.  
  918.     periodical: function(periodical, bind, args){
  919.         return this.create({bind: bind, arguments: args, periodical: periodical})();
  920.     }
  921.  
  922. });
  923.  
  924. /*
  925. ---
  926.  
  927. script: Number.js
  928.  
  929. description: Contains Number Prototypes like limit, round, times, and ceil.
  930.  
  931. license: MIT-style license.
  932.  
  933. requires:
  934. - /Native
  935. - /$util
  936.  
  937. provides: [Number]
  938.  
  939. ...
  940. */
  941.  
  942. Number.implement({
  943.  
  944.     limit: function(min, max){
  945.         return Math.min(max, Math.max(min, this));
  946.     },
  947.  
  948.     round: function(precision){
  949.         precision = Math.pow(10, precision || 0);
  950.         return Math.round(this * precision) / precision;
  951.     },
  952.  
  953.     times: function(fn, bind){
  954.         for (var i = 0; i < this; i++) fn.call(bind, i, this);
  955.     },
  956.  
  957.     toFloat: function(){
  958.         return parseFloat(this);
  959.     },
  960.  
  961.     toInt: function(base){
  962.         return parseInt(this, base || 10);
  963.     }
  964.  
  965. });
  966.  
  967. Number.alias('times', 'each');
  968.  
  969. (function(math){
  970.     var methods = {};
  971.     math.each(function(name){
  972.         if (!Number[name]) methods[name] = function(){
  973.             return Math[name].apply(null, [this].concat($A(arguments)));
  974.         };
  975.     });
  976.     Number.implement(methods);
  977. })(['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'sin', 'sqrt', 'tan']);
  978.  
  979. /*
  980. ---
  981.  
  982. script: Hash.js
  983.  
  984. description: Contains Hash Prototypes. Provides a means for overcoming the JavaScript practical impossibility of extending native Objects.
  985.  
  986. license: MIT-style license.
  987.  
  988. requires:
  989. - /Hash.base
  990.  
  991. provides: [Hash]
  992.  
  993. ...
  994. */
  995.  
  996. Hash.implement({
  997.  
  998.     has: Object.prototype.hasOwnProperty,
  999.  
  1000.     keyOf: function(value){
  1001.         for (var key in this){
  1002.             if (this.hasOwnProperty(key) && this[key] === value) return key;
  1003.         }
  1004.         return null;
  1005.     },
  1006.  
  1007.     hasValue: function(value){
  1008.         return (Hash.keyOf(this, value) !== null);
  1009.     },
  1010.  
  1011.     extend: function(properties){
  1012.         Hash.each(properties || {}, function(value, key){
  1013.             Hash.set(this, key, value);
  1014.         }, this);
  1015.         return this;
  1016.     },
  1017.  
  1018.     combine: function(properties){
  1019.         Hash.each(properties || {}, function(value, key){
  1020.             Hash.include(this, key, value);
  1021.         }, this);
  1022.         return this;
  1023.     },
  1024.  
  1025.     erase: function(key){
  1026.         if (this.hasOwnProperty(key)) delete this[key];
  1027.         return this;
  1028.     },
  1029.  
  1030.     get: function(key){
  1031.         return (this.hasOwnProperty(key)) ? this[key] : null;
  1032.     },
  1033.  
  1034.     set: function(key, value){
  1035.         if (!this[key] || this.hasOwnProperty(key)) this[key] = value;
  1036.         return this;
  1037.     },
  1038.  
  1039.     empty: function(){
  1040.         Hash.each(this, function(value, key){
  1041.             delete this[key];
  1042.         }, this);
  1043.         return this;
  1044.     },
  1045.  
  1046.     include: function(key, value){
  1047.         if (this[key] == undefined) this[key] = value;
  1048.         return this;
  1049.     },
  1050.  
  1051.     map: function(fn, bind){
  1052.         var results = new Hash;
  1053.         Hash.each(this, function(value, key){
  1054.             results.set(key, fn.call(bind, value, key, this));
  1055.         }, this);
  1056.         return results;
  1057.     },
  1058.  
  1059.     filter: function(fn, bind){
  1060.         var results = new Hash;
  1061.         Hash.each(this, function(value, key){
  1062.             if (fn.call(bind, value, key, this)) results.set(key, value);
  1063.         }, this);
  1064.         return results;
  1065.     },
  1066.  
  1067.     every: function(fn, bind){
  1068.         for (var key in this){
  1069.             if (this.hasOwnProperty(key) && !fn.call(bind, this[key], key)) return false;
  1070.         }
  1071.         return true;
  1072.     },
  1073.  
  1074.     some: function(fn, bind){
  1075.         for (var key in this){
  1076.             if (this.hasOwnProperty(key) && fn.call(bind, this[key], key)) return true;
  1077.         }
  1078.         return false;
  1079.     },
  1080.  
  1081.     getKeys: function(){
  1082.         var keys = [];
  1083.         Hash.each(this, function(value, key){
  1084.             keys.push(key);
  1085.         });
  1086.         return keys;
  1087.     },
  1088.  
  1089.     getValues: function(){
  1090.         var values = [];
  1091.         Hash.each(this, function(value){
  1092.             values.push(value);
  1093.         });
  1094.         return values;
  1095.     },
  1096.  
  1097.     toQueryString: function(base){
  1098.         var queryString = [];
  1099.         Hash.each(this, function(value, key){
  1100.             if (base) key = base + '[' + key + ']';
  1101.             var result;
  1102.             switch ($type(value)){
  1103.                 case 'object': result = Hash.toQueryString(value, key); break;
  1104.                 case 'array':
  1105.                     var qs = {};
  1106.                     value.each(function(val, i){
  1107.                         qs[i] = val;
  1108.                     });
  1109.                     result = Hash.toQueryString(qs, key);
  1110.                 break;
  1111.                 default: result = key + '=' + encodeURIComponent(value);
  1112.             }
  1113.             if (value != undefined) queryString.push(result);
  1114.         });
  1115.  
  1116.         return queryString.join('&');
  1117.     }
  1118.  
  1119. });
  1120.  
  1121. Hash.alias({keyOf: 'indexOf', hasValue: 'contains'});
  1122.  
  1123. /*
  1124. ---
  1125.  
  1126. script: Element.js
  1127.  
  1128. 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.
  1129.  
  1130. license: MIT-style license.
  1131.  
  1132. requires:
  1133. - /Window
  1134. - /Document
  1135. - /Array
  1136. - /String
  1137. - /Function
  1138. - /Number
  1139. - /Hash
  1140.  
  1141. provides: [Element, Elements, $, $$, Iframe]
  1142.  
  1143. ...
  1144. */
  1145.  
  1146. var Element = new Native({
  1147.  
  1148.     name: 'Element',
  1149.  
  1150.     legacy: window.Element,
  1151.  
  1152.     initialize: function(tag, props){
  1153.         var konstructor = Element.Constructors.get(tag);
  1154.         if (konstructor) return konstructor(props);
  1155.         if (typeof tag == 'string') return document.newElement(tag, props);
  1156.         return document.id(tag).set(props);
  1157.     },
  1158.  
  1159.     afterImplement: function(key, value){
  1160.         Element.Prototype[key] = value;
  1161.         if (Array[key]) return;
  1162.         Elements.implement(key, function(){
  1163.             var items = [], elements = true;
  1164.             for (var i = 0, j = this.length; i < j; i++){
  1165.                 var returns = this[i][key].apply(this[i], arguments);
  1166.                 items.push(returns);
  1167.                 if (elements) elements = ($type(returns) == 'element');
  1168.             }
  1169.             return (elements) ? new Elements(items) : items;
  1170.         });
  1171.     }
  1172.  
  1173. });
  1174.  
  1175. Element.Prototype = {$family: {name: 'element'}};
  1176.  
  1177. Element.Constructors = new Hash;
  1178.  
  1179. var IFrame = new Native({
  1180.  
  1181.     name: 'IFrame',
  1182.  
  1183.     generics: false,
  1184.  
  1185.     initialize: function(){
  1186.         var params = Array.link(arguments, {properties: Object.type, iframe: $defined});
  1187.         var props = params.properties || {};
  1188.         var iframe = document.id(params.iframe);
  1189.         var onload = props.onload || $empty;
  1190.         delete props.onload;
  1191.         props.id = props.name = $pick(props.id, props.name, iframe ? (iframe.id || iframe.name) : 'IFrame_' + $time());
  1192.         iframe = new Element(iframe || 'iframe', props);
  1193.         var onFrameLoad = function(){
  1194.             var host = $try(function(){
  1195.                 return iframe.contentWindow.location.host;
  1196.             });
  1197.             if (!host || host == window.location.host){
  1198.                 var win = new Window(iframe.contentWindow);
  1199.                 new Document(iframe.contentWindow.document);
  1200.                 if(!win.Element.prototype) win.Element.prototype = {};
  1201.                 $extend(win.Element.prototype, Element.Prototype);
  1202.             }
  1203.             onload.call(iframe.contentWindow, iframe.contentWindow.document);
  1204.         };
  1205.         var contentWindow = $try(function(){
  1206.             return iframe.contentWindow;
  1207.         });
  1208.         ((contentWindow && contentWindow.document.body) || window.frames[props.id]) ? onFrameLoad() : iframe.addListener('load', onFrameLoad);
  1209.         return iframe;
  1210.     }
  1211.  
  1212. });
  1213.  
  1214. var Elements = new Native({
  1215.  
  1216.     initialize: function(elements, options){
  1217.         options = $extend({ddup: true, cash: true}, options);
  1218.         elements = elements || [];
  1219.         if (options.ddup || options.cash){
  1220.             var uniques = {}, returned = [];
  1221.             for (var i = 0, l = elements.length; i < l; i++){
  1222.                 var el = document.id(elements[i], !options.cash);
  1223.                 if (options.ddup){
  1224.                     if (uniques[el.uid]) continue;
  1225.                     uniques[el.uid] = true;
  1226.                 }
  1227.                 if (el) returned.push(el);
  1228.             }
  1229.             elements = returned;
  1230.         }
  1231.         return (options.cash) ? $extend(elements, this) : elements;
  1232.     }
  1233.  
  1234. });
  1235.  
  1236. Elements.implement({
  1237.  
  1238.     filter: function(filter, bind){
  1239.         if (!filter) return this;
  1240.         return new Elements(Array.filter(this, (typeof filter == 'string') ? function(item){
  1241.             return item.match(filter);
  1242.         } : filter, bind));
  1243.     }
  1244.  
  1245. });
  1246.  
  1247. Document.implement({
  1248.  
  1249.     newElement: function(tag, props){
  1250.         if (Browser.Engine.trident && props){
  1251.             ['name', 'type', 'checked'].each(function(attribute){
  1252.                 if (!props[attribute]) return;
  1253.                 tag += ' ' + attribute + '="' + props[attribute] + '"';
  1254.                 if (attribute != 'checked') delete props[attribute];
  1255.             });
  1256.             tag = '<' + tag + '>';
  1257.         }
  1258.         return document.id(this.createElement(tag)).set(props);
  1259.     },
  1260.  
  1261.     newTextNode: function(text){
  1262.         return this.createTextNode(text);
  1263.     },
  1264.  
  1265.     getDocument: function(){
  1266.         return this;
  1267.     },
  1268.  
  1269.     getWindow: function(){
  1270.         return this.window;
  1271.     },
  1272.  
  1273.     id: (function(){
  1274.  
  1275.         var types = {
  1276.  
  1277.             string: function(id, nocash, doc){
  1278.                 id = doc.getElementById(id);
  1279.                 return (id) ? types.element(id, nocash) : null;
  1280.             },
  1281.  
  1282.             element: function(el, nocash){
  1283.                 $uid(el);
  1284.                 if (!nocash && !el.$family && !(/^object|embed$/i).test(el.tagName)){
  1285.                     var proto = Element.Prototype;
  1286.                     for (var p in proto) el[p] = proto[p];
  1287.                 };
  1288.                 return el;
  1289.             },
  1290.  
  1291.             object: function(obj, nocash, doc){
  1292.                 if (obj.toElement) return types.element(obj.toElement(doc), nocash);
  1293.                 return null;
  1294.             }
  1295.  
  1296.         };
  1297.  
  1298.         types.textnode = types.whitespace = types.window = types.document = $arguments(0);
  1299.  
  1300.         return function(el, nocash, doc){
  1301.             if (el && el.$family && el.uid) return el;
  1302.             var type = $type(el);
  1303.             return (types[type]) ? types[type](el, nocash, doc || document) : null;
  1304.         };
  1305.  
  1306.     })()
  1307.  
  1308. });
  1309.  
  1310. if (window.$ == null) Window.implement({
  1311.     $: function(el, nc){
  1312.         return document.id(el, nc, this.document);
  1313.     }
  1314. });
  1315.  
  1316. Window.implement({
  1317.  
  1318.     $$: function(selector){
  1319.         if (arguments.length == 1 && typeof selector == 'string') return this.document.getElements(selector);
  1320.         var elements = [];
  1321.         var args = Array.flatten(arguments);
  1322.         for (var i = 0, l = args.length; i < l; i++){
  1323.             var item = args[i];
  1324.             switch ($type(item)){
  1325.                 case 'element': elements.push(item); break;
  1326.                 case 'string': elements.extend(this.document.getElements(item, true));
  1327.             }
  1328.         }
  1329.         return new Elements(elements);
  1330.     },
  1331.  
  1332.     getDocument: function(){
  1333.         return this.document;
  1334.     },
  1335.  
  1336.     getWindow: function(){
  1337.         return this;
  1338.     }
  1339.  
  1340. });
  1341.  
  1342. Native.implement([Element, Document], {
  1343.  
  1344.     getElement: function(selector, nocash){
  1345.         return document.id(this.getElements(selector, true)[0] || null, nocash);
  1346.     },
  1347.  
  1348.     getElements: function(tags, nocash){
  1349.         tags = tags.split(',');
  1350.         var elements = [];
  1351.         var ddup = (tags.length > 1);
  1352.         tags.each(function(tag){
  1353.             var partial = this.getElementsByTagName(tag.trim());
  1354.             (ddup) ? elements.extend(partial) : elements = partial;
  1355.         }, this);
  1356.         return new Elements(elements, {ddup: ddup, cash: !nocash});
  1357.     }
  1358.  
  1359. });
  1360.  
  1361. (function(){
  1362.  
  1363. var collected = {}, storage = {};
  1364. var props = {input: 'checked', option: 'selected', textarea: (Browser.Engine.webkit && Browser.Engine.version < 420) ? 'innerHTML' : 'value'};
  1365.  
  1366. var get = function(uid){
  1367.     return (storage[uid] || (storage[uid] = {}));
  1368. };
  1369.  
  1370. var clean = function(item, retain){
  1371.     if (!item) return;
  1372.     var uid = item.uid;
  1373.     if (Browser.Engine.trident){
  1374.         if (item.clearAttributes){
  1375.             var clone = retain && item.cloneNode(false);
  1376.             item.clearAttributes();
  1377.             if (clone) item.mergeAttributes(clone);
  1378.         } else if (item.removeEvents){
  1379.             item.removeEvents();
  1380.         }
  1381.         if ((/object/i).test(item.tagName)){
  1382.             for (var p in item){
  1383.                 if (typeof item[p] == 'function') item[p] = $empty;
  1384.             }
  1385.             Element.dispose(item);
  1386.         }
  1387.     }
  1388.     if (!uid) return;
  1389.     collected[uid] = storage[uid] = null;
  1390. };
  1391.  
  1392. var purge = function(){
  1393.     Hash.each(collected, clean);
  1394.     if (Browser.Engine.trident) $A(document.getElementsByTagName('object')).each(clean);
  1395.     if (window.CollectGarbage) CollectGarbage();
  1396.     collected = storage = null;
  1397. };
  1398.  
  1399. var walk = function(element, walk, start, match, all, nocash){
  1400.     var el = element[start || walk];
  1401.     var elements = [];
  1402.     while (el){
  1403.         if (el.nodeType == 1 && (!match || Element.match(el, match))){
  1404.             if (!all) return document.id(el, nocash);
  1405.             elements.push(el);
  1406.         }
  1407.         el = el[walk];
  1408.     }
  1409.     return (all) ? new Elements(elements, {ddup: false, cash: !nocash}) : null;
  1410. };
  1411.  
  1412. var attributes = {
  1413.     'html': 'innerHTML',
  1414.     'class': 'className',
  1415.     'for': 'htmlFor',
  1416.     'defaultValue': 'defaultValue',
  1417.     'text': (Browser.Engine.trident || (Browser.Engine.webkit && Browser.Engine.version < 420)) ? 'innerText' : 'textContent'
  1418. };
  1419. var bools = ['compact', 'nowrap', 'ismap', 'declare', 'noshade', 'checked', 'disabled', 'readonly', 'multiple', 'selected', 'noresize', 'defer'];
  1420. var camels = ['value', 'type', 'defaultValue', 'accessKey', 'cellPadding', 'cellSpacing', 'colSpan', 'frameBorder', 'maxLength', 'readOnly', 'rowSpan', 'tabIndex', 'useMap'];
  1421.  
  1422. bools = bools.associate(bools);
  1423.  
  1424. Hash.extend(attributes, bools);
  1425. Hash.extend(attributes, camels.associate(camels.map(String.toLowerCase)));
  1426.  
  1427. var inserters = {
  1428.  
  1429.     before: function(context, element){
  1430.         if (element.parentNode) element.parentNode.insertBefore(context, element);
  1431.     },
  1432.  
  1433.     after: function(context, element){
  1434.         if (!element.parentNode) return;
  1435.         var next = element.nextSibling;
  1436.         (next) ? element.parentNode.insertBefore(context, next) : element.parentNode.appendChild(context);
  1437.     },
  1438.  
  1439.     bottom: function(context, element){
  1440.         element.appendChild(context);
  1441.     },
  1442.  
  1443.     top: function(context, element){
  1444.         var first = element.firstChild;
  1445.         (first) ? element.insertBefore(context, first) : element.appendChild(context);
  1446.     }
  1447.  
  1448. };
  1449.  
  1450. inserters.inside = inserters.bottom;
  1451.  
  1452. Hash.each(inserters, function(inserter, where){
  1453.  
  1454.     where = where.capitalize();
  1455.  
  1456.     Element.implement('inject' + where, function(el){
  1457.         inserter(this, document.id(el, true));
  1458.         return this;
  1459.     });
  1460.  
  1461.     Element.implement('grab' + where, function(el){
  1462.         inserter(document.id(el, true), this);
  1463.         return this;
  1464.     });
  1465.  
  1466. });
  1467.  
  1468. Element.implement({
  1469.  
  1470.     set: function(prop, value){
  1471.         switch ($type(prop)){
  1472.             case 'object':
  1473.                 for (var p in prop) this.set(p, prop[p]);
  1474.                 break;
  1475.             case 'string':
  1476.                 var property = Element.Properties.get(prop);
  1477.                 (property && property.set) ? property.set.apply(this, Array.slice(arguments, 1)) : this.setProperty(prop, value);
  1478.         }
  1479.         return this;
  1480.     },
  1481.  
  1482.     get: function(prop){
  1483.         var property = Element.Properties.get(prop);
  1484.         return (property && property.get) ? property.get.apply(this, Array.slice(arguments, 1)) : this.getProperty(prop);
  1485.     },
  1486.  
  1487.     erase: function(prop){
  1488.         var property = Element.Properties.get(prop);
  1489.         (property && property.erase) ? property.erase.apply(this) : this.removeProperty(prop);
  1490.         return this;
  1491.     },
  1492.  
  1493.     setProperty: function(attribute, value){
  1494.         var key = attributes[attribute];
  1495.         if (value == undefined) return this.removeProperty(attribute);
  1496.         if (key && bools[attribute]) value = !!value;
  1497.         (key) ? this[key] = value : this.setAttribute(attribute, '' + value);
  1498.         return this;
  1499.     },
  1500.  
  1501.     setProperties: function(attributes){
  1502.         for (var attribute in attributes) this.setProperty(attribute, attributes[attribute]);
  1503.         return this;
  1504.     },
  1505.  
  1506.     getProperty: function(attribute){
  1507.         var key = attributes[attribute];
  1508.         var value = (key) ? this[key] : this.getAttribute(attribute, 2);
  1509.         return (bools[attribute]) ? !!value : (key) ? value : value || null;
  1510.     },
  1511.  
  1512.     getProperties: function(){
  1513.         var args = $A(arguments);
  1514.         return args.map(this.getProperty, this).associate(args);
  1515.     },
  1516.  
  1517.     removeProperty: function(attribute){
  1518.         var key = attributes[attribute];
  1519.         (key) ? this[key] = (key && bools[attribute]) ? false : '' : this.removeAttribute(attribute);
  1520.         return this;
  1521.     },
  1522.  
  1523.     removeProperties: function(){
  1524.         Array.each(arguments, this.removeProperty, this);
  1525.         return this;
  1526.     },
  1527.  
  1528.     hasClass: function(className){
  1529.         return this.className.contains(className, ' ');
  1530.     },
  1531.  
  1532.     addClass: function(className){
  1533.         if (!this.hasClass(className)) this.className = (this.className + ' ' + className).clean();
  1534.         return this;
  1535.     },
  1536.  
  1537.     removeClass: function(className){
  1538.         this.className = this.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1');
  1539.         return this;
  1540.     },
  1541.  
  1542.     toggleClass: function(className){
  1543.         return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
  1544.     },
  1545.  
  1546.     adopt: function(){
  1547.         Array.flatten(arguments).each(function(element){
  1548.             element = document.id(element, true);
  1549.             if (element) this.appendChild(element);
  1550.         }, this);
  1551.         return this;
  1552.     },
  1553.  
  1554.     appendText: function(text, where){
  1555.         return this.grab(this.getDocument().newTextNode(text), where);
  1556.     },
  1557.  
  1558.     grab: function(el, where){
  1559.         inserters[where || 'bottom'](document.id(el, true), this);
  1560.         return this;
  1561.     },
  1562.  
  1563.     inject: function(el, where){
  1564.         inserters[where || 'bottom'](this, document.id(el, true));
  1565.         return this;
  1566.     },
  1567.  
  1568.     replaces: function(el){
  1569.         el = document.id(el, true);
  1570.         el.parentNode.replaceChild(this, el);
  1571.         return this;
  1572.     },
  1573.  
  1574.     wraps: function(el, where){
  1575.         el = document.id(el, true);
  1576.         return this.replaces(el).grab(el, where);
  1577.     },
  1578.  
  1579.     getPrevious: function(match, nocash){
  1580.         return walk(this, 'previousSibling', null, match, false, nocash);
  1581.     },
  1582.  
  1583.     getAllPrevious: function(match, nocash){
  1584.         return walk(this, 'previousSibling', null, match, true, nocash);
  1585.     },
  1586.  
  1587.     getNext: function(match, nocash){
  1588.         return walk(this, 'nextSibling', null, match, false, nocash);
  1589.     },
  1590.  
  1591.     getAllNext: function(match, nocash){
  1592.         return walk(this, 'nextSibling', null, match, true, nocash);
  1593.     },
  1594.  
  1595.     getFirst: function(match, nocash){
  1596.         return walk(this, 'nextSibling', 'firstChild', match, false, nocash);
  1597.     },
  1598.  
  1599.     getLast: function(match, nocash){
  1600.         return walk(this, 'previousSibling', 'lastChild', match, false, nocash);
  1601.     },
  1602.  
  1603.     getParent: function(match, nocash){
  1604.         return walk(this, 'parentNode', null, match, false, nocash);
  1605.     },
  1606.  
  1607.     getParents: function(match, nocash){
  1608.         return walk(this, 'parentNode', null, match, true, nocash);
  1609.     },
  1610.  
  1611.     getSiblings: function(match, nocash){
  1612.         return this.getParent().getChildren(match, nocash).erase(this);
  1613.     },
  1614.  
  1615.     getChildren: function(match, nocash){
  1616.         return walk(this, 'nextSibling', 'firstChild', match, true, nocash);
  1617.     },
  1618.  
  1619.     getWindow: function(){
  1620.         return this.ownerDocument.window;
  1621.     },
  1622.  
  1623.     getDocument: function(){
  1624.         return this.ownerDocument;
  1625.     },
  1626.  
  1627.     getElementById: function(id, nocash){
  1628.         var el = this.ownerDocument.getElementById(id);
  1629.         if (!el) return null;
  1630.         for (var parent = el.parentNode; parent != this; parent = parent.parentNode){
  1631.             if (!parent) return null;
  1632.         }
  1633.         return document.id(el, nocash);
  1634.     },
  1635.  
  1636.     getSelected: function(){
  1637.         return new Elements($A(this.options).filter(function(option){
  1638.             return option.selected;
  1639.         }));
  1640.     },
  1641.  
  1642.     getComputedStyle: function(property){
  1643.         if (this.currentStyle) return this.currentStyle[property.camelCase()];
  1644.         var computed = this.getDocument().defaultView.getComputedStyle(this, null);
  1645.         return (computed) ? computed.getPropertyValue([property.hyphenate()]) : null;
  1646.     },
  1647.  
  1648.     toQueryString: function(){
  1649.         var queryString = [];
  1650.         this.getElements('input, select, textarea', true).each(function(el){
  1651.             if (!el.name || el.disabled || el.type == 'submit' || el.type == 'reset' || el.type == 'file') return;
  1652.             var value = (el.tagName.toLowerCase() == 'select') ? Element.getSelected(el).map(function(opt){
  1653.                 return opt.value;
  1654.             }) : ((el.type == 'radio' || el.type == 'checkbox') && !el.checked) ? null : el.value;
  1655.             $splat(value).each(function(val){
  1656.                 if (typeof val != 'undefined') queryString.push(el.name + '=' + encodeURIComponent(val));
  1657.             });
  1658.         });
  1659.         return queryString.join('&');
  1660.     },
  1661.  
  1662.     clone: function(contents, keepid){
  1663.         contents = contents !== false;
  1664.         var clone = this.cloneNode(contents);
  1665.         var clean = function(node, element){
  1666.             if (!keepid) node.removeAttribute('id');
  1667.             if (Browser.Engine.trident){
  1668.                 node.clearAttributes();
  1669.                 node.mergeAttributes(element);
  1670.                 node.removeAttribute('uid');
  1671.                 if (node.options){
  1672.                     var no = node.options, eo = element.options;
  1673.                     for (var j = no.length; j--;) no[j].selected = eo[j].selected;
  1674.                 }
  1675.             }
  1676.             var prop = props[element.tagName.toLowerCase()];
  1677.             if (prop && element[prop]) node[prop] = element[prop];
  1678.         };
  1679.  
  1680.         if (contents){
  1681.             var ce = clone.getElementsByTagName('*'), te = this.getElementsByTagName('*');
  1682.             for (var i = ce.length; i--;) clean(ce[i], te[i]);
  1683.         }
  1684.  
  1685.         clean(clone, this);
  1686.         return document.id(clone);
  1687.     },
  1688.  
  1689.     destroy: function(){
  1690.         Element.empty(this);
  1691.         Element.dispose(this);
  1692.         clean(this, true);
  1693.         return null;
  1694.     },
  1695.  
  1696.     empty: function(){
  1697.         $A(this.childNodes).each(function(node){
  1698.             Element.destroy(node);
  1699.         });
  1700.         return this;
  1701.     },
  1702.  
  1703.     dispose: function(){
  1704.         return (this.parentNode) ? this.parentNode.removeChild(this) : this;
  1705.     },
  1706.  
  1707.     hasChild: function(el){
  1708.         el = document.id(el, true);
  1709.         if (!el) return false;
  1710.         if (Browser.Engine.webkit && Browser.Engine.version < 420) return $A(this.getElementsByTagName(el.tagName)).contains(el);
  1711.         return (this.contains) ? (this != el && this.contains(el)) : !!(this.compareDocumentPosition(el) & 16);
  1712.     },
  1713.  
  1714.     match: function(tag){
  1715.         return (!tag || (tag == this) || (Element.get(this, 'tag') == tag));
  1716.     }
  1717.  
  1718. });
  1719.  
  1720. Native.implement([Element, Window, Document], {
  1721.  
  1722.     addListener: function(type, fn){
  1723.         if (type == 'unload'){
  1724.             var old = fn, self = this;
  1725.             fn = function(){
  1726.                 self.removeListener('unload', fn);
  1727.                 old();
  1728.             };
  1729.         } else {
  1730.             collected[this.uid] = this;
  1731.         }
  1732.         if (this.addEventListener) this.addEventListener(type, fn, false);
  1733.         else this.attachEvent('on' + type, fn);
  1734.         return this;
  1735.     },
  1736.  
  1737.     removeListener: function(type, fn){
  1738.         if (this.removeEventListener) this.removeEventListener(type, fn, false);
  1739.         else this.detachEvent('on' + type, fn);
  1740.         return this;
  1741.     },
  1742.  
  1743.     retrieve: function(property, dflt){
  1744.         var storage = get(this.uid), prop = storage[property];
  1745.         if (dflt != undefined && prop == undefined) prop = storage[property] = dflt;
  1746.         return $pick(prop);
  1747.     },
  1748.  
  1749.     store: function(property, value){
  1750.         var storage = get(this.uid);
  1751.         storage[property] = value;
  1752.         return this;
  1753.     },
  1754.  
  1755.     eliminate: function(property){
  1756.         var storage = get(this.uid);
  1757.         delete storage[property];
  1758.         return this;
  1759.     }
  1760.  
  1761. });
  1762.  
  1763. window.addListener('unload', purge);
  1764.  
  1765. })();
  1766.  
  1767. Element.Properties = new Hash;
  1768.  
  1769. Element.Properties.style = {
  1770.  
  1771.     set: function(style){
  1772.         this.style.cssText = style;
  1773.     },
  1774.  
  1775.     get: function(){
  1776.         return this.style.cssText;
  1777.     },
  1778.  
  1779.     erase: function(){
  1780.         this.style.cssText = '';
  1781.     }
  1782.  
  1783. };
  1784.  
  1785. Element.Properties.tag = {
  1786.  
  1787.     get: function(){
  1788.         return this.tagName.toLowerCase();
  1789.     }
  1790.  
  1791. };
  1792.  
  1793. Element.Properties.html = (function(){
  1794.     var wrapper = document.createElement('div');
  1795.  
  1796.     var translations = {
  1797.         table: [1, '<table>', '</table>'],
  1798.         select: [1, '<select>', '</select>'],
  1799.         tbody: [2, '<table><tbody>', '</tbody></table>'],
  1800.         tr: [3, '<table><tbody><tr>', '</tr></tbody></table>']
  1801.     };
  1802.     translations.thead = translations.tfoot = translations.tbody;
  1803.  
  1804.     var html = {
  1805.         set: function(){
  1806.             var html = Array.flatten(arguments).join('');
  1807.             var wrap = Browser.Engine.trident && translations[this.get('tag')];
  1808.             if (wrap){
  1809.                 var first = wrapper;
  1810.                 first.innerHTML = wrap[1] + html + wrap[2];
  1811.                 for (var i = wrap[0]; i--;) first = first.firstChild;
  1812.                 this.empty().adopt(first.childNodes);
  1813.             } else {
  1814.                 this.innerHTML = html;
  1815.             }
  1816.         }
  1817.     };
  1818.  
  1819.     html.erase = html.set;
  1820.  
  1821.     return html;
  1822. })();
  1823.  
  1824. if (Browser.Engine.webkit && Browser.Engine.version < 420) Element.Properties.text = {
  1825.     get: function(){
  1826.         if (this.innerText) return this.innerText;
  1827.         var temp = this.ownerDocument.newElement('div', {html: this.innerHTML}).inject(this.ownerDocument.body);
  1828.         var text = temp.innerText;
  1829.         temp.destroy();
  1830.         return text;
  1831.     }
  1832. };
  1833.  
  1834. /*
  1835. ---
  1836.  
  1837. script: Element.Style.js
  1838.  
  1839. description: Contains methods for interacting with the styles of Elements in a fashionable way.
  1840.  
  1841. license: MIT-style license.
  1842.  
  1843. requires:
  1844. - /Element
  1845.  
  1846. provides: [Element.Style]
  1847.  
  1848. ...
  1849. */
  1850.  
  1851. Element.Properties.styles = {set: function(styles){
  1852.     this.setStyles(styles);
  1853. }};
  1854.  
  1855. Element.Properties.opacity = {
  1856.  
  1857.     set: function(opacity, novisibility){
  1858.         if (!novisibility){
  1859.             if (opacity == 0){
  1860.                 if (this.style.visibility != 'hidden') this.style.visibility = 'hidden';
  1861.             } else {
  1862.                 if (this.style.visibility != 'visible') this.style.visibility = 'visible';
  1863.             }
  1864.         }
  1865.         if (!this.currentStyle || !this.currentStyle.hasLayout) this.style.zoom = 1;
  1866.         if (Browser.Engine.trident) this.style.filter = (opacity == 1) ? '' : 'alpha(opacity=' + opacity * 100 + ')';
  1867.         this.style.opacity = opacity;
  1868.         this.store('opacity', opacity);
  1869.     },
  1870.  
  1871.     get: function(){
  1872.         return this.retrieve('opacity', 1);
  1873.     }
  1874.  
  1875. };
  1876.  
  1877. Element.implement({
  1878.  
  1879.     setOpacity: function(value){
  1880.         return this.set('opacity', value, true);
  1881.     },
  1882.  
  1883.     getOpacity: function(){
  1884.         return this.get('opacity');
  1885.     },
  1886.  
  1887.     setStyle: function(property, value){
  1888.         switch (property){
  1889.             case 'opacity': return this.set('opacity', parseFloat(value));
  1890.             case 'float': property = (Browser.Engine.trident) ? 'styleFloat' : 'cssFloat';
  1891.         }
  1892.         property = property.camelCase();
  1893.         if ($type(value) != 'string'){
  1894.             var map = (Element.Styles.get(property) || '@').split(' ');
  1895.             value = $splat(value).map(function(val, i){
  1896.                 if (!map[i]) return '';
  1897.                 return ($type(val) == 'number') ? map[i].replace('@', Math.round(val)) : val;
  1898.             }).join(' ');
  1899.         } else if (value == String(Number(value))){
  1900.             value = Math.round(value);
  1901.         }
  1902.         this.style[property] = value;
  1903.         return this;
  1904.     },
  1905.  
  1906.     getStyle: function(property){
  1907.         switch (property){
  1908.             case 'opacity': return this.get('opacity');
  1909.             case 'float': property = (Browser.Engine.trident) ? 'styleFloat' : 'cssFloat';
  1910.         }
  1911.         property = property.camelCase();
  1912.         var result = this.style[property];
  1913.         if (!$chk(result)){
  1914.             result = [];
  1915.             for (var style in Element.ShortStyles){
  1916.                 if (property != style) continue;
  1917.                 for (var s in Element.ShortStyles[style]) result.push(this.getStyle(s));
  1918.                 return result.join(' ');
  1919.             }
  1920.             result = this.getComputedStyle(property);
  1921.         }
  1922.         if (result){
  1923.             result = String(result);
  1924.             var color = result.match(/rgba?\([\d\s,]+\)/);
  1925.             if (color) result = result.replace(color[0], color[0].rgbToHex());
  1926.         }
  1927.         if (Browser.Engine.presto || (Browser.Engine.trident && !$chk(parseInt(result, 10)))){
  1928.             if (property.test(/^(height|width)$/)){
  1929.                 var values = (property == 'width') ? ['left', 'right'] : ['top', 'bottom'], size = 0;
  1930.                 values.each(function(value){
  1931.                     size += this.getStyle('border-' + value + '-width').toInt() + this.getStyle('padding-' + value).toInt();
  1932.                 }, this);
  1933.                 return this['offset' + property.capitalize()] - size + 'px';
  1934.             }
  1935.             if ((Browser.Engine.presto) && String(result).test('px')) return result;
  1936.             if (property.test(/(border(.+)Width|margin|padding)/)) return '0px';
  1937.         }
  1938.         return result;
  1939.     },
  1940.  
  1941.     setStyles: function(styles){
  1942.         for (var style in styles) this.setStyle(style, styles[style]);
  1943.         return this;
  1944.     },
  1945.  
  1946.     getStyles: function(){
  1947.         var result = {};
  1948.         Array.flatten(arguments).each(function(key){
  1949.             result[key] = this.getStyle(key);
  1950.         }, this);
  1951.         return result;
  1952.     }
  1953.  
  1954. });
  1955.  
  1956. Element.Styles = new Hash({
  1957.     left: '@px', top: '@px', bottom: '@px', right: '@px',
  1958.     width: '@px', height: '@px', maxWidth: '@px', maxHeight: '@px', minWidth: '@px', minHeight: '@px',
  1959.     backgroundColor: 'rgb(@, @, @)', backgroundPosition: '@px @px', color: 'rgb(@, @, @)',
  1960.     fontSize: '@px', letterSpacing: '@px', lineHeight: '@px', clip: 'rect(@px @px @px @px)',
  1961.     margin: '@px @px @px @px', padding: '@px @px @px @px', border: '@px @ rgb(@, @, @) @px @ rgb(@, @, @) @px @ rgb(@, @, @)',
  1962.     borderWidth: '@px @px @px @px', borderStyle: '@ @ @ @', borderColor: 'rgb(@, @, @) rgb(@, @, @) rgb(@, @, @) rgb(@, @, @)',
  1963.     zIndex: '@', 'zoom': '@', fontWeight: '@', textIndent: '@px', opacity: '@'
  1964. });
  1965.  
  1966. Element.ShortStyles = {margin: {}, padding: {}, border: {}, borderWidth: {}, borderStyle: {}, borderColor: {}};
  1967.  
  1968. ['Top', 'Right', 'Bottom', 'Left'].each(function(direction){
  1969.     var Short = Element.ShortStyles;
  1970.     var All = Element.Styles;
  1971.     ['margin', 'padding'].each(function(style){
  1972.         var sd = style + direction;
  1973.         Short[style][sd] = All[sd] = '@px';
  1974.     });
  1975.     var bd = 'border' + direction;
  1976.     Short.border[bd] = All[bd] = '@px @ rgb(@, @, @)';
  1977.     var bdw = bd + 'Width', bds = bd + 'Style', bdc = bd + 'Color';
  1978.     Short[bd] = {};
  1979.     Short.borderWidth[bdw] = Short[bd][bdw] = All[bdw] = '@px';
  1980.     Short.borderStyle[bds] = Short[bd][bds] = All[bds] = '@';
  1981.     Short.borderColor[bdc] = Short[bd][bdc] = All[bdc] = 'rgb(@, @, @)';
  1982. });
  1983.  
  1984. /*
  1985. ---
  1986.  
  1987. script: Element.Dimensions.js
  1988.  
  1989. description: Contains methods to work with size, scroll, or positioning of Elements and the window object.
  1990.  
  1991. license: MIT-style license.
  1992.  
  1993. credits:
  1994. - Element positioning based on the [qooxdoo](http://qooxdoo.org/) code and smart browser fixes, [LGPL License](http://www.gnu.org/licenses/lgpl.html).
  1995. - Viewport dimensions based on [YUI](http://developer.yahoo.com/yui/) code, [BSD License](http://developer.yahoo.com/yui/license.html).
  1996.  
  1997. requires:
  1998. - /Element
  1999.  
  2000. provides: [Element.Dimensions]
  2001.  
  2002. ...
  2003. */
  2004.  
  2005. (function(){
  2006.  
  2007. Element.implement({
  2008.  
  2009.     scrollTo: function(x, y){
  2010.         if (isBody(this)){
  2011.             this.getWindow().scrollTo(x, y);
  2012.         } else {
  2013.             this.scrollLeft = x;
  2014.             this.scrollTop = y;
  2015.         }
  2016.         return this;
  2017.     },
  2018.  
  2019.     getSize: function(){
  2020.         if (isBody(this)) return this.getWindow().getSize();
  2021.         return {x: this.offsetWidth, y: this.offsetHeight};
  2022.     },
  2023.  
  2024.     getScrollSize: function(){
  2025.         if (isBody(this)) return this.getWindow().getScrollSize();
  2026.         return {x: this.scrollWidth, y: this.scrollHeight};
  2027.     },
  2028.  
  2029.     getScroll: function(){
  2030.         if (isBody(this)) return this.getWindow().getScroll();
  2031.         return {x: this.scrollLeft, y: this.scrollTop};
  2032.     },
  2033.  
  2034.     getScrolls: function(){
  2035.         var element = this, position = {x: 0, y: 0};
  2036.         while (element && !isBody(element)){
  2037.             position.x += element.scrollLeft;
  2038.             position.y += element.scrollTop;
  2039.             element = element.parentNode;
  2040.         }
  2041.         return position;
  2042.     },
  2043.  
  2044.     getOffsetParent: function(){
  2045.         var element = this;
  2046.         if (isBody(element)) return null;
  2047.         if (!Browser.Engine.trident) return element.offsetParent;
  2048.         while ((element = element.parentNode) && !isBody(element)){
  2049.             if (styleString(element, 'position') != 'static') return element;
  2050.         }
  2051.         return null;
  2052.     },
  2053.  
  2054.     getOffsets: function(){
  2055.         if (this.getBoundingClientRect){
  2056.             var bound = this.getBoundingClientRect(),
  2057.                 html = document.id(this.getDocument().documentElement),
  2058.                 htmlScroll = html.getScroll(),
  2059.                 elemScrolls = this.getScrolls(),
  2060.                 elemScroll = this.getScroll(),
  2061.                 isFixed = (styleString(this, 'position') == 'fixed');
  2062.  
  2063.             return {
  2064.                 x: bound.left.toInt() + elemScrolls.x - elemScroll.x + ((isFixed) ? 0 : htmlScroll.x) - html.clientLeft,
  2065.                 y: bound.top.toInt()  + elemScrolls.y - elemScroll.y + ((isFixed) ? 0 : htmlScroll.y) - html.clientTop
  2066.             };
  2067.         }
  2068.  
  2069.         var element = this, position = {x: 0, y: 0};
  2070.         if (isBody(this)) return position;
  2071.  
  2072.         while (element && !isBody(element)){
  2073.             position.x += element.offsetLeft;
  2074.             position.y += element.offsetTop;
  2075.  
  2076.             if (Browser.Engine.gecko){
  2077.                 if (!borderBox(element)){
  2078.                     position.x += leftBorder(element);
  2079.                     position.y += topBorder(element);
  2080.                 }
  2081.                 var parent = element.parentNode;
  2082.                 if (parent && styleString(parent, 'overflow') != 'visible'){
  2083.                     position.x += leftBorder(parent);
  2084.                     position.y += topBorder(parent);
  2085.                 }
  2086.             } else if (element != this && Browser.Engine.webkit){
  2087.                 position.x += leftBorder(element);
  2088.                 position.y += topBorder(element);
  2089.             }
  2090.  
  2091.             element = element.offsetParent;
  2092.         }
  2093.         if (Browser.Engine.gecko && !borderBox(this)){
  2094.             position.x -= leftBorder(this);
  2095.             position.y -= topBorder(this);
  2096.         }
  2097.         return position;
  2098.     },
  2099.  
  2100.     getPosition: function(relative){
  2101.         if (isBody(this)) return {x: 0, y: 0};
  2102.         var offset = this.getOffsets(),
  2103.                 scroll = this.getScrolls();
  2104.         var position = {
  2105.             x: offset.x - scroll.x,
  2106.             y: offset.y - scroll.y
  2107.         };
  2108.         var relativePosition = (relative && (relative = document.id(relative))) ? relative.getPosition() : {x: 0, y: 0};
  2109.         return {x: position.x - relativePosition.x, y: position.y - relativePosition.y};
  2110.     },
  2111.  
  2112.     getCoordinates: function(element){
  2113.         if (isBody(this)) return this.getWindow().getCoordinates();
  2114.         var position = this.getPosition(element),
  2115.                 size = this.getSize();
  2116.         var obj = {
  2117.             left: position.x,
  2118.             top: position.y,
  2119.             width: size.x,
  2120.             height: size.y
  2121.         };
  2122.         obj.right = obj.left + obj.width;
  2123.         obj.bottom = obj.top + obj.height;
  2124.         return obj;
  2125.     },
  2126.  
  2127.     computePosition: function(obj){
  2128.         return {
  2129.             left: obj.x - styleNumber(this, 'margin-left'),
  2130.             top: obj.y - styleNumber(this, 'margin-top')
  2131.         };
  2132.     },
  2133.  
  2134.     setPosition: function(obj){
  2135.         return this.setStyles(this.computePosition(obj));
  2136.     }
  2137.  
  2138. });
  2139.  
  2140.  
  2141. Native.implement([Document, Window], {
  2142.  
  2143.     getSize: function(){
  2144.         if (Browser.Engine.presto || Browser.Engine.webkit){
  2145.             var win = this.getWindow();
  2146.             return {x: win.innerWidth, y: win.innerHeight};
  2147.         }
  2148.         var doc = getCompatElement(this);
  2149.         return {x: doc.clientWidth, y: doc.clientHeight};
  2150.     },
  2151.  
  2152.     getScroll: function(){
  2153.         var win = this.getWindow(), doc = getCompatElement(this);
  2154.         return {x: win.pageXOffset || doc.scrollLeft, y: win.pageYOffset || doc.scrollTop};
  2155.     },
  2156.  
  2157.     getScrollSize: function(){
  2158.         var doc = getCompatElement(this), min = this.getSize();
  2159.         return {x: Math.max(doc.scrollWidth, min.x), y: Math.max(doc.scrollHeight, min.y)};
  2160.     },
  2161.  
  2162.     getPosition: function(){
  2163.         return {x: 0, y: 0};
  2164.     },
  2165.  
  2166.     getCoordinates: function(){
  2167.         var size = this.getSize();
  2168.         return {top: 0, left: 0, bottom: size.y, right: size.x, height: size.y, width: size.x};
  2169.     }
  2170.  
  2171. });
  2172.  
  2173. // private methods
  2174.  
  2175. var styleString = Element.getComputedStyle;
  2176.  
  2177. function styleNumber(element, style){
  2178.     return styleString(element, style).toInt() || 0;
  2179. };
  2180.  
  2181. function borderBox(element){
  2182.     return styleString(element, '-moz-box-sizing') == 'border-box';
  2183. };
  2184.  
  2185. function topBorder(element){
  2186.     return styleNumber(element, 'border-top-width');
  2187. };
  2188.  
  2189. function leftBorder(element){
  2190.     return styleNumber(element, 'border-left-width');
  2191. };
  2192.  
  2193. function isBody(element){
  2194.     return (/^(?:body|html)$/i).test(element.tagName);
  2195. };
  2196.  
  2197. function getCompatElement(element){
  2198.     var doc = element.getDocument();
  2199.     return (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body;
  2200. };
  2201.  
  2202. })();
  2203.  
  2204. //aliases
  2205. Element.alias('setPosition', 'position'); //compatability
  2206.  
  2207. Native.implement([Window, Document, Element], {
  2208.  
  2209.     getHeight: function(){
  2210.         return this.getSize().y;
  2211.     },
  2212.  
  2213.     getWidth: function(){
  2214.         return this.getSize().x;
  2215.     },
  2216.  
  2217.     getScrollTop: function(){
  2218.         return this.getScroll().y;
  2219.     },
  2220.  
  2221.     getScrollLeft: function(){
  2222.         return this.getScroll().x;
  2223.     },
  2224.  
  2225.     getScrollHeight: function(){
  2226.         return this.getScrollSize().y;
  2227.     },
  2228.  
  2229.     getScrollWidth: function(){
  2230.         return this.getScrollSize().x;
  2231.     },
  2232.  
  2233.     getTop: function(){
  2234.         return this.getPosition().y;
  2235.     },
  2236.  
  2237.     getLeft: function(){
  2238.         return this.getPosition().x;
  2239.     }
  2240.  
  2241. });
  2242.  
  2243. /*
  2244. ---
  2245.  
  2246. script: Selectors.js
  2247.  
  2248. description: Adds advanced CSS-style querying capabilities for targeting HTML Elements. Includes pseudo selectors.
  2249.  
  2250. license: MIT-style license.
  2251.  
  2252. requires:
  2253. - /Element
  2254.  
  2255. provides: [Selectors]
  2256.  
  2257. ...
  2258. */
  2259.  
  2260. Native.implement([Document, Element], {
  2261.  
  2262.     getElements: function(expression, nocash){
  2263.         expression = expression.split(',');
  2264.         var items, local = {};
  2265.         for (var i = 0, l = expression.length; i < l; i++){
  2266.             var selector = expression[i], elements = Selectors.Utils.search(this, selector, local);
  2267.             if (i != 0 && elements.item) elements = $A(elements);
  2268.             items = (i == 0) ? elements : (items.item) ? $A(items).concat(elements) : items.concat(elements);
  2269.         }
  2270.         return new Elements(items, {ddup: (expression.length > 1), cash: !nocash});
  2271.     }
  2272.  
  2273. });
  2274.  
  2275. Element.implement({
  2276.  
  2277.     match: function(selector){
  2278.         if (!selector || (selector == this)) return true;
  2279.         var tagid = Selectors.Utils.parseTagAndID(selector);
  2280.         var tag = tagid[0], id = tagid[1];
  2281.         if (!Selectors.Filters.byID(this, id) || !Selectors.Filters.byTag(this, tag)) return false;
  2282.         var parsed = Selectors.Utils.parseSelector(selector);
  2283.         return (parsed) ? Selectors.Utils.filter(this, parsed, {}) : true;
  2284.     }
  2285.  
  2286. });
  2287.  
  2288. var Selectors = {Cache: {nth: {}, parsed: {}}};
  2289.  
  2290. Selectors.RegExps = {
  2291.     id: (/#([\w-]+)/),
  2292.     tag: (/^(\w+|\*)/),
  2293.     quick: (/^(\w+|\*)$/),
  2294.     splitter: (/\s*([+>~\s])\s*([a-zA-Z#.*:\[])/g),
  2295.     combined: (/\.([\w-]+)|\[(\w+)(?:([!*^$~|]?=)(["']?)([^\4]*?)\4)?\]|:([\w-]+)(?:\(["']?(.*?)?["']?\)|$)/g)
  2296. };
  2297.  
  2298. Selectors.Utils = {
  2299.  
  2300.     chk: function(item, uniques){
  2301.         if (!uniques) return true;
  2302.         var uid = $uid(item);
  2303.         if (!uniques[uid]) return uniques[uid] = true;
  2304.         return false;
  2305.     },
  2306.  
  2307.     parseNthArgument: function(argument){
  2308.         if (Selectors.Cache.nth[argument]) return Selectors.Cache.nth[argument];
  2309.         var parsed = argument.match(/^([+-]?\d*)?([a-z]+)?([+-]?\d*)?$/);
  2310.         if (!parsed) return false;
  2311.         var inta = parseInt(parsed[1], 10);
  2312.         var a = (inta || inta === 0) ? inta : 1;
  2313.         var special = parsed[2] || false;
  2314.         var b = parseInt(parsed[3], 10) || 0;
  2315.         if (a != 0){
  2316.             b--;
  2317.             while (b < 1) b += a;
  2318.             while (b >= a) b -= a;
  2319.         } else {
  2320.             a = b;
  2321.             special = 'index';
  2322.         }
  2323.         switch (special){
  2324.             case 'n': parsed = {a: a, b: b, special: 'n'}; break;
  2325.             case 'odd': parsed = {a: 2, b: 0, special: 'n'}; break;
  2326.             case 'even': parsed = {a: 2, b: 1, special: 'n'}; break;
  2327.             case 'first': parsed = {a: 0, special: 'index'}; break;
  2328.             case 'last': parsed = {special: 'last-child'}; break;
  2329.             case 'only': parsed = {special: 'only-child'}; break;
  2330.             default: parsed = {a: (a - 1), special: 'index'};
  2331.         }
  2332.  
  2333.         return Selectors.Cache.nth[argument] = parsed;
  2334.     },
  2335.  
  2336.     parseSelector: function(selector){
  2337.         if (Selectors.Cache.parsed[selector]) return Selectors.Cache.parsed[selector];
  2338.         var m, parsed = {classes: [], pseudos: [], attributes: []};
  2339.         while ((m = Selectors.RegExps.combined.exec(selector))){
  2340.             var cn = m[1], an = m[2], ao = m[3], av = m[5], pn = m[6], pa = m[7];
  2341.             if (cn){
  2342.                 parsed.classes.push(cn);
  2343.             } else if (pn){
  2344.                 var parser = Selectors.Pseudo.get(pn);
  2345.                 if (parser) parsed.pseudos.push({parser: parser, argument: pa});
  2346.                 else parsed.attributes.push({name: pn, operator: '=', value: pa});
  2347.             } else if (an){
  2348.                 parsed.attributes.push({name: an, operator: ao, value: av});
  2349.             }
  2350.         }
  2351.         if (!parsed.classes.length) delete parsed.classes;
  2352.         if (!parsed.attributes.length) delete parsed.attributes;
  2353.         if (!parsed.pseudos.length) delete parsed.pseudos;
  2354.         if (!parsed.classes && !parsed.attributes && !parsed.pseudos) parsed = null;
  2355.         return Selectors.Cache.parsed[selector] = parsed;
  2356.     },
  2357.  
  2358.     parseTagAndID: function(selector){
  2359.         var tag = selector.match(Selectors.RegExps.tag);
  2360.         var id = selector.match(Selectors.RegExps.id);
  2361.         return [(tag) ? tag[1] : '*', (id) ? id[1] : false];
  2362.     },
  2363.  
  2364.     filter: function(item, parsed, local){
  2365.         var i;
  2366.         if (parsed.classes){
  2367.             for (i = parsed.classes.length; i--; i){
  2368.                 var cn = parsed.classes[i];
  2369.                 if (!Selectors.Filters.byClass(item, cn)) return false;
  2370.             }
  2371.         }
  2372.         if (parsed.attributes){
  2373.             for (i = parsed.attributes.length; i--; i){
  2374.                 var att = parsed.attributes[i];
  2375.                 if (!Selectors.Filters.byAttribute(item, att.name, att.operator, att.value)) return false;
  2376.             }
  2377.         }
  2378.         if (parsed.pseudos){
  2379.             for (i = parsed.pseudos.length; i--; i){
  2380.                 var psd = parsed.pseudos[i];
  2381.                 if (!Selectors.Filters.byPseudo(item, psd.parser, psd.argument, local)) return false;
  2382.             }
  2383.         }
  2384.         return true;
  2385.     },
  2386.  
  2387.     getByTagAndID: function(ctx, tag, id){
  2388.         if (id){
  2389.             var item = (ctx.getElementById) ? ctx.getElementById(id, true) : Element.getElementById(ctx, id, true);
  2390.             return (item && Selectors.Filters.byTag(item, tag)) ? [item] : [];
  2391.         } else {
  2392.             return ctx.getElementsByTagName(tag);
  2393.         }
  2394.     },
  2395.  
  2396.     search: function(self, expression, local){
  2397.         var splitters = [];
  2398.  
  2399.         var selectors = expression.trim().replace(Selectors.RegExps.splitter, function(m0, m1, m2){
  2400.             splitters.push(m1);
  2401.             return ':)' + m2;
  2402.         }).split(':)');
  2403.  
  2404.         var items, filtered, item;
  2405.  
  2406.         for (var i = 0, l = selectors.length; i < l; i++){
  2407.  
  2408.             var selector = selectors[i];
  2409.  
  2410.             if (i == 0 && Selectors.RegExps.quick.test(selector)){
  2411.                 items = self.getElementsByTagName(selector);
  2412.                 continue;
  2413.             }
  2414.  
  2415.             var splitter = splitters[i - 1];
  2416.  
  2417.             var tagid = Selectors.Utils.parseTagAndID(selector);
  2418.             var tag = tagid[0], id = tagid[1];
  2419.  
  2420.             if (i == 0){
  2421.                 items = Selectors.Utils.getByTagAndID(self, tag, id);
  2422.             } else {
  2423.                 var uniques = {}, found = [];
  2424.                 for (var j = 0, k = items.length; j < k; j++) found = Selectors.Getters[splitter](found, items[j], tag, id, uniques);
  2425.                 items = found;
  2426.             }
  2427.  
  2428.             var parsed = Selectors.Utils.parseSelector(selector);
  2429.  
  2430.             if (parsed){
  2431.                 filtered = [];
  2432.                 for (var m = 0, n = items.length; m < n; m++){
  2433.                     item = items[m];
  2434.                     if (Selectors.Utils.filter(item, parsed, local)) filtered.push(item);
  2435.                 }
  2436.                 items = filtered;
  2437.             }
  2438.  
  2439.         }
  2440.  
  2441.         return items;
  2442.  
  2443.     }
  2444.  
  2445. };
  2446.  
  2447. Selectors.Getters = {
  2448.  
  2449.     ' ': function(found, self, tag, id, uniques){
  2450.         var items = Selectors.Utils.getByTagAndID(self, tag, id);
  2451.         for (var i = 0, l = items.length; i < l; i++){
  2452.             var item = items[i];
  2453.             if (Selectors.Utils.chk(item, uniques)) found.push(item);
  2454.         }
  2455.         return found;
  2456.     },
  2457.  
  2458.     '>': function(found, self, tag, id, uniques){
  2459.         var children = Selectors.Utils.getByTagAndID(self, tag, id);
  2460.         for (var i = 0, l = children.length; i < l; i++){
  2461.             var child = children[i];
  2462.             if (child.parentNode == self && Selectors.Utils.chk(child, uniques)) found.push(child);
  2463.         }
  2464.         return found;
  2465.     },
  2466.  
  2467.     '+': function(found, self, tag, id, uniques){
  2468.         while ((self = self.nextSibling)){
  2469.             if (self.nodeType == 1){
  2470.                 if (Selectors.Utils.chk(self, uniques) && Selectors.Filters.byTag(self, tag) && Selectors.Filters.byID(self, id)) found.push(self);
  2471.                 break;
  2472.             }
  2473.         }
  2474.         return found;
  2475.     },
  2476.  
  2477.     '~': function(found, self, tag, id, uniques){
  2478.         while ((self = self.nextSibling)){
  2479.             if (self.nodeType == 1){
  2480.                 if (!Selectors.Utils.chk(self, uniques)) break;
  2481.                 if (Selectors.Filters.byTag(self, tag) && Selectors.Filters.byID(self, id)) found.push(self);
  2482.             }
  2483.         }
  2484.         return found;
  2485.     }
  2486.  
  2487. };
  2488.  
  2489. Selectors.Filters = {
  2490.  
  2491.     byTag: function(self, tag){
  2492.         return (tag == '*' || (self.tagName && self.tagName.toLowerCase() == tag));
  2493.     },
  2494.  
  2495.     byID: function(self, id){
  2496.         return (!id || (self.id && self.id == id));
  2497.     },
  2498.  
  2499.     byClass: function(self, klass){
  2500.         return (self.className && self.className.contains && self.className.contains(klass, ' '));
  2501.     },
  2502.  
  2503.     byPseudo: function(self, parser, argument, local){
  2504.         return parser.call(self, argument, local);
  2505.     },
  2506.  
  2507.     byAttribute: function(self, name, operator, value){
  2508.         var result = Element.prototype.getProperty.call(self, name);
  2509.         if (!result) return (operator == '!=');
  2510.         if (!operator || value == undefined) return true;
  2511.         switch (operator){
  2512.             case '=': return (result == value);
  2513.             case '*=': return (result.contains(value));
  2514.             case '^=': return (result.substr(0, value.length) == value);
  2515.             case '$=': return (result.substr(result.length - value.length) == value);
  2516.             case '!=': return (result != value);
  2517.             case '~=': return result.contains(value, ' ');
  2518.             case '|=': return result.contains(value, '-');
  2519.         }
  2520.         return false;
  2521.     }
  2522.  
  2523. };
  2524.  
  2525. Selectors.Pseudo = new Hash({
  2526.  
  2527.     // w3c pseudo selectors
  2528.  
  2529.     checked: function(){
  2530.         return this.checked;
  2531.     },
  2532.  
  2533.     empty: function(){
  2534.         return !(this.innerText || this.textContent || '').length;
  2535.     },
  2536.  
  2537.     not: function(selector){
  2538.         return !Element.match(this, selector);
  2539.     },
  2540.  
  2541.     contains: function(text){
  2542.         return (this.innerText || this.textContent || '').contains(text);
  2543.     },
  2544.  
  2545.     'first-child': function(){
  2546.         return Selectors.Pseudo.index.call(this, 0);
  2547.     },
  2548.  
  2549.     'last-child': function(){
  2550.         var element = this;
  2551.         while ((element = element.nextSibling)){
  2552.             if (element.nodeType == 1) return false;
  2553.         }
  2554.         return true;
  2555.     },
  2556.  
  2557.     'only-child': function(){
  2558.         var prev = this;
  2559.         while ((prev = prev.previousSibling)){
  2560.             if (prev.nodeType == 1) return false;
  2561.         }
  2562.         var next = this;
  2563.         while ((next = next.nextSibling)){
  2564.             if (next.nodeType == 1) return false;
  2565.         }
  2566.         return true;
  2567.     },
  2568.  
  2569.     'nth-child': function(argument, local){
  2570.         argument = (argument == undefined) ? 'n' : argument;
  2571.         var parsed = Selectors.Utils.parseNthArgument(argument);
  2572.         if (parsed.special != 'n') return Selectors.Pseudo[parsed.special].call(this, parsed.a, local);
  2573.         var count = 0;
  2574.         local.positions = local.positions || {};
  2575.         var uid = $uid(this);
  2576.         if (!local.positions[uid]){
  2577.             var self = this;
  2578.             while ((self = self.previousSibling)){
  2579.                 if (self.nodeType != 1) continue;
  2580.                 count ++;
  2581.                 var position = local.positions[$uid(self)];
  2582.                 if (position != undefined){
  2583.                     count = position + count;
  2584.                     break;
  2585.                 }
  2586.             }
  2587.             local.positions[uid] = count;
  2588.         }
  2589.         return (local.positions[uid] % parsed.a == parsed.b);
  2590.     },
  2591.  
  2592.     // custom pseudo selectors
  2593.  
  2594.     index: function(index){
  2595.         var element = this, count = 0;
  2596.         while ((element = element.previousSibling)){
  2597.             if (element.nodeType == 1 && ++count > index) return false;
  2598.         }
  2599.         return (count == index);
  2600.     },
  2601.  
  2602.     even: function(argument, local){
  2603.         return Selectors.Pseudo['nth-child'].call(this, '2n+1', local);
  2604.     },
  2605.  
  2606.     odd: function(argument, local){
  2607.         return Selectors.Pseudo['nth-child'].call(this, '2n', local);
  2608.     },
  2609.  
  2610.     selected: function(){
  2611.         return this.selected;
  2612.     },
  2613.  
  2614.     enabled: function(){
  2615.         return (this.disabled === false);
  2616.     }
  2617.  
  2618. });
  2619.  
  2620. /*
  2621. ---
  2622.  
  2623. script: Event.js
  2624.  
  2625. description: Contains the Event Class, to make the event object cross-browser.
  2626.  
  2627. license: MIT-style license.
  2628.  
  2629. requires:
  2630. - /Window
  2631. - /Document
  2632. - /Hash
  2633. - /Array
  2634. - /Function
  2635. - /String
  2636.  
  2637. provides: [Event]
  2638.  
  2639. ...
  2640. */
  2641.  
  2642. var Event = new Native({
  2643.  
  2644.     name: 'Event',
  2645.  
  2646.     initialize: function(event, win){
  2647.         win = win || window;
  2648.         var doc = win.document;
  2649.         event = event || win.event;
  2650.         if (event.$extended) return event;
  2651.         this.$extended = true;
  2652.         var type = event.type;
  2653.         var target = event.target || event.srcElement;
  2654.         while (target && target.nodeType == 3) target = target.parentNode;
  2655.  
  2656.         if (type.test(/key/)){
  2657.             var code = event.which || event.keyCode;
  2658.             var key = Event.Keys.keyOf(code);
  2659.             if (type == 'keydown'){
  2660.                 var fKey = code - 111;
  2661.                 if (fKey > 0 && fKey < 13) key = 'f' + fKey;
  2662.             }
  2663.             key = key || String.fromCharCode(code).toLowerCase();
  2664.         } else if (type.match(/(click|mouse|menu)/i)){
  2665.             doc = (!doc.compatMode || doc.compatMode == 'CSS1Compat') ? doc.html : doc.body;
  2666.             var page = {
  2667.                 x: event.pageX || event.clientX + doc.scrollLeft,
  2668.                 y: event.pageY || event.clientY + doc.scrollTop
  2669.             };
  2670.             var client = {
  2671.                 x: (event.pageX) ? event.pageX - win.pageXOffset : event.clientX,
  2672.                 y: (event.pageY) ? event.pageY - win.pageYOffset : event.clientY
  2673.             };
  2674.             if (type.match(/DOMMouseScroll|mousewheel/)){
  2675.                 var wheel = (event.wheelDelta) ? event.wheelDelta / 120 : -(event.detail || 0) / 3;
  2676.             }
  2677.             var rightClick = (event.which == 3) || (event.button == 2);
  2678.             var related = null;
  2679.             if (type.match(/over|out/)){
  2680.                 switch (type){
  2681.                     case 'mouseover': related = event.relatedTarget || event.fromElement; break;
  2682.                     case 'mouseout': related = event.relatedTarget || event.toElement;
  2683.                 }
  2684.                 if (!(function(){
  2685.                     while (related && related.nodeType == 3) related = related.parentNode;
  2686.                     return true;
  2687.                 }).create({attempt: Browser.Engine.gecko})()) related = false;
  2688.             }
  2689.         }
  2690.  
  2691.         return $extend(this, {
  2692.             event: event,
  2693.             type: type,
  2694.  
  2695.             page: page,
  2696.             client: client,
  2697.             rightClick: rightClick,
  2698.  
  2699.             wheel: wheel,
  2700.  
  2701.             relatedTarget: related,
  2702.             target: target,
  2703.  
  2704.             code: code,
  2705.             key: key,
  2706.  
  2707.             shift: event.shiftKey,
  2708.             control: event.ctrlKey,
  2709.             alt: event.altKey,
  2710.             meta: event.metaKey
  2711.         });
  2712.     }
  2713.  
  2714. });
  2715.  
  2716. Event.Keys = new Hash({
  2717.     'enter': 13,
  2718.     'up': 38,
  2719.     'down': 40,
  2720.     'left': 37,
  2721.     'right': 39,
  2722.     'esc': 27,
  2723.     'space': 32,
  2724.     'backspace': 8,
  2725.     'tab': 9,
  2726.     'delete': 46
  2727. });
  2728.  
  2729. Event.implement({
  2730.  
  2731.     stop: function(){
  2732.         return this.stopPropagation().preventDefault();
  2733.     },
  2734.  
  2735.     stopPropagation: function(){
  2736.         if (this.event.stopPropagation) this.event.stopPropagation();
  2737.         else this.event.cancelBubble = true;
  2738.         return this;
  2739.     },
  2740.  
  2741.     preventDefault: function(){
  2742.         if (this.event.preventDefault) this.event.preventDefault();
  2743.         else this.event.returnValue = false;
  2744.         return this;
  2745.     }
  2746.  
  2747. });
  2748.  
  2749. /*
  2750. ---
  2751.  
  2752. script: Element.Event.js
  2753.  
  2754. description: Contains Element methods for dealing with events. This file also includes mouseenter and mouseleave custom Element Events.
  2755.  
  2756. license: MIT-style license.
  2757.  
  2758. requires:
  2759. - /Element
  2760. - /Event
  2761.  
  2762. provides: [Element.Event]
  2763.  
  2764. ...
  2765. */
  2766.  
  2767. Element.Properties.events = {set: function(events){
  2768.     this.addEvents(events);
  2769. }};
  2770.  
  2771. Native.implement([Element, Window, Document], {
  2772.  
  2773.     addEvent: function(type, fn){
  2774.         var events = this.retrieve('events', {});
  2775.         events[type] = events[type] || {'keys': [], 'values': []};
  2776.         if (events[type].keys.contains(fn)) return this;
  2777.         events[type].keys.push(fn);
  2778.         var realType = type, custom = Element.Events.get(type), condition = fn, self = this;
  2779.         if (custom){
  2780.             if (custom.onAdd) custom.onAdd.call(this, fn);
  2781.             if (custom.condition){
  2782.                 condition = function(event){
  2783.                     if (custom.condition.call(this, event)) return fn.call(this, event);
  2784.                     return true;
  2785.                 };
  2786.             }
  2787.             realType = custom.base || realType;
  2788.         }
  2789.         var defn = function(){
  2790.             return fn.call(self);
  2791.         };
  2792.         var nativeEvent = Element.NativeEvents[realType];
  2793.         if (nativeEvent){
  2794.             if (nativeEvent == 2){
  2795.                 defn = function(event){
  2796.                     event = new Event(event, self.getWindow());
  2797.                     if (condition.call(self, event) === false) event.stop();
  2798.                 };
  2799.             }
  2800.             this.addListener(realType, defn);
  2801.         }
  2802.         events[type].values.push(defn);
  2803.         return this;
  2804.     },
  2805.  
  2806.     removeEvent: function(type, fn){
  2807.         var events = this.retrieve('events');
  2808.         if (!events || !events[type]) return this;
  2809.         var pos = events[type].keys.indexOf(fn);
  2810.         if (pos == -1) return this;
  2811.         events[type].keys.splice(pos, 1);
  2812.         var value = events[type].values.splice(pos, 1)[0];
  2813.         var custom = Element.Events.get(type);
  2814.         if (custom){
  2815.             if (custom.onRemove) custom.onRemove.call(this, fn);
  2816.             type = custom.base || type;
  2817.         }
  2818.         return (Element.NativeEvents[type]) ? this.removeListener(type, value) : this;
  2819.     },
  2820.  
  2821.     addEvents: function(events){
  2822.         for (var event in events) this.addEvent(event, events[event]);
  2823.         return this;
  2824.     },
  2825.  
  2826.     removeEvents: function(events){
  2827.         var type;
  2828.         if ($type(events) == 'object'){
  2829.             for (type in events) this.removeEvent(type, events[type]);
  2830.             return this;
  2831.         }
  2832.         var attached = this.retrieve('events');
  2833.         if (!attached) return this;
  2834.         if (!events){
  2835.             for (type in attached) this.removeEvents(type);
  2836.             this.eliminate('events');
  2837.         } else if (attached[events]){
  2838.             while (attached[events].keys[0]) this.removeEvent(events, attached[events].keys[0]);
  2839.             attached[events] = null;
  2840.         }
  2841.         return this;
  2842.     },
  2843.  
  2844.     fireEvent: function(type, args, delay){
  2845.         var events = this.retrieve('events');
  2846.         if (!events || !events[type]) return this;
  2847.         events[type].keys.each(function(fn){
  2848.             fn.create({'bind': this, 'delay': delay, 'arguments': args})();
  2849.         }, this);
  2850.         return this;
  2851.     },
  2852.  
  2853.     cloneEvents: function(from, type){
  2854.         from = document.id(from);
  2855.         var fevents = from.retrieve('events');
  2856.         if (!fevents) return this;
  2857.         if (!type){
  2858.             for (var evType in fevents) this.cloneEvents(from, evType);
  2859.         } else if (fevents[type]){
  2860.             fevents[type].keys.each(function(fn){
  2861.                 this.addEvent(type, fn);
  2862.             }, this);
  2863.         }
  2864.         return this;
  2865.     }
  2866.  
  2867. });
  2868.  
  2869. Element.NativeEvents = {
  2870.     click: 2, dblclick: 2, mouseup: 2, mousedown: 2, contextmenu: 2, //mouse buttons
  2871.     mousewheel: 2, DOMMouseScroll: 2, //mouse wheel
  2872.     mouseover: 2, mouseout: 2, mousemove: 2, selectstart: 2, selectend: 2, //mouse movement
  2873.     keydown: 2, keypress: 2, keyup: 2, //keyboard
  2874.     focus: 2, blur: 2, change: 2, reset: 2, select: 2, submit: 2, //form elements
  2875.     load: 1, unload: 1, beforeunload: 2, resize: 1, move: 1, DOMContentLoaded: 1, readystatechange: 1, //window
  2876.     error: 1, abort: 1, scroll: 1 //misc
  2877. };
  2878.  
  2879. (function(){
  2880.  
  2881. var $check = function(event){
  2882.     var related = event.relatedTarget;
  2883.     if (related == undefined) return true;
  2884.     if (related === false) return false;
  2885.     return ($type(this) != 'document' && related != this && related.prefix != 'xul' && !this.hasChild(related));
  2886. };
  2887.  
  2888. Element.Events = new Hash({
  2889.  
  2890.     mouseenter: {
  2891.         base: 'mouseover',
  2892.         condition: $check
  2893.     },
  2894.  
  2895.     mouseleave: {
  2896.         base: 'mouseout',
  2897.         condition: $check
  2898.     },
  2899.  
  2900.     mousewheel: {
  2901.         base: (Browser.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel'
  2902.     }
  2903.  
  2904. });
  2905.  
  2906. })();
  2907.  
  2908. /*
  2909. ---
  2910.  
  2911. script: Class.js
  2912.  
  2913. description: Contains the Class Function for easily creating, extending, and implementing reusable Classes.
  2914.  
  2915. license: MIT-style license.
  2916.  
  2917. requires:
  2918. - /$util
  2919. - /Native
  2920. - /Array
  2921. - /String
  2922. - /Function
  2923. - /Number
  2924. - /Hash
  2925.  
  2926. provides: [Class]
  2927.  
  2928. ...
  2929. */
  2930.  
  2931. function Class(params){
  2932.  
  2933.     if (params instanceof Function) params = {initialize: params};
  2934.  
  2935.     var newClass = function(){
  2936.         Object.reset(this);
  2937.         if (newClass._prototyping) return this;
  2938.         this._current = $empty;
  2939.         var value = (this.initialize) ? this.initialize.apply(this, arguments) : this;
  2940.         delete this._current; delete this.caller;
  2941.         return value;
  2942.     }.extend(this);
  2943.  
  2944.     newClass.implement(params);
  2945.  
  2946.     newClass.constructor = Class;
  2947.     newClass.prototype.constructor = newClass;
  2948.  
  2949.     return newClass;
  2950.  
  2951. };
  2952.  
  2953. Function.prototype.protect = function(){
  2954.     this._protected = true;
  2955.     return this;
  2956. };
  2957.  
  2958. Object.reset = function(object, key){
  2959.  
  2960.     if (key == null){
  2961.         for (var p in object) Object.reset(object, p);
  2962.         return object;
  2963.     }
  2964.  
  2965.     delete object[key];
  2966.  
  2967.     switch ($type(object[key])){
  2968.         case 'object':
  2969.             var F = function(){};
  2970.             F.prototype = object[key];
  2971.             var i = new F;
  2972.             object[key] = Object.reset(i);
  2973.         break;
  2974.         case 'array': object[key] = $unlink(object[key]); break;
  2975.     }
  2976.  
  2977.     return object;
  2978.  
  2979. };
  2980.  
  2981. new Native({name: 'Class', initialize: Class}).extend({
  2982.  
  2983.     instantiate: function(F){
  2984.         F._prototyping = true;
  2985.         var proto = new F;
  2986.         delete F._prototyping;
  2987.         return proto;
  2988.     },
  2989.  
  2990.     wrap: function(self, key, method){
  2991.         if (method._origin) method = method._origin;
  2992.  
  2993.         return function(){
  2994.             if (method._protected && this._current == null) throw new Error('The method "' + key + '" cannot be called.');
  2995.             var caller = this.caller, current = this._current;
  2996.             this.caller = current; this._current = arguments.callee;
  2997.             var result = method.apply(this, arguments);
  2998.             this._current = current; this.caller = caller;
  2999.             return result;
  3000.         }.extend({_owner: self, _origin: method, _name: key});
  3001.  
  3002.     }
  3003.  
  3004. });
  3005.  
  3006. Class.implement({
  3007.  
  3008.     implement: function(key, value){
  3009.  
  3010.         if ($type(key) == 'object'){
  3011.             for (var p in key) this.implement(p, key[p]);
  3012.             return this;
  3013.         }
  3014.  
  3015.         var mutator = Class.Mutators[key];
  3016.  
  3017.         if (mutator){
  3018.             value = mutator.call(this, value);
  3019.             if (value == null) return this;
  3020.         }
  3021.  
  3022.         var proto = this.prototype;
  3023.  
  3024.         switch ($type(value)){
  3025.  
  3026.             case 'function':
  3027.                 if (value._hidden) return this;
  3028.                 proto[key] = Class.wrap(this, key, value);
  3029.             break;
  3030.  
  3031.             case 'object':
  3032.                 var previous = proto[key];
  3033.                 if ($type(previous) == 'object') $mixin(previous, value);
  3034.                 else proto[key] = $unlink(value);
  3035.             break;
  3036.  
  3037.             case 'array':
  3038.                 proto[key] = $unlink(value);
  3039.             break;
  3040.  
  3041.             default: proto[key] = value;
  3042.  
  3043.         }
  3044.  
  3045.         return this;
  3046.  
  3047.     }
  3048.  
  3049. });
  3050.  
  3051. Class.Mutators = {
  3052.  
  3053.     Extends: function(parent){
  3054.  
  3055.         this.parent = parent;
  3056.         this.prototype = Class.instantiate(parent);
  3057.  
  3058.         this.implement('parent', function(){
  3059.             var name = this.caller._name, previous = this.caller._owner.parent.prototype[name];
  3060.             if (!previous) throw new Error('The method "' + name + '" has no parent.');
  3061.             return previous.apply(this, arguments);
  3062.         }.protect());
  3063.  
  3064.     },
  3065.  
  3066.     Implements: function(items){
  3067.         $splat(items).each(function(item){
  3068.             if (item instanceof Function) item = Class.instantiate(item);
  3069.             this.implement(item);
  3070.         }, this);
  3071.  
  3072.     }
  3073.  
  3074. };
  3075.  
  3076. /*
  3077. ---
  3078.  
  3079. script: Class.Extras.js
  3080.  
  3081. description: Contains Utility Classes that can be implemented into your own Classes to ease the execution of many common tasks.
  3082.  
  3083. license: MIT-style license.
  3084.  
  3085. requires:
  3086. - /Class
  3087.  
  3088. provides: [Chain, Events, Options]
  3089.  
  3090. ...
  3091. */
  3092.  
  3093. var Chain = new Class({
  3094.  
  3095.     $chain: [],
  3096.  
  3097.     chain: function(){
  3098.         this.$chain.extend(Array.flatten(arguments));
  3099.         return this;
  3100.     },
  3101.  
  3102.     callChain: function(){
  3103.         return (this.$chain.length) ? this.$chain.shift().apply(this, arguments) : false;
  3104.     },
  3105.  
  3106.     clearChain: function(){
  3107.         this.$chain.empty();
  3108.         return this;
  3109.     }
  3110.  
  3111. });
  3112.  
  3113. var Events = new Class({
  3114.  
  3115.     $events: {},
  3116.  
  3117.     addEvent: function(type, fn, internal){
  3118.         type = Events.removeOn(type);
  3119.         if (fn != $empty){
  3120.             this.$events[type] = this.$events[type] || [];
  3121.             this.$events[type].include(fn);
  3122.             if (internal) fn.internal = true;
  3123.         }
  3124.         return this;
  3125.     },
  3126.  
  3127.     addEvents: function(events){
  3128.         for (var type in events) this.addEvent(type, events[type]);
  3129.         return this;
  3130.     },
  3131.  
  3132.     fireEvent: function(type, args, delay){
  3133.         type = Events.removeOn(type);
  3134.         if (!this.$events || !this.$events[type]) return this;
  3135.         this.$events[type].each(function(fn){
  3136.             fn.create({'bind': this, 'delay': delay, 'arguments': args})();
  3137.         }, this);
  3138.         return this;
  3139.     },
  3140.  
  3141.     removeEvent: function(type, fn){
  3142.         type = Events.removeOn(type);
  3143.         if (!this.$events[type]) return this;
  3144.         if (!fn.internal) this.$events[type].erase(fn);
  3145.         return this;
  3146.     },
  3147.  
  3148.     removeEvents: function(events){
  3149.         var type;
  3150.         if ($type(events) == 'object'){
  3151.             for (type in events) this.removeEvent(type, events[type]);
  3152.             return this;
  3153.         }
  3154.         if (events) events = Events.removeOn(events);
  3155.         for (type in this.$events){
  3156.             if (events && events != type) continue;
  3157.             var fns = this.$events[type];
  3158.             for (var i = fns.length; i--; i) this.removeEvent(type, fns[i]);
  3159.         }
  3160.         return this;
  3161.     }
  3162.  
  3163. });
  3164.  
  3165. Events.removeOn = function(string){
  3166.     return string.replace(/^on([A-Z])/, function(full, first){
  3167.         return first.toLowerCase();
  3168.     });
  3169. };
  3170.  
  3171. var Options = new Class({
  3172.  
  3173.     setOptions: function(){
  3174.         this.options = $merge.run([this.options].extend(arguments));
  3175.         if (!this.addEvent) return this;
  3176.         for (var option in this.options){
  3177.             if ($type(this.options[option]) != 'function' || !(/^on[A-Z]/).test(option)) continue;
  3178.             this.addEvent(option, this.options[option]);
  3179.             delete this.options[option];
  3180.         }
  3181.         return this;
  3182.     }
  3183.  
  3184. });
  3185.  
  3186. /*
  3187. ---
  3188.  
  3189. script: Request.js
  3190.  
  3191. description: Powerful all purpose Request Class. Uses XMLHTTPRequest.
  3192.  
  3193. license: MIT-style license.
  3194.  
  3195. requires:
  3196. - /Element
  3197. - /Chain
  3198. - /Events
  3199. - /Options
  3200. - /Browser
  3201.  
  3202. provides: [Request]
  3203.  
  3204. ...
  3205. */
  3206.  
  3207. var Request = new Class({
  3208.  
  3209.     Implements: [Chain, Events, Options],
  3210.  
  3211.     options: {/*
  3212.         onRequest: $empty,
  3213.         onComplete: $empty,
  3214.         onCancel: $empty,
  3215.         onSuccess: $empty,
  3216.         onFailure: $empty,
  3217.         onException: $empty,*/
  3218.         url: '',
  3219.         data: '',
  3220.         headers: {
  3221.             'X-Requested-With': 'XMLHttpRequest',
  3222.             'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
  3223.         },
  3224.         async: true,
  3225.         format: false,
  3226.         method: 'post',
  3227.         link: 'ignore',
  3228.         isSuccess: null,
  3229.         emulation: true,
  3230.         urlEncoded: true,
  3231.         encoding: 'utf-8',
  3232.         evalScripts: false,
  3233.         evalResponse: false,
  3234.         noCache: false
  3235.     },
  3236.  
  3237.     initialize: function(options){
  3238.         this.xhr = new Browser.Request();
  3239.         this.setOptions(options);
  3240.         this.options.isSuccess = this.options.isSuccess || this.isSuccess;
  3241.         this.headers = new Hash(this.options.headers);
  3242.     },
  3243.  
  3244.     onStateChange: function(){
  3245.         if (this.xhr.readyState != 4 || !this.running) return;
  3246.         this.running = false;
  3247.         this.status = 0;
  3248.         $try(function(){
  3249.             this.status = this.xhr.status;
  3250.         }.bind(this));
  3251.         this.xhr.onreadystatechange = $empty;
  3252.         if (this.options.isSuccess.call(this, this.status)){
  3253.             this.response = {text: this.xhr.responseText, xml: this.xhr.responseXML};
  3254.             this.success(this.response.text, this.response.xml);
  3255.         } else {
  3256.             this.response = {text: null, xml: null};
  3257.             this.failure();
  3258.         }
  3259.     },
  3260.  
  3261.     isSuccess: function(){
  3262.         return ((this.status >= 200) && (this.status < 300));
  3263.     },
  3264.  
  3265.     processScripts: function(text){
  3266.         if (this.options.evalResponse || (/(ecma|java)script/).test(this.getHeader('Content-type'))) return $exec(text);
  3267.         return text.stripScripts(this.options.evalScripts);
  3268.     },
  3269.  
  3270.     success: function(text, xml){
  3271.         this.onSuccess(this.processScripts(text), xml);
  3272.     },
  3273.  
  3274.     onSuccess: function(){
  3275.         this.fireEvent('complete', arguments).fireEvent('success', arguments).callChain();
  3276.     },
  3277.  
  3278.     failure: function(){
  3279.         this.onFailure();
  3280.     },
  3281.  
  3282.     onFailure: function(){
  3283.         this.fireEvent('complete').fireEvent('failure', this.xhr);
  3284.     },
  3285.  
  3286.     setHeader: function(name, value){
  3287.         this.headers.set(name, value);
  3288.         return this;
  3289.     },
  3290.  
  3291.     getHeader: function(name){
  3292.         return $try(function(){
  3293.             return this.xhr.getResponseHeader(name);
  3294.         }.bind(this));
  3295.     },
  3296.  
  3297.     check: function(){
  3298.         if (!this.running) return true;
  3299.         switch (this.options.link){
  3300.             case 'cancel': this.cancel(); return true;
  3301.             case 'chain': this.chain(this.caller.bind(this, arguments)); return false;
  3302.         }
  3303.         return false;
  3304.     },
  3305.  
  3306.     send: function(options){
  3307.         if (!this.check(options)) return this;
  3308.         this.running = true;
  3309.  
  3310.         var type = $type(options);
  3311.         if (type == 'string' || type == 'element') options = {data: options};
  3312.  
  3313.         var old = this.options;
  3314.         options = $extend({data: old.data, url: old.url, method: old.method}, options);
  3315.         var data = options.data, url = String(options.url), method = options.method.toLowerCase();
  3316.  
  3317.         switch ($type(data)){
  3318.             case 'element': data = document.id(data).toQueryString(); break;
  3319.             case 'object': case 'hash': data = Hash.toQueryString(data);
  3320.         }
  3321.  
  3322.         if (this.options.format){
  3323.             var format = 'format=' + this.options.format;
  3324.             data = (data) ? format + '&' + data : format;
  3325.         }
  3326.  
  3327.         if (this.options.emulation && !['get', 'post'].contains(method)){
  3328.             var _method = '_method=' + method;
  3329.             data = (data) ? _method + '&' + data : _method;
  3330.             method = 'post';
  3331.         }
  3332.  
  3333.         if (this.options.urlEncoded && method == 'post'){
  3334.             var encoding = (this.options.encoding) ? '; charset=' + this.options.encoding : '';
  3335.             this.headers.set('Content-type', 'application/x-www-form-urlencoded' + encoding);
  3336.         }
  3337.  
  3338.         if (this.options.noCache){
  3339.             var noCache = 'noCache=' + new Date().getTime();
  3340.             data = (data) ? noCache + '&' + data : noCache;
  3341.         }
  3342.  
  3343.         var trimPosition = url.lastIndexOf('/');
  3344.         if (trimPosition > -1 && (trimPosition = url.indexOf('#')) > -1) url = url.substr(0, trimPosition);
  3345.  
  3346.         if (data && method == 'get'){
  3347.             url = url + (url.contains('?') ? '&' : '?') + data;
  3348.             data = null;
  3349.         }
  3350.  
  3351.         this.xhr.open(method.toUpperCase(), url, this.options.async);
  3352.  
  3353.         this.xhr.onreadystatechange = this.onStateChange.bind(this);
  3354.  
  3355.         this.headers.each(function(value, key){
  3356.             try {
  3357.                 this.xhr.setRequestHeader(key, value);
  3358.             } catch (e){
  3359.                 this.fireEvent('exception', [key, value]);
  3360.             }
  3361.         }, this);
  3362.  
  3363.         this.fireEvent('request');
  3364.         this.xhr.send(data);
  3365.         if (!this.options.async) this.onStateChange();
  3366.         return this;
  3367.     },
  3368.  
  3369.     cancel: function(){
  3370.         if (!this.running) return this;
  3371.         this.running = false;
  3372.         this.xhr.abort();
  3373.         this.xhr.onreadystatechange = $empty;
  3374.         this.xhr = new Browser.Request();
  3375.         this.fireEvent('cancel');
  3376.         return this;
  3377.     }
  3378.  
  3379. });
  3380.  
  3381. (function(){
  3382.  
  3383. var methods = {};
  3384. ['get', 'post', 'put', 'delete', 'GET', 'POST', 'PUT', 'DELETE'].each(function(method){
  3385.     methods[method] = function(){
  3386.         var params = Array.link(arguments, {url: String.type, data: $defined});
  3387.         return this.send($extend(params, {method: method}));
  3388.     };
  3389. });
  3390.  
  3391. Request.implement(methods);
  3392.  
  3393. })();
  3394.  
  3395. Element.Properties.send = {
  3396.  
  3397.     set: function(options){
  3398.         var send = this.retrieve('send');
  3399.         if (send) send.cancel();
  3400.         return this.eliminate('send').store('send:options', $extend({
  3401.             data: this, link: 'cancel', method: this.get('method') || 'post', url: this.get('action')
  3402.         }, options));
  3403.     },
  3404.  
  3405.     get: function(options){
  3406.         if (options || !this.retrieve('send')){
  3407.             if (options || !this.retrieve('send:options')) this.set('send', options);
  3408.             this.store('send', new Request(this.retrieve('send:options')));
  3409.         }
  3410.         return this.retrieve('send');
  3411.     }
  3412.  
  3413. };
  3414.  
  3415. Element.implement({
  3416.  
  3417.     send: function(url){
  3418.         var sender = this.get('send');
  3419.         sender.send({data: this, url: url || sender.options.url});
  3420.         return this;
  3421.     }
  3422.  
  3423. });
  3424.  
  3425. /*
  3426. ---
  3427.  
  3428. script: Request.HTML.js
  3429.  
  3430. description: Extends the basic Request Class with additional methods for interacting with HTML responses.
  3431.  
  3432. license: MIT-style license.
  3433.  
  3434. requires:
  3435. - /Request
  3436. - /Element
  3437.  
  3438. provides: [Request.HTML]
  3439.  
  3440. ...
  3441. */
  3442.  
  3443. Request.HTML = new Class({
  3444.  
  3445.     Extends: Request,
  3446.  
  3447.     options: {
  3448.         update: false,
  3449.         append: false,
  3450.         evalScripts: true,
  3451.         filter: false
  3452.     },
  3453.  
  3454.     processHTML: function(text){
  3455.         var match = text.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
  3456.         text = (match) ? match[1] : text;
  3457.  
  3458.         var container = new Element('div');
  3459.  
  3460.         return $try(function(){
  3461.             var root = '<root>' + text + '</root>', doc;
  3462.             if (Browser.Engine.trident){
  3463.                 doc = new ActiveXObject('Microsoft.XMLDOM');
  3464.                 doc.async = false;
  3465.                 doc.loadXML(root);
  3466.             } else {
  3467.                 doc = new DOMParser().parseFromString(root, 'text/xml');
  3468.             }
  3469.             root = doc.getElementsByTagName('root')[0];
  3470.             if (!root) return null;
  3471.             for (var i = 0, k = root.childNodes.length; i < k; i++){
  3472.                 var child = Element.clone(root.childNodes[i], true, true);
  3473.                 if (child) container.grab(child);
  3474.             }
  3475.             return container;
  3476.         }) || container.set('html', text);
  3477.     },
  3478.  
  3479.     success: function(text){
  3480.         var options = this.options, response = this.response;
  3481.  
  3482.         response.html = text.stripScripts(function(script){
  3483.             response.javascript = script;
  3484.         });
  3485.  
  3486.         var temp = this.processHTML(response.html);
  3487.  
  3488.         response.tree = temp.childNodes;
  3489.         response.elements = temp.getElements('*');
  3490.  
  3491.         if (options.filter) response.tree = response.elements.filter(options.filter);
  3492.         if (options.update) document.id(options.update).empty().set('html', response.html);
  3493.         else if (options.append) document.id(options.append).adopt(temp.getChildren());
  3494.         if (options.evalScripts) $exec(response.javascript);
  3495.  
  3496.         this.onSuccess(response.tree, response.elements, response.html, response.javascript);
  3497.     }
  3498.  
  3499. });
  3500.  
  3501. Element.Properties.load = {
  3502.  
  3503.     set: function(options){
  3504.         var load = this.retrieve('load');
  3505.         if (load) load.cancel();
  3506.         return this.eliminate('load').store('load:options', $extend({data: this, link: 'cancel', update: this, method: 'get'}, options));
  3507.     },
  3508.  
  3509.     get: function(options){
  3510.         if (options || ! this.retrieve('load')){
  3511.             if (options || !this.retrieve('load:options')) this.set('load', options);
  3512.             this.store('load', new Request.HTML(this.retrieve('load:options')));
  3513.         }
  3514.         return this.retrieve('load');
  3515.     }
  3516.  
  3517. };
  3518.  
  3519. Element.implement({
  3520.  
  3521.     load: function(){
  3522.         this.get('load').send(Array.link(arguments, {data: Object.type, url: String.type}));
  3523.         return this;
  3524.     }
  3525.  
  3526. });
  3527.  
  3528. /*
  3529. ---
  3530.  
  3531. script: Fx.js
  3532.  
  3533. description: Contains the basic animation logic to be extended by all other Fx Classes.
  3534.  
  3535. license: MIT-style license.
  3536.  
  3537. requires:
  3538. - /Chain
  3539. - /Events
  3540. - /Options
  3541.  
  3542. provides: [Fx]
  3543.  
  3544. ...
  3545. */
  3546.  
  3547. var Fx = new Class({
  3548.  
  3549.     Implements: [Chain, Events, Options],
  3550.  
  3551.     options: {
  3552.         /*
  3553.         onStart: $empty,
  3554.         onCancel: $empty,
  3555.         onComplete: $empty,
  3556.         */
  3557.         fps: 50,
  3558.         unit: false,
  3559.         duration: 500,
  3560.         link: 'ignore'
  3561.     },
  3562.  
  3563.     initialize: function(options){
  3564.         this.subject = this.subject || this;
  3565.         this.setOptions(options);
  3566.         this.options.duration = Fx.Durations[this.options.duration] || this.options.duration.toInt();
  3567.         var wait = this.options.wait;
  3568.         if (wait === false) this.options.link = 'cancel';
  3569.     },
  3570.  
  3571.     getTransition: function(){
  3572.         return function(p){
  3573.             return -(Math.cos(Math.PI * p) - 1) / 2;
  3574.         };
  3575.     },
  3576.  
  3577.     step: function(){
  3578.         var time = $time();
  3579.         if (time < this.time + this.options.duration){
  3580.             var delta = this.transition((time - this.time) / this.options.duration);
  3581.             this.set(this.compute(this.from, this.to, delta));
  3582.         } else {
  3583.             this.set(this.compute(this.from, this.to, 1));
  3584.             this.complete();
  3585.         }
  3586.     },
  3587.  
  3588.     set: function(now){
  3589.         return now;
  3590.     },
  3591.  
  3592.     compute: function(from, to, delta){
  3593.         return Fx.compute(from, to, delta);
  3594.     },
  3595.  
  3596.     check: function(){
  3597.         if (!this.timer) return true;
  3598.         switch (this.options.link){
  3599.             case 'cancel': this.cancel(); return true;
  3600.             case 'chain': this.chain(this.caller.bind(this, arguments)); return false;
  3601.         }
  3602.         return false;
  3603.     },
  3604.  
  3605.     start: function(from, to){
  3606.         if (!this.check(from, to)) return this;
  3607.         this.from = from;
  3608.         this.to = to;
  3609.         this.time = 0;
  3610.         this.transition = this.getTransition();
  3611.         this.startTimer();
  3612.         this.onStart();
  3613.         return this;
  3614.     },
  3615.  
  3616.     complete: function(){
  3617.         if (this.stopTimer()) this.onComplete();
  3618.         return this;
  3619.     },
  3620.  
  3621.     cancel: function(){
  3622.         if (this.stopTimer()) this.onCancel();
  3623.         return this;
  3624.     },
  3625.  
  3626.     onStart: function(){
  3627.         this.fireEvent('start', this.subject);
  3628.     },
  3629.  
  3630.     onComplete: function(){
  3631.         this.fireEvent('complete', this.subject);
  3632.         if (!this.callChain()) this.fireEvent('chainComplete', this.subject);
  3633.     },
  3634.  
  3635.     onCancel: function(){
  3636.         this.fireEvent('cancel', this.subject).clearChain();
  3637.     },
  3638.  
  3639.     pause: function(){
  3640.         this.stopTimer();
  3641.         return this;
  3642.     },
  3643.  
  3644.     resume: function(){
  3645.         this.startTimer();
  3646.         return this;
  3647.     },
  3648.  
  3649.     stopTimer: function(){
  3650.         if (!this.timer) return false;
  3651.         this.time = $time() - this.time;
  3652.         this.timer = $clear(this.timer);
  3653.         return true;
  3654.     },
  3655.  
  3656.     startTimer: function(){
  3657.         if (this.timer) return false;
  3658.         this.time = $time() - this.time;
  3659.         this.timer = this.step.periodical(Math.round(1000 / this.options.fps), this);
  3660.         return true;
  3661.     }
  3662.  
  3663. });
  3664.  
  3665. Fx.compute = function(from, to, delta){
  3666.     return (to - from) * delta + from;
  3667. };
  3668.  
  3669. Fx.Durations = {'short': 250, 'normal': 500, 'long': 1000};
  3670.  
  3671. /*
  3672. ---
  3673.  
  3674. script: Fx.CSS.js
  3675.  
  3676. description: Contains the CSS animation logic. Used by Fx.Tween, Fx.Morph, Fx.Elements.
  3677.  
  3678. license: MIT-style license.
  3679.  
  3680. requires:
  3681. - /Fx
  3682. - /Element.Style
  3683.  
  3684. provides: [Fx.CSS]
  3685.  
  3686. ...
  3687. */
  3688.  
  3689. Fx.CSS = new Class({
  3690.  
  3691.     Extends: Fx,
  3692.  
  3693.     //prepares the base from/to object
  3694.  
  3695.     prepare: function(element, property, values){
  3696.         values = $splat(values);
  3697.         var values1 = values[1];
  3698.         if (!$chk(values1)){
  3699.             values[1] = values[0];
  3700.             values[0] = element.getStyle(property);
  3701.         }
  3702.         var parsed = values.map(this.parse);
  3703.         return {from: parsed[0], to: parsed[1]};
  3704.     },
  3705.  
  3706.     //parses a value into an array
  3707.  
  3708.     parse: function(value){
  3709.         value = $lambda(value)();
  3710.         value = (typeof value == 'string') ? value.split(' ') : $splat(value);
  3711.         return value.map(function(val){
  3712.             val = String(val);
  3713.             var found = false;
  3714.             Fx.CSS.Parsers.each(function(parser, key){
  3715.                 if (found) return;
  3716.                 var parsed = parser.parse(val);
  3717.                 if ($chk(parsed)) found = {value: parsed, parser: parser};
  3718.             });
  3719.             found = found || {value: val, parser: Fx.CSS.Parsers.String};
  3720.             return found;
  3721.         });
  3722.     },
  3723.  
  3724.     //computes by a from and to prepared objects, using their parsers.
  3725.  
  3726.     compute: function(from, to, delta){
  3727.         var computed = [];
  3728.         (Math.min(from.length, to.length)).times(function(i){
  3729.             computed.push({value: from[i].parser.compute(from[i].value, to[i].value, delta), parser: from[i].parser});
  3730.         });
  3731.         computed.$family = {name: 'fx:css:value'};
  3732.         return computed;
  3733.     },
  3734.  
  3735.     //serves the value as settable
  3736.  
  3737.     serve: function(value, unit){
  3738.         if ($type(value) != 'fx:css:value') value = this.parse(value);
  3739.         var returned = [];
  3740.         value.each(function(bit){
  3741.             returned = returned.concat(bit.parser.serve(bit.value, unit));
  3742.         });
  3743.         return returned;
  3744.     },
  3745.  
  3746.     //renders the change to an element
  3747.  
  3748.     render: function(element, property, value, unit){
  3749.         element.setStyle(property, this.serve(value, unit));
  3750.     },
  3751.  
  3752.     //searches inside the page css to find the values for a selector
  3753.  
  3754.     search: function(selector){
  3755.         if (Fx.CSS.Cache[selector]) return Fx.CSS.Cache[selector];
  3756.         var to = {};
  3757.         Array.each(document.styleSheets, function(sheet, j){
  3758.             var href = sheet.href;
  3759.             if (href && href.contains('://') && !href.contains(document.domain)) return;
  3760.             var rules = sheet.rules || sheet.cssRules;
  3761.             Array.each(rules, function(rule, i){
  3762.                 if (!rule.style) return;
  3763.                 var selectorText = (rule.selectorText) ? rule.selectorText.replace(/^\w+/, function(m){
  3764.                     return m.toLowerCase();
  3765.                 }) : null;
  3766.                 if (!selectorText || !selectorText.test('^' + selector + '$')) return;
  3767.                 Element.Styles.each(function(value, style){
  3768.                     if (!rule.style[style] || Element.ShortStyles[style]) return;
  3769.                     value = String(rule.style[style]);
  3770.                     to[style] = (value.test(/^rgb/)) ? value.rgbToHex() : value;
  3771.                 });
  3772.             });
  3773.         });
  3774.         return Fx.CSS.Cache[selector] = to;
  3775.     }
  3776.  
  3777. });
  3778.  
  3779. Fx.CSS.Cache = {};
  3780.  
  3781. Fx.CSS.Parsers = new Hash({
  3782.  
  3783.     Color: {
  3784.         parse: function(value){
  3785.             if (value.match(/^#[0-9a-f]{3,6}$/i)) return value.hexToRgb(true);
  3786.             return ((value = value.match(/(\d+),\s*(\d+),\s*(\d+)/))) ? [value[1], value[2], value[3]] : false;
  3787.         },
  3788.         compute: function(from, to, delta){
  3789.             return from.map(function(value, i){
  3790.                 return Math.round(Fx.compute(from[i], to[i], delta));
  3791.             });
  3792.         },
  3793.         serve: function(value){
  3794.             return value.map(Number);
  3795.         }
  3796.     },
  3797.  
  3798.     Number: {
  3799.         parse: parseFloat,
  3800.         compute: Fx.compute,
  3801.         serve: function(value, unit){
  3802.             return (unit) ? value + unit : value;
  3803.         }
  3804.     },
  3805.  
  3806.     String: {
  3807.         parse: $lambda(false),
  3808.         compute: $arguments(1),
  3809.         serve: $arguments(0)
  3810.     }
  3811.  
  3812. });
  3813.  
  3814. /*
  3815. ---
  3816.  
  3817. script: Fx.Tween.js
  3818.  
  3819. description: Formerly Fx.Style, effect to transition any CSS property for an element.
  3820.  
  3821. license: MIT-style license.
  3822.  
  3823. requires:
  3824. - /Fx.CSS
  3825.  
  3826. provides: [Fx.Tween, Element.fade, Element.highlight]
  3827.  
  3828. ...
  3829. */
  3830.  
  3831. Fx.Tween = new Class({
  3832.  
  3833.     Extends: Fx.CSS,
  3834.  
  3835.     initialize: function(element, options){
  3836.         this.element = this.subject = document.id(element);
  3837.         this.parent(options);
  3838.     },
  3839.  
  3840.     set: function(property, now){
  3841.         if (arguments.length == 1){
  3842.             now = property;
  3843.             property = this.property || this.options.property;
  3844.         }
  3845.         this.render(this.element, property, now, this.options.unit);
  3846.         return this;
  3847.     },
  3848.  
  3849.     start: function(property, from, to){
  3850.         if (!this.check(property, from, to)) return this;
  3851.         var args = Array.flatten(arguments);
  3852.         this.property = this.options.property || args.shift();
  3853.         var parsed = this.prepare(this.element, this.property, args);
  3854.         return this.parent(parsed.from, parsed.to);
  3855.     }
  3856.  
  3857. });
  3858.  
  3859. Element.Properties.tween = {
  3860.  
  3861.     set: function(options){
  3862.         var tween = this.retrieve('tween');
  3863.         if (tween) tween.cancel();
  3864.         return this.eliminate('tween').store('tween:options', $extend({link: 'cancel'}, options));
  3865.     },
  3866.  
  3867.     get: function(options){
  3868.         if (options || !this.retrieve('tween')){
  3869.             if (options || !this.retrieve('tween:options')) this.set('tween', options);
  3870.             this.store('tween', new Fx.Tween(this, this.retrieve('tween:options')));
  3871.         }
  3872.         return this.retrieve('tween');
  3873.     }
  3874.  
  3875. };
  3876.  
  3877. Element.implement({
  3878.  
  3879.     tween: function(property, from, to){
  3880.         this.get('tween').start(arguments);
  3881.         return this;
  3882.     },
  3883.  
  3884.     fade: function(how){
  3885.         var fade = this.get('tween'), o = 'opacity', toggle;
  3886.         how = $pick(how, 'toggle');
  3887.         switch (how){
  3888.             case 'in': fade.start(o, 1); break;
  3889.             case 'out': fade.start(o, 0); break;
  3890.             case 'show': fade.set(o, 1); break;
  3891.             case 'hide': fade.set(o, 0); break;
  3892.             case 'toggle':
  3893.                 var flag = this.retrieve('fade:flag', this.get('opacity') == 1);
  3894.                 fade.start(o, (flag) ? 0 : 1);
  3895.                 this.store('fade:flag', !flag);
  3896.                 toggle = true;
  3897.             break;
  3898.             default: fade.start(o, arguments);
  3899.         }
  3900.         if (!toggle) this.eliminate('fade:flag');
  3901.         return this;
  3902.     },
  3903.  
  3904.     highlight: function(start, end){
  3905.         if (!end){
  3906.             end = this.retrieve('highlight:original', this.getStyle('background-color'));
  3907.             end = (end == 'transparent') ? '#fff' : end;
  3908.         }
  3909.         var tween = this.get('tween');
  3910.         tween.start('background-color', start || '#ffff88', end).chain(function(){
  3911.             this.setStyle('background-color', this.retrieve('highlight:original'));
  3912.             tween.callChain();
  3913.         }.bind(this));
  3914.         return this;
  3915.     }
  3916.  
  3917. });
  3918.  
  3919. /*
  3920. ---
  3921.  
  3922. script: Fx.Transitions.js
  3923.  
  3924. description: Contains a set of advanced transitions to be used with any of the Fx Classes.
  3925.  
  3926. license: MIT-style license.
  3927.  
  3928. credits:
  3929. - Easing Equations by Robert Penner, <http://www.robertpenner.com/easing/>, modified and optimized to be used with MooTools.
  3930.  
  3931. requires:
  3932. - /Fx
  3933.  
  3934. provides: [Fx.Transitions]
  3935.  
  3936. ...
  3937. */
  3938.  
  3939. Fx.implement({
  3940.  
  3941.     getTransition: function(){
  3942.         var trans = this.options.transition || Fx.Transitions.Sine.easeInOut;
  3943.         if (typeof trans == 'string'){
  3944.             var data = trans.split(':');
  3945.             trans = Fx.Transitions;
  3946.             trans = trans[data[0]] || trans[data[0].capitalize()];
  3947.             if (data[1]) trans = trans['ease' + data[1].capitalize() + (data[2] ? data[2].capitalize() : '')];
  3948.         }
  3949.         return trans;
  3950.     }
  3951.  
  3952. });
  3953.  
  3954. Fx.Transition = function(transition, params){
  3955.     params = $splat(params);
  3956.     return $extend(transition, {
  3957.         easeIn: function(pos){
  3958.             return transition(pos, params);
  3959.         },
  3960.         easeOut: function(pos){
  3961.             return 1 - transition(1 - pos, params);
  3962.         },
  3963.         easeInOut: function(pos){
  3964.             return (pos <= 0.5) ? transition(2 * pos, params) / 2 : (2 - transition(2 * (1 - pos), params)) / 2;
  3965.         }
  3966.     });
  3967. };
  3968.  
  3969. Fx.Transitions = new Hash({
  3970.  
  3971.     linear: $arguments(0)
  3972.  
  3973. });
  3974.  
  3975. Fx.Transitions.extend = function(transitions){
  3976.     for (var transition in transitions) Fx.Transitions[transition] = new Fx.Transition(transitions[transition]);
  3977. };
  3978.  
  3979. Fx.Transitions.extend({
  3980.  
  3981.     Pow: function(p, x){
  3982.         return Math.pow(p, x[0] || 6);
  3983.     },
  3984.  
  3985.     Expo: function(p){
  3986.         return Math.pow(2, 8 * (p - 1));
  3987.     },
  3988.  
  3989.     Circ: function(p){
  3990.         return 1 - Math.sin(Math.acos(p));
  3991.     },
  3992.  
  3993.     Sine: function(p){
  3994.         return 1 - Math.sin((1 - p) * Math.PI / 2);
  3995.     },
  3996.  
  3997.     Back: function(p, x){
  3998.         x = x[0] || 1.618;
  3999.         return Math.pow(p, 2) * ((x + 1) * p - x);
  4000.     },
  4001.  
  4002.     Bounce: function(p){
  4003.         var value;
  4004.         for (var a = 0, b = 1; 1; a += b, b /= 2){
  4005.             if (p >= (7 - 4 * a) / 11){
  4006.                 value = b * b - Math.pow((11 - 6 * a - 11 * p) / 4, 2);
  4007.                 break;
  4008.             }
  4009.         }
  4010.         return value;
  4011.     },
  4012.  
  4013.     Elastic: function(p, x){
  4014.         return Math.pow(2, 10 * --p) * Math.cos(20 * p * Math.PI * (x[0] || 1) / 3);
  4015.     }
  4016.  
  4017. });
  4018.  
  4019. ['Quad', 'Cubic', 'Quart', 'Quint'].each(function(transition, i){
  4020.     Fx.Transitions[transition] = new Fx.Transition(function(p){
  4021.         return Math.pow(p, [i + 2]);
  4022.     });
  4023. });
  4024.  
  4025. /*
  4026. ---
  4027.  
  4028. script: Fx.Morph.js
  4029.  
  4030. 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.
  4031.  
  4032. license: MIT-style license.
  4033.  
  4034. requires:
  4035. - /Fx.CSS
  4036.  
  4037. provides: [Fx.Morph]
  4038.  
  4039. ...
  4040. */
  4041.  
  4042. Fx.Morph = new Class({
  4043.  
  4044.     Extends: Fx.CSS,
  4045.  
  4046.     initialize: function(element, options){
  4047.         this.element = this.subject = document.id(element);
  4048.         this.parent(options);
  4049.     },
  4050.  
  4051.     set: function(now){
  4052.         if (typeof now == 'string') now = this.search(now);
  4053.         for (var p in now) this.render(this.element, p, now[p], this.options.unit);
  4054.         return this;
  4055.     },
  4056.  
  4057.     compute: function(from, to, delta){
  4058.         var now = {};
  4059.         for (var p in from) now[p] = this.parent(from[p], to[p], delta);
  4060.         return now;
  4061.     },
  4062.  
  4063.     start: function(properties){
  4064.         if (!this.check(properties)) return this;
  4065.         if (typeof properties == 'string') properties = this.search(properties);
  4066.         var from = {}, to = {};
  4067.         for (var p in properties){
  4068.             var parsed = this.prepare(this.element, p, properties[p]);
  4069.             from[p] = parsed.from;
  4070.             to[p] = parsed.to;
  4071.         }
  4072.         return this.parent(from, to);
  4073.     }
  4074.  
  4075. });
  4076.  
  4077. Element.Properties.morph = {
  4078.  
  4079.     set: function(options){
  4080.         var morph = this.retrieve('morph');
  4081.         if (morph) morph.cancel();
  4082.         return this.eliminate('morph').store('morph:options', $extend({link: 'cancel'}, options));
  4083.     },
  4084.  
  4085.     get: function(options){
  4086.         if (options || !this.retrieve('morph')){
  4087.             if (options || !this.retrieve('morph:options')) this.set('morph', options);
  4088.             this.store('morph', new Fx.Morph(this, this.retrieve('morph:options')));
  4089.         }
  4090.         return this.retrieve('morph');
  4091.     }
  4092.  
  4093. };
  4094.  
  4095. Element.implement({
  4096.  
  4097.     morph: function(props){
  4098.         this.get('morph').start(props);
  4099.         return this;
  4100.     }
  4101.  
  4102. });
  4103.  
  4104. /*
  4105. ---
  4106.  
  4107. script: DomReady.js
  4108.  
  4109. description: Contains the custom event domready.
  4110.  
  4111. license: MIT-style license.
  4112.  
  4113. requires:
  4114. - /Element.Event
  4115.  
  4116. provides: [DomReady]
  4117.  
  4118. ...
  4119. */
  4120.  
  4121. Element.Events.domready = {
  4122.  
  4123.     onAdd: function(fn){
  4124.         if (Browser.loaded) fn.call(this);
  4125.     }
  4126.  
  4127. };
  4128.  
  4129. (function(){
  4130.  
  4131.     var domready = function(){
  4132.         if (Browser.loaded) return;
  4133.         Browser.loaded = true;
  4134.         window.fireEvent('domready');
  4135.         document.fireEvent('domready');
  4136.     };
  4137.  
  4138.     window.addEvent('load', domready);
  4139.  
  4140.     if (Browser.Engine.trident){
  4141.         var temp = document.createElement('div');
  4142.         (function(){
  4143.             ($try(function(){
  4144.                 temp.doScroll(); // Technique by Diego Perini
  4145.                 return document.id(temp).inject(document.body).set('html', 'temp').dispose();
  4146.             })) ? domready() : arguments.callee.delay(50);
  4147.         })();
  4148.     } else if (Browser.Engine.webkit && Browser.Engine.version < 525){
  4149.         (function(){
  4150.             (['loaded', 'complete'].contains(document.readyState)) ? domready() : arguments.callee.delay(50);
  4151.         })();
  4152.     } else {
  4153.         document.addEvent('DOMContentLoaded', domready);
  4154.     }
  4155.  
  4156. })();
  4157.  
  4158. /*
  4159. ---
  4160.  
  4161. script: Cookie.js
  4162.  
  4163. description: Class for creating, reading, and deleting browser Cookies.
  4164.  
  4165. license: MIT-style license.
  4166.  
  4167. credits:
  4168. - Based on the functions by Peter-Paul Koch (http://quirksmode.org).
  4169.  
  4170. requires:
  4171. - /Options
  4172.  
  4173. provides: [Cookie]
  4174.  
  4175. ...
  4176. */
  4177.  
  4178. var Cookie = new Class({
  4179.  
  4180.     Implements: Options,
  4181.  
  4182.     options: {
  4183.         path: false,
  4184.         domain: false,
  4185.         duration: false,
  4186.         secure: false,
  4187.         document: document
  4188.     },
  4189.  
  4190.     initialize: function(key, options){
  4191.         this.key = key;
  4192.         this.setOptions(options);
  4193.     },
  4194.  
  4195.     write: function(value){
  4196.         value = encodeURIComponent(value);
  4197.         if (this.options.domain) value += '; domain=' + this.options.domain;
  4198.         if (this.options.path) value += '; path=' + this.options.path;
  4199.         if (this.options.duration){
  4200.             var date = new Date();
  4201.             date.setTime(date.getTime() + this.options.duration * 24 * 60 * 60 * 1000);
  4202.             value += '; expires=' + date.toGMTString();
  4203.         }
  4204.         if (this.options.secure) value += '; secure';
  4205.         this.options.document.cookie = this.key + '=' + value;
  4206.         return this;
  4207.     },
  4208.  
  4209.     read: function(){
  4210.         var value = this.options.document.cookie.match('(?:^|;)\\s*' + this.key.escapeRegExp() + '=([^;]*)');
  4211.         return (value) ? decodeURIComponent(value[1]) : null;
  4212.     },
  4213.  
  4214.     dispose: function(){
  4215.         new Cookie(this.key, $merge(this.options, {duration: -1})).write('');
  4216.         return this;
  4217.     }
  4218.  
  4219. });
  4220.  
  4221. Cookie.write = function(key, value, options){
  4222.     return new Cookie(key, options).write(value);
  4223. };
  4224.  
  4225. Cookie.read = function(key){
  4226.     return new Cookie(key).read();
  4227. };
  4228.  
  4229. Cookie.dispose = function(key, options){
  4230.     return new Cookie(key, options).dispose();
  4231. };
  4232.  
  4233. /*
  4234. ---
  4235.  
  4236. script: Swiff.js
  4237.  
  4238. description: Wrapper for embedding SWF movies. Supports External Interface Communication.
  4239.  
  4240. license: MIT-style license.
  4241.  
  4242. credits:
  4243. - Flash detection & Internet Explorer + Flash Player 9 fix inspired by SWFObject.
  4244.  
  4245. requires:
  4246. - /Options
  4247. - /$util
  4248.  
  4249. provides: [Swiff]
  4250.  
  4251. ...
  4252. */
  4253.  
  4254. var Swiff = new Class({
  4255.  
  4256.     Implements: [Options],
  4257.  
  4258.     options: {
  4259.         id: null,
  4260.         height: 1,
  4261.         width: 1,
  4262.         container: null,
  4263.         properties: {},
  4264.         params: {
  4265.             quality: 'high',
  4266.             allowScriptAccess: 'always',
  4267.             wMode: 'transparent',
  4268.             swLiveConnect: true
  4269.         },
  4270.         callBacks: {},
  4271.         vars: {}
  4272.     },
  4273.  
  4274.     toElement: function(){
  4275.         return this.object;
  4276.     },
  4277.  
  4278.     initialize: function(path, options){
  4279.         this.instance = 'Swiff_' + $time();
  4280.  
  4281.         this.setOptions(options);
  4282.         options = this.options;
  4283.         var id = this.id = options.id || this.instance;
  4284.         var container = document.id(options.container);
  4285.  
  4286.         Swiff.CallBacks[this.instance] = {};
  4287.  
  4288.         var params = options.params, vars = options.vars, callBacks = options.callBacks;
  4289.         var properties = $extend({height: options.height, width: options.width}, options.properties);
  4290.  
  4291.         var self = this;
  4292.  
  4293.         for (var callBack in callBacks){
  4294.             Swiff.CallBacks[this.instance][callBack] = (function(option){
  4295.                 return function(){
  4296.                     return option.apply(self.object, arguments);
  4297.                 };
  4298.             })(callBacks[callBack]);
  4299.             vars[callBack] = 'Swiff.CallBacks.' + this.instance + '.' + callBack;
  4300.         }
  4301.  
  4302.         params.flashVars = Hash.toQueryString(vars);
  4303.         if (Browser.Engine.trident){
  4304.             properties.classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
  4305.             params.movie = path;
  4306.         } else {
  4307.             properties.type = 'application/x-shockwave-flash';
  4308.             properties.data = path;
  4309.         }
  4310.         var build = '<object id="' + id + '"';
  4311.         for (var property in properties) build += ' ' + property + '="' + properties[property] + '"';
  4312.         build += '>';
  4313.         for (var param in params){
  4314.             if (params[param]) build += '<param name="' + param + '" value="' + params[param] + '" />';
  4315.         }
  4316.         build += '</object>';
  4317.         this.object = ((container) ? container.empty() : new Element('div')).set('html', build).firstChild;
  4318.     },
  4319.  
  4320.     replaces: function(element){
  4321.         element = document.id(element, true);
  4322.         element.parentNode.replaceChild(this.toElement(), element);
  4323.         return this;
  4324.     },
  4325.  
  4326.     inject: function(element){
  4327.         document.id(element, true).appendChild(this.toElement());
  4328.         return this;
  4329.     },
  4330.  
  4331.     remote: function(){
  4332.         return Swiff.remote.apply(Swiff, [this.toElement()].extend(arguments));
  4333.     }
  4334.  
  4335. });
  4336.  
  4337. Swiff.CallBacks = {};
  4338.  
  4339. Swiff.remote = function(obj, fn){
  4340.     var rs = obj.CallFunction('<invoke name="' + fn + '" returntype="javascript">' + __flash__argumentsToXML(arguments, 2) + '</invoke>');
  4341.     return eval(rs);
  4342. };
  4343.  
  4344. // end Greased MooTools
  4345. //
  4346. // hack to circumvent 'bug' when overriding toString (and others):
  4347. // https://mootools.lighthouseapp.com/projects/2706/tickets/651-classtostring-broken-on-122-big-regression
  4348. ['toString', 'toLocaleString', 'valueOf', 'toSource', 'watch', 'unwatch', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable'].each(function (method) {
  4349.     Class.Mutators[method] = $arguments(0);
  4350. });
  4351.  
  4352. // Browser specifics
  4353.  
  4354. var getJSVariable = function (regex) {
  4355.         // Thanks to Vispillo for this compact code
  4356.         var retval;
  4357.         $$('script').each( function (script) {
  4358.             if (retval != undefined) {
  4359.                 return;
  4360.             }
  4361.             var html = script.innerHTML;
  4362.             try {
  4363.                 retval = html.match(regex)[1];
  4364.             } catch (e) {
  4365.             }
  4366.         });
  4367.         return retval;
  4368.     }
  4369.  
  4370.     GM_getMagisterLudi = function () {
  4371.         var reMatch = /global_magisterLudi[ =]+\'([^\']+)\'/;
  4372.        var retval = getJSVariable(reMatch);
  4373.     if (!$chk(retval))
  4374.         retval = getJSVariable(/\"?api_key\"?\s*[ :]+[\'\"]([^\'\"]+)[\'\"]/);
  4375.     return retval;
  4376.    }
  4377.    GM_getAuthHash = function () {
  4378.        var reMatch = /global_auth_hash[ =]+\'([^\']+)\'/;
  4379.         var retval = getJSVariable(reMatch);
  4380.     if (!$chk(retval))
  4381.         retval = getJSVariable(/\"?auth_hash\"?\s*[ :]+[\'\"]([^\'\"]+)[\'\"]/);
  4382.     return retval;
  4383.     }
  4384.  
  4385.     GM_getAuthToken = function () {
  4386.         var reMatch = /global_auth_token[ =]+\'([^\']+)\'/;
  4387.        var retval = getJSVariable(reMatch);
  4388.     if (!$chk(retval))
  4389.         retval = getJSVariable(/\"?auth_token\"?\s*[ :]+[\'\"]([^\'\"]+)[\'\"]/);
  4390.        return retval;
  4391.    }
  4392.  
  4393.    GM_getUserNsid = function () {
  4394.         return getJSVariable(/\"nsid\"[ :]+[\'\"]([^\'\"]+)[\'\"]/);
  4395.    }
  4396.  
  4397. function toFixed(value, precision) {
  4398.    var power = Math.pow(10, precision || 0);
  4399.    return String(Math.round(value * power) / power);
  4400. }
  4401.  
  4402. function formatPercentage(value) {
  4403.    if (value < 1.0) {
  4404.        return toFixed(value * 10, 0) + "\u2030";
  4405.    } else {
  4406.        return Math.round(value) + "%";
  4407.    }
  4408. }
  4409.  
  4410. // version check code
  4411. var scriptNumber = 78638;
  4412.  
  4413. function showUpdateNotification(data) {
  4414.    var version = data.version;
  4415.    var onlineVersion = data.onlineVersion;
  4416.    var beta = data.beta;
  4417.  
  4418.    var color = 'white';
  4419.     var updatespan = $('AlesaDams_updates_span');
  4420.     if (!$chk(updatespan)) {
  4421.         updatespan = new Element('span', {
  4422.         id: 'AlesaDams_updates_span',
  4423.         // copied from Google++ userscript:
  4424.         styles: {
  4425.             'background': '#E0E0E0',
  4426.             padding: '2px 4px',
  4427.             display: 'block',
  4428.             '-moz-background-clip': 'border',
  4429.             '-moz-background-origin': 'padding',
  4430.             '-moz-background-inline-policy': 'continuous',
  4431.             position: 'fixed',
  4432.             opacity: '0.7',
  4433.             'z-index': 1011, // the lightbox layer is 1004 on the new photo page
  4434.             bottom: '5px',
  4435.             right: '5px',
  4436.             left: '5px'
  4437.         }
  4438.         }).inject($(document).getElement("body"));
  4439.     } else {
  4440.         // make it darker if already created by another script:
  4441.         updatespan.setStyle('background', '#E0E0E0');
  4442.     }
  4443.    var bgColor = beta ? 'grey' : 'black';
  4444.     var updater = new Element('span', {
  4445.         styles: {
  4446.             background: bgColor + ' none repeat scroll 0% 0%',
  4447.             margin: '2px 5px',
  4448.             position: 'relative',
  4449.             'float': beta ? 'left' : 'right',
  4450.             opacity: beta ? '0.5' : ''
  4451.         }
  4452.     }).inject(updatespan);
  4453.    new Element('a', {
  4454.        html: 'Number of Favs: ' + (beta ? 'beta ' + version : onlineVersion + ' available'),
  4455.        href: 'http://userscripts.org/scripts/show/' + scriptNumber,
  4456.        target: '_blank',
  4457.        title: 'to the scripts install page (opens in new tab)',
  4458.        styles: {
  4459.            'color': color,
  4460.            'text-decoration': 'none'
  4461.        },
  4462.        events: {
  4463.            click: function () {
  4464.                    GM_deleteValue("onlineVersion");
  4465.            }
  4466.        }
  4467.    }).inject(updater);
  4468.    new Element('a', {
  4469.        html: beta ? ' (feedback)' : ' (Changes)',
  4470.        title: 'opens in new tab',
  4471.        href: 'https://www.flickr.com/groups/flickrhacks/discuss/72157624112096017//lastpage',
  4472.        styles: {
  4473.            'text-decoration': 'none'
  4474.        },
  4475.        target: '_blank'
  4476.    }).inject(updater);
  4477. }
  4478.  
  4479. function getReplyInfo(data) {
  4480.        var threadId = data.threadId;
  4481.     var replyId = data.replyId;
  4482.        var callback = data.callback;
  4483.  
  4484.        try {
  4485.                new Request({
  4486.                        url: 'https://www.flickr.com',
  4487.                        onSuccess: function (responseText, responseXML) {
  4488.                                    try {
  4489.                                        var result;
  4490.                                        try {
  4491.                                            result = JSON.parse(responseText);
  4492.                                        } catch (e) {
  4493.                                     GM_log("[NOFOP] error parsing JSON reply for thread " + threadId + " (" + e + "): '" + responseText);
  4494.                             callback({ threadId: threadId, success: false, message: e });
  4495.                         return;
  4496.                                        }
  4497.                                        if (result.stat === 'fail') {
  4498.                                                callback({ threadId: threadId, success: false, message: result.message });
  4499.                                        } else {
  4500.                                                callback({ threadId: threadId, replyId: replyId, success: true, message: result.reply.message._content });
  4501.                                        }
  4502.                                    } catch (e) {
  4503.                                        GM_log("[NOFOP] ERROR processing result: " + e);
  4504.                                        callback({ threadId: threadId, success: false, message: "ERROR processing result: " + e });
  4505.                                    }
  4506.                                },
  4507.                                onFailure: function (response) {
  4508.                                        GM_log("[NOFOP] error: " + response.statusText);
  4509.                                        callback({ threadId: threadId, success: false, message: response.statusText });
  4510.                                }
  4511.                }).get('/services/rest', {
  4512.                        api_key: GM_getMagisterLudi(),
  4513.                        auth_hash: GM_getAuthHash(),
  4514.                        auth_token: GM_getAuthToken(),
  4515.                        format: 'json',
  4516.                        method: 'flickr.groups.discuss.replies.getInfo',
  4517.                        nojsoncallback: 1,
  4518.                        topic_id: threadId,
  4519.             reply_id: replyId
  4520.                });
  4521.        }
  4522. //PB POP ERROR TEST by Hacker09 AND konf
  4523. catch (e) {
  4524. //                callback({ threadId: threadId, success: false, message: 'Exception: ' + e });
  4525.        }
  4526.  
  4527. }
  4528.  
  4529. function checkVersion(version) {
  4530.  try {
  4531.    var lastVersionCheckTime = GM_getValue("lastVersionCheckTime");
  4532.    var elapsedtime;
  4533.    var CPStartTime = new Date();
  4534.    if (lastVersionCheckTime !== undefined) {
  4535.        elapsedtime = CPStartTime.getTime() - lastVersionCheckTime;
  4536.    }
  4537.    if (!lastVersionCheckTime || elapsedtime / 1000 > 60 * 60 * 12) { //more then 12h ago
  4538.         getReplyInfo({ threadId: '72157634086550096', replyId: '72157634357479746', callback: function(retval) {
  4539.                 var success = retval.success;
  4540.                 var message = retval.message;
  4541.                 if (!success) {
  4542.                     GM_log("[NOFOP] error getting version info: " + message);
  4543.                     GM_deleteValue("onlineVersion");
  4544.                     GM_deleteValue("lastVersionCheckTime");
  4545.                     return;
  4546.                 }
  4547.                 var onlineVersion = message.split(/<i>current version:\s*/)[1].split(/<\/i>/)[0];
  4548.                 GM_setValue("onlineVersion", onlineVersion);
  4549.                 GM_setValue("lastVersionCheckTime", (new Date()).getTime().toString());
  4550.             }
  4551.         });
  4552.    }
  4553.  
  4554.    var onlineVersion = GM_getValue("onlineVersion");
  4555.    if ($chk(onlineVersion)) {
  4556.        var updateAvailable = false;
  4557.        var reVersionMatch      = /(\d+)\.(\d+)\.(\d+)/;
  4558.        var onlineVersionParts  = reVersionMatch.exec(onlineVersion);
  4559.        var currentVersionParts = reVersionMatch.exec(version);
  4560.        var onlineVersionMajor, onlineVersionMinor, onlineVersionBuild;
  4561.        //[ onlineVersion, onlineVersionMajor, onlineVersionMinor] = onlineVersionParts; 'invalid left-hand side' in Chrome
  4562.        onlineVersionMajor = onlineVersionParts[1];
  4563.        onlineVersionMinor = onlineVersionParts[2];
  4564.        onlineVersionBuild = onlineVersionParts[3];
  4565.        var currentVersionMajor, currentVersionMinor, currentVersionBuild;
  4566.        //[ currentVersion, currentVersionMajor, currentVersionMinor] = currentVersionParts;
  4567.        currentVersionMajor = currentVersionParts[1];
  4568.        currentVersionMinor = currentVersionParts[2];
  4569.        currentVersionBuild = currentVersionParts[3];
  4570.        // first check major: important update! => rewrite, flickr updates, greasemonkey updates
  4571.        if (parseInt(onlineVersionMajor, 10) > parseInt(currentVersionMajor, 10)) {
  4572.            updateAvailable = true;
  4573.        } else if (parseInt(onlineVersionMajor, 10) === parseInt(currentVersionMajor, 10)) { // we don't want to downgrade
  4574.            // minor version update => new functionality
  4575.            if (parseInt(onlineVersionMinor, 10) > parseInt(currentVersionMinor, 10)) {
  4576.                updateAvailable = true;
  4577.            } else if (parseInt(onlineVersionMinor, 10) === parseInt(currentVersionMinor, 10)) {
  4578.         if (parseInt(onlineVersionBuild, 10) > parseInt(currentVersionBuild, 10)) {
  4579.             updateAvailable = true;
  4580.         }
  4581.         }
  4582.        }
  4583.        if (updateAvailable) {
  4584.            showUpdateNotification({ onlineVersion: onlineVersion });
  4585.     } else if (version != onlineVersion) {
  4586.         showUpdateNotification({ version: version, beta: true });
  4587.        }
  4588.    } else {
  4589.     GM_deleteValue("lastVersionCheckTime");
  4590.    }
  4591.  } catch (e) {
  4592.    GM_log("[NOFOP] checkVersion error: " + e);
  4593.  }
  4594. }
  4595.  
  4596. GM_setValue("version", NOFOPversion);
  4597. checkVersion(NOFOPversion);
  4598.  
  4599. // end version check code
  4600.  
  4601.    // the following api_key is reserved for this application
  4602.    // if you need an api_key for your own application, please request one at
  4603.    // http://www.flickr.com/services/apps/create/apply/
  4604.    // if you request a Non-Commercial key, you'll get it instantly
  4605.    var api_key = 'da04056ee38245449676dfcbbade0025';
  4606.  
  4607.    function getViewsAndCommentsAndNotes (photoId, async, callback, sessionKey) {
  4608.        new Request({
  4609.            method: 'get',
  4610.            url: 'https://www.flickr.com/',
  4611.         async: async,
  4612.            onSuccess: function (responseText, responseXML) {
  4613.                var result;
  4614.                try {
  4615.                    result = JSON.parse(responseText);
  4616.                } catch (e) {
  4617.                    result = eval('(' + responseText + ')');
  4618.                }
  4619.                if (result.stat === 'fail') {
  4620.                    if (!$chk(sessionKey)) {
  4621.                        var magisterLudi = GM_getMagisterLudi();
  4622.                        GM_log("[NOFOP] ERROR reading views and comments and notes (" + photoId + "): " + result.message + " (a private photo?) - retrying with your current session key '" + magisterLudi + "'");
  4623.                        if ($chk(magisterLudi)) {
  4624.                            getViewsAndCommentsAndNotes(photoId, async, callback, magisterLudi);
  4625.                        } else {
  4626.                            GM_log("[NOFOP] ERROR: could not find magisterLudi; not logged in?");
  4627.                        }
  4628.                    } else {
  4629.                        GM_log("[NOFOP] ERROR (" + photoId + "): " + responseText);
  4630.                    }
  4631.                    return;
  4632.                }
  4633.         var retval = {
  4634.             photoId: photoId,
  4635.             views: 0,
  4636.      comments: 0,
  4637.             notes: 0,
  4638.             contributedNotes: false,
  4639.             url: "#"
  4640.         };
  4641.         if ($chk(result.photo.views)) {
  4642.             retval.views = result.photo.views;
  4643.         }
  4644.         if ($chk(result.photo.comments)) {
  4645.             retval.comments = result.photo.comments._content;
  4646.         }
  4647.         if ($chk(result.photo.notes)) {
  4648.             retval.notes = result.photo.notes.note.length;
  4649.         }
  4650.         if (SHOW_NOTE_CONTRIBUTION_COLOR) {
  4651.             if ($chk(result.photo.notes)) {
  4652.                 var userNsid = GM_getUserNsid();
  4653.                 retval.contributedNotes = result.photo.notes.note.some(function (note) {
  4654.                     return (note.author == userNsid);
  4655.                 });
  4656.             }
  4657.         }
  4658.         if ($chk(result.photo.urls) && $chk(result.photo.urls.url) && $chk(result.photo.urls.url.length > 0)) {
  4659.             retval.url = result.photo.urls.url[0]._content;
  4660.         }
  4661.         callback(retval);
  4662.            },
  4663.         onFailure: function (response) {
  4664.         GM_log("[NOFOP] getViewsAndCommentsAndNotes failed: " + response.statusText);
  4665.         }
  4666.        }).get('/services/rest', {
  4667.            api_key:        $chk(sessionKey) ? sessionKey : api_key,
  4668.            auth_hash:      $chk(sessionKey) ? GM_getAuthHash() : undefined,
  4669.            format:         'json',
  4670.            nojsoncallback: '1',
  4671.            method:         'flickr.photos.getInfo',
  4672.            photo_id:        photoId
  4673.        });
  4674.    }
  4675.  
  4676.    function getFavs (photoId, views, callback, sessionKey) {
  4677.        new Request({
  4678.            method: 'get',
  4679.            url: 'https://www.flickr.com/',
  4680.            onSuccess: function (responseText, responseXML) {
  4681.                var result;
  4682.                try {
  4683.                    result = JSON.parse(responseText);
  4684.                } catch (e) {
  4685.                    result = eval('(' + responseText + ')');
  4686.                }
  4687.                if (result.stat === 'fail') {
  4688.                    if (!$chk(sessionKey)) {
  4689.                        var magisterLudi = GM_getMagisterLudi();
  4690.                        GM_log("[NOFOP] ERROR reading favs (" + photoId + "): " + result.message + " (a private photo?) - retrying with your current session key '" + magisterLudi + "'");
  4691.                        // don't bother:
  4692.                        // when a photo changes into 'private', it looses all its favs; even if it returns to 'public'
  4693.                        // but we might do this for special cases: friends / family restricted?
  4694.                        if ($chk(magisterLudi)) {
  4695.                            getFavs(photoId, views, callback, magisterLudi);
  4696.                        } else {
  4697.                            GM_log("[NOFOP] ERROR: could not find magisterLudi; not logged in?");
  4698.                        }
  4699.                    } else {
  4700.                        GM_log("[NOFOP] ERROR (" + photoId + "): " + responseText);
  4701.                    }
  4702.                    return;
  4703.                }
  4704.                var favs = result.photo.total;
  4705.         callback(photoId, views, favs);
  4706.            },
  4707.         onFailure: function (response) {
  4708.         GM_log("[NOFOP] getFavorites failed: " + response.statusText);
  4709.         }
  4710.        }).get('/services/rest', {
  4711.            api_key:        $chk(sessionKey) ? sessionKey : api_key,
  4712.            auth_hash:      $chk(sessionKey) ? GM_getAuthHash() : undefined,
  4713.            format:         'json',
  4714.            nojsoncallback: '1',
  4715.            method:         'flickr.photos.getFavorites',
  4716.            photo_id:        photoId
  4717.        });
  4718.    }
  4719.  
  4720.    function getGalleries (photoId, callback, sessionKey) {
  4721.        new Request({
  4722.            method: 'get',
  4723.            url: 'https://www.flickr.com/',
  4724.            onSuccess: function (responseText, responseXML) {
  4725.                var result;
  4726.                try {
  4727.                    result = JSON.parse(responseText);
  4728.                } catch (e) {
  4729.                    result = eval('(' + responseText + ')');
  4730.                }
  4731.                if (result.stat === 'fail') {
  4732.                    if (!$chk(sessionKey)) {
  4733.                        var magisterLudi = GM_getMagisterLudi();
  4734.                        GM_log("[NOFOP] ERROR reading galleries (" + photoId + "): " + result.message + " (a private photo?) - retrying with your current session key '" + magisterLudi + "'");
  4735.                        // don't bother:
  4736.                        // when a photo changes into 'private', it looses all its favs; even if it returns to 'public'
  4737.                        // but we might do this for special cases: friends / family restricted?
  4738.                        if ($chk(magisterLudi)) {
  4739.                            getGalleries(photoId, callback, magisterLudi);
  4740.                        } else {
  4741.                            GM_log("[NOFOP] ERROR: could not find magisterLudi; not logged in?");
  4742.                        }
  4743.                    } else {
  4744.                        GM_log("[NOFOP] ERROR (" + photoId + "): " + responseText);
  4745.                    }
  4746.                    return;
  4747.                }
  4748.                var galleries = result.galleries['total'];
  4749.                if (galleries === undefined) { // bug solved ?
  4750.                    galleries = result.galleries['total '];
  4751.                }
  4752.         callback(photoId, galleries);
  4753.            },
  4754.         onFailure: function (response) {
  4755.         GM_log("[NOFOP] getViewsGalleries failed: " + response.statusText);
  4756.         }
  4757.        }).get('/services/rest', {
  4758.            api_key:        $chk(sessionKey) ? sessionKey : api_key,
  4759.            auth_hash:      $chk(sessionKey) ? GM_getAuthHash() : undefined,
  4760.            format:         'json',
  4761.            nojsoncallback: '1',
  4762.            method:         'flickr.galleries.getListForPhoto',
  4763.            page:           1,
  4764.            per_page:       1,
  4765.            photo_id:       photoId
  4766.        });
  4767.    }
  4768.  
  4769.    // photostream page
  4770. /*    if (!document.location.href.test(/.*\/sets\/\d+/)) { // set pages contain these divs also
  4771.         $$("div.photo-display-item[id*=photo]").each(function (streamView) {
  4772.             showNumbersOnStreamView(streamView);
  4773.         });
  4774.    }
  4775. */
  4776.  
  4777.    function prepareShowNumbersOnStreamView(streamView) {
  4778.     showNumbersOnStreamView(streamView);
  4779.     streamView.addEventListener('mouseover', function(evt) {
  4780.             var photoId = streamView.id.replace(/^([^\d]+)/, '');
  4781.         if (SHOW_STREAM_VIEWS_COUNT || SHOWSTREAM_NOTES_COUNT) {
  4782.             $('nofop_views_' + photoId).fireEvent('get-views-and-comments-and-notes-count');
  4783.         }
  4784.         if (SHOW_STREAM_GALLERIES_COUNT) {
  4785.             var url = streamView.getElement('a[data-track=photo-click]').get('href');
  4786.             $('nof_gallery_' + photoId).fireEvent('get-galleries-count', url + '/galleries');
  4787.         }
  4788.     });
  4789.    }
  4790.  
  4791.    function showNumbersOnStreamView(streamView) {
  4792.        var photoId = streamView.id.replace(/^([^\d]+)/, '');
  4793.        // add % to title of 'comments'
  4794.        var activity = streamView.getElement('span.inline-icons');
  4795.     if (!$chk(activity)) return; // pool page!!
  4796.  
  4797.     if ($chk($('nofop_views_' + photoId))) return;
  4798.  
  4799.     var photoElement = $('photo_' + photoId);
  4800.     var insertionPoint = photoElement.getElement('span.inline-icons').getElement('a[data-track=favorite]');
  4801.  
  4802.     // add all elements, but hidden if necessary
  4803.     var views = new Element('a', {
  4804.         id: 'nofop_views_' + photoId,
  4805.         href: "#",
  4806.         'class': 'rapidnofollow',
  4807.         styles: {
  4808.             display: 'none',
  4809.             visibility: 'hidden'
  4810.         },
  4811.         events: {
  4812.             'get-views-and-comments-and-notes-count': function(evt) {
  4813.                 if (this.hasClass('nofop_processed')) return;
  4814.                 this.addClass('nofop_processed');
  4815.                 if (SHOW_STREAM_VIEWS_COUNT) {
  4816.                     var views = $('nofop_views_' + photoId);
  4817.                     views.setStyles({ display : '', visibility : 'visible' });
  4818.                     views.adopt(
  4819.                         new Element('img', {
  4820.                             src: "http://l.yimg.com/g/images/spaceball.gif",
  4821.                             'class': 'img',
  4822.                             width: 12,
  4823.                             height: 12,
  4824.                             styles: {
  4825.                                 background: 'transparent url(http://l.yimg.com/g/images/sprites/icons/views.png) no-repeat center'
  4826.                             }
  4827.                         })
  4828.                     );
  4829.                 }
  4830.                 if (SHOW_STREAM_NOTES_COUNT) {
  4831.                     var notes = $('nofop_notes_' + photoId);
  4832.                     notes.setStyles({ display : '', visibility : 'visible' });
  4833.                     notes.adopt(
  4834.                         new Element('img', {
  4835.                             src: "http://l.yimg.com/g/images/spaceball.gif",
  4836.                             'class': 'img',
  4837.                             width: 12,
  4838.                             height: 12,
  4839.                             styles: {
  4840.                                 background: 'transparent url(http://l.yimg.com/g/images/sprites/icons/notes.png) no-repeat center'
  4841.                             }
  4842.                         })
  4843.                     );
  4844.                 }
  4845.                 getViewsAndCommentsAndNotes(photoId, false, function(data) {
  4846.                     var notes = data.notes;
  4847.                     var views = data.views;
  4848.                     if (SHOW_STREAM_VIEWS_COUNT && views && parseInt(views, 10) > 0) {
  4849.                         new Element('span', {
  4850.                             'class': 'view-count count',
  4851.                             html: views,
  4852.                             styles: {
  4853.                                 display: 'inline'
  4854.                             }
  4855.                         }).inject($('nofop_views_' + photoId));
  4856.                     }
  4857.                     if (SHOW_STREAM_NOTES_COUNT && notes && parseInt(notes, 10) > 0) {
  4858.                         new Element('span', {
  4859.                             'class': 'note-count count',
  4860.                             html: notes,
  4861.                             styles: {
  4862.                                 display: 'inline'
  4863.                             }
  4864.                         }).inject($('nofop_notes_' + photoId));
  4865.                     }
  4866.                 });
  4867.             }
  4868.         }
  4869.     }).inject(insertionPoint, 'before');
  4870.  
  4871.     var notes = new Element('a', {
  4872.         id: 'nofop_notes_' + photoId,
  4873.         href: "#",
  4874.         'class': 'rapidnofollow',
  4875.         styles: {
  4876.             display: 'none',
  4877.             visibility: 'hidden'
  4878.         }
  4879.         // events: is processed together with views
  4880.     }).inject(insertionPoint, 'before');
  4881.  
  4882.     var galleries = new Element('a', {
  4883.         id: 'nof_gallery_' + photoId,
  4884.         href: "#",
  4885.         'class': 'rapidnofollow',
  4886.         styles: {
  4887.             display: 'none',
  4888.             visibility: 'hidden'
  4889.         },
  4890.         events: {
  4891.             'get-galleries-count': function (evt) {
  4892.                 if (this.hasClass('nofop_processed')) return;
  4893.                 this.addClass('nofop_processed');
  4894.                 this.set('href', evt);
  4895.                 if (SHOW_STREAM_GALLERIES_COUNT) {
  4896.                     var galleries = $('nof_gallery_' + photoId);
  4897.                     galleries.setStyles({ display : '', visibility : 'visible' });
  4898.                     galleries.adopt(
  4899.                         new Element('img', {
  4900.                             src: "http://l.yimg.com/g/images/spaceball.gif",
  4901.                             'class': 'img',
  4902.                             width: 12,
  4903.                             height: 12,
  4904.                             styles: {
  4905.                                 background: 'transparent url(http://l.yimg.com/g/images/sprites/icons/gallery.png) no-repeat center'
  4906.                             }
  4907.                         })
  4908.                     );
  4909.                     getGalleries(photoId, function(photoId, galleries) {
  4910.                         if (galleries && parseInt(galleries, 10) > 0) {
  4911.                             new Element('span', {
  4912.                                 'class': 'gallery-count count',
  4913.                                 html: galleries
  4914.                             }).inject($('nof_gallery_' + photoId));
  4915.                             markGalleryContribution(photoId);
  4916.                         }
  4917.                     });
  4918.                 }
  4919.             },
  4920.             click: function (evt) {
  4921.                 document.location.href = this.href;
  4922.             }
  4923.         }
  4924.     }).inject(insertionPoint, 'before');
  4925.  
  4926.        /*if (viewsElement) {
  4927.         views = parseInt(viewsElement.get('html').trim().replace(/[,.]/g, ''), 10);
  4928.            var commentsElement = activity.getFirst('a.Plain');
  4929.            var comments = parseInt(commentsElement.get('html').trim().replace(/[,.]/g, ''), 10);
  4930.            if (comments > 0) {
  4931.                commentsElement.set('title', formatPercentage(comments * 100 / views) + " of views" +
  4932.                                             " (1 comment per " + toFixed(views / comments, 2) + " views)");
  4933.            }
  4934.        }*/
  4935.    }
  4936.  
  4937.    // photo page
  4938.    var photoStats = $('stats_ul');
  4939.    if (photoStats) {
  4940.     if (!SHOW_PHOTOPAGE_VIEWS_COUNT && !SHOW_PHOTOPAGE_NOTES_COUNT && !SHOW_PHOTOPAGE_GALLERIES_COUNT) return;
  4941.  
  4942.     var photoId = document.location.href.match(/flickr\.com\/photos\/[^\/]+\/(\d+)/)[1];
  4943.     if (SHOW_PHOTOPAGE_NOTES_COUNT) {
  4944.         var notes = new Element('li', {
  4945.             id: 'nofop_notes_' + photoId,
  4946.             styles: {
  4947.                 cursor: 'pointer',
  4948.                 'margin-left': '12px',
  4949.                 'marging-right': '12px'
  4950.             }
  4951.         }).inject($('stats_ul'), 'top');
  4952.         notes.adopt(
  4953.             new Element('img', {
  4954.                 src: "http://l.yimg.com/g/images/spaceball.gif",
  4955.                 'class': 'img',
  4956.                 width: 16,
  4957.                 height: 16,
  4958.                 styles: {
  4959.                     background: 'transparent url(http://l.yimg.com/g/images/sprites/icons/notes.png) no-repeat center'
  4960.                 }
  4961.             })
  4962.         );
  4963.     }
  4964.     if (SHOW_PHOTOPAGE_GALLERIES_COUNT) {
  4965.         var galleries = new Element('li', {
  4966.             id: 'nofop_galleries_' + photoId,
  4967.             styles: {
  4968.                 cursor: 'pointer',
  4969.                 'margin-left': '12px',
  4970.                 'marging-right': '12px'
  4971.             }
  4972.         }).inject($('stats_ul'), 'top');
  4973.         galleries.adopt(
  4974.             new Element('img', {
  4975.                 src: "http://l.yimg.com/g/images/spaceball.gif",
  4976.                 'class': 'img',
  4977.                 width: 16,
  4978.                 height: 16,
  4979.                 styles: {
  4980.                     background: 'transparent url(http://l.yimg.com/g/images/sprites/icons/gallery.png) no-repeat center'
  4981.                 }
  4982.             })
  4983.         );
  4984.     }
  4985.     if (SHOW_PHOTOPAGE_VIEWS_COUNT) {
  4986.         var views = new Element('li', {
  4987.             id: 'nofop_views_' + photoId,
  4988.             styles: {
  4989.                 cursor: 'pointer',
  4990.                 'margin-left': '12px',
  4991.                 'marging-right': '12px'
  4992.             }
  4993.         }).inject($('stats_ul'), 'top');
  4994.         views.adopt(
  4995.             new Element('img', {
  4996.                 src: "http://l.yimg.com/g/images/spaceball.gif",
  4997.                 'class': 'img',
  4998.                 width: 16,
  4999.                 height: 16,
  5000.                 styles: {
  5001.                     background: 'transparent url(http://l.yimg.com/g/images/sprites/icons/views.png) no-repeat center'
  5002.                 }
  5003.             })
  5004.         );
  5005.     }
  5006.  
  5007.         getViewsAndCommentsAndNotes (photoId, true, function(data) {
  5008.             var photoId = data.photoId;
  5009.         var views = data.views;
  5010.         var comments = data.comments;
  5011.         var notes = data.notes;
  5012.  
  5013.         if (SHOW_PHOTOPAGE_VIEWS_COUNT) {
  5014.             new Element('a', {
  5015.                 'class': 'rapidnofollow',
  5016.                 href: "#",
  5017.                 html: views.toLocaleString(),
  5018.                 styles: {
  5019.                     display: 'inline',
  5020.                     'margin-left': '10px',
  5021.                     'margin-right': '10px'
  5022.                 }
  5023.             }).inject($('nofop_views_' + photoId));
  5024.             $('nofop_views_' + photoId).set('title', views.toLocaleString() + ' views');
  5025.         }
  5026.         if (SHOW_PHOTOPAGE_NOTES_COUNT) {
  5027.             new Element('a', {
  5028.                 'class': 'rapidnofollow',
  5029.                 href: "#",
  5030.                 html: notes,
  5031.                 styles: {
  5032.                     display: 'inline',
  5033.                     'margin-left': '10px',
  5034.                     'margin-right': '10px'
  5035.                 }
  5036.             }).inject($('nofop_notes_' + photoId));
  5037.             $('nofop_notes_' + photoId).set('title', notes + ' notes');
  5038.         }
  5039.         if (SHOW_PHOTOPAGE_GALLERIES_COUNT) {
  5040.             getGalleries(photoId, function(photoId, galleries) {
  5041.                 new Element('a', {
  5042.                     'class': 'rapidnofollow',
  5043.                     href: "#",
  5044.                     html: galleries,
  5045.                     styles: {
  5046.                         display: 'inline',
  5047.                         'margin-left': '10px',
  5048.                         'margin-right': '10px'
  5049.                     }
  5050.                 }).inject($('nofop_galleries_' + photoId));
  5051.                 $('nofop_galleries_' + photoId).set('title', galleries + ' galleries');
  5052.             });
  5053.         }
  5054.         $('comment-count').set('title', formatPercentage(comments * 100 / views) + " of views" +
  5055.                             " (1 comment per " + toFixed(views / comments, 2) + " views)");
  5056.         getFavs (photoId, views, function(photoId, views, favs) {
  5057.             $('fave-count').set('title', formatPercentage(favs * 100 / views) + " of views" +
  5058.                                 " (1 fave per " + toFixed(views / favs, 2) + " views)");
  5059.         });
  5060.     });
  5061.    }
  5062.  
  5063.    // pool-like page
  5064.    $$('p.PoolList').each(function (poolItem) {
  5065.     showNumbersOnPoolLikeItem(poolItem);
  5066.    });
  5067.  
  5068.    // DECEMBRE 2025 - group pool && faves
  5069.    if (document.location.href.test(/.*flickr.com\/groups\/[^\/]+\/pool/) ||
  5070.     document.location.href.test(/.*flickr.com\/groups\/[^\/]+\/$/) ||
  5071.        document.location.href.test(/https:\/\/www\.flickr\.com\/groups_pool\.gne\?path=[^&]+&nsid=&page=&jump_to=&thumb=1/) || // 2025 - match any path value for NEW pool sm url
  5072.     document.location.href.test(/.*flickr.com\/photos\/[^\/]+\/archives\//)) {
  5073.         var photos = $$('div.pool-photo');
  5074.     if (photos.length == 0 && document.location.href.test(/favorites/)) {
  5075.         photos = $$('div.fave');
  5076.     }
  5077.     if (photos.length == 0 && document.location.href.test(/archives/)) {
  5078.         photos = $$('div.archive');
  5079.     }
  5080.         var justifiedPoolView = undefined;
  5081.         var poolItemDecorator = showNumbersOnPoolItem; // assume justified view
  5082.         if (photos.length > 0) {
  5083.             if ($$('span.pc_s').length == photos.length) { // square
  5084.         photos.each(function(poolItem) {
  5085.                 poolItem.setStyle('height', POOL_ITEM_HEIGHT);
  5086.         });
  5087.         justifiedPoolView = false;
  5088.         poolItemDecorator = showNumbersOnPoolLikeItem;
  5089.  
  5090.         } else if ($$('span.pc_t').length == photos.length) { // small
  5091.         $$('a.fave-star-inline').each(function(meta) { meta.setStyles({ display:'inline-block' }); });
  5092.         photos.each(function(poolItem) {
  5093.                 poolItem.setStyle('height', POOL_ITEM_HEIGHT);
  5094.         });
  5095.         justifiedPoolView = false;
  5096.         poolItemDecorator = showNumbersOnPoolLikeItem;
  5097.  
  5098.         } else if ($$('span.pc_m').length == photos.length) { // medium
  5099.         $$('a.fave-star-inline').each(function(meta) { meta.setStyles({ display:'inline-block' }); });
  5100.         justifiedPoolView = false;
  5101.         poolItemDecorator = showNumbersOnPoolLikeItem;
  5102.  
  5103.         } else if ($$('span.pc_z').length == photos.length) { // large
  5104.         $$('a.fave-star-inline').each(function(meta) { meta.setStyles({ display:'inline-block' }); });
  5105.         justifiedPoolView = false;
  5106.         poolItemDecorator = showNumbersOnPoolLikeItem;
  5107.  
  5108.         } else {
  5109.                 GM_log("[NOFOP] photos: " + photos.length + " - square: " + $$('span.pc_s').length + " - small: " + $$('span.pc_t').length + " - medium: " + $$('span.pc_m').length + " - large: " + $$('span.pc_z').length);
  5110.         // pool, justified
  5111.         photos = $$('span.inline-icons');
  5112.         justifiedPoolView = true;
  5113.         ICON_NOTATION = true;
  5114.         poolItemDecorator = showNumbersOnPoolItem;
  5115.         }
  5116.     }
  5117.     if (!justifiedPoolView) {
  5118.         photos.each(function(poolItem) {
  5119.         poolItemDecorator(poolItem);
  5120.         });
  5121.     }
  5122.    } else if (document.location.href.test(/.*flickr.com\/photos\/[^\/]+\/favorites/)) {
  5123.     justifiedPoolView = false; // special case
  5124.     poolItemDecorator = prepareShowNumbersOnStreamView;
  5125.    }
  5126.  
  5127.    // tags page
  5128.    $$('p.UserTagList, p.StreamList').each(function (taggedItem) {
  5129.         showNumbersOnTaggedItem(taggedItem);
  5130.    });
  5131.  
  5132.    // set pages
  5133.    if (document.location.href.test(/.*\/sets\/\d+\/?\?detail=1/)) { // 'normal' mode == justified, using showNumbersOnStreamView
  5134.             $$('div.photo-display-item').each(function(setItem) {
  5135.             showNumbersOnSetItem(setItem);
  5136.             });
  5137.    }
  5138.  
  5139.    function addCount(data) {
  5140.         var photoId = data.photoId;
  5141.     var count = data.count;
  5142.     var label = data.label;
  5143.     var photoPage = data.photoPage;
  5144.  
  5145.     if (!count || parseInt(count, 10) <= 0 || $chk($('nof_' + label + '_' + photoId))) {
  5146.         return;
  5147.     }
  5148.     try {
  5149.         var meta = $('photo_' + photoId).getElement('div.meta');
  5150.     } catch (e) {
  5151.         // ignore
  5152.     }
  5153.     var stats = $('photo-story-stats-' + photoId);
  5154.     if (ICON_NOTATION) {
  5155.         var anchor = new Element('a', {
  5156.         id: 'nof_' + label + '_' + photoId,
  5157.         href: photoPage,
  5158.         'class': 'nof_pool_icon'
  5159.         }).inject(meta ? meta : stats ? stats : $('photo_' + photoId), meta || stats ? 'before' : undefined);
  5160.         anchor.adopt(
  5161.             new Element('span', {
  5162.                 html: count,
  5163.                 title: count + ' ' + label,
  5164.                 'class': 'nof_pool_count nof_pool_count_' + label + ' nof_pool_label'
  5165.             })/*,
  5166.             new Element('span', {
  5167.                 html: count,
  5168.                 title: count + ' ' + label,
  5169.                 'class': 'nof_pool_label'
  5170.             })*/
  5171.         );
  5172.     } else {
  5173.         if ($('photo-story-stats-' + photoId).getChildren().length > 0) {
  5174.             new Element('span', { html: ' / ', styles: { display: 'inline' } }).inject($('photo-story-stats-' + photoId));
  5175.         }
  5176.         new Element('a', {
  5177.             'class': 'Plain',
  5178.             id: 'nof_' + label + '_' + photoId,
  5179.             href: photoPage,
  5180.             html: count + (SHORT_NOTATION ? label.replace(/^(.).*$/, '$1') : ' ' + label),
  5181.             title: count + ' ' + label
  5182.             }).inject($('photo-story-stats-' + photoId));
  5183.     }
  5184.    }
  5185.  
  5186.    function showNumbersOnPoolLikeItem(poolItem) {
  5187.         var photoId = poolItem.get('data-photo-id');
  5188.     if (!$chk(photoId)) {
  5189.         GM_log("[NOFOP] could not get photoId");
  5190.         return;
  5191.     }
  5192.     new Element('div', {
  5193.         id: 'photo-story-stats-' + photoId,
  5194.         class: 'nof_stats'
  5195.     }).inject(poolItem);
  5196.     showNumbersOnPoollikeItem(poolItem, photoId, {
  5197.         views: SHOW_POOL_VIEWS_COUNT,
  5198.         comments: SHOW_POOL_COMMENTS_COUNT,
  5199.         notes: SHOW_POOL_NOTES_COUNT,
  5200.         favorites: SHOW_POOL_FAVORITES_COUNT,
  5201.         galleries: SHOW_POOL_GALLERIES_COUNT
  5202.     });
  5203.    }
  5204.  
  5205.    function addPoolCount(data) {
  5206.         var photoId = data.photoId;
  5207.     var count = data.count;
  5208.     var label = data.label;
  5209.     var bgPosition = data.bgPosition;
  5210.     var photoPage = data.photoPage;
  5211.     var inlineIcons = data.inlineIcons;
  5212.  
  5213.     if (!count || parseInt(count, 10) <= 0 || $chk($('nof_' + label + '_' + photoId))) {
  5214.         return;
  5215.     }
  5216.     if (ICON_NOTATION) {
  5217.         var anchor = new Element('a', {
  5218.         id: 'nof_' + label + '_' + photoId,
  5219.         href: photoPage,
  5220.         'class': 'rapidnofollow'
  5221.         }).inject(inlineIcons, 'top');
  5222.         anchor.adopt(
  5223.             new Element('img', {
  5224.             width: 11,
  5225.             height: 12,
  5226.             alt: label,
  5227.             title: label,
  5228.             src: 'http://l.yimg.com/g/images/spaceball.gif',
  5229.             styles: {
  5230.                 'background': 'url("http://l.yimg.com/g/images/photo-sprite.png.v8") no-repeat scroll 0 0 transparent',
  5231.                 'background-position': bgPosition
  5232.             }
  5233.         }),
  5234.         new Element('span', {
  5235.             title: label,
  5236.             html: count,
  5237.             'class': 'comment-count count'
  5238.         })
  5239.         );
  5240.     } else {
  5241.         if ($('photo-story-stats-' + photoId).getChildren().length > 0) {
  5242.             new Element('span', { html: ' / ', styles: { display: 'inline' } }).inject($('photo-story-stats-' + photoId));
  5243.         }
  5244.         new Element('a', {
  5245.             'class': 'Plain',
  5246.             id: 'nof_' + label + '_' + photoId,
  5247.             href: photoPage,
  5248.             html: count + (SHORT_NOTATION ? label.replace(/^(.).*$/, '$1') : ' ' + label),
  5249.             title: count + ' ' + label
  5250.             }).inject($('photo-story-stats-' + photoId));
  5251.     }
  5252.    }
  5253.  
  5254.    function showNumbersOnPoolItem(inlineIcons) {
  5255.         inlineIcons.setStyle('opacity', 1);
  5256.         try {
  5257.         var photoId = inlineIcons.getParent('div.pool-photo').get('data-photo-id');
  5258.     } catch (e) {
  5259.         try {
  5260.             photoId = inlineIcons.getParent('div.fave').get('data-photo-id');
  5261.         } catch (e) {
  5262.             try {
  5263.                 photoId = inlineIcons.getParent('div.archive').get('data-photo-id');
  5264.             } catch (e) {
  5265.                 GM_log("[NOFOP] error getting photo id: " + e);
  5266.                 return;
  5267.             }
  5268.         }
  5269.     }
  5270.     if (SHOW_POOL_VIEWS_COUNT || SHOW_POOL_COMMENTS_COUNT || SHOW_POOL_NOTES_COUNT) {
  5271.         getViewsAndCommentsAndNotes(photoId, true, function(data) {
  5272.             var photoId = data.photoId;
  5273.         var views = data.views;
  5274.         var comments = data.comments;
  5275.         var notes = data.notes;
  5276.  
  5277.         var anchorElement = inlineIcons.getElement('a[href*=' + photoId + ']');
  5278.         if (!anchorElement) {
  5279.             anchorElement = $('photo_' + photoId).getElement('a[href*=' + photoId + ']');
  5280.         }
  5281.         var photoPage = anchorElement.href.match(/(.*flickr.com\/photos\/[^\/]+\/\d+)\/?/)[1] + '/';
  5282.         addPoolCount({
  5283.             photoId: photoId,
  5284.             count: views,
  5285.             label: 'Views',
  5286.             bgPosition: '-15px -15px',
  5287.             photoPage: photoPage,
  5288.             inlineIcons: inlineIcons
  5289.         });
  5290.         addPoolCount({
  5291.             photoId: photoId,
  5292.             count: notes,
  5293.             label: 'Notes',
  5294.             bgPosition: '-1895px -15px',
  5295.             photoPage: photoPage,
  5296.             inlineIcons: inlineIcons
  5297.         });
  5298.         if (SHOW_NOTE_CONTRIBUTION_COLOR) {
  5299.             markNoteContribution(photoId, data.contributedNotes);
  5300.         }
  5301.         if (SHOW_COMMENT_CONTRIBUTION_COLOR) {
  5302.             var commentsAnchor = inlineIcons.getElement('a[href$=comments]');
  5303.             if (commentsAnchor) {
  5304.                 commentsAnchor.set('id', 'nof_comments_' + photoId);
  5305.                 markCommentContribution(photoId);
  5306.             }
  5307.         }
  5308.         });
  5309.     }
  5310.     if (SHOW_POOL_GALLERIES_COUNT) {
  5311.         getGalleries(photoId, function(photoId, galleries) {
  5312.         var anchorElement = inlineIcons.getElement('a[href*=' + photoId + ']');
  5313.         if (!anchorElement) {
  5314.             anchorElement = $('photo_' + photoId).getElement('a[href*=' + photoId + ']');
  5315.         }
  5316.         var photoPage = anchorElement.href.match(/(.*flickr.com\/photos\/[^\/]+\/\d+)\/?/)[1] + '/';
  5317.             addPoolCount({
  5318.             photoId: photoId,
  5319.             count: galleries,
  5320.             label: 'Galleries',
  5321.             bgPosition: '-135px -15px',
  5322.             photoPage: photoPage + '/galleries/',
  5323.             inlineIcons: inlineIcons
  5324.         });
  5325.         if (SHOW_GALLERY_CONTRIBUTION_COLOR) {
  5326.             markGalleryContribution(photoId);
  5327.         }
  5328.         });
  5329.     }
  5330.    }
  5331.  
  5332.    function showNumbersOnTaggedItem(taggedItem) {
  5333.         taggedItem.setStyle('height', TAGS_ITEM_HEIGHT);
  5334.     try {
  5335.             var photoId = taggedItem.getElement('img').src.match(/^https:\/\/[^\/]+\/\d+\/(\d+)_.*jpg/)[1];
  5336.     } catch (e) {
  5337.         return;
  5338.     }
  5339.     new Element('div', {
  5340.         id: 'photo-story-stats-' + photoId,
  5341.         class: 'nof_stats'
  5342.     }).inject(taggedItem);
  5343.     showNumbersOnPoollikeItem(taggedItem, photoId, {
  5344.         views: SHOW_TAGS_VIEWS_COUNT,
  5345.         comments: SHOW_TAGS_COMMENTS_COUNT,
  5346.         notes: SHOW_TAGS_NOTES_COUNT,
  5347.         favorites: SHOW_TAGS_FAVORITES_COUNT,
  5348.         galleries: SHOW_TAGS_GALLERIES_COUNT
  5349.     });
  5350.    }
  5351.  
  5352.    function showNumbersOnSetItem(setItem) {
  5353.     try {
  5354.             var photoId = setItem.getElement('img').src.match(/^https:\/\/[^\/]+\/\d+\/(\d+)_.*jpg/)[1];
  5355.     } catch (e) {
  5356.         return;
  5357.     }
  5358.     new Element('div', {
  5359.         id: 'photo-story-stats-' + photoId,
  5360.         class: 'nof_stats'
  5361.     }).inject(setItem);
  5362.     showNumbersOnPoollikeItem(setItem, photoId, {
  5363.         views: SHOW_SET_VIEWS_COUNT,
  5364.         comments: SHOW_SET_COMMENTS_COUNT,
  5365.         notes: SHOW_SET_NOTES_COUNT,
  5366.         favorites: SHOW_SET_FAVORITES_COUNT,
  5367.         galleries: SHOW_SET_GALLERIES_COUNT
  5368.     });
  5369.    }
  5370.  
  5371.    function markNoteContribution(photoId, contributedNotes) {
  5372.     if ($chk($('nof_notes_' + photoId)) && contributedNotes) {
  5373.         $('nof_notes_' + photoId).addClass('nof_note_contributed');
  5374.     }
  5375.    }
  5376.  
  5377.    function markCommentContribution(photoId, sessionKey) {
  5378.         if (!$chk($('nof_comments_' + photoId))) {
  5379.         return;
  5380.     }
  5381.         new Request({
  5382.            method: 'get',
  5383.            url: 'https://www.flickr.com/',
  5384.            onSuccess: function (responseText, responseXML) {
  5385.                var result;
  5386.                try {
  5387.                    result = JSON.parse(responseText);
  5388.                } catch (e) {
  5389.                    result = eval('(' + responseText + ')');
  5390.                }
  5391.                if (result.stat === 'fail') {
  5392.                    if (!$chk(sessionKey)) {
  5393.                        var magisterLudi = GM_getMagisterLudi();
  5394.                        GM_log("[NOFOP] ERROR reading comments (" + photoId + "): " + result.message + " (a private photo?) - retrying with your current session key '" + magisterLudi + "'");
  5395.                        if ($chk(magisterLudi)) {
  5396.                            markCommentContribution(photoId, magisterLudi);
  5397.                        } else {
  5398.                            GM_log("[NOFOP] ERROR: could not find magisterLudi; not logged in?");
  5399.                        }
  5400.                    } else {
  5401.                        GM_log("[NOFOP] ERROR (" + photoId + "): " + responseText);
  5402.                    }
  5403.                    return;
  5404.                }
  5405.         if (SHOW_COMMENT_CONTRIBUTION_COLOR) {
  5406.             if ($chk(result.comments)) {
  5407.                 var userNsid = GM_getUserNsid();
  5408.                 var contributed = false;
  5409.                 if ($chk(result.comments) && $chk(result.comments.comment)) {
  5410.                     contributed = result.comments.comment.some(function (comment) {
  5411.                         return (comment.author == userNsid);
  5412.                     });
  5413.                 }
  5414.                 if (contributed) {
  5415.                     $('nof_comments_' + photoId).addClass('nof_comment_contributed');
  5416.                 }
  5417.             }
  5418.         }
  5419.            },
  5420.         onFailure: function (response) {
  5421.         GM_log("[NOFOP] markCommentContribution failed: " + response.statusText);
  5422.         }
  5423.        }).get('/services/rest', {
  5424.            api_key:        $chk(sessionKey) ? sessionKey : api_key,
  5425.            auth_hash:      $chk(sessionKey) ? GM_getAuthHash() : undefined,
  5426.            format:         'json',
  5427.            nojsoncallback: '1',
  5428.            method:         'flickr.photos.comments.getList',
  5429.            photo_id:        photoId
  5430.        });
  5431.    }
  5432.  
  5433.    function markFavoriteContribution(photoId, page) {
  5434.         if (!$chk($('nof_favs_' + photoId))) {
  5435.         return;
  5436.     }
  5437.        new Request({
  5438.            method: 'get',
  5439.            url: 'https://www.flickr.com/',
  5440.            onSuccess: function (responseText, responseXML) {
  5441.                var result;
  5442.                try {
  5443.                    result = JSON.parse(responseText);
  5444.                } catch (e) {
  5445.                    result = eval('(' + responseText + ')');
  5446.                }
  5447.                if (result.stat === 'fail') {
  5448.                    GM_log("[NOFOP] ERROR (" + photoId + "): " + result.msg);
  5449.                    return;
  5450.                }
  5451.         if ($chk(result.photo.person)) {
  5452.             var userNsid = GM_getUserNsid();
  5453.             var contributed = result.photo.person.some( function (person) {
  5454.                 return person.nsid == userNsid;
  5455.             });
  5456.             if (contributed) {
  5457.                 $('nof_favs_' + photoId).addClass('nof_fave_contributed');
  5458.             } else {
  5459.                 var page = parseInt(result.photo.page);
  5460.                 var pages = parseInt(result.photo.pages);
  5461.                 if (page < pages) {
  5462.                     markFavoriteContribution(photoId, page + 1);
  5463.                 }
  5464.             }
  5465.         }
  5466.            },
  5467.         onFailure: function (response) {
  5468.         GM_log("[NOFOP] getFavorites failed (2): " + response.statusText);
  5469.         }
  5470.        }).get('/services/rest', {
  5471.            api_key:        GM_getMagisterLudi(),
  5472.            auth_hash:      GM_getAuthHash(),
  5473.            format:         'json',
  5474.            nojsoncallback: '1',
  5475.            method:         'flickr.photos.getFavorites',
  5476.            photo_id:        photoId,
  5477.         per_page:        500,
  5478.         page:        $chk(page) ? page : 1
  5479.        });
  5480.    }
  5481.  
  5482.    function markGalleryContribution(photoId, page) {
  5483.         if (!$chk($('nof_galleries_' + photoId))) {
  5484.         return;
  5485.     }
  5486.        new Request({
  5487.            method: 'get',
  5488.            url: 'https://www.flickr.com/',
  5489.            onSuccess: function (responseText, responseXML) {
  5490.                var result;
  5491.                try {
  5492.                    result = JSON.parse(responseText);
  5493.                } catch (e) {
  5494.                    result = eval('(' + responseText + ')');
  5495.                }
  5496.                if (result.stat === 'fail') {
  5497.                    GM_log("[NOFOP] ERROR (" + photoId + "): " + result.msg);
  5498.                    return;
  5499.                }
  5500.         if ($chk(result.galleries)) {
  5501.             var userNsid = GM_getUserNsid();
  5502.             var contributed = result.galleries.gallery.some( function (gallery) {
  5503.                 return gallery.owner == userNsid;
  5504.             });
  5505.             if (contributed) {
  5506.                 $('nof_galleries_' + photoId).addClass('nof_gallery_contributed');
  5507.             } else {
  5508.                 var page = parseInt(result.galleries.page);
  5509.                 var pages = parseInt(result.galleries.pages);
  5510.                 if (page < pages) {
  5511.                     markGalleryContribution(photoId, page + 1);
  5512.                 }
  5513.             }
  5514.         }
  5515.            },
  5516.         onFailure: function (response) {
  5517.         GM_log("[NOFOP] getListForPhoto failed: " + response.statusText);
  5518.         }
  5519.        }).get('/services/rest', {
  5520.            api_key:        GM_getMagisterLudi(),
  5521.            format:         'json',
  5522.            nojsoncallback: '1',
  5523.            method:         'flickr.galleries.getListForPhoto',
  5524.            photo_id:        photoId,
  5525.         per_page:        500,
  5526.         page:        $chk(page) ? page : 1
  5527.        });
  5528.    }
  5529.  
  5530.    function showNumbersOnPoollikeItem(imgItem, photoId, counts) {
  5531.     if (counts.views || counts.comments || counts.notes) {
  5532.         getViewsAndCommentsAndNotes(photoId, true, function(data) {
  5533.             var photoId = data.photoId;
  5534.         var views = data.views;
  5535.         var comments = data.comments;
  5536.         var notes = data.notes;
  5537.  
  5538.         var anchorElement = imgItem.getElement('a[href*=' + photoId + ']');
  5539.         if (!anchorElement) {
  5540.             anchorElement = $('photo_' + photoId).getElement('a[href*=' + photoId + ']');
  5541.         }
  5542.         var photoPage = anchorElement.href.replace(/\/in\/pool-.*$/, ''); // does nothing on tagged pages
  5543.         if (counts.views) {
  5544.             addCount({
  5545.             photoId: photoId,
  5546.             count: views,
  5547.             label: 'views',
  5548.             photoPage: photoPage
  5549.             });
  5550.         }
  5551.         if (counts.comments) {
  5552.             addCount({
  5553.             photoId: photoId,
  5554.             count: comments,
  5555.             label: 'comments',
  5556.             photoPage: photoPage+"#comments"
  5557.             });
  5558.         }
  5559.         if (counts.notes) {
  5560.             addCount({
  5561.             photoId: photoId,
  5562.             count: notes,
  5563.             label: 'notes',
  5564.             photoPage: photoPage
  5565.             });
  5566.         }
  5567.         if (SHOW_NOTE_CONTRIBUTION_COLOR) {
  5568.             markNoteContribution(photoId, data.contributedNotes);
  5569.         }
  5570.         if (SHOW_COMMENT_CONTRIBUTION_COLOR) {
  5571.             markCommentContribution(photoId);
  5572.         }
  5573.         });
  5574.     }
  5575.     if (counts.favorites) {
  5576.         getFavs(photoId, 0, function(photoId, views, favs) {
  5577.         var anchorElement = imgItem.getElement('a[href*=' + photoId + ']');
  5578.         if (!anchorElement) {
  5579.             anchorElement = $('photo_' + photoId).getElement('a[href*=' + photoId + ']');
  5580.         }
  5581.         var photoPage = anchorElement.href.replace(/\/in\/pool-.*$/, ''); // does nothing on tagged pages
  5582.             addCount({
  5583.             photoId: photoId,
  5584.             count: favs,
  5585.             label: 'favs',
  5586.             photoPage: photoPage + '/favorites/'
  5587.         });
  5588.         if (SHOW_FAVORITE_CONTRIBUTION_COLOR) {
  5589.             markFavoriteContribution(photoId);
  5590.         }
  5591.         });
  5592.     }
  5593.     if (counts.galleries) {
  5594.         getGalleries(photoId, function(photoId, galleries) {
  5595.         var anchorElement = imgItem.getElement('a[href*=' + photoId + ']');
  5596.         if (!anchorElement) {
  5597.             anchorElement = $('photo_' + photoId).getElement('a[href*=' + photoId + ']');
  5598.         }
  5599.         var photoPage = anchorElement.href.replace(/\/in\/pool-.*$/, ''); // does nothing on tagged pages
  5600.             addCount({
  5601.             photoId: photoId,
  5602.             count: galleries,
  5603.             label: 'galleries',
  5604.             photoPage: photoPage + '/galleries/'
  5605.         });
  5606.         if (SHOW_GALLERY_CONTRIBUTION_COLOR) {
  5607.             markGalleryContribution(photoId);
  5608.         }
  5609.         });
  5610.     }
  5611.    }
  5612.  
  5613.    try {
  5614.     $$('body')[0].addEventListener('DOMNodeInsertedIntoDocument', function (evt) {
  5615.         setTimeout(function() { // workaround: addEventListener callback gets called in unsafeWindow!
  5616.             try {
  5617.                 var target = $(evt.target);
  5618.                 if (!$chk(target)) return;
  5619.                 if (target.nodeName == 'P') {
  5620.                     var p = $(target);
  5621.                     if (p.hasClass('PoolList')) {
  5622.                         showNumbersOnPoolLikeItem(p);
  5623.                     } else if (p.hasClass('UserTagList') || p.hasClass('StreamList')) {
  5624.                         showNumbersOnTaggedItem(p);
  5625.                     }
  5626.                 } else if (target.nodeName == 'DIV') {
  5627.                     var div = $(target);
  5628.                     if ((div.hasClass('pool-photo') || div.hasClass('photo-display-item')) && $chk(div.id) && div.id.match('photo')) {
  5629.                         if (//document.location.href.match(/.*flickr.com\/groups\/[^\/]+\/pool/) ||
  5630.                             document.location.href.match(/.*flickr.com\/photos\/[^\/]+\/favorites/) ||
  5631.                             document.location.href.match(/.*flickr.com\/photos\/[^\/]+\/archives/)) {
  5632.                             if (justifiedPoolView != undefined) {
  5633.                                 if (justifiedPoolView == true) {
  5634.                                     var inlineIcons = div.getElement('span.inline-icons');
  5635.                                         poolItemDecorator(inlineIcons);
  5636.                                 } else { // justifiedPoolView == false
  5637.                                     poolItemDecorator(div);
  5638.                                 }
  5639.                             } else {
  5640.                                 GM_log("[NOFOP] TODO?");
  5641.                             }
  5642.                         } else {
  5643.                             prepareShowNumbersOnStreamView(div);
  5644.                         }
  5645.                     } else if (div.hasClass('HoldPhotos')) { // AutoPager support
  5646.                         div.getElements('p.PoolList').each(function (poolItem) {
  5647.                                 showNumbersOnPoolLikeItem(poolItem);
  5648.                         });
  5649.                             div.getElements('p.UserTagList, p.StreamList').each(function (taggedItem) {
  5650.                                 showNumbersOnTaggedItem(taggedItem);
  5651.                             });
  5652.                     }
  5653.                 }
  5654.             } catch (e) {
  5655.                 GM_log("[NOFOP] error on insert: " + e);
  5656.             }
  5657.         }, 0);
  5658.     }, true);
  5659.    } catch (e) {
  5660.         GM_log("[NOFOP] ERROR: unable to add event listener");
  5661.    }
  5662.  
  5663. })();
  5664.  
  5665.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment