

function d2h(d) {return d.toString(16);}
function h2d(h) {return parseInt(h,16);}


var colorH = 0;
var colorW = 0;
var i = 0;
var iDo = 5;
function changeColor(e) {
	
	// mouse position
	if (!e) {
  		//e = window.event;
  		screenx = parseInt(Math.random()*screen.width);
  		screeny = parseInt(Math.random()*screen.height);
	} else {
		screenx = e.screenX;
		screeny = e.screenY;
	}
	
	x = screen.width - screenx;
	if (x<0) {
		x=0;
	}
	
	y = screen.height - screeny;
	if (y<0) {
		y=0;
	}
	
	
	// max color
	maxColorD = h2d('FFFFFF');
	relW = parseInt(maxColorD / screen.width);
	relH = parseInt(maxColorD / screen.height);
	colorW = d2h(x*relW);
	colorH = d2h(y*relH);
	
	
	var style = {'gradient-start-color': '0x'+colorW, 'gradient-end-color': '0x'+colorH,
				 'border-radius': 0.1};
	OSGradient.applyGradient(style, elt);
}

function moved(e) {
	
	removeCanvas();
	changeColor(e);
	
	/*
	if (i==iDo) {
		changeColor(e);
		i=0;
	} else {
		i++;
	}*/
}

function resized() {
	
	removeCanvas();
	changeColor();
}


function removeCanvas() {
	c1 = document.getElementsByTagName("canvas")[0];
	if (c1 != null) {
		document.getElementById("mybody").removeChild(c1);
	}
}

document.onmousemove = moved;
window.onresize = resized;
