Advertisement
decembre

GM - Number of Favs on Photostream (Alesadam) 2017

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