/*

	Colourizer 0.2 Version für HEAD.

	Für mehr Farbe!

	Carsten Ruppert - carsten.ruppert at web.de
	07.12.2005
	Copyright 2005 by Carsten Ruppert


*/

function colouredLink(node,color,oev1,oev2) {

	var _cl = this;
	this.cl = node;
	this.color = color;
	this.natcolor = null;

	this.oev1 = oev1;
	this.oev2 = oev2;

	this.appendListeners = function () {
		if ( document.attachEvent ) {
			_cl.cl.attachEvent('on'+_cl.oev1,_cl.colorize);
			_cl.cl.attachEvent('on'+_cl.oev2,_cl.uncolorize);
			}
		else {
			_cl.cl.addEventListener(_cl.oev1,_cl.colorize,false);
			_cl.cl.addEventListener(_cl.oev2,_cl.uncolorize,false);
			}
		return;
		}
	this.colorize = function () {
		_cl.cl.style.backgroundColor = '#'+_cl.color;
		return;
		}
	this.uncolorize = function () {
		_cl.cl.style.backgroundColor = _cl.natcolor;
		return;
		}


	if ( this.cl && this.color ) {

		this.natcolor = this.cl.style.backgroundColor;
		void this.appendListeners();

		return;
		}
	}


function colourizer(nname,palette,onEventOne,onEventTwo) {

	var cr = this;
	this.palette = palette;

	this.nodename = nname;
	this.node = null;

	this.oev1 = onEventOne;
	this.oev2 = onEventTwo;

	var c = 0; var p = 0; var cl;
	while ( this.node = document.getElementsByTagName(this.nodename)[c] ) {
		if ( p == this.palette.length ) { p = 0; }
		var _tmp = this.node.getAttributeNode('colourize');
		if ( _tmp && _tmp.value == 'yes' ) {
			cl = new colouredLink(this.node,this.palette[p],this.oev1,this.oev2);
			}
		++c; ++p;
		}
	}
