I have written the following:

```
var motion;
var yPosStart = 0;
var yPosEnd = 0;
var lastDrag;
var mouseDown = false;

function drag(){
    $("*")
    .mousedown(function() {
        $(window).unbind('mousedown');
        if( mouseDown === false ) {
            mouseDown = true;
            $(window).mousemove(function(e) {
                if( yPosStart == 0 ) {
                    yPosStart = e.pageY;
                }else{
                    yPosEnd = e.pageY;  
                }
            });
        }
    })
    .mouseup(function() {
        mouseDown = false;
        lastDrag = ( yPosStart < yPosEnd ? 'down' : 'up' );
        yPosStart = 0;
        yPosEnd = 0;
        alert( lastDrag );
        $(window).bind('mousedown');
    });
}

```

I am trying to detect a drag down or drag up, but I also want to know how far. This does not seem to be working correctly and also alerts multiple times in some instances. Can anyone advise me where I am going wrong please.