if(detectBrowser.modernBrowser()){



document.observe("contentloaded",function(){

	/* seedable random number functionality */

	var RandSeed = 0;
	var initRandSeed=null;

	// used by seedble random number functionality
	function PrfxTo(S, L, C) {
		S += ""
		if (C.length>0){
			while (S.length<L) {
				S = C + S ;
			}
		}
		return S;
	}

	// used by seedble random number functionality
	function StrU(X, M, N) { // X > -0.5e-N ; to M digits point N digits
		var S = String(Math.round(X*Math.pow(10, N)));

		if (/\D/.test(S)){
			return SpcsTo(X, M+N+1); // cannot cope
		}
		S = PrfxTo(S, M+N, '0');
		var T = S.length - N;
		return S.substring(0, T) + '.' + S.substring(T);
	}

	// used by seedble random number functionality
	function SpcsTo(S, L) {
		S += "" // SpcsTo is a reduction of PrfxTo
		while (S.length<L) {
			S = " " + S;
		}
		return S;
	}

	// used by seedble random number functionality
	function StrT(X, M, N) {
		return SpcsTo(StrU(X, 1, N), M+N+2);
	}

	// used by seedble random number functionality
	function RRN2(_initseed) {
		if(initRandSeed==null){
			initRandSeed = _initseed;
		}
		var Q
		var XX = [];
		var rnge = Math.pow(2, 32);
		function SeedRand() {
			return (RandSeed = ((134775813*initRandSeed)*RandSeed+1)%rnge)/rnge;
		}
		for (var Q = 0; Q < 9; Q++){
			XX[Q] = StrT(SeedRand(), 1, 3);
		}
		return XX[XX.length - 1];
	}


	function drawCloud(container){
		var words = container.getElementsBySelector("li a").map(function(item){
			var h = $H({ name: item.innerHTML.strip(), href: item.readAttribute('href') });
			return h;
		});

		// start up the random generator using our word list as the seed
		var randInit = (Math.round(RRN2(words.join("").split("").inject(0,function(acc,n){
			return (acc = acc + n.charCodeAt(0));
		})) * 12));

		var basketHeight = 45;

		var tagCloudWrapperContainer = new Element("div");

		for(var i=0;i<words.length;i++){

			var d = new Element("div");
			d.appendChild(new Element("div"));
			d.firstChild.appendChild(new Element("a",{'href':words[i]['href']}));
			d.firstChild.firstChild.appendChild(document.createTextNode(words[i]['name']));
			d.setStyle({
				'height':'45px',
				'float':'left'
			});

			var link = $(d.firstChild.firstChild);
			(function(elem){
				Event.observe(elem,"mouseover",function(){
					elem.setStyle({'color':'#99ccff'});
				});
				Event.observe(elem,"mouseout",function(){
					elem.setStyle({'color':'#ffffff'});
				});
			})(link);
			link.setStyle({'color':'#ffffff'});

			// TODO : this text size will not be randomized but rather depend on a priority attribute on the tags from eTouch.
			var textsize = 12 + Math.round(RRN2() * 13);
			$(d.firstChild).setStyle({
				'fontSize':textsize+'px',
				'lineHeight':textsize+'px',
				'whiteSpace':'nowrap',
				'paddingLeft':'8px',
				'paddingRight':'8px',
				'paddingTop':Math.round(RRN2() * (basketHeight - textsize)) + "px"
			});
			tagCloudWrapperContainer.appendChild(d);
		}
		
		container.appendChild(tagCloudWrapperContainer);
	}

	//
	// tag cloud boot strap
	//
	$$('.tag_cloud').each(function(container){
		drawCloud(container);
	});

});



}