﻿/*coolapp@163.com*/(function($){
    $.fn.drag=function(h){
        return this.each(function(){
            var me=$(this);
            var hdl=me.find('.drag');
            if (hdl.length<1)
                hdl=typeof h=='object'? h : me;
            hdl.css('cursor','move');
            var _move=false;
            if(isNaN(parseInt(me.css("left"))))me.css("left",me.offset().left+me.parent().offset().left);
            if(isNaN(parseInt(me.css("top"))))me.css("top",me.offset().top+me.parent().offset().top);
            hdl.mousedown(function(e){
                _move=true;
                _x=e.pageX-parseInt(me.css("left"));
                _y=e.pageY-parseInt(me.css("top"));
                me.fadeTo(200,.95);
                $(document).unbind('mousemove').mousemove(function(e){
                    var x=e.pageX-_x;
                    var y=e.pageY-_y;
                    me.css({top:y,left:x});
                }).bind('selectstart',function(){return false;}).css('-moz-user-select','none');
            }).mouseup(function(e){
                $(document).unbind('mousemove').unbind('selectstart').css('-moz-user-select','');
                _move=false;
                me.fadeTo(20,1);
            });
        });
    }
})(jQuery);
