<!--
/*
//        x: (event.clientX - rect.left) / (rect.right - rect.left) * canvas.width,
//        y: (event.clientY - rect.top) / (rect.bottom - rect.top) * canvas.height
  var target = event.target || event.srcElement;
//  event.pageX = event.pageX || (event.clientX + (document.scrollLeft || document.body.scrollLeft || 0) - (document.clientLeft || document.body.clientLeft || 0));
//  event.pageY = event.pageY || (event.clientY + (document.scrollTop  || document.body.scrollTop  || 0) - (document.clientTop  || document.body.clientTop  || 0));

	return {
		target: target,
		x: event.pageX - target.offsetLeft,
		y: event.pageY - target.offsetTop
		}
*/


//var canvas = MM.obj.canvas;
//document.getElementById("my-canvas")

//var canvas = document.getElementById('canvas'),
//var
//    ctx = canvas.getContext('2d'),
//    rect = {},
//    drag = false;

//function init() {
//}


//init();



/*
var
	context = canvas.getContext("2d"),
	img = document.createElement("img"),
	mouseDown = false,
	brushColor = "rgb(0, 0, 0)",
	hasText = true,
	clearCanvas = function () {
		if (hasText) {
			context.clearRect(0, 0, canvas.width, canvas.height);
			hasText = false;
		}
	};
	
// Adding instructions
context.fillText("Drop an image onto the canvas", 240, 200);
context.fillText("Click a spot to set as brush color", 240, 220);

// Image for loading	
img.addEventListener("load", function () {
	clearCanvas();
	context.drawImage(img, 0, 0);
}, false);

// Detect mousedown
canvas.addEventListener("mousedown", function (evt) {
	clearCanvas();
	mouseDown = true;
	context.beginPath();
}, false);

// Detect mouseup
canvas.addEventListener("mouseup", function (evt) {
	mouseDown = false;
	var colors = context.getImageData(evt.layerX, evt.layerY, 1, 1).data;
	brushColor = "rgb(" + colors[0] + ", " + colors[1] + ", " + colors[2] + ")";
}, false);

// Draw, if mouse button is pressed
canvas.addEventListener("mousemove", function (evt) {
	if (mouseDown) {
		context.strokeStyle = brushColor;								
		context.lineWidth = 20;
		context.lineJoin = "round";
		context.lineTo(evt.layerX+1, evt.layerY+1);
		context.stroke();
	}
}, false);

// To enable drag and drop
canvas.addEventListener("dragover", function (evt) {
	evt.preventDefault();
}, false);

// Handle dropped image file - only Firefox and Google Chrome
canvas.addEventListener("drop", function (evt) {
	var files = evt.dataTransfer.files;
	if (files.length > 0) {
		var file = files[0];
		if (typeof FileReader !== "undefined" && file.type.indexOf("image") != -1) {
			var reader = new FileReader();
			// Note: addEventListener doesn't work in Google Chrome for this event
			reader.onload = function (evt) {
				img.src = evt.target.result;
			};
			reader.readAsDataURL(file);
		}
	}
	evt.preventDefault();
}, false);

function saveX(evt) {
  window.open(canvas.toDataURL("image/png"));
  evt.preventDefault();
}
*/


/*
// Save image
var saveImage = document.createElement("button");
saveImage.innerHTML = "Save canvas";
saveImage.addEventListener("click", function (evt) {
	window.open(canvas.toDataURL("image/png"));
	evt.preventDefault();
}, false);
document.getElementById("main-content").appendChild(saveImage);
*/

MM.func.mouseOut = function(event) {
/*
  var mouse = MM.func.mouseEventCanvas(event);
  canvas = MM.obj.canvas;
  rect   = MM.data.rect;
//alert(canvas.offsetLeft);
  if (mouse.x<0)
	{
    rect.w = 0 - rect.startX;
	}
  MM.data.rect = rect;
    MM.func.rectClear();
    MM.func.rectDraw(rect);
//		y: mouse.y - canvas.offsetTop

MM.obj.mouse.innerHTML = mouse.toSource();
*/
}

MM.func.mouseDown = function(event) {
/*
    MM.func.rectClear();
  var mouse = MM.func.mouseEventCanvas(event);
  MM.data.rect.startX = mouse.x;
  MM.data.rect.y = mouse.y;
  MM.data.drag = true;
*/
}

MM.func.mouseUp = function() {
//  MM.data.drag = false;
//    MM.func.rectClear();
}
MM.func.mouseMove = function(event) {
/*
  if (MM.data.drag) {
    var mouse, rect;
	mouse = MM.func.mouseEventCanvas(event);
	rect  = MM.data.rect;
    rect.w = mouse.x - rect.startX;
    rect.h = mouse.y - rect.y;
    MM.data.rect = rect;
    MM.func.rectClear();
    MM.func.rectDraw(rect);
  }
*/
}


/*
 border_as, rect_as, canvas
	rect = MM.data.size;
//	size = MM.data.size;
	border = {w: canvas.width-10, h: canvas.height-10};

	border_as = border.w / border.h;
	rect_as   = rect.w   / rect.h;

	if (border_as > rect_as)
		{scale = border.h / rect.h;}
	else
		{scale = border.w / rect.w;}

	rect.w = Math.floor(rect.w * scale);
	rect.h = Math.floor(rect.h * scale);
	rect.x = (border.w - rect.w) >> 1;
	rect.y = (border.h - rect.h) >> 1;
*/

/*
//, diff, dx, dy
		data  = MM.data.resizer;
		rect = MM.data.resizer_all[res.n];
		diff = {x:0,y:0,w:0,h:0};
//		dx = res.start.x - coord.x;
//		dy = data.start.y - coord.y;
		switch(data.n)
			{
			case 0:
			case 1:
			case 2:
			case 3:
				diff.x+=dx;
				diff.y+=dy;
				diff.w-=dx;
				diff.h-=dy;
				break;
			case 4:
				diff.y+=dy;
				diff.w-=dy;
				break;
			case 5:
				diff.y-=dy;
				diff.w+=dy;
				break;
			case 7:
				diff.x+=dx;
				diff.h-=dx;
				break;
			case 8:
				diff.x+=dx;
				diff.h-=dx;
				break;
			default: break;
			}
*/
/*
MM.func.resizer.Rect = function(diff) {
	var size, border, scale, rect, border_as, rect_as, i;
	rect = MM.data.size;
//	size = MM.data.size;
//	border = {w: MM.obj.canvas_rect.width-10, h: MM.obj.canvas_rect.height-10};
	border = MM.data.rect;
	for (i in diff)
		{
		border[i] += diff[i];
		}

    border_as = border.w / border.h;
    rect_as   = rect.w   / rect.h;

    if (border_as > rect_as)
        {scale = border.h / rect.h;}
    else
        {scale = border.w / rect.w;}

	rect.w = Math.floor(rect.w * scale);
	rect.h = Math.floor(rect.h * scale);
	rect.x = (border.w - rect.w) >> 1;
	rect.y = (border.h - rect.h) >> 1;
	MM.data.rect = rect;
	MM.func.rect.canvasClear();
	MM.func.rect.draw(rect);
	}
*/



------


/*
	

	canvas.addEventListener('mousedown', MM.imager.func.mouseDown, false);
	canvas.addEventListener('mouseup'  , MM.imager.func.mouseUp  , false);
	canvas.addEventListener('mousemove', MM.imager.func.mouseMove, false);

	data.mouseDown = false;
	data.brushColor = "rgb(0, 0, 0)";

function saveX(evt) {
  window.open(canvas.toDataURL("image/png"));
  evt.preventDefault();
}



MM.imager.func.mouseDown = function(event)
	{
	MM.imager.func.canvasClear();
	MM.imager.data.mouseDown = true;
	MM.imager.obj.ctx0.beginPath();
	}

// Detect mouseup
MM.imager.func.mouseUp = function(event)
	{
	var colors;
	MM.imager.data.mouseDown = false;
	colors = MM.imager.obj.ctx0.getImageData(event.layerX, event.layerY, 1, 1).data;
	MM.imager.data.brushColor = "rgb(" + colors[0] + ", " + colors[1] + ", " + colors[2] + ")";
	}

// Draw, if mouse button is pressed
MM.imager.func.mouseMove = function(event)
	{
	var ctx;
	if (MM.imager.data.mouseDown) {
		ctx = MM.imager.obj.ctx0;
		ctx.strokeStyle = MM.imager.data.mouseDownbrushColor;								
		ctx.lineWidth = 20;
		ctx.lineJoin = "round";
		ctx.lineTo(event.layerX+1, event.layerY+1);
		ctx.stroke();
	}
	}
*/

-----

-->
