/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (MIT_LICENSE.txt)
 * and GPL Version 2 (GPL_LICENSE.txt) licenses.
 *
 * Version: 1.1.1
 * Requires jQuery 1.3+
 * Docs: http://docs.jquery.com/Plugins/livequery
 */

(function($){$.extend($.fn,{livequery:function(type,fn,fn2){var self=this,q;if($.isFunction(type))fn2=fn,fn=type,type=undefined;$.each($.livequery.queries,function(i,query){if(self.selector==query.selector&&self.context==query.context&&type==query.type&&(!fn||fn.$lqguid==query.fn.$lqguid)&&(!fn2||fn2.$lqguid==query.fn2.$lqguid))return(q=query)&&false});q=q||new $.livequery(this.selector,this.context,type,fn,fn2);q.stopped=false;q.run();return this},expire:function(type,fn,fn2){var self=this;if($.isFunction(type))fn2=fn,fn=type,type=undefined;$.each($.livequery.queries,function(i,query){if(self.selector==query.selector&&self.context==query.context&&(!type||type==query.type)&&(!fn||fn.$lqguid==query.fn.$lqguid)&&(!fn2||fn2.$lqguid==query.fn2.$lqguid)&&!this.stopped)$.livequery.stop(query.id)});return this}});$.livequery=function(selector,context,type,fn,fn2){this.selector=selector;this.context=context;this.type=type;this.fn=fn;this.fn2=fn2;this.elements=[];this.stopped=false;this.id=$.livequery.queries.push(this)-1;fn.$lqguid=fn.$lqguid||$.livequery.guid++;if(fn2)fn2.$lqguid=fn2.$lqguid||$.livequery.guid++;return this};$.livequery.prototype={stop:function(){var query=this;if(this.type)this.elements.unbind(this.type,this.fn);else if(this.fn2)this.elements.each(function(i,el){query.fn2.apply(el)});this.elements=[];this.stopped=true},run:function(){if(this.stopped)return;var query=this;var oEls=this.elements,els=$(this.selector,this.context),nEls=els.not(oEls);this.elements=els;if(this.type){nEls.bind(this.type,this.fn);if(oEls.length>0)$.each(oEls,function(i,el){if($.inArray(el,els)<0)$.event.remove(el,query.type,query.fn)})}else{nEls.each(function(){query.fn.apply(this)});if(this.fn2&&oEls.length>0)$.each(oEls,function(i,el){if($.inArray(el,els)<0)query.fn2.apply(el)})}}};$.extend($.livequery,{guid:0,queries:[],queue:[],running:false,timeout:null,checkQueue:function(){if($.livequery.running&&$.livequery.queue.length){var length=$.livequery.queue.length;while(length--)$.livequery.queries[$.livequery.queue.shift()].run()}},pause:function(){$.livequery.running=false},play:function(){$.livequery.running=true;$.livequery.run()},registerPlugin:function(){$.each(arguments,function(i,n){if(!$.fn[n])return;var old=$.fn[n];$.fn[n]=function(){var r=old.apply(this,arguments);$.livequery.run();return r}})},run:function(id){if(id!=undefined){if($.inArray(id,$.livequery.queue)<0)$.livequery.queue.push(id)}else $.each($.livequery.queries,function(id){if($.inArray(id,$.livequery.queue)<0)$.livequery.queue.push(id)});if($.livequery.timeout)clearTimeout($.livequery.timeout);$.livequery.timeout=setTimeout($.livequery.checkQueue,20)},stop:function(id){if(id!=undefined)$.livequery.queries[id].stop();else $.each($.livequery.queries,function(id){$.livequery.queries[id].stop()})}});$.livequery.registerPlugin('append','prepend','after','before','wrap','attr','removeAttr','addClass','removeClass','toggleClass','empty','remove','html');$(function(){$.livequery.play()})})(jQuery);


/**
 * Appendo Plugin for jQuery v1.01
 * Creates interface to create duplicate clones of last table row (usually for forms)
 * (c) 2008 Kelly Hallman. Free software released under MIT License.
 * See http://deepliquid.com/content/Appendo.html for more info
 */

jQuery.fn.appendo=function(opt){this.each(function(){jQuery.appendo.init(this,opt)});return this};jQuery.appendo=function(){var myself=this;this.opt={};this.init=function(obj,opt){var options=jQuery.extend({labelAdd:'Add Row',labelDel:'Remove',allowDelete:true,copyHandlers:false,focusFirst:true,onAdd:function(){return true},onDel:function(){return true},maxRows:0,wrapClass:'appendoButtons',wrapStyle:{padding:'.4em .2em .5em'},buttonStyle:{marginRight:'.5em'},subSelect:'tr:last'},myself.opt,opt);var $cpy=jQuery(obj).find(options.subSelect).clone(options.copyHandlers);var rows=1;var $add_btn=jQuery('#form-child-add').click(clicked_add),$del_btn=new_button(options.labelDel).click(clicked_del).hide();function add_row(){var $dup=$cpy.clone(options.copyHandlers);$dup.appendTo(obj);update_buttons(1);if(typeof(options.onAdd)=="function")options.onAdd($dup);if(!!options.focusFirst)$dup.find('input:first').focus()};function del_row(){var $row=jQuery(obj).find(options.subSelect);if((typeof(options.onDel)!="function")||options.onDel($row)){$row.remove();update_buttons(-1)}};function update_buttons(rowdelta){rows=rows+(rowdelta||0);(options.allowDelete&&(rows>1))?$del_btn.show():$del_btn.hide()};function new_button(label){return jQuery('<button />').css(options.buttonStyle).html(label)};function nothing(e){e.stopPropagation();e.preventDefault();return false};function clicked_add(e){if(!options.maxRows||(rows<options.maxRows))add_row();return nothing(e)};function clicked_del(e){if(rows>1)del_row();return nothing(e)};update_buttons()};return this}();
