+ /**
+ * Remove items that aren't matched in an array. The function passed
+ * in to this method will be passed two arguments: 'a' (which is the
+ * array item) and 'i' (which is the index of the item in the array).
+ *
+ * @private
+ * @name $.grep
+ * @type Array
+ * @param Array array The Array to find items in.
+ * @param Function fn The function to process each item against.
+ * @param Boolean inv Invert the selection - select the opposite of the function.
+ */
+ grep: function(a,f,s) {
+ // If a string is passed in for the function, make a function
+ // for it (a handy shortcut)
+ if ( f.constructor == String )
+ f = new Function("a","i","return " + f);
+
+ var r = [];
+
+ // Go through the array, only saving the items
+ // that pass the validator function
+ for ( var i = 0; i < a.length; i++ )
+ if ( !s && f(a[i],i) || s && !f(a[i],i) )
+ r.push( a[i] );
+
+ return r;
+ },
+
+ /**
+ * Translate all items in array to another array of items. The translation function
+ * that is provided to this method is passed one argument: 'a' (the item to be
+ * translated). If an array is returned, that array is mapped out and merged into
+ * the full array. Additionally, returning 'null' or 'undefined' will delete the item
+ * from the array. Both of these changes imply that the size of the array may not
+ * be the same size upon completion, as it was when it started.
+ *
+ * @private
+ * @name $.map
+ * @type Array
+ * @param Array array The Array to translate.
+ * @param Function fn The function to process each item against.
+ */
+ map: function(a,f) {
+ // If a string is passed in for the function, make a function
+ // for it (a handy shortcut)
+ if ( f.constructor == String )
+ f = new Function("a","return " + f);
+
+ var r = [];
+
+ // Go through the array, translating each of the items to their
+ // new value (or values).
+ for ( var i = 0; i < a.length; i++ ) {
+ var t = f(a[i],i);
+ if ( t !== null && t != undefined ) {
+ if ( t.constructor != Array ) t = [t];
+ r = jQuery.merge( t, r );
+ }
+ }
+ return r;
+ },
+
+ /*
+ * A number of helper functions used for managing events.
+ * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
+ */
+ event: {
+
+ // Bind an event to an element
+ // Original by Dean Edwards
+ add: function(element, type, handler) {
+ // For whatever reason, IE has trouble passing the window object
+ // around, causing it to be cloned in the process
+ if ( jQuery.browser.msie && element.setInterval != undefined )
+ element = window;
+
+ // Make sure that the function being executed has a unique ID
+ if ( !handler.guid )
+ handler.guid = this.guid++;
+
+ // Init the element's event structure
+ if (!element.events)
+ element.events = {};
+
+ // Get the current list of functions bound to this event
+ var handlers = element.events[type];
+
+ // If it hasn't been initialized yet
+ if (!handlers) {
+ // Init the event handler queue
+ handlers = element.events[type] = {};
+
+ // Remember an existing handler, if it's already there
+ if (element["on" + type])
+ handlers[0] = element["on" + type];
+ }
+
+ // Add the function to the element's handler list
+ handlers[handler.guid] = handler;
+
+ // And bind the global event handler to the element
+ element["on" + type] = this.handle;
+
+ // Remember the function in a global list (for triggering)
+ if (!this.global[type])
+ this.global[type] = [];
+ this.global[type].push( element );
+ },
+
+ guid: 1,
+ global: {},
+
+ // Detach an event or set of events from an element
+ remove: function(element, type, handler) {
+ if (element.events)
+ if (type && element.events[type])
+ if ( handler )
+ delete element.events[type][handler.guid];
+ else
+ for ( var i in element.events[type] )
+ delete element.events[type][i];
+ else
+ for ( var j in element.events )
+ this.remove( element, j );
+ },
+
+ trigger: function(type,data,element) {
+ // Touch up the incoming data
+ data = data || [];