function technicolour (el) {
	if (!el) return false;
	var info = document.getElementById('webkit');
	if (info) info = info.getElementsByTagName('span')[0];
	
	// one-time initialization
	if (!el._technicolour) {
		el._iteration = 0;
		el._rgbT = [255,255,255];
		el._rgbF = [255,255,255];
		el._stepsF = [-1,-1,-1];
		el._stepsT = [-1,-1,-1];
		el._technicolour = {};
	} else {
		el._technicolour.timeout = null;
	}
	
	var step = 0;
	el._technicolour.interval = window.setInterval(function() {
		var rand; step++;
		
		// reverse steps
		if (step % 10 == 0) {
			rand = Math.round((Math.random()*10));
			if (rand == 7) el._stepsF[step%3] *= -1;
			if (rand == 3) el._stepsT[step%3] *= -1;
		}
		
		// limits
		for (var j=0; j < el._rgbT.length; j++) {
			if (el._rgbT[j] == 30) el._stepsT[j] = +1;
			if (el._rgbT[j] == 255) el._stepsT[j] = -1;
			
			if (el._rgbF[j] == 30) el._stepsF[j] = +1;
			if (el._rgbF[j] == 255) el._stepsF[j] = -1;
		}
		
		// increments
		rand = Math.round((Math.random()*10)/4.0001);
		el._rgbF[rand] += el._stepsF[rand];
		if (step % 2) {
			rand = Math.round((Math.random()*10)/4.0001);
			el._rgbT[rand] += el._stepsT[rand];
		}
		
		el.style.backgroundImage = '-webkit-gradient(linear, left top, left bottom, from(rgb('+el._rgbF+')), to(rgb('+el._rgbT+')))';
		
		if (info) {
			var a = '', b = '';
			for (var i=0; i < el._rgbT.length; i++) {
				a += el._rgbF[i].toString(16);
				b += el._rgbT[i].toString(16);
			}
			info.innerText = '#' + a.toUpperCase() + ' to #' + b.toUpperCase();
		}
		
		if (step >= 100) {
			window.clearInterval(el._technicolour.interval);
			el._technicolour.interval = null;
			
			el._stepsF[el._iteration] *= -1;
			if (el._rgbF[el._iteration] % 10 == 0) el._stepsT[2-el._iteration] *= -1;
			el._iteration++;
			el._iteration %= 3;
			el._technicolour.timeout = window.setTimeout(function() { technicolour(el) }, 700); // take a breather
		}
	}, 150);
}

function initPlayPause (el) {
	if (!el) return false;
	el._play = el.innerText; // default is play
	el._pause = '=';
	el.onclick = function() {
		if (el.className == 'play') {
			// play
			technicolour(document.body);
			
			el.className = 'pause';
			el.innerText = el._pause;
		} else {
			// pause
			if (document.body._technicolour.interval) window.clearInterval(document.body._technicolour.interval);
			if (document.body._technicolour.timeout) window.clearTimeout(document.body._technicolour.timeout);
			document.body._technicolour.interval = null;
			document.body._technicolour.timeout = null;
			
			el.className = 'play';
			el.innerText = el._play;
		}
		return false;
	}
}


