home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / plugins / twitter / res / utils.js < prev   
Encoding:
JavaScript  |  2010-11-24  |  24.4 KB  |  813 lines

  1.  
  2. function useStringIdentifiers(obj, properties) {
  3.     for (var i = 0; i < properties.length; ++i)
  4.         useStringIdentifier(obj, properties[i]);
  5. }
  6.  
  7. // adaptive function for the new string IDs for Twitter API objects (Snowflake)
  8. function useStringIdentifier(obj, property) {
  9.   var property_str = property + "_str";
  10.   if (!obj) {
  11.    return;
  12.   }
  13.  
  14.   if (obj[property_str]) {
  15.     obj[property] = obj[property_str].toString();
  16.     delete obj[property_str];
  17.   } else if (obj[property]) {
  18.     obj[property] = obj[property].toString();
  19.   }
  20. }
  21.  
  22. function shallowCopy(obj) {
  23.     var o = {};
  24.     for (var k in obj)
  25.         o[k] = obj[k];
  26.     return o;
  27. }
  28. function last(array) {
  29.     return array[array.length-1];
  30. }
  31.  
  32. function get(obj, attr, def) {
  33.     if (typeof obj === 'undefined')
  34.         return def;
  35.     else
  36.         var val = obj[attr];
  37.         return typeof val === 'undefined' ? def : val;
  38. }
  39.  
  40. function sum(array, start) {
  41.     if (typeof start === 'undefined')
  42.         start = 0;
  43.     for (var i = array.length-1; i >= 0; --i) start += array[i];
  44.     return start;
  45. }
  46.  
  47. function joinSingleQuotedStringArray(arr, joinStr) {
  48.     var res = "";
  49.     for (var i = 0; i < arr.length; ++i) {
  50.         res += "'" + arr[i] + "'";
  51.         if (i != arr.length - 1)
  52.             res += joinStr;
  53.     }
  54.     return res;
  55. }
  56.  
  57. function arraysEqual(a, b, cmp) {
  58.     if (a.length !== b.length)
  59.         return false;
  60.  
  61.     for (var i = 0; i < a.length; ++i) {
  62.         if (cmp(a[i], b[i]) !== 0)
  63.             return false;
  64.     }
  65.  
  66.     return true;
  67. }
  68.  
  69. function isSorted(a, sortFunc) {
  70.     var copy = Array.apply(null, a);
  71.     copy.sort(sortFunc);
  72.     return arraysEqual(a, copy, sortFunc);
  73. }
  74.  
  75. function objectLength(self) {
  76.     var count = 0;
  77.     for (var key in self)
  78.         ++count;
  79.     return count;
  80. }
  81.  
  82. function objectKeys(self) {
  83.     assert(self !== undefined);
  84.     var keys = [];
  85.     for (var key in self)
  86.         keys.push(key);
  87.     return keys;
  88. }
  89.  
  90. function objectValues(self) {
  91.     assert(self !== undefined);
  92.     var values = [];
  93.     for (var key in self)
  94.         values.push(self[key]);
  95.     return values;
  96. }
  97.  
  98. /**
  99.  * Inserts the items in array2 into array at pos. If pos is not given, the
  100.  * elements are inserted at the end.
  101.  */
  102. function arrayExtend(array, array2, pos) {
  103.     if (pos === undefined)
  104.         pos = array.length;
  105.  
  106.     array.splice.apply(array, [pos, 0].concat(array2));
  107. }
  108.  
  109. Function.prototype.inheritsFrom = function(superClass, functions) {
  110.     var proto = this.prototype = new superClass();
  111.     proto.constructor = this;
  112.     if (functions)
  113.         $.extend(proto, functions);
  114. };
  115.  
  116.  
  117. function AssertionError(message) { this.message = message; }
  118. AssertionError.prototype.toString = function() { return 'AssertionError(' + this.message + ')'; };
  119.  
  120. function assert(x, message) {
  121.     if (!x) {
  122.         console.error('ASSERT FAILED: ' + (message || ''));
  123.         printStackTrace();
  124.         throw new AssertionError(message || '');
  125.     }
  126. }
  127.  
  128. /**
  129.  * given an Array, makes an Object where each element in the array is a key with a value of true
  130.  */
  131. function set(seq) {
  132.     var set = {};
  133.     for (var i = seq.length - 1; i >= 0; --i)
  134.         set[seq[i]] = true;
  135.     return set;
  136. }
  137.  
  138. function setsEqual(a, b) {
  139.     for (var key in a)
  140.         if (!(key in b))
  141.             return false;
  142.     for (var key in b)
  143.         if (!(key in a))
  144.             return false;
  145.     return true;
  146. }
  147.  
  148. function urlQuery(url, args, do_escape) {
  149.     do_escape = (do_escape === undefined ? true : do_escape);
  150.     var pairs = [];
  151.     for (var k in args)
  152.         pairs.push(k + '=' + (do_escape ? encodeURIComponent(args[k]) : args[k]));
  153.  
  154.     var separator = url.search(/\?/) == -1 ? '?' : '&';
  155.     return url + separator + pairs.join('&');
  156. }
  157.  
  158. /**
  159.  * Turns '?key=value&foo' into {key: 'value', foo: true}
  160.  */
  161. function queryParse(query) {
  162.     if (query.indexOf('?') === 0)
  163.         query = query.substring(1);
  164.  
  165.     query = query.split('&');
  166.     var args = {};
  167.  
  168.     for (var i = 0; i < query.length; ++i) {
  169.         var arg = query[i];
  170.         var j = arg.indexOf('=');
  171.         var key, value;
  172.         if (j == -1) {
  173.             key = arg;
  174.             value = true;
  175.         } else {
  176.             key = arg.substring(0, j);
  177.             value = arg.substring(j + 1);
  178.         }
  179.  
  180.         args[key] = value;
  181.     }
  182.  
  183.     return args;
  184. }
  185.  
  186. /*
  187.  * JavaScript Pretty Date
  188.  * Copyright (c) 2008 John Resig (jquery.com)
  189.  * Licensed under the MIT license.
  190.  */
  191. // Takes an ISO time and returns a string representing how
  192. // long ago the date represents.
  193. function prettyDate(time){
  194.     var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")),
  195.         diff = (((new Date()).getTime() - date.getTime()) / 1000),
  196.         day_diff = Math.floor(diff / 86400);
  197.             
  198.     if ( isNaN(day_diff) || day_diff < 0 )
  199.         return 'just now';//longDateFormat(date);
  200.             
  201.     return day_diff === 0 && (
  202.             diff < 60 && "just now" ||
  203.             diff < 120 && "1 minute ago" ||
  204.             diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" ||
  205.             diff < 7200 && "1 hour ago" ||
  206.             diff < 86400 && Math.floor( diff / 3600 ) + " hours ago") ||
  207.         day_diff === 1 && "Yesterday" ||
  208.         day_diff < 7 && day_diff + " days ago" ||
  209.         Math.ceil( day_diff / 7 ) + " weeks ago";
  210. }
  211.  
  212. function longDateFormat(date) {
  213.     return date.toLocaleDateString() + ' ' + date.toLocaleTimeString()
  214. }
  215.  
  216. function uniquify(seq, key) {
  217.     var seen = {};
  218.     var items = [];
  219.     for (var i = 0; i < seq.length; ++i) {
  220.         var k = key(seq[i]);
  221.         if (!(k in seen)) {
  222.             seen[k] = true;
  223.             items.push(seq[i]);
  224.         }
  225.     }
  226.  
  227.     return items;
  228. }
  229.  
  230. function all(seq) {
  231.     for (var i = 0; i < seq.length; ++i) {
  232.         if (!seq[i])
  233.             return false;
  234.     }
  235.  
  236.     return true;
  237. }
  238.  
  239. function binarySearch(o, v, key) {
  240.     /*
  241.      * o: an ordered Array of elements
  242.      * v: the value to search for
  243.      * key: an optional key function
  244.      *
  245.      * thanks http://jsfromhell.com/array/search
  246.      */
  247.     if (key === undefined) key = function(o) { return o; };
  248.     var vkey = key(v);
  249.     var h = o.length, l = -1, m;
  250.  
  251.     while(h - l > 1)
  252.         if (key(o[m = h + l >> 1]) < vkey) l = m;
  253.         else h = m;
  254.  
  255.     return h;
  256. };
  257.  
  258. function stackTrace() {
  259.     var curr  = arguments.callee.caller,
  260.         FUNC  = 'function', ANON = "{anonymous}",
  261.         fnRE  = /function\s*([\w\-$]+)?\s*\(/i,
  262.         stack = [],j=0,
  263.         fn,args,i;
  264.  
  265.     var count = 0;
  266.     while (curr && count++ < 40) {
  267.         fn    = fnRE.test(curr.toString()) ? RegExp.$1 || ANON : ANON;
  268.         if (fn === ANON)
  269.             fn = curr.toString();
  270.         args  = stack.slice.call(curr.arguments);
  271.         i     = args.length;
  272.  
  273.         while (i--) {
  274.             switch (typeof args[i]) {
  275.                 case 'string'  : args[i] = '"'+args[i].replace(/"/g,'\\"')+'"'; break;
  276.                 case 'function': args[i] = FUNC; break;
  277.             }
  278.         }
  279.  
  280.         stack[j++] = fn + '(' + args.join().toString().slice(0, 80) + ')';
  281.         stack[j++] = '--------------------------------';
  282.         curr = curr.caller;
  283.     }
  284.  
  285.     return stack;
  286. }
  287.  
  288. function printStackTrace() {
  289.     console.error(stackTrace().join('\n'));
  290. }
  291.  
  292. function printException(e) {
  293.     console.error(e.name + ' ' + e.sourceURL + '(' + e.line + '): ' + e.message);
  294. }
  295.  
  296. function guard(f) {
  297.     try {
  298.         f();
  299.     } catch (err) {
  300.         printStackTrace();
  301.         printException(err);
  302.     }
  303. }
  304.  
  305. function callEach(seq, funcName) {
  306.     var args = Array.apply(null, arguments);
  307.     var results = [];
  308.     args.shift();
  309.     args.shift();
  310.  
  311.     $.each(seq, function (i, obj) {
  312.         results.push(obj[funcName].apply(obj, args));
  313.     });
  314.  
  315.     return results;
  316. }
  317.  
  318.  
  319. // Mozilla 1.8 has support for indexOf, lastIndexOf, forEach, filter, map, some, every
  320. // http://developer-test.mozilla.org/docs/Core_JavaScript_1.5_Reference:Objects:Array:lastIndexOf
  321. function arrayIndexOf (array, obj, fromIndex) {
  322.     if (fromIndex == null) {
  323.         fromIndex = 0;
  324.     } else if (fromIndex < 0) {
  325.         fromIndex = Math.max(0, array.length + fromIndex);
  326.     }
  327.     for (var i = fromIndex; i < array.length; i++) {
  328.         if (array[i] === obj)
  329.             return i;
  330.     }
  331.     return -1;
  332. };
  333.  
  334. function arrayRemove(array, obj) {
  335.     var i = arrayIndexOf(array, obj);
  336.     if (i != -1) {
  337.         array.splice(i, 1);
  338.         return true;
  339.     }
  340.  
  341.     return false;
  342. };
  343.  
  344. (function($){
  345.  
  346.     var $preload = $.preload = function( original, settings ){
  347.         if( original.split ) // selector
  348.             original = $(original);
  349.  
  350.         settings = $.extend( {}, $preload.defaults, settings );
  351.         var sources = $.map( original, function( source ){
  352.             if( !source ) 
  353.                 return; // skip
  354.             if( source.split ) // URL Mode
  355.                 return settings.base + source + settings.ext;
  356.             var url = source.src || source.href; // save the original source
  357.             if( typeof settings.placeholder == 'string' && source.src ) // Placeholder Mode, if it's an image, set it.
  358.                 source.src = settings.placeholder;
  359.             if( url && settings.find ) // Rollover mode
  360.                 url = url.replace( settings.find, settings.replace );
  361.             return url || null; // skip if empty string
  362.         });
  363.  
  364.         var data = {
  365.             loaded:0, // how many were loaded successfully
  366.             failed:0, // how many urls failed
  367.             next:0, // which one's the next image to load (index)
  368.             done:0, // how many urls were tried
  369.             /*
  370.             index:0, // index of the related image            
  371.             found:false, // whether the last one was successful
  372.             */
  373.             total:sources.length // how many images are being preloaded overall
  374.         };
  375.         
  376.         if( !data.total ) // nothing to preload
  377.             return finish();
  378.         
  379.         var imgs = $(Array(settings.threshold+1).join('<img/>'))
  380.             .load(handler).error(handler).bind('abort',handler).each(fetch);
  381.         
  382.         function handler( e ){
  383.             data.element = this;
  384.             data.found = e.type == 'load';
  385.             data.image = this.src;
  386.             data.index = this.index;
  387.             var orig = data.original = original[this.index];
  388.             data[data.found?'loaded':'failed']++;
  389.             data.done++;
  390.  
  391.             // This will ensure that the images aren't "un-cached" after a while
  392.             if( settings.enforceCache )
  393.                 $preload.cache.push( 
  394.                     $('<img/>').attr('src',data.image)[0]
  395.                 );
  396.  
  397.             if( settings.placeholder && orig.src ) // special case when on placeholder mode
  398.                 orig.src = data.found ? data.image : settings.notFound || orig.src;
  399.             if( settings.onComplete )
  400.                 settings.onComplete( data );
  401.             if( data.done < data.total ) // let's continue
  402.                 fetch( 0, this );
  403.             else{ // we are finished
  404.                 if( imgs && imgs.unbind )
  405.                     imgs.unbind('load').unbind('error').unbind('abort'); // cleanup
  406.                 imgs = null;
  407.                 finish();
  408.             }
  409.         };
  410.         function fetch( i, img, retry ){
  411.             // IE problem, can't preload more than 15
  412.             if( img.attachEvent /* msie */ && data.next && data.next % $preload.gap == 0 && !retry ){
  413.                 setTimeout(function(){ fetch( i, img, true ); }, 0);
  414.                 return false;
  415.             }
  416.             if( data.next == data.total ) return false; // no more to fetch
  417.             img.index = data.next; // save it, we'll need it.
  418.             img.src = sources[data.next++];
  419.             if( settings.onRequest ){
  420.                 data.index = img.index;
  421.                 data.element = img;
  422.                 data.image = img.src;
  423.                 data.original = original[data.next-1];
  424.                 settings.onRequest( data );
  425.             }
  426.         };
  427.         function finish(){
  428.             if( settings.onFinish )
  429.                 settings.onFinish( data );
  430.         };
  431.     };
  432.  
  433.      // each time we load this amount and it's IE, we must rest for a while, make it lower if you get stack overflow.
  434.     $preload.gap = 14; 
  435.     $preload.cache = [];
  436.     
  437.     $preload.defaults = {
  438.         threshold:2, // how many images to load simultaneously
  439.         base:'', // URL mode: a base url can be specified, it is prepended to all string urls
  440.         ext:'', // URL mode:same as base, but it's appended after the original url.
  441.         replace:'' // Rollover mode: replacement (can be left empty)
  442.         /*
  443.         enforceCache: false, // If true, the plugin will save a copy of the images in $.preload.cache
  444.         find:null, // Rollover mode: a string or regex for the replacement
  445.         notFound:'' // Placeholder Mode: Optional url of an image to use when the original wasn't found
  446.         placeholder:'', // Placeholder Mode: url of an image to set while loading
  447.         onRequest:function( data ){ ... }, // callback called every time a new url is requested
  448.         onComplete:function( data ){ ... }, // callback called every time a response is received(successful or not)
  449.         onFinish:function( data ){ ... } // callback called after all the images were loaded(or failed)
  450.         */
  451.     };
  452.  
  453.     $.fn.preload = function( settings ){
  454.         $preload( this, settings );
  455.         return this;
  456.     };
  457.  
  458. })(jQuery);
  459.  
  460.  
  461. function cmp(a, b) {
  462.     if (a < b)
  463.         return -1;
  464.     else if (b < a)
  465.         return 1;
  466.     else
  467.         return 0;
  468. }
  469.  
  470. function cmpByKey(key, a, b) {
  471.     return function(a, b) { return cmp(a[key], b[key]); };
  472. }
  473.  
  474. function pp(obj) {
  475.     var s = [];
  476.     for (var key in obj)
  477.         s.push(key + ': ' + obj[key]);
  478.  
  479.     console.log('{' + s.join(', ') + '}');
  480. }
  481.  
  482. /*!
  483.  * linkify - v0.3 - 6/27/2009
  484.  * http://benalman.com/code/test/js-linkify/
  485.  * 
  486.  * Copyright (c) 2009 "Cowboy" Ben Alman
  487.  * Licensed under the MIT license
  488.  * http://benalman.com/about/license/
  489.  * 
  490.  * Some regexps adapted from http://userscripts.org/scripts/review/7122
  491.  */
  492.  
  493. // Turn text into linkified html.
  494. // 
  495. // var html = linkify( text, options );
  496. // 
  497. // options:
  498. // 
  499. //  callback (Function) - default: undefined - if defined, this will be called
  500. //    for each link- or non-link-chunk with two arguments, text and href. If the
  501. //    chunk is non-link, href will be omitted.
  502. // 
  503. //  punct_regexp (RegExp | Boolean) - a RegExp that can be used to trim trailing
  504. //    punctuation from links, instead of the default.
  505. // 
  506. // This is a work in progress, please let me know if (and how) it fails!
  507.  
  508. window.linkify = (function(){
  509.   var
  510.     PROTOCOLS = 'ftp|https?|gopher|msnim|icq|telnet|nntp|aim|file|svn',
  511.     SCHEME = "(?:" + PROTOCOLS + ")://",
  512.     IPV4 = "(?:(?:[0-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}(?:[0-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])",
  513.     HOSTNAME = "(?:(?:[^\\s!@#$%^&*()_=+[\\]{}\\\\|;:'\",.<>/?]+)\\.)+",
  514.     TLD = "(?:ac|ad|aero|ae|af|ag|ai|al|am|an|ao|aq|arpa|ar|asia|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|biz|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|cat|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|coop|com|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|info|int|in|io|iq|ir|is|it|je|jm|jobs|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mobi|mo|mp|mq|mr|ms|mt|museum|mu|mv|mw|mx|my|mz|name|na|nc|net|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pro|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|travel|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|xn--0zwm56d|xn--11b5bs3a9aj6g|xn--80akhbyknj4f|xn--9t4b11yi5a|xn--deba0ad|xn--g6w251d|xn--hgbk6aj7f53bba|xn--hlcj6aya9esc7a|xn--jxalpdlp|xn--kgbechtv|xn--zckzah|ye|yt|yu|za|zm|zw)",
  515.     HOST_OR_IP = "(?:" + HOSTNAME + TLD + "|" + IPV4 + ")",
  516.     PATH = "(?:[;/][^#?<>\\s]*)?",
  517.     QUERY_FRAG = "(?:\\?[^#<>\\s]*)?(?:#[^<>\\s\\u3000]*)?", // include \\u3000 here and in the line below--webkit's js engine does not for \s
  518.     URI1 = "\\b" + SCHEME + "[^<>\\s\\u3000]+",
  519.     URI2 = "\\b" + HOST_OR_IP + PATH + QUERY_FRAG + "(?!\\w)",
  520.     
  521.     MAILTO = "mailto:",
  522.     EMAIL = "(?:" + MAILTO + ")?[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@" + HOST_OR_IP + QUERY_FRAG + "(?!\\w)",
  523.     
  524.     URI_RE = new RegExp( "(?:" + URI1 + "|" + URI2 + "|" + EMAIL + ")", "ig" ),
  525.     SCHEME_RE = new RegExp( "^" + SCHEME, "i" ),
  526.     
  527.     quotes = {
  528.       "'": "`",
  529.       '>': '<',
  530.       ')': '(',
  531.       ']': '[',
  532.       '}': '{',
  533.       '┬╗': '┬½',
  534.       'ΓÇ║': 'ΓÇ╣'
  535.     },
  536.     
  537.     default_options = {
  538.       callback: function( text, href ) {
  539.         return href ? '<a href="' + href + '" title="' + href + '">' + text + '<\/a>' : text;
  540.       },
  541.       punct_regexp: /(?:[!?.,:;'"]|(?:&|&)(?:lt|gt|quot|apos|raquo|laquo|rsaquo|lsaquo);)$/
  542.     };
  543.   
  544.   return function( txt, options ) {
  545.     if (!txt) return '';
  546.     options = options || {};
  547.     
  548.     // Temp variables.
  549.     var arr,
  550.       i,
  551.       link,
  552.       href,
  553.       
  554.       // Output HTML.
  555.       html = '',
  556.       
  557.       // Store text / link parts, in order, for re-combination.
  558.       parts = [],
  559.       
  560.       // Used for keeping track of indices in the text.
  561.       idx_prev,
  562.       idx_last,
  563.       idx,
  564.       link_last,
  565.       
  566.       // Used for trimming trailing punctuation and quotes from links.
  567.       matches_begin,
  568.       matches_end,
  569.       quote_begin,
  570.       quote_end;
  571.     
  572.     // Initialize options.
  573.     for ( i in default_options ) {
  574.       if ( options[ i ] === undefined ) {
  575.         options[ i ] = default_options[ i ];
  576.       }
  577.     }
  578.     
  579.     // Find links.
  580.     while ( arr = URI_RE.exec( txt ) ) {
  581.       
  582.       link = arr[0];
  583.       idx_last = URI_RE.lastIndex;
  584.       idx = idx_last - link.length;
  585.       
  586.       // Not a link if preceded by certain characters.
  587.       if ( /[\/:]/.test( txt.charAt( idx - 1 ) ) ) {
  588.         continue;
  589.       }
  590.       
  591.       // Trim trailing punctuation.
  592.       do {
  593.         // If no changes are made, we don't want to loop forever!
  594.         link_last = link;
  595.         
  596.         quote_end = link.substr( -1 )
  597.         quote_begin = quotes[ quote_end ];
  598.         
  599.         // Ending quote character?
  600.         if ( quote_begin ) {
  601.           matches_begin = link.match( new RegExp( '\\' + quote_begin + '(?!$)', 'g' ) );
  602.           matches_end = link.match( new RegExp( '\\' + quote_end, 'g' ) );
  603.           
  604.           // If quotes are unbalanced, remove trailing quote character.
  605.           if ( ( matches_begin ? matches_begin.length : 0 ) < ( matches_end ? matches_end.length : 0 ) ) {
  606.             link = link.substr( 0, link.length - 1 );
  607.             idx_last--;
  608.           }
  609.         }
  610.         
  611.         // Ending non-quote punctuation character?
  612.         if ( options.punct_regexp ) {
  613.           link = link.replace( options.punct_regexp, function(a){
  614.             idx_last -= a.length;
  615.             return '';
  616.           });
  617.         }
  618.       } while ( link.length && link !== link_last );
  619.       
  620.       href = link;
  621.       
  622.       // Add appropriate protocol to naked links.
  623.       if ( !SCHEME_RE.test( href ) ) {
  624.         href = ( href.indexOf( '@' ) !== -1 ? ( !href.indexOf( MAILTO ) ? '' : MAILTO )
  625.           : !href.indexOf( 'irc.' ) ? 'irc://'
  626.           : !href.indexOf( 'ftp.' ) ? 'ftp://'
  627.           : 'http://' )
  628.           + href;
  629.       }
  630.       
  631.       // Push preceding non-link text onto the array.
  632.       if ( idx_prev != idx ) {
  633.         parts.push([ txt.slice( idx_prev, idx ) ]);
  634.         idx_prev = idx_last;
  635.       }
  636.       
  637.       // Push massaged link onto the array
  638.       parts.push([ link, href ]);
  639.     };
  640.     
  641.     // Push remaining non-link text onto the array.
  642.     parts.push([ txt.substr( idx_prev ) ]);
  643.     
  644.     // Process the array items.
  645.     for ( i = 0; i < parts.length; i++ ) {
  646.       html += options.callback.apply( window, parts[i] );
  647.     }
  648.     
  649.     // In case of catastrophic failure, return the original text;
  650.     return html || txt;
  651.   };
  652.   
  653. })();
  654.  
  655. // t: current time, b: begInnIng value, c: change In value, d: duration
  656. jQuery.easing['jswing'] = jQuery.easing['swing'];
  657.  
  658. jQuery.extend( jQuery.easing,
  659. {
  660.     def: 'easeOutQuad',
  661.     swing: function (x, t, b, c, d) {
  662.         //alert(jQuery.easing.default);
  663.         return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
  664.     },
  665.     easeInQuad: function (x, t, b, c, d) {
  666.         return c*(t/=d)*t + b;
  667.     },
  668.     easeOutQuad: function (x, t, b, c, d) {
  669.         return -c *(t/=d)*(t-2) + b;
  670.     },
  671.     easeInOutQuad: function (x, t, b, c, d) {
  672.         if ((t/=d/2) < 1) return c/2*t*t + b;
  673.         return -c/2 * ((--t)*(t-2) - 1) + b;
  674.     },
  675.     easeInCubic: function (x, t, b, c, d) {
  676.         return c*(t/=d)*t*t + b;
  677.     },
  678.     easeOutCubic: function (x, t, b, c, d) {
  679.         return c*((t=t/d-1)*t*t + 1) + b;
  680.     },
  681.     easeInOutCubic: function (x, t, b, c, d) {
  682.         if ((t/=d/2) < 1) return c/2*t*t*t + b;
  683.         return c/2*((t-=2)*t*t + 2) + b;
  684.     },
  685.     easeInQuart: function (x, t, b, c, d) {
  686.         return c*(t/=d)*t*t*t + b;
  687.     },
  688.     easeOutQuart: function (x, t, b, c, d) {
  689.         return -c * ((t=t/d-1)*t*t*t - 1) + b;
  690.     },
  691.     easeInOutQuart: function (x, t, b, c, d) {
  692.         if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
  693.         return -c/2 * ((t-=2)*t*t*t - 2) + b;
  694.     },
  695.     easeInQuint: function (x, t, b, c, d) {
  696.         return c*(t/=d)*t*t*t*t + b;
  697.     },
  698.     easeOutQuint: function (x, t, b, c, d) {
  699.         return c*((t=t/d-1)*t*t*t*t + 1) + b;
  700.     },
  701.     easeInOutQuint: function (x, t, b, c, d) {
  702.         if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
  703.         return c/2*((t-=2)*t*t*t*t + 2) + b;
  704.     },
  705.     easeInSine: function (x, t, b, c, d) {
  706.         return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
  707.     },
  708.     easeOutSine: function (x, t, b, c, d) {
  709.         return c * Math.sin(t/d * (Math.PI/2)) + b;
  710.     },
  711.     easeInOutSine: function (x, t, b, c, d) {
  712.         return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
  713.     },
  714.     easeInExpo: function (x, t, b, c, d) {
  715.         return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
  716.     },
  717.     easeOutExpo: function (x, t, b, c, d) {
  718.         return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
  719.     },
  720.     easeInOutExpo: function (x, t, b, c, d) {
  721.         if (t==0) return b;
  722.         if (t==d) return b+c;
  723.         if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
  724.         return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
  725.     },
  726.     easeInCirc: function (x, t, b, c, d) {
  727.         return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
  728.     },
  729.     easeOutCirc: function (x, t, b, c, d) {
  730.         return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
  731.     },
  732.     easeInOutCirc: function (x, t, b, c, d) {
  733.         if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
  734.         return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
  735.     },
  736.     easeInElastic: function (x, t, b, c, d) {
  737.         var s=1.70158;var p=0;var a=c;
  738.         if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
  739.         if (a < Math.abs(c)) { a=c; var s=p/4; }
  740.         else var s = p/(2*Math.PI) * Math.asin (c/a);
  741.         return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
  742.     },
  743.     easeOutElastic: function (x, t, b, c, d) {
  744.         var s=1.70158;var p=0;var a=c;
  745.         if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
  746.         if (a < Math.abs(c)) { a=c; var s=p/4; }
  747.         else var s = p/(2*Math.PI) * Math.asin (c/a);
  748.         return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
  749.     },
  750.     easeInOutElastic: function (x, t, b, c, d) {
  751.         var s=1.70158;var p=0;var a=c;
  752.         if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
  753.         if (a < Math.abs(c)) { a=c; var s=p/4; }
  754.         else var s = p/(2*Math.PI) * Math.asin (c/a);
  755.         if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
  756.         return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
  757.     },
  758.     easeInBack: function (x, t, b, c, d, s) {
  759.         if (s == undefined) s = 1.70158;
  760.         return c*(t/=d)*t*((s+1)*t - s) + b;
  761.     },
  762.     easeOutBack: function (x, t, b, c, d, s) {
  763.         if (s == undefined) s = 1.70158;
  764.         return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
  765.     },
  766.     easeInOutBack: function (x, t, b, c, d, s) {
  767.         if (s == undefined) s = 1.70158; 
  768.         if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
  769.         return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
  770.     },
  771.     easeInBounce: function (x, t, b, c, d) {
  772.         return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
  773.     },
  774.     easeOutBounce: function (x, t, b, c, d) {
  775.         if ((t/=d) < (1/2.75)) {
  776.             return c*(7.5625*t*t) + b;
  777.         } else if (t < (2/2.75)) {
  778.             return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
  779.         } else if (t < (2.5/2.75)) {
  780.             return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
  781.         } else {
  782.             return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
  783.         }
  784.     },
  785.     easeInOutBounce: function (x, t, b, c, d) {
  786.         if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
  787.         return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
  788.     }
  789. });
  790.  
  791. function nodeInAll(n) {
  792.     for (var i = 0; i < document.all.length; ++i)
  793.         if (document[i] === n)
  794.             return true;
  795.  
  796.     return false;
  797. }
  798.  
  799. function arrayShuffle(o) {
  800.     for(var j, x, i = o.length; i; 
  801.         j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
  802.  
  803.     return o;
  804. }
  805.  
  806. function htmlEntitiesEscape(html) {
  807.   return html.
  808.     replace(/&/gmi, '&').
  809.     replace(/"/gmi, '"').
  810.     replace(/>/gmi, '>').
  811.     replace(/</gmi, '<')
  812. }
  813.