(function(a){a.extend(a.fn,{livequery:function(c,e,f){var g=this,h;if(a.isFunction(c))f=e,e=c,c=undefined;a.each(a.livequery.queries,function(d,b){if(g.selector==b.selector&&g.context==b.context&&c==b.type&&(!e||e.$lqguid==b.fn.$lqguid)&&(!f||f.$lqguid==b.fn2.$lqguid))return(h=b)&&false});h=h||new a.livequery(this.selector,this.context,c,e,f);h.stopped=false;a.livequery.run(h.id);return this},expire:function(c,e,f){var g=this;if(a.isFunction(c))f=e,e=c,c=undefined;a.each(a.livequery.queries,function(d,b){if(g.selector==b.selector&&g.context==b.context&&(!c||c==b.type)&&(!e||e.$lqguid==b.fn.$lqguid)&&(!f||f.$lqguid==b.fn2.$lqguid)&&!this.stopped)a.livequery.stop(b.id)});return this}});a.livequery=function(d,b,c,e,f){this.selector=d;this.context=b||document;this.type=c;this.fn=e;this.fn2=f;this.elements=[];this.stopped=false;this.id=a.livequery.queries.push(this)-1;e.$lqguid=e.$lqguid||a.livequery.guid++;if(f)f.$lqguid=f.$lqguid||a.livequery.guid++;return this};a.livequery.prototype={stop:function(){var d=this;if(this.type)this.elements.unbind(this.type,this.fn);else if(this.fn2)this.elements.each(function(i,el){d.fn2.apply(el)});this.elements=[];this.stopped=true},run:function(){if(this.stopped)return;var d=this;var b=this.elements,c=a(this.selector,this.context),e=c.not(b);this.elements=c;if(this.type){e.bind(this.type,this.fn);if(b.length>0)a.each(b,function(i,el){if(a.inArray(el,c)<0)a.event.remove(el,d.type,d.fn)})}else{e.each(function(){d.fn.apply(this)});if(this.fn2&&b.length>0)a.each(b,function(i,el){if(a.inArray(el,c)<0)d.fn2.apply(el)})}}};a.extend(a.livequery,{guid:0,queries:[],queue:[],running:false,timeout:null,checkQueue:function(){if(a.livequery.running&&a.livequery.queue.length){var d=a.livequery.queue.length;while(d--)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,c){if(!a.fn[c])return;var e=a.fn[c];a.fn[c]=function(){var d=e.apply(this,arguments);a.livequery.run();return d}})},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(d){if(a.inArray(d,a.livequery.queue)<0)a.livequery.queue.push(d)});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(d){a.livequery.queries[d].stop()})}});a.livequery.registerPlugin('append','prepend','after','before','wrap','attr','removeAttr','addClass','removeClass','toggleClass','empty','remove');a(function(){a.livequery.play()});var j=a.prototype.init;a.prototype.init=function(d,b){var c=j.apply(this,arguments);if(d&&d.selector)c.context=d.context,c.selector=d.selector;if(typeof d=='string')c.context=b||document,c.selector=d;return c};a.prototype.init.prototype=a.prototype})(jQuery);