/* jquery.event.drop.js * v1.2 Copyright (c) 2008-2009, Three Dub Media (http://threedubmedia.com) Liscensed under the MIT License (http://threedubmedia.googlecode.com/files/MIT-LICENSE.txt) */ (function(f){f.fn.drop=function(i,h,g){if(h){this.bind("dropstart",i)}if(g){this.bind("dropend",g)}return !i?this.trigger("drop"):this.bind("drop",h?h:i)};f.dropManage=function(g){g=g||{};c.data=[];c.filter=g.filter||"*";c.delay=g.delay||c.delay;c.tolerance=g.tolerance||null;c.mode=g.mode||c.mode||"intersect";return c.$targets.filter(c.filter).each(function(){c.data[c.data.length]=c.locate(this)})};var d=f.event,b=d.special,c=b.drop={delay:100,mode:"intersect",$targets:f([]),data:[],setup:function(){c.$targets=c.$targets.add(this);c.data[c.data.length]=c.locate(this)},teardown:function(){var g=this;c.$targets=c.$targets.not(this);c.data=f.grep(c.data,function(h){return(h.elem!==g)})},handler:function(h){var g=null,i;h.dropTarget=c.dropping||undefined;if(c.data.length&&h.dragTarget){switch(h.type){case"drag":c.event=h;if(!c.timer){c.timer=setTimeout(e,20)}break;case"mouseup":c.timer=clearTimeout(c.timer);if(!c.dropping){break}if(c.allowed){i=a(h,"drop",c.dropping)}g=false;case c.dropping&&"dropstart":g=g===null&&c.allowed?true:false;case c.dropping&&"dropend":a(h,"dropend",c.dropping);c.dropping=null;if(i===false){h.dropTarget=undefined}if(!g){break}case c.allowed&&"dropstart":h.dropTarget=this;c.dropping=a(h,"dropstart",this)!==false?this:null;break}}},locate:function(k){var i=f(k),l=i.offset(),j=i.outerHeight(),g=i.outerWidth();return{elem:k,L:l.left,R:l.left+g,T:l.top,B:l.top+j,W:g,H:j}},contains:function(g,h){return((h[0]||h.L)>=g.L&&(h[0]||h.R)<=g.R&&(h[1]||h.T)>=g.T&&(h[1]||h.B)<=g.B)},modes:{intersect:function(h,g,i){return this.contains(i,[h.pageX,h.pageY])?i:this.modes.overlap.apply(this,arguments)},overlap:function(h,g,i){i.overlap=Math.max(0,Math.min(i.B,g.B)-Math.max(i.T,g.T))*Math.max(0,Math.min(i.R,g.R)-Math.max(i.L,g.L));if(i.overlap>((this.best||{}).overlap||0)){this.best=i}return null},fit:function(h,g,i){return this.contains(i,g)?i:null},middle:function(h,g,i){return this.contains(i,[g.L+g.W/2,g.T+g.H/2])?i:null}}};function a(k,i,j){k.type=i;try{var g=d.handle.call(j,k)}catch(h){}return g===false?false:g||k.result}function e(){var h=0,g,j,k=[c.event.pageX,c.event.pageY],l=c.locate(c.event.dragProxy);c.tolerance=c.tolerance||c.modes[c.mode];do{if(g=c.data[h]){j=c.tolerance?c.tolerance.call(c,c.event,l,g):c.contains(g,k)?g:null}}while(++h