window.addEvent('load',function()
{
	tHeight 		= $('domeinen').offsetHeight;
	tWidth 			= $('domeinen').offsetWidth;	
	var cloudTags 	= $('domeinen').getElements('div');	
	var wIndex		= 1;
	var colors		= $("domeinen").getAttribute('colors').split(',');

	cloudTags.each(function(a)
	{
		color		= colors[Math.floor(Math.random()*(colors.length))];
		fontsize	= Math.floor(Math.random()*20+20);
		wIndex		= wIndex+1;
		a.setStyles(
		{
			'color': color,
			'z-index': wIndex,
			'font-size': fontsize
		});	
	
		//Position the tags
		var ranNum 			= Math.floor(Math.random()*(tWidth-a.offsetWidth));
		a.style.left 		= ranNum + 'px';
		var ranNum 			= Math.floor(Math.random()*(tHeight-a.offsetHeight)) ;	
		a.style.top 		= ranNum + 'px';
		a.style.visibility 	= 'visible';
		
		a.setAttribute('theight',tHeight);
		a.setAttribute('twidth',tWidth);
		
		a.setAttribute('my_width',a.offsetWidth);
		a.setAttribute('my_height',a.offsetHeight);	
				
		driftTag(a);	
	});
});
		
function driftTag(element)
{
	var colors		= $("domeinen").getAttribute('colors').split(',');
	color			= colors[Math.floor(Math.random()*(colors.length))];
	element.setStyle('color',color);
	
	var cycleTime 	= Math.floor(Math.random()*5000+2000);	
	var tHeight 	= element.getAttribute('theight');
	var tWidth 		= element.getAttribute('twidth');

	var ranLeft 	= Math.floor(Math.random()*(tWidth-element.getAttribute('my_width')))+'px';
	var ranTop 		= Math.floor(Math.random()*(tHeight-element.getAttribute('my_height')))+'px';	
	
	var myfunction	= function(){driftTag(element);};
	
	var myEffect 	= new Fx.Morph(element, 
	{
		duration: 'long', 
		transition: Fx.Transitions.Sine.easeOut,
		onComplete: function()
		{
			myfunction.delay(2000);
		}
	});
	myEffect.start({
	    'left': ranLeft,
	    'top': ranTop
	});
}
