function initalize()
  {
  classNCols('threeCol', 3);
  classNCols('twoCol', 2);
  classNCols('oneCol', 1);
  }

app.addOnload(new objfn(initalize));

function nColList(src, n) {
  var origList = src;
  var items = new Array ();
  var lis   = new Array ();
  
  if ( origList.hasChildNodes() ) {
    var children;
    var itemlength = new Array ();
    var j = 0;
    var i;
    var k = 0;
    var l = 0;

    var numlist = 0;
    children = origList.childNodes;
    for ( i = 0; i < children.length; i++) {
      if (children.item(i).tagName)
	if ('li' == children.item(i).tagName.toLowerCase ()) {
	  numlist++;
	}
    }
    for ( i = 0; i < n; i++) {
      itemlength[i] = 0;
    }
    for ( i = 0; i < numlist; i++ ) {
      itemlength[j++]++;
      if ( j >= n ) {
	j= 0;
      }
    }

    for ( i = 0; i < n; i++ )
      items[i] = document.createDocumentFragment ();
    
    // starts with an 'li' node
    var first = 0;
    i = 0;
    j = 0;
    l = children.length
    for ( k = 0; k < l; k++ ) {
      if (children.item(0).tagName){
	if ( 'li' == (''+children.item(0).tagName).toLowerCase() )
	  {
	    j++;
	    if ( first == 1 ) {
	      if ( j >= itemlength[i] ) 
		{
		  i++;
		  j = 0;
		}
	    }
	    else {
	      first = 1;
	      j = 0;
	    }
	  }
      }
      items[i].appendChild (children.item(0));
    }
  }
  return items;
}

//Currenlty only handles tags of top ul and ol

function nColDisplayHandler (origList, items, whichclass) {

	var container = document.createElement('div');
	container.setAttribute ('id', origList.getAttribute ('id'));
	origList.removeAttribute ('id');
	var s = origList.getAttribute('start');
	var tw = 0;
	var n  = items.length;
	var i;
	for ( i = 0; i < n; i++ ) {
		var list = document.createElement('div');
		var cw = ( ( i + 1 ) * 100 / n );
		//		list.style.backgroundColor = 'red';
		var pw = Math.ceil( cw - tw );
		tw = tw + pw;
		list.style.width = (pw) + '%';
                list.className = whichclass + " float_left";
		var uls = origList.cloneNode(false);
		uls.style.listStyleType = 'none';
		uls.style.marginLeft = '5px';
		uls.style.marginRight = '5px';
		uls.style.paddingLeft = '0px';
		uls.setAttribute('start', s );
		var j = 0;
		if (items[i].hasChildNodes()) {
		      var children = items[i].childNodes;
		      var l = children.length;
		      for ( j = 0; j < l; j++ ) {
			if (children.item(0).tagName)
			  if ( 'li' == children.item(0).tagName.toLowerCase()) s++;
			uls.appendChild(children.item(0));
		      }
		}
		list.appendChild(uls);
		container.appendChild(list);
	}

	var clearing = document.createElement ('div');
	clearing.style.clear = 'both';
	container.appendChild (clearing);
	origList.parentNode.replaceChild(container, origList);
}


function classNColsTag (whichclass,n,type)
{
  var uls;
  uls = document.getElementsByTagName(type); 
  for (var i=0; i< uls.length; i++) 
    { 
      var parent = uls.item(i).parentNode; 
      if ('div' ==  parent.tagName.toLowerCase () ) 
        { 
	  if (parent.getAttribute('class') == whichclass || 
	      parent.getAttribute('className') == whichclass) 
	    { 
	      nColDisplayHandler (uls.item(i), nColList(uls.item(i), n), whichclass); 
	    } 
        } 
    } 
} 


function classNCols (whichclass,n) 
{ 
  classNColsTag (whichclass, n, 'ul');
  classNColsTag (whichclass, n, 'ol');
}

