/* Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* Version: 1.1.0-pre
* Requires jQuery 1.3+
* Docs: http://docs.jquery.com/Plugins/livequery
*/
(function(a){a.extend(a.fn,{livequery:function(d,c,f){var e=this,b;if(a.isFunction(d)){f=c,c=d,d=undefined;}a.each(a.livequery.queries,function(h,g){if(e.selector==g.selector&&e.context==g.context&&d==g.type&&(!c||c.$lqguid==g.fn.$lqguid)&&(!f||f.$lqguid==g.fn2.$lqguid)){return(b=g)&&false;}});b=b||new a.livequery(this.selector,this.context,d,c,f);b.stopped=false;b.run();return this;},expire:function(c,b,e){var d=this;if(a.isFunction(c)){e=b,b=c,c=undefined;}a.each(a.livequery.queries,function(g,f){if(d.selector==f.selector&&d.context==f.context&&(!c||c==f.type)&&(!b||b.$lqguid==f.fn.$lqguid)&&(!e||e.$lqguid==f.fn2.$lqguid)&&!this.stopped){a.livequery.stop(f.id);}});return this;}});a.livequery=function(e,b,d,c,f){this.selector=e;this.context=b;this.type=d;this.fn=c;this.fn2=f;this.elements=[];this.stopped=false;this.id=a.livequery.queries.push(this)-1;c.$lqguid=c.$lqguid||a.livequery.guid++;if(f){f.$lqguid=f.$lqguid||a.livequery.guid++;}return this;};a.livequery.prototype={stop:function(){var b=this;if(this.type){this.elements.unbind(this.type,this.fn);}else{if(this.fn2){this.elements.each(function(d,c){b.fn2.apply(c);});}}this.elements=[];this.stopped=true;},run:function(){if(this.stopped){return;}var d=this;var e=this.elements,c=a(this.selector,this.context),b=c.not(e);this.elements=c;if(this.type){b.bind(this.type,this.fn);if(e.length>0){a.each(e,function(g,f){if(a.inArray(f,c)<0){a.event.remove(f,d.type,d.fn);}});}}else{b.each(function(){d.fn.apply(this);});if(this.fn2&&e.length>0){a.each(e,function(g,f){if(a.inArray(f,c)<0){d.fn2.apply(f);}});}}}};a.extend(a.livequery,{guid:0,queries:[],queue:[],running:false,timeout:null,checkQueue:function(){if(a.livequery.running&&a.livequery.queue.length){var b=a.livequery.queue.length;while(b--){a.livequery.queries[a.livequery.queue.shift()].run();}}},pause:function(){a.livequery.running=false;},play:function(){a.livequery.running=true;a.livequery.run();},registerPlugin:function(){a.each(arguments,function(b,d){if(!a.fn[d]){return;}var c=a.fn[d];a.fn[d]=function(){var e=c.apply(this,arguments);a.livequery.run();return e;};});},run:function(b){if(b!=undefined){if(a.inArray(b,a.livequery.queue)<0){a.livequery.queue.push(b);}}else{a.each(a.livequery.queries,function(c){if(a.inArray(c,a.livequery.queue)<0){a.livequery.queue.push(c);}});}if(a.livequery.timeout){clearTimeout(a.livequery.timeout);}a.livequery.timeout=setTimeout(a.livequery.checkQueue,20);},stop:function(b){if(b!=undefined){a.livequery.queries[b].stop();}else{a.each(a.livequery.queries,function(c){a.livequery.queries[c].stop();});}}});a.livequery.registerPlugin("append","prepend","after","before","wrap","attr","removeAttr","addClass","removeClass","toggleClass","empty","remove");a(function(){a.livequery.play();});})(jQuery);