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