﻿var od = document.getElementById("back");
var back = document.getElementById("divShadow");
var dx, dy, mx, my, mouseD;
var odrag;
var isIE = document.all ? true : false;
document.onmousedown = function(e) {
    var e = e ? e : event;
    if (e.button == (document.all ? 1 : 0)) {
        mouseD = true;
    }
}
document.onmouseup = function() {
    mouseD = false;
    odrag = "";
    if (isIE) {
        od.releaseCapture();
        back.releaseCapture();
    }
    else {
        window.releaseEvents(od.MOUSEMOVE);
        window.releaseEvents(back.MOUSEMOVE);
        od.style.opacity = 1;
        back.style.opacity = 1;
    }
}
od.onmousedown = function(e) {
    odrag = this;
    var e = e ? e : event;
    if (e.button == (document.all ? 1 : 0)) {
        mx = e.clientX;
        my = e.clientY;
        od.style.left = od.offsetLeft + "px";
        od.style.top = od.offsetTop + "px";
        back.style.left = (od.offsetLeft - 7) + "px";
        back.style.top = (od.offsetTop - 6) + "px";
        if (isIE) {
            od.setCapture();
            back.setCapture();
        }
        else {
            window.captureEvents(Event.MOUSEMOVE);
            od.style.opacity = 0.5;
            back.style.opacity = 0.5;
        }
    }
}
document.onmousemove = function(e) {
    var e = e ? e : event;
    if (mouseD == true && odrag) {
        var mrx = e.clientX - mx;
        var mry = e.clientY - my;
        od.style.left = parseInt(od.style.left) + mrx + "px";
        od.style.top = parseInt(od.style.top) + mry + "px";
        back.style.left = parseInt(od.style.left) + (mrx - 7) + "px";
        back.style.top = parseInt(od.style.top) + (mry - 6) + "px";
        mx = e.clientX;
        my = e.clientY;
    }
}