/* Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)  */
(function(D){D.fn.delegate=function(F,E,G,H){return this.each(function(){D.event.delegate.add(this,F,E,G,H)})};D.fn.undelegate=function(F,E,G){return this.each(function(){D.event.delegate.remove(this,F,E,G)})};D.event.delegate={add:function(J,G,E,H,K){if(arguments.length<4){return }var F=B(E,A),I=D.data(J,"delegates")||D.data(J,"delegates",{});D.each(B(G,C),function(M,N){var L=I[N]||(I[N]=[]);if(!L.length){D.event.add(J,N,D.event.delegate.handle,K)}D.each(F,function(P,O){if(!O.length){return }L[L.length]={selector:O,handler:H}})})},remove:function(J,G,E,H){var F=B(E,A),I=D.data(J,"delegates")||{};if(J&&!G){D.each(I,function(K){D.event.remove(J,K,D.event.delegate.handle)});D.removeData(J,"delegates");return }D.each(B(G,C),function(K,L){if(E&&E.length){I[L]=D.grep(I[L]||[],function(N,M){if(N){D.each(F,function(P,O){if(N.selector===O&&(!H||N.handler===H)){return(M=false)}})}return(M!==false)});if(I[L].length){return }}D.event.remove(J,L,D.event.delegate.handle);delete I[L]})},handle:function(H){H.delegateParent=this;var I=H.target,G=arguments,F,E=(D.data(this,"delegates")||{})[H.type]||[];if(E.length){do{D.each(E,function(J,K){if(K&&D(I).is(K.selector)){F=K.handler.apply(I,G);return(F!==false)}})}while(F!==false&&I!=this&&(I=I.parentNode))}return F}};var C=/\s+/,A=/\s*,\s*/;function B(F,E){return D.trim(F).split(E)}})(jQuery);