var hmlTags = {

	tagCloud : null,
	
	
	//*************************************************************************************
	//** INITIALIZETAGCLOUD
	//*************************************************************************************
	initializeTagCloud : function () {
	
	hmlHome.tagCloud = new StringBuffer();
	
	//alert($('mixesAjaxContainer').style.width);
	hmlHome.tagCloud.append("<div id='tagCloud'>")
	pars = "req=atag";
	hmlHome.ajaxCall(hmlHome.ajaxURL,pars,hmlTags.buildTags);
	
	},
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------
	
	
	//*************************************************************************************
	//** BUILDTAGS
	//*************************************************************************************
	buildTags : function(resp) {
	
	var tagMap = {};
	
	var tags = resp.responseText.split('|')
	
	for (var tagCount = 0; tagCount < tags.length - 1; tagCount++){
	
	var tagsSplit = tags[tagCount].split('*')
	tagMap[tagsSplit[0].replace(/\s*/g,'')]=tagsSplit[1];
	
	}
		
	
		//draw the cloud
		hmlTags.drawTagCloud(tagMap,6);
		
		//hmlHome.tagCloud.append("</div>")
	
		//write the cloud to the page
		hmlHome.showPage();
		var theString = hmlHome.tagCloud.toString();
		$('tagCloudTable').innerHTML = theString + "</div>"
		
	
	},
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------

	
	//*************************************************************************************
	//** MAXARRAY
	//*************************************************************************************
	maxArray : function ( arr ) {
	
	
		// this function calculates the maximum value in the associative array
		var max = 0;
		for(var i in arr){
			if (arr[i] > max)
  	    		max = arr[i];
		}
		
		return max;
	},
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------
	
	
	
	//*************************************************************************************
	//** MINARRAY:
	//*************************************************************************************
	minArray : function ( arr ) {
	
		// this function calculates the minimum value in the associative array
		var min;
		var count = 0;
		
		for(var i in arr){
		
			// initialize minimum value with first value of associative array
			if (count==0)
				min = arr[i];
			if (arr[i] < min)
  	    		min = arr[i];
				count++;
		}
		
  	return min;
	
	},
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------
	
	
	//*************************************************************************************
	//** DRAWTAGCLOUD 
	//*************************************************************************************
	drawTagCloud : function (map, maxStyle) {
	
		
		// this function draws the tag cloud using the associative javascript array generated by the Notes view
		// calculate the maximum entries in the cloud. if not found, no tags are found
		var maxEntries = hmlTags.maxArray(map);
		if (maxEntries==0) {
			document.write('No tags found');
		}
	
		//	calculate the minimum entries in the cloud
		var minEntries = hmlTags.minArray(map);
	
		// calculate the range
		var range = maxEntries - minEntries;
		if (range <= 0)
			range = 1; 
	
		// loop through the tag map to draw each tag.
		
		for(var tag in map){
		
		
		
			hmlTags.drawTag(tag, map[tag], minEntries, maxEntries, maxStyle);
			
		}
		
	},
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------


	
	//*************************************************************************************
	//** DRAWTAG
	//*************************************************************************************
	drawTag : function (tag, count, min, max, maxStyle) {
	
	// this function renders a tag line. first determine
	// the size tag to use for this tag count
	sizeTag = Math.round((((maxStyle-1)/(max-min))*count) +(1*max-maxStyle*min)/(max-min));
  
	// now write the link to the page
	//tagElement = document.createElement("a");
	//tagElement.setAttribute("href","http://www.cnn.com")
	//tagElement.className = "tag" + sizeTag;
	//tagElement.innerHTML = tag
	//$('tagCloud').appendChild(tagElement)
	
	//var oldDiv = $('tagCloud')
	//var parentDiv = $('tagCloud').parentNode;
	//parentDiv.insertBefore(tagElement, oldDiv);
	hmlHome.tagCloud.append('<a href="links.html#req=tag&tag=' + tag + '" class="tag' + sizeTag + '">' + tag + '</a>');
	//hmlHome.tagCloud.append(tag + '&nbsp;');
	}
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------
	
	







}