function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


function getNextByName(node, name) {
	while (node != null) {
		node = node.nextSibling;
		if ( (node != null) && (node.nodeName == name) )
			return node;
	}
	return null;
}

function getFirstByName(node, nodename) {
	if (node != null) {
		child = node.firstChild;
		while (child != null)	{
			if (child.nodeName == nodename) {
				return child;
			} else {
				child = child.nextSibling;
			}
		}
	}
}



function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function toggleNext(event) {
  var nextDiv = getNextByName(this.parentNode.parentNode, 'DIV');
  if (nextDiv != null) {
    nextDiv.style.display = 'block';
//    this.onclick = function() {return false;}
//    this.style.cursor = 'default';
    this.parentNode.innerHTML = this.innerHTML;
  }
  return false;
}


function initHiddenInfo() {
  var deskletList = document.getElementById('desklets');

  if (deskletList != null)
  {
    var moreinfos = getElementsByClass('moreinfo', deskletList, 'P');
    var descriptions = getElementsByClass('description', deskletList, 'DIV');

    for (var i = 0; i < moreinfos.length; i++) {
      var anchor = getFirstByName(moreinfos[i], 'A');
      anchor.onclick = toggleNext;
      anchor.style.cursor = 'pointer';
    }
    
    for (var i = 0; i < descriptions.length; i++)
      descriptions[i].style.display = 'none';
  }
}


addLoadEvent(initHiddenInfo);

