var tagid = 'tags';

var defRed = 20 //percentage
var defBlue = 100
var defGreen = null //colour marked as null will be used

var defMax = 60 // defColour 0% <=> 60%, font-size <= 1.6em
var defMin = 0

var direction = false
var hideItems = false

function createAttributes(object, value) {
	fontSize = 1 + value / 100;
	
	color = (direction)? defMin + value : defMax - value;
	
	if(defRed) r = defRed; else r = color;
	if(defGreen) g = defGreen; else g = color;
	if(defBlue) b = defBlue; else b = color;
	
	object.style.color = 'rgb(' + r +'%,' + g + '%,' + b + '%)';
	object.style.fontSize = fontSize + 'em';
}

function hideitems()
{
	if(!hideItems) return null;

	elem = document.getElementById(tagid);
	hideelems = elem.getElementsByTagName('span');
	if(!hideelems) return null;

	for(i = 0; i < hideelems.length; i++) {
		hideelems[i].style.display = 'none';
	}
}

function mktags() {
	tagel = document.getElementById(tagid);
	if(!tagel) return null;
	
	children = tagel.getElementsByTagName('a');
	if(!children) return null;
	
	maxval = 0;		

	hideitems();

	for(i = 0; i < children.length; i++) {
		maxval = Math.max(maxval, children[i].getAttribute('title'));
	}

	step = maxval/(defMax - defMin);	
	
	for(i = 0; i < children.length; i++) {
		createAttributes(children[i], Math.round(children[i].getAttribute('title')/step));
	}
}

//*** This code is copyright 2003 by Gavin Kistner, gavin@refinery.com
//*** It is covered under the license viewable at http://phrogz.net/JS/_ReuseLicense.txt

function AttachEvent(obj,evt,fnc,useCapture){
	if (!useCapture) useCapture=false;
	if (obj.addEventListener){
		obj.addEventListener(evt,fnc,useCapture);
		return true;
	} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
	else{
		MyAttachEvent(obj,evt,fnc);
		obj['on'+evt]=function(){ MyFireEvent(obj,evt) };
	}
} 

function MyAttachEvent(obj,evt,fnc){
	if (!obj.myEvents) obj.myEvents={};
	if (!obj.myEvents[evt]) obj.myEvents[evt]=[];
	var evts = obj.myEvents[evt];
	evts[evts.length]=fnc;
}
function MyFireEvent(obj,evt){
	if (!obj || !obj.myEvents || !obj.myEvents[evt]) return;
	var evts = obj.myEvents[evt];
	for (var i=0,len=evts.length;i<len;i++) evts[i]();
}

AttachEvent(window, 'load', mktags, false);
