var cntl;
var spotOn = true;
var _height;
var _width;
var _radius = 70;
var _radiusFull = 330;

if (!window.ItalyMap)
	window.ItalyMap = {};

ItalyMap.Page = function() 
{
}

ItalyMap.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		cntl = control;
		_height = cntl.content.findName("Page").Height;
		_width = cntl.content.findName("Page").Width;
		target = cntl.content.findName("Spot");
		setRadius(target, _radius);
		target = cntl.content.findName("SpotBorder");
		setRadius(target, _radius);
		
		// Sample event hookup:	
        	rootElement.addEventListener("MouseMove", handleMouseMove);
       		rootElement.addEventListener("MouseLeave", handleMouseLeave);
		rootElement.addEventListener("MouseLeftButtonDown", handleMouseDown);
		rootElement.addEventListener("MouseLeftButtonUp", handleMouseUp);
	}
}

function handleMouseMove(sender, mouseEventArgs) {
    if (spotOn) {
        var pt = mouseEventArgs.getPosition(null);
        pX = pt.x;
        pY = pt.y;
    	sender.findName("Collage").Visibility = "Visible";
    	sender.findName("Spot").Center = pX + ',' + pY;
	sender.findName("SpotBorder").center = pX + ',' + pY;
        sender.findName("MoveSpot").Begin();
    }
}

function handleMouseLeave(sender, mouseEventArgs) {
    sender.findName("Collage").Visibility = "Collapsed";
    //cntl.content.findName("Mask").Visibility = "Visible";
    sender.findName("MoveSpot").Begin();
}

function handleMouseDown(sender, mouseEventArgs) {
    spotOn = false;
    target = sender.findName("Spot");
    target.Center = _width/2 + ',' + _height/2;
    setRadius(target, _radiusFull);
    sender.findName("SpotBorderCanvas").Visibility = "Collapsed";
    sender.ReleaseMouseCapture();
}

function handleMouseUp(sender, mouseEventArgs) {
    spotOn = true;
    sender.CaptureMouse();
    target = sender.findName("Spot");
    setRadius(target, _radius);
    sender.findName("SpotBorderCanvas").Visibility = "Visible";
    handleMouseMove(sender, mouseEventArgs);
}

function setRadius(target, radius) {
    target.RadiusX = radius;
    target.RadiusY = radius;
}

