var c;
var resultDoc;
addary = new Array();
addary[0] = new Array(0,1,0);	 //red
addary[1] = new Array(-1,0,0);	//red green
addary[2] = new Array(0,0,1);	 //green
addary[3] = new Array(0,-1,0);	//green blue
addary[4] = new Array(1,0,0);	 //blue
addary[5] = new Array(0,0,-1);	//blue red
addary[6] = new Array(255,1,1);  //red

clrary = new Array(360);
for (i = 0; i < 6; i++)
	for (j = 0; j < 60; j++) {
		clrary[60 * i + j] = new Array(3);
	for (k = 0; k < 3; k++) {
		clrary[60 * i + j][k] = addary[6][k];
	addary[6][k] += (addary[i][k] * 4);
	}
}

function moved(evt) {
	y = 4 * ((document.all) ? event.offsetX : (evt.pageX - evt.target.offsetLeft - document.body.offsetLeft));
	x = 4 * ((document.all) ? event.offsetY : (evt.pageY - evt.target.offsetTop - document.body.offsetTop)) + 10;
	sx = x - 512;
	sy = y - 512;
	qx = (sx < 0)?0:1;
	qy = (sy < 0)?0:1;
	q = 2 * qy + qx;
	quad = new Array(-180,360,180,0);
	xa = Math.abs(sx);
	ya = Math.abs(sy);
	d = ya * 45 / xa;
	if (ya > xa) d = 90 - (xa * 45 / ya);
	deg = Math.floor(Math.abs(quad[q] - d));
	n = 0;
	sx = Math.abs(x - 512);
	sy = Math.abs(y - 512);
	r = Math.sqrt((sx * sx) + (sy * sy));

	if (x == 512 & y == 512) {
		c = '000000';
	} else {
		for (i = 0; i < 3; i++) {
			r2 = clrary[deg][i] * r / 256;
		if (r > 256) r2 += Math.floor(r - 256);
			if (r2 > 255) r2 = 255;
				n = 256 * n + Math.floor(r2);
		}
		c = n.toString(16);
		while(c.length < 6) c = '0' + c;
	}

	theBird.style.backgroundColor = '#' + c;
	theButterfly.style.backgroundColor = '#' + c;
	theParrot.style.backgroundColor = '#' + c;
	theDog.style.backgroundColor = '#' + c;
	theRabbit.style.backgroundColor = '#' + c;

	return false;
}

function moDia() {
	if (isIE) {
		if (resultDoc) {resultDoc.close()};
		resultDoc = showModelessDialog('Result.html', '', "center:'yes'; dialogHeight:'390px'; dialogWidth:'440px'; help:'no'; resizeable:'no'; status:'no'");
		resultDoc.document.bgColor = '#' + c;
		resultDoc.document.getElementById('Result').value = '#' + c;
		resultDoc.document.getElementById('Result').select();
	} else {
		window.prompt('Color code for you to copy:', '#' + c);
	}
}

