﻿$.fn.Drag=function(k){var e={modal:false,center:true,drag:null,clbtn:null,bgcss:""};var b=$.extend(e,k);g=$("<div></div>");var i=new Object();i[b.drag]=$(this);var c;var a;var g;if(b.clbtn){$("#"+b.clbtn).click(function(){j()})}var f=function(){$(this).unbind();document.onselectstart=function(){return true};i[b.drag].css({zIndex:1001})};var d=function(m){var l=m.clientX-c;var n=m.clientY-a;i[b.drag].setLocation({top:n,left:l,zIndex:600});return false};this.close=function(){j()};this.open=function(l){b.modal=l;if(b.modal){g.width($(document).width()).height($(document).height()).appendTo("body").show();if(b.bgcss){g.addClass(b.bgcss)}g.setLocation({zIndex:598})}h();i[b.drag].show();$(window).resize(h);$(window).scroll(h)};var h=function(){var l=document.documentElement.clientWidth/2-document.documentElement.scrollLeft-i[b.drag].width()/2;var m=document.documentElement.clientHeight/2+document.documentElement.scrollTop-i[b.drag].height()/2;l=Math.round(l);m=Math.round(m);i[b.drag].setLocation({top:m,left:l,zIndex:900}).show()};var j=function(){i[b.drag].hide();g.hide();$(window).unbind("resize",h);$(window).unbind("scroll",h)};$("#"+b.drag).mousedown(function(l){c=l.clientX-i[b.drag].offset().left;a=l.clientY-i[b.drag].offset().top;$(document).mousemove(d);$(document).mouseup(f);document.onselectstart=function(){return false};return false});return this};
