var BloggerTagCloud_sElemName = '';

function BloggerTagCloud_GetNChildByTagName(e, sName, nCount)
{
	eChild = null;

	for (var i = 0; i < e.childNodes.length; i++) {
		if (e.childNodes[i].tagName == sName) {
			if (nCount <= 0) {
				eChild = e.childNodes[i];
				break;
			}
			nCount --;
		}
	}
	
	return eChild;
}

function BloggerTagCloud_Onload()
{
	var eUL = null;
	
	var eLabel1 = document.getElementById(BloggerTagCloud_sElemName);
	if (eLabel1 != null) {
		var eLabel1Div = BloggerTagCloud_GetNChildByTagName(eLabel1, 'DIV', 0);
		if (eLabel1Div != null) {
			var eLabel1DivUL = BloggerTagCloud_GetNChildByTagName(eLabel1Div, 'UL', 0);
			if (eLabel1DivUL != null) {
				eUL = eLabel1DivUL;
			}
		}
	}
	
	if (eUL != null) {
		var s = '';			
		var i = 0;
		while (eLI = BloggerTagCloud_GetNChildByTagName(eUL, 'LI', i)) {
			var sHtml = eLI.innerHTML;
			
			var sText = '';
			for (j = 0; j < sHtml.length; j++) {
				var sChar = sHtml.substr(j, 1);
				if (sChar != '\n' && sChar != '\r') {
					sText += sChar;
				}
			}

			var aMatches = sText.match(/(.*<\/[aA]>).*[^(]\(([0-9]+)\)/);
			//var aMatches = sText.match(/(.*)[^(]\(([0-9]+)\)/);
			//var aMatches = sText.match(/\<[aA](.*)[^(]\(([0-9]+)\)\<\/[aA]\>/);
			//var aMatches = sText.match(/(.*<\/[aA]>)[^(]\(([0-9]+)\)/);
			if (aMatches != null) {
				s += aMatches.length + ' ' + aMatches[1] + '\n';
				if (aMatches.length == 3) {
					var sLink = aMatches[1];
					var sNum = aMatches[2];
					eLI.style.fontSize = Math.floor(BloggerTagCloud_fScale * (100 + 30 * Math.log(parseInt(sNum)))) + '%';
					eLI.innerHTML = sLink;
					//s += sLink + '\n';
				}
			}
			i++;
		}
		//alert(s);
	}
}

function BloggerTagCloud(sSidebarElementId, fScale)
{
  BloggerTagCloud_sElemName = sSidebarElementId;
  if (fScale == null) { fScale = 1.0; }
  BloggerTagCloud_fScale = fScale;
  //onload = BloggerTagCloud_Onload;
  setTimeout('BloggerTagCloud_Onload();', 3000);
}

