var loaded = false;
var initialize = false;
var image = new Image();
var pattern1;
var r = 100;
var px = 400;
var py = 400;
var bak_px = px;
var bak_py = py;

function drawImage()
{
	if(!loaded)
		return;
	
	var canvas = document.getElementById("canvas_image");
	if(canvas.getContext)
	{
		var ctx = canvas.getContext("2d");
		
		if (!initialize)
		{
			pattern1 = ctx.createPattern(image, "no-repeat");
			initialize = true;
		}
		
		ctx.fillStyle = pattern1;
//		ctx.strokeStyle = "rgb(200, 200, 250)";
//		ctx.lineWidth = 2;
		
		ctx.beginPath();
		ctx.clearRect(bak_px-r-5, bak_py-r-5, (r+5)*2, (r+5)*2);
		ctx.moveTo(px + r, py);
		ctx.arc(px, py, r, 0, Math.PI*2, false);
		ctx.closePath();
		ctx.fill();
//		ctx.stroke();
	}
}

image.onload = function() {
	loaded = true;
}
image.src = "cg/nitori1_.png"

function notori1Mouse(x,y)
{
	bak_px = px;
	bak_py = py;
	px = x - 60;
	py = y - 60;
	drawImage();
}

function commonInit() {
	cmn_OP = (navigator.userAgent.indexOf("Opera",0) != -1)?1:0;	//OP
	cmn_N6 = document.getElementById;		// N6 or IE
	cmn_IE = document.all;					// IE
	cmn_N4 = document.layers;				// N4
	
	if (cmn_OP){							// OP?
		document.onmousemove = cmn_MoveOP;
	}else if (cmn_IE){					// IE?
		document.onmousemove = cmn_MoveIE;
	}else if (cmn_N6){					// N6?
		window.addEventListener("mousemove",cmn_MoveN6,true);
	}else if (cmn_N4){					// N4?
		window.captureEvents(Event.MOUSEMOVE);
		window.onmousemove = cmn_MoveN4;
	}
}

function cmn_MoveOP(){			// OPでマウスが動いた
	if (typeof notori1Mouse == 'function')
		notori1Mouse(window.event.clientX + window.pageXOffset, window.event.clientY + window.pageYOffset);
}
function cmn_MoveN6(Event){		// N6でマウスが動いた
	if (typeof notori1Mouse == 'function')
  		notori1Mouse(Event.clientX + window.pageXOffset, Event.clientY + window.pageYOffset);
}
function cmn_MoveIE(){			// IEでマウスが動いた
	if (typeof notori1Mouse == 'function')
		notori1Mouse(window.event.clientX + document.body.scrollLeft, window.event.clientY + document.body.scrollTop);
}
function cmn_MoveN4(Event){		// N4でマウスが動いた
	if (typeof notori1Mouse == 'function')
		notori1Mouse(Event.x, Event.y);
}


