﻿//
//This file contains the necessary functions for drag&drop support of the gallery
//

//handler for start dragging
function dragStart(sender, eventArgs)
{
    if(!zoomedIn){
        dragEnabled = true;
        sender.captureMouse();

        dragStartX = eventArgs.getPosition(null).X;
        dragStartY = eventArgs.getPosition(null).Y;
    }
}

//handler for stop dragging
function dragStop(sender, eventArgs)
{
    if(!zoomedIn)
    {
        dragEnabled = false;
        sender.releaseMouseCapture();
    }
}

//handler for dragging (here the content is moved according to the mouse movements)
function drag(sender, eventArgs)
{
    if(dragEnabled)
    {
        photoCanvas["Canvas.Left"] += eventArgs.getPosition(null).X - dragStartX;
        photoCanvas["Canvas.Top"] += eventArgs.getPosition(null).Y - dragStartY;
        
        dragStartX = eventArgs.getPosition(null).X;
        dragStartY = eventArgs.getPosition(null).Y;
    }
}

//happens when the user clicks on an image
function imageButtonDown(sender, eventArgs)
{
    //set the click time to distinuish between a click on the image and a drag operation (see the imageButtonUp)
    imageClickTime = (new Date()).getTime();
    dragStart(sender, eventArgs);
}

//happens when the mousebutton is released on an image
function imageButtonUp(sender, eventArgs)
{
    dragStop(sender, eventArgs);
    
    //to distinguish between "clicks" on an image and drag operations, we compare the current time to the timestamp, when the mousebutton was pressed down.
    //if the timespan is smaller than 200ms, it's counted as a click and the zoom (in or out) is started
    if((new Date()).getTime() - imageClickTime < 200)
    {
        clickedImage = sender;
        if(zoomedIn)
        {
            btnPauseClick();
            zoomOutStep1();
        }
        else 
        {
            zoomInStep1(sender, eventArgs);
        }
    }
}