/* 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(J){var H=F(J),K=H.offset(),I=H.outerHeight(),G=H.outerWidth();return{elem:J,L:K.left,R:K.left+G,T:K.top,B:K.top+I,W:G,H:I}},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,I,J=[C.event.pageX,C.event.pageY],K=C.locate(C.event.dragProxy);C.tolerance=C.tolerance||C.modes[C.mode];do{if(G=C.data[H]){I=C.tolerance?C.tolerance.call(C,C.event,K,G):C.contains(G,J)?G:null}}while(++H<C.data.length&&!I);C.event.type=(I=I||C.best)?"dropstart":"dropend";if(C.event.type=="dropend"||I.elem!=C.dropping){C.handler.call(I?I.elem:C.dropping,C.event)}if(C.last&&J[0]==C.last.pageX&&J[1]==C.last.pageY){delete C.timer}else{C.timer=setTimeout(E,C.delay)}C.last=C.event;C.best=null}})(jQuery);