// random
Math.randomize = function() {var minValue=0,maxValue=0;if(arguments.length==1){maxValue=((isNaN(Number(arguments[0])))?(0):(parseInt(arguments[0])));}else if(arguments.length==2){minValue=((isNaN(Number(arguments[0])))?(0):(parseInt(arguments[0])));maxValue=((isNaN(Number(arguments[1])))?(0):(parseInt(arguments[1])));}if(maxValue<minValue){var tmpValue=minValue;minValue=maxValue;maxValue=tmpValue;}Math.randomize.startValue=(((Math.randomize.startValue*Math.randomize.a)+Math.randomize.b)%Math.randomize.c);return((minValue==maxValue)?(Math.randomize.startValue/Math.randomize.c):(minValue+Math.floor((maxValue-minValue+1)*Math.randomize.startValue/Math.randomize.c)));};Math.randomize.a=4096;Math.randomize.b=150889;Math.randomize.c=714025;Math.randomize.startValue=(((new Date()).getTime())%Math.randomize.c);
Array.prototype.remove = function(obj) {var arr=this,i=0;while(i<arr.length){if(arr[i]===obj){arr=arr.slice(0,i).concat(arr.slice(i+1,arr.length));--i;}++i;}for(i=0;i<arr.length;++i){this[i]=arr[i];}this.length=arr.length;};


//initializes tagcloud
function startTagCloud() {
	writeTagCloud(keyword);
}

// returns an array with mixed entries
function getSequence(tempArr,num) {
	var arr = [];
 	var teaserArr = tempArr ;
 	var arrLength = num;
 	var lotteryPot = [], i;
 	for (i=0; i<teaserArr.length; ++i) {
  		 lotteryPot[lotteryPot.length] = i;
 	}
	while (arr.length < arrLength) {
   	i = lotteryPot[Math.floor(Math.randomize()*lotteryPot.length)];
   	lotteryPot.remove(i);
   	arr[arr.length] = teaserArr[i];
 	}
 	return arr;
}

var keywordOrder = new Array();
function writeTagCloud(keyword) {
  var htmlContent = "";
	
	// write array for random mechanism
	for(i=0; i < keyword.length; i++) {
		keywordOrder[i] = i;
	}
	// after executing function, the entries are mixed. They are responsible for random display
	var cnt = 30;
	var tempArr = new Array;
	var tempCodeArr = new Array;
	var tempHeightArr = new Array;
	var tempHtmlContent = "";
	
	for(j=0;j < cnt;j++){
		tempHtmlContent = "";
		tempArr.push(getSequence(keywordOrder, keyword.length));
		for(i=0; i < keyword.length; i++) {
			tempHtmlContent += '<a href="' + keyword[tempArr[j][i]][2] + '"class="tagCloud_' + keyword[tempArr[j][i]][1] + '">' + keyword[tempArr[j][i]][0] + '</a> ';
	 	}
		tempCodeArr.push(tempHtmlContent);
		document.getElementById('tcb').innerHTML = tempHtmlContent;
		document.getElementById('tagCloudContainer').style.display = "block";
 		document.getElementById('tagCloudContainer').style.visibility = "hidden";
		tempHeightArr.push(document.getElementById('tagCloudContainer').offsetHeight);
		document.getElementById('tcb').innerHTML = "";
	}
	
	for(j=0;j < cnt-1;j++){
		if(tempHeightArr[0] < tempHeightArr[1] ) {
			tempHeightArr.splice(1, 1);
			tempCodeArr.splice(1, 1);
		}else{
			tempHeightArr.splice(0, 1);
			tempCodeArr.splice(0, 1);
		}
	}
	
	
  htmlContent += tempCodeArr[0]

  document.getElementById('tagCloudContent').innerHTML = htmlContent;
  document.getElementById('tagCloudContainer').style.display = "block";
  document.getElementById('tagCloudContainer').style.visibility = "visible";
 
  
}