Added a fix for the hover mouseover/mouseout problem.
[jquery.git] / jquery / jquery.js
1 /*
2  * jQuery - New Wave Javascript
3  *
4  * Copyright (c) 2006 John Resig (jquery.com)
5  * Licensed under the MIT License:
6  *   http://www.opensource.org/licenses/mit-license.php
7  *
8  * $Date$
9  * $Rev$
10  */
11
12 // Global undefined variable
13 window.undefined = window.undefined;
14
15 // Map over the $ in case of overwrite
16 if ( $ ) var _$ = $;
17
18 /**
19  * Create a new jQuery Object
20  * @constructor
21  */
22 var $ = jQuery = function(a,c) {
23         /*
24         * Handle support for overriding other $() functions. Way too many libraries
25         * provide this function to simply ignore it and overwrite it.
26         */
27
28         // Check to see if this is a possible collision case
29         if ( _$ && !c && ( a.constructor == String && 
30       
31                 // Make sure that the expression is a colliding one
32                 !/[^a-zA-Z0-9_-]/.test(a) &&
33         
34                 // and that there are no elements that match it
35                 // (this is the one truly ambiguous case)
36                 !document.getElementsByTagName(a).length ) ||
37
38                 // Watch for an array being passed in (Prototype 1.5)
39                 a.constructor == Array )
40
41                         // Use the default method, in case it works some voodoo
42                         return _$( a );
43
44         // Watch for when a jQuery object is passed in as an arg
45         if ( a && a.jquery )
46                 return a;
47         
48         // If the context is global, return a new object
49         if ( window == this )
50                 return new jQuery(a,c);
51         
52         // Find the matching elements and save them for later
53         this.cur = jQuery.Select(
54                 a || jQuery.context || document,
55                 c && c.jquery && c.get(0) || c
56         );
57 }
58
59 jQuery.fn = jQuery.prototype = {
60         /**
61          * The current SVN version of jQuery.
62          *
63          * @private
64          * @type String
65          */
66         jquery: "$Rev$",
67         
68         /**
69          * The number of elements currently matched.
70          *
71          * @type Number
72          */
73         size: function() {
74                 return this.get().length;
75         },
76         
77         /**
78          * Access the elements matched. If a number is provided,
79          * the Nth element is returned, otherwise, an array of all
80          * matched items is returned.
81          *
82          * @type Array,DOMElement
83          */
84         get: function(num) {
85                 return num == undefined ? this.cur : this.cur[num];
86         },
87         
88         each: function(f) {
89                 for ( var i = 0; i < this.size(); i++ )
90                         f.apply( this.get(i), [i] );
91                 return this;
92         },
93         set: function(a,b) {
94                 return this.each(function(){
95                         if ( b === undefined )
96                                 for ( var j in a )
97                                         jQuery.attr(this,j,a[j]);
98                         else
99                                 jQuery.attr(this,a,b);
100                 });
101         },
102         html: function(h) {
103                 return h == undefined && this.size() ?
104                         this.get(0).innerHTML : this.set( "innerHTML", h );
105         },
106         val: function(h) {
107                 return h == undefined && this.size() ?
108                         this.get(0).value : this.set( "value", h );
109         },
110         text: function(e) {
111                 e = e || this.get();
112                 var t = "";
113                 for ( var j = 0; j < e.length; j++ ) {
114                         var r = e[j].childNodes;
115                         for ( var i = 0; i < r.length; i++ )
116                                 t += r[i].nodeType != 1 ?
117                                         r[i].nodeValue : jQuery.fn.text([ r[i] ]);
118                 }
119                 return t;
120         },
121         
122         css: function(a,b) {
123                 return a.constructor != String || b ?
124                         this.each(function(){
125                                 if ( b === undefined )
126                                         for ( var j in a )
127                                                 jQuery.attr(this.style,j,a[j]);
128                                 else
129                                         jQuery.attr(this.style,a,b);
130                         }) : jQuery.css( this.get(0), a );
131         },
132         toggle: function() {
133                 return this.each(function(){
134                         var d = jQuery.css(this,"display");
135                         if ( !d || d == "none" )
136                                 $(this).show();
137                         else
138                                 $(this).hide();
139                 });
140         },
141         show: function() {
142                 return this.each(function(){
143                         this.style.display = this.oldblock ? this.oldblock : "";
144                         if ( jQuery.css(this,"display") == "none" )
145                                 this.style.display = "block";
146                 });
147         },
148         hide: function() {
149                 return this.each(function(){
150                         this.oldblock = jQuery.css(this,"display");
151                         if ( this.oldblock == "none" )
152                                 this.oldblock = "block";
153                         this.style.display = "none";
154                 });
155         },
156         addClass: function(c) {
157                 return this.each(function(){
158                         jQuery.className.add(this,c);
159                 });
160         },
161         removeClass: function(c) {
162                 return this.each(function(){
163                         jQuery.className.remove(this,c);
164                 });
165         },
166
167         toggleClass: function(c) {
168                 return this.each(function(){
169                         if (jQuery.hasWord(this,c))
170                                 jQuery.className.remove(this,c);
171                         else
172                                 jQuery.className.add(this,c);
173                 });
174         },
175         remove: function() {
176                 this.each(function(){this.parentNode.removeChild( this );});
177                 return this.pushStack( [] );
178         },
179         
180         wrap: function() {
181                 var a = jQuery.clean(arguments);
182                 return this.each(function(){
183                         var b = a[0].cloneNode(true);
184                         this.parentNode.insertBefore( b, this );
185                         while ( b.firstChild )
186                                 b = b.firstChild;
187                         b.appendChild( this );
188                 });
189         },
190         
191         append: function() {
192                 var clone = this.size() > 1;
193                 var a = jQuery.clean(arguments);
194                 return this.domManip(function(){
195                         for ( var i = 0; i < a.length; i++ )
196                                 this.appendChild( clone ? a[i].cloneNode(true) : a[i] );
197                 });
198         },
199         
200         appendTo: function() {
201                 var a = arguments;
202                 return this.each(function(){
203                         for ( var i = 0; i < a.length; i++ )
204                                 $(a[i]).append( this );
205                 });
206         },
207         
208         prepend: function() {
209                 var clone = this.size() > 1;
210                 var a = jQuery.clean(arguments);
211                 return this.domManip(function(){
212                         for ( var i = a.length - 1; i >= 0; i-- )
213                                 this.insertBefore( clone ? a[i].cloneNode(true) : a[i], this.firstChild );
214                 });
215         },
216         
217         before: function() {
218                 var clone = this.size() > 1;
219                 var a = jQuery.clean(arguments);
220                 return this.each(function(){
221                         for ( var i = 0; i < a.length; i++ )
222                                 this.parentNode.insertBefore( clone ? a[i].cloneNode(true) : a[i], this );
223                 });
224         },
225         
226         after: function() {
227                 var clone = this.size() > 1;
228                 var a = jQuery.clean(arguments);
229                 return this.each(function(){
230                         for ( var i = a.length - 1; i >= 0; i-- )
231                                 this.parentNode.insertBefore( clone ? a[i].cloneNode(true) : a[i], this.nextSibling );
232                 });
233         },
234         
235         empty: function() {
236                 return this.each(function(){
237                         while ( this.firstChild )
238                                 this.removeChild( this.firstChild );
239                 });
240         },
241         
242         bind: function(t,f) {
243                 return this.each(function(){jQuery.event.add(this,t,f);});
244         },
245         unbind: function(t,f) {
246                 return this.each(function(){jQuery.event.remove(this,t,f);});
247         },
248         trigger: function(t) {
249                 return this.each(function(){jQuery.event.trigger(this,t);});
250         },
251         
252         pushStack: function(a) {
253                 if ( !this.stack ) this.stack = [];
254                 this.stack.unshift( this.cur );
255                 if ( a ) this.cur = a;
256                 return this;
257         },
258         
259         find: function(t) {
260                 var ret = [];
261                 this.each(function(){
262                         ret = jQuery.merge( ret, jQuery.Select(t,this) );
263                 });
264                 this.pushStack( ret );
265                 return this;
266         },
267         
268         end: function() {
269                 this.cur = this.stack.shift();
270                 return this;
271         },
272         
273         parent: function(a) {
274                 var ret = jQuery.map(this.cur,"a.parentNode");
275                 if ( a ) ret = jQuery.filter(a,ret).r;
276                 return this.pushStack(ret);
277         },
278         
279         parents: function(a) {
280                 var ret = jQuery.map(this.cur,jQuery.parents);
281                 if ( a ) ret = jQuery.filter(a,ret).r;
282                 return this.pushStack(ret);
283         },
284         
285         siblings: function(a) {
286                 // Incorrect, need to exclude current element
287                 var ret = jQuery.map(this.cur,jQuery.sibling);
288                 if ( a ) ret = jQuery.filter(a,ret).r;
289                 return this.pushStack(ret);
290         },
291         
292         filter: function(t) {
293                 return this.pushStack( jQuery.filter(t,this.cur).r );
294         },
295         not: function(t) {
296                 return this.pushStack( t.constructor == String ?
297                         jQuery.filter(t,this.cur,false).r :
298                         jQuery.grep(this.cur,function(a){ return a != t; }) );
299         },
300         add: function(t) {
301                 return this.pushStack( jQuery.merge( this.cur, t.constructor == String ?
302                         jQuery.Select(t) : t.constructor == Array ? t : [t] ) );
303         },
304         
305         /**
306          * A wrapper function for each() to be used by append and prepend.
307          * Handles cases where you're trying to modify the inner contents of
308          * a table, when you actually need to work with the tbody.
309          *
310          * @member jQuery
311          * @param {String} expr The expression with which to filter
312          * @type Boolean
313          */
314         is: function(expr) {
315                 return jQuery.filter(expr,this.cur).r.length > 0;
316         },
317         
318         /**
319          * A wrapper function for each() to be used by append and prepend.
320          * Handles cases where you're trying to modify the inner contents of
321          * a table, when you actually need to work with the tbody.
322          *
323          * @private
324          * @member jQuery
325          * @param {Function} fn The function doing the DOM manipulation.
326          * @type jQuery
327          */
328         domManip: function(fn){
329                 return this.each(function(){
330                         var obj = this;
331                         
332                         if ( this.nodeName == "TABLE" ) {
333                                 var tbody = this.getElementsByTagName("tbody");
334
335                                 if ( !tbody.length ) {
336                                         obj = document.createElement("tbody");
337                                         this.appendChild( obj );
338                                 } else
339                                         obj = tbody[0];
340                         }
341         
342                         fn.apply( obj );
343                 });
344         }
345 };
346
347 jQuery.className = {
348         add: function(o,c){
349                 if (jQuery.hasWord(o,c)) return;
350                 o.className += ( o.className ? " " : "" ) + c;
351         },
352         remove: function(o,c){
353                 o.className = !c ? "" :
354                         o.className.replace(
355                                 new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
356         }
357 };
358
359 (function(){
360         var b = navigator.userAgent.toLowerCase();
361
362         // Figure out what browser is being used
363         jQuery.browser =
364                 ( /webkit/.test(b) && "safari" ) ||
365                 ( /opera/.test(b) && "opera" ) ||
366                 ( /msie/.test(b) && "msie" ) ||
367                 ( !/compatible/.test(b) && "mozilla" ) ||
368                 "other";
369
370         // Check to see if the W3C box model is being used
371         jQuery.boxModel = ( jQuery.browser != "msie" || document.compatMode == "CSS1Compat" );
372 })();
373
374 jQuery.css = function(e,p) {
375         // Adapted from Prototype 1.4.0
376         if ( p == "height" || p == "width" ) {
377
378                 // Handle extra width/height provided by the W3C box model
379                 var ph = (!jQuery.boxModel ? 0 :
380                         jQuery.css(e,"paddingTop") + jQuery.css(e,"paddingBottom") +
381                         jQuery.css(e,"borderTopWidth") + jQuery.css(e,"borderBottomWidth")) || 0;
382
383                 var pw = (!jQuery.boxModel ? 0 :
384                         jQuery.css(e,"paddingLeft") + jQuery.css(e,"paddingRight") +
385                         jQuery.css(e,"borderLeftWidth") + jQuery.css(e,"borderRightWidth")) || 0;
386
387                 var oHeight, oWidth;
388
389                 if (jQuery.css(e,"display") != 'none') {
390                         oHeight = e.offsetHeight || parseInt(e.style.height) || 0;
391                         oWidth = e.offsetWidth || parseInt(e.style.width) || 0;
392                 } else {
393                         var els = e.style;
394                         var ov = els.visibility;
395                         var op = els.position;
396                         var od = els.display;
397                         els.visibility = "hidden";
398                         els.position = "absolute";
399                         els.display = "";
400                         oHeight = e.clientHeight || parseInt(e.style.height);
401                         oWidth = e.clientWidth || parseInt(e.style.width);
402                         els.display = od;
403                         els.position = op;
404                         els.visibility = ov;
405                 }
406
407                 return p == "height" ?
408                         (oHeight - ph < 0 ? 0 : oHeight - ph) :
409                         (oWidth - pw < 0 ? 0 : oWidth - pw);
410         }
411         
412         var r;
413
414         if (e.style[p])
415                 r = e.style[p];
416         else if (e.currentStyle)
417                 r = e.currentStyle[p];
418         else if (document.defaultView && document.defaultView.getComputedStyle) {
419                 p = p.replace(/([A-Z])/g,"-$1").toLowerCase();
420                 var s = document.defaultView.getComputedStyle(e,"");
421                 r = s ? s.getPropertyValue(p) : null;
422         }
423         
424         return /top|right|left|bottom/i.test(p) ? parseFloat( r ) : r;
425 };
426
427 jQuery.clean = function(a) {
428         var r = [];
429         for ( var i = 0; i < a.length; i++ ) {
430                 if ( a[i].constructor == String ) {
431
432                         if ( !a[i].indexOf("<tr") ) {
433                                 var tr = true;
434                                 a[i] = "<table>" + a[i] + "</table>";
435                         } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
436                                 var td = true;
437                                 a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
438                         }
439
440                         var div = document.createElement("div");
441                         div.innerHTML = a[i];
442
443                         if ( tr || td ) {
444                                 div = div.firstChild.firstChild;
445                                 if ( td ) div = div.firstChild;
446                         }
447
448                         for ( var j = 0; j < div.childNodes.length; j++ )
449                                 r[r.length] = div.childNodes[j];
450                 } else if ( a[i].length && !a[i].nodeType )
451                         for ( var k = 0; k < a[i].length; k++ )
452                                 r[r.length] = a[i][k];
453                 else if ( a[i] !== null )
454                         r[r.length] =
455                                 a[i].nodeType ? a[i] : document.createTextNode(a[i].toString());
456         }
457         return r;
458 };
459
460 jQuery.g = {
461         "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
462         "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
463         ":": {
464                 lt: "i<m[3]-0",
465                 gt: "i>m[3]-0",
466                 nth: "m[3]-0==i",
467                 eq: "m[3]-0==i",
468                 first: "i==0",
469                 last: "i==r.length-1",
470                 even: "i%2==0",
471                 odd: "i%2==1",
472                 "first-child": "jQuery.sibling(a,0).cur",
473                 "nth-child": "(m[3]=='even'?jQuery.sibling(a,m[3]).n%2==0:(m[3]=='odd'?jQuery.sibling(a,m[3]).n%2==1:jQuery.sibling(a,m[3]).cur))",
474                 "last-child": "jQuery.sibling(a,0,true).cur",
475                 "nth-last-child": "jQuery.sibling(a,m[3],true).cur",
476                 "first-of-type": "jQuery.ofType(a,0)",
477                 "nth-of-type": "jQuery.ofType(a,m[3])",
478                 "last-of-type": "jQuery.ofType(a,0,true)",
479                 "nth-last-of-type": "jQuery.ofType(a,m[3],true)",
480                 "only-of-type": "jQuery.ofType(a)==1",
481                 "only-child": "jQuery.sibling(a).length==1",
482                 parent: "a.childNodes.length",
483                 empty: "!a.childNodes.length",
484                 root: "a==(a.ownerDocument||document).documentElement",
485                 contains: "(a.innerText||a.innerHTML).indexOf(m[3])!=-1",
486                 visible: "(!a.type||a.type!='hidden')&&(jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!= 'hidden')",
487                 hidden: "(a.type&&a.type=='hidden')||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')== 'hidden'",
488                 enabled: "!a.disabled",
489                 disabled: "a.disabled",
490                 checked: "a.checked"
491         },
492         ".": "jQuery.hasWord(a,m[2])",
493         "@": {
494                 "=": "jQuery.attr(a,m[3])==m[4]",
495                 "!=": "jQuery.attr(a,m[3])!=m[4]",
496                 "~=": "jQuery.hasWord(jQuery.attr(a,m[3]),m[4])",
497                 "|=": "!jQuery.attr(a,m[3]).indexOf(m[4])",
498                 "^=": "!jQuery.attr(a,m[3]).indexOf(m[4])",
499                 "$=": "jQuery.attr(a,m[3]).substr( jQuery.attr(a,m[3]).length - m[4].length,m[4].length )==m[4]",
500                 "*=": "jQuery.attr(a,m[3]).indexOf(m[4])>=0",
501                 "": "m[3]=='*'?a.attributes.length>0:jQuery.attr(a,m[3])"
502         },
503         "[": "jQuery.Select(m[2],a).length"
504 };
505
506 jQuery.token = [
507         "\\.\\.|/\\.\\.", "a.parentNode",
508         ">|/", "jQuery.sibling(a.firstChild)",
509         "\\+", "jQuery.sibling(a).next",
510         "~", function(a){
511                 var r = [];
512                 var s = jQuery.sibling(a);
513                 if ( s.n > 0 )
514                         for ( var i = s.n; i < s.length; i++ )
515                                 r[r.length] = s[i];
516                 return r;
517         }
518 ];
519
520 jQuery.Select = function( t, context ) {
521         context = context || jQuery.context || document;
522         if ( t.constructor != String )
523                 return t.constructor == Array ? t : [t];
524
525         if ( !t.indexOf("//") ) {
526                 context = context.documentElement;
527                 t = t.substr(2,t.length);
528         } else if ( !t.indexOf("/") ) {
529                 context = context.documentElement;
530                 t = t.substr(1,t.length);
531                 // FIX Assume the root element is right :(
532                 if ( t.indexOf("/") >= 1 )
533                         t = t.substr(t.indexOf("/"),t.length);
534         }
535
536         var ret = [context];
537         var done = [];
538         var last = null;
539
540         while ( t.length > 0 && last != t ) {
541     var r = [];
542                 last = t;
543
544     t = jQuery.cleanSpaces(t).replace( /^\/\//i, "" );
545                 
546                 var foundToken = false;
547                 
548                 for ( var i = 0; i < jQuery.token.length; i += 2 ) {
549                         var re = new RegExp("^(" + jQuery.token[i] + ")");
550                         var m = re.exec(t);
551                         
552                         if ( m ) {
553                                 r = ret = jQuery.map( ret, jQuery.token[i+1] );
554                                 t = jQuery.cleanSpaces( t.replace( re, "" ) );
555                                 foundToken = true;
556                         }
557                 }
558                 
559                 if ( !foundToken ) {
560
561                         if ( !t.indexOf(",") || !t.indexOf("|") ) {
562                                 if ( ret[0] == context ) ret.shift();
563                                 done = jQuery.merge( done, ret );
564                                 r = ret = [context];
565                                 t = " " + t.substr(1,t.length);
566                         } else {
567                                 var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
568                                 var m = re2.exec(t);
569         
570                                 if ( m[1] == "#" ) {
571                                         // Ummm, should make this work in all XML docs
572                                         var oid = document.getElementById(m[2]);
573                                         r = ret = oid ? [oid] : [];
574                                         t = t.replace( re2, "" );
575                                 } else {
576                                         if ( !m[2] || m[1] == "." ) m[2] = "*";
577         
578                                         for ( var i = 0; i < ret.length; i++ )
579                                                 r = jQuery.merge( r,
580                                                         m[2] == "*" ?
581                                                                 jQuery.getAll(ret[i]) :
582                                                                 ret[i].getElementsByTagName(m[2])
583                                                 );
584                                 }
585                         }
586                         
587                 }
588
589                 if ( t ) {
590                         var val = jQuery.filter(t,r);
591                         ret = r = val.r;
592                         t = jQuery.cleanSpaces(val.t);
593                 }
594         }
595
596         if ( ret && ret[0] == context ) ret.shift();
597         done = jQuery.merge( done, ret );
598
599         return done;
600 };
601
602 jQuery.getAll = function(o,r) {
603         r = r || [];
604         var s = o.childNodes;
605         for ( var i = 0; i < s.length; i++ )
606                 if ( s[i].nodeType == 1 ) {
607                         r[r.length] = s[i];
608                         jQuery.getAll( s[i], r );
609                 }
610         return r;
611 };
612
613 jQuery.attr = function(o,a,v){
614         if ( a && a.constructor == String ) {
615                 var fix = {
616                         "for": "htmlFor",
617                         "class": "className",
618                         "float": "cssFloat"
619                 };
620                 a = (fix[a] && fix[a].replace && fix[a]) || a;
621                 var r = /-([a-z])/ig;
622                 a = a.replace(r,function(z,b){return b.toUpperCase();});
623                 if ( v != undefined ) {
624                         o[a] = v;
625                         if ( o.setAttribute && a != "disabled" )
626                                 o.setAttribute(a,v);
627                 }
628                 return o[a] || o.getAttribute(a) || "";
629         } else
630                 return "";
631 };
632
633 jQuery.filter = function(t,r,not) {
634         var g = jQuery.grep;
635         if ( not === false )
636                 g = function(a,f) {return jQuery.grep(a,f,true);};
637
638         while ( t && t.match(/^[:\\.#\\[a-zA-Z\\*]/) ) {
639                 var re = /^\[ *@([a-z0-9*()_-]+) *([~!|*$^=]*) *'?"?([^'"]*)'?"? *\]/i;
640                 var m = re.exec(t);
641
642                 if ( m )
643                         m = ["", "@", m[2], m[1], m[3]];
644                 else {
645                         re = /^(\[) *([^\]]*) *\]/i;
646                         m = re.exec(t);
647
648                         if ( !m ) {
649                                 re = /^(:)([a-z0-9*_-]*)\( *["']?([^ \)'"]*)['"]? *\)/i;
650                                 m = re.exec(t);
651
652                                 if ( !m ) {
653                                         re = /^([:\.#]*)([a-z0-9*_-]*)/i;
654                                         m = re.exec(t);
655                                 }
656                         }
657                 }
658                 t = t.replace( re, "" );
659
660                 if ( m[1] == ":" && m[2] == "not" )
661                         r = jQuery.filter(m[3],r,false).r;
662                 else {
663                         var f = null;
664
665                         if ( jQuery.g[m[1]].constructor == String )
666                                 f = jQuery.g[m[1]];
667                         else if ( jQuery.g[m[1]][m[2]] )
668                                 f = jQuery.g[m[1]][m[2]];
669
670                         if ( f ) {
671                                 eval("f = function(a,i){return " + f + "}");
672                                 r = g( r, f );
673                         }
674                 }
675         }
676
677         return { r: r, t: t };
678 };
679
680 jQuery.parents = function(a){
681         var b = [];
682         var c = a.parentNode;
683         while ( c && c != document ) {
684                 b[b.length] = c;
685                 c = c.parentNode;
686         }
687         return b;
688 };
689
690 jQuery.cleanSpaces = function(t){
691         return t.replace(/^\s+|\s+$/g, "");
692 };
693
694 jQuery.ofType = function(a,n,e) {
695         var t = jQuery.grep(jQuery.sibling(a),function(b){ return b.nodeName == a.nodeName; });
696         if ( e ) n = t.length - n - 1;
697         return n != undefined ? t[n] == a : t.length;
698 };
699
700 jQuery.sibling = function(a,n,e) {
701         var type = [];
702         var tmp = a.parentNode.childNodes;
703         for ( var i = 0; i < tmp.length; i++ ) {
704                 if ( tmp[i].nodeType == 1 )
705                         type[type.length] = tmp[i];
706                 if ( tmp[i] == a )
707                         type.n = type.length - 1;
708         }
709         if ( e ) n = type.length - n - 1;
710         type.cur = ( type[n] == a );
711         type.prev = ( type.n > 0 ? type[type.n - 1] : null );
712         type.next = ( type.n < type.length - 1 ? type[type.n + 1] : null );
713         return type;
714 };
715
716 jQuery.hasWord = function(e,a) {
717         if ( e == undefined ) return;
718         if ( e.className ) e = e.className;
719         return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
720 };
721
722 jQuery.merge = function(a,b) {
723         var d = [];
724         for ( var k = 0; k < b.length; k++ ) d[k] = b[k];
725
726         for ( var i = 0; i < a.length; i++ ) {
727                 var c = true;
728                 for ( var j = 0; j < b.length; j++ )
729                         if ( a[i] == b[j] )
730                                 c = false;
731                 if ( c ) d[d.length] = a[i];
732         }
733
734         return d;
735 };
736
737 jQuery.grep = function(a,f,s) {
738         if ( f.constructor == String )
739                 f = new Function("a","i","return " + f);
740         var r = [];
741         if ( a )
742                 for ( var i = 0; i < a.length; i++ )
743                         if ( (!s && f(a[i],i)) || (s && !f(a[i],i)) )
744                                 r[r.length] = a[i];
745         return r;
746 };
747
748 jQuery.map = function(a,f) {
749         if ( f.constructor == String )
750                 f = new Function("a","return " + f);
751         
752         var r = [];
753         for ( var i = 0; i < a.length; i++ ) {
754                 var t = f(a[i],i);
755                 if ( t !== null && t != undefined ) {
756                         if ( t.constructor != Array ) t = [t];
757                         r = jQuery.merge( t, r );
758                 }
759         }
760         return r;
761 };
762
763 jQuery.event = {
764
765         // Bind an event to an element
766         // Original by Dean Edwards
767         add: function(element, type, handler) {
768                 // For whatever reason, IE has trouble passing the window object
769                 // around, causing it to be cloned in the process
770                 if ( jQuery.browser == "msie" && element.setInterval != undefined )
771                         element = window;
772         
773                 if (!handler.guid) handler.guid = jQuery.event.guid++;
774                 if (!element.events) element.events = {};
775                 var handlers = element.events[type];
776                 if (!handlers) {
777                         handlers = element.events[type] = {};
778                         if (element["on" + type])
779                                 handlers[0] = element["on" + type];
780                 }
781                 handlers[handler.guid] = handler;
782                 element["on" + type] = jQuery.event.handle;
783         },
784         
785         guid: 1,
786         
787         // Detach an event or set of events from an element
788         remove: function(element, type, handler) {
789                 if (element.events)
790                         if (type && element.events[type])
791                                 if ( handler )
792                                         delete element.events[type][handler.guid];
793                                 else
794                                         for ( var i in element.events[type] )
795                                                 delete element.events[type][i];
796                         else
797                                 for ( var j in element.events )
798                                         jQuery.event.remove( element, j );
799         },
800         
801         trigger: function(element,type,data) {
802                 data = data || [ jQuery.event.fix({ type: type }) ];
803                 if ( element && element["on" + type] )
804                         element["on" + type].apply( element, data );
805         },
806         
807         handle: function(event) {
808                 // Handle adding events to items in IFrames, in IE
809                 event = event ||
810                         jQuery.event.fix( ((this.ownerDocument || this.document || 
811                                 this).parentWindow || window).event );
812
813                 // If no correct event was found, fail
814                 if ( !event ) return;
815         
816                 var returnValue = true, handlers = [];
817         
818                 for ( var j in this.events[event.type] )
819                         handlers[handlers.length] = this.events[event.type][j];
820         
821                 for ( var i = 0; i < handlers.length; i++ )
822                         if ( handlers[i].constructor == Function ) {
823                                 this.handleEvent = handlers[i];
824                                 if (this.handleEvent(event) === false) {
825                                         event.preventDefault();
826                                         event.stopPropagation();
827                                         returnValue = false;
828                                 }
829                         }
830                 return returnValue;
831         },
832         
833         fix: function(event) {
834                 if ( event ) {
835                         event.preventDefault = function() {
836                                 this.returnValue = false;
837                         };
838                 
839                         event.stopPropagation = function() {
840                                 this.cancelBubble = true;
841                         };
842                 }
843                 
844                 return event;
845         }
846
847 };