(function(a){a.extend(a.fn,{liveQuery:function(b,c,d){var e=this,f;if(a.isFunction(b)){d=c;c=b;b=undefined}a.each(a.liveQuery.queries,function(g,h){if(e.selector==h.selector&&e.context==h.context&&b==h.type&&(!c||c.$lqguid==h.fn.$lqguid)&&(!d||d.$lqguid==h.fn2.$lqguid))return(f=h)&&false});f=f||new a.liveQuery(this.selector,this.context,b,c,d);f.stopped=false;f.run();return this},expire:function(b,c,d){var e=this;if(a.isFunction(b)){d=c;c=b;b=undefined}a.each(a.liveQuery.queries,function(f,g){if(e.selector==
g.selector&&e.context==g.context&&(!b||b==g.type)&&(!c||c.$lqguid==g.fn.$lqguid)&&(!d||d.$lqguid==g.fn2.$lqguid)&&!this.stopped)a.liveQuery.stop(g.id)});return this}});a.liveQuery=function(b,c,d,e,f){this.selector=b;this.context=c||document;this.type=d;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 b=this;if(this.type)this.elements.unbind(this.type,
this.fn);else this.fn2&&this.elements.each(function(c,d){b.fn2.apply(d)});this.elements=[];this.stopped=true},run:function(){if(!this.stopped){var b=this,c=this.elements,d=a(this.selector,this.context),e=d.not(c);this.elements=d;if(this.type){e.bind(this.type,this.fn);c.length>0&&a.each(c,function(f,g){a.inArray(g,d)<0&&a.event.remove(g,b.type,b.fn)})}else{e.each(function(){b.fn.apply(this)});this.fn2&&c.length>0&&a.each(c,function(f,g){a.inArray(g,d)<0&&b.fn2.apply(g)})}}}};a.extend(a.liveQuery,
{guid:0,queries:[],queue:[],running:false,timeout:null,checkQueue:function(){if(a.liveQuery.running&&a.liveQuery.queue.length)for(var b=a.liveQuery.queue.length;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,c){if(a.fn[c]){var d=a.fn[c];a.fn[c]=function(){var e=d.apply(this,arguments);a.liveQuery.run();return e}}})},run:function(b){if(b!=
undefined)a.inArray(b,a.liveQuery.queue)<0&&a.liveQuery.queue.push(b);else a.each(a.liveQuery.queries,function(c){a.inArray(c,a.liveQuery.queue)<0&&a.liveQuery.queue.push(c)});a.liveQuery.timeout&&clearTimeout(a.liveQuery.timeout);a.liveQuery.timeout=setTimeout(a.liveQuery.checkQueue,20)},stop:function(b){b!=undefined?a.liveQuery.queries[b].stop():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()});var i=a.prototype.init;a.prototype.init=function(b,c){var d=i.apply(this,arguments);if(b&&b.selector){d.context=b.context;d.selector=b.selector}if(typeof b=="string"){d.context=c||document;d.selector=b}return d};a.prototype.init.prototype=a.prototype})(jQuery);
