function TopList( listelem, textelem )
{
	this.topelem = textelem;
	this.closeimg = null;
	this.toptext = new Object();
	this.toptext.title = null;
	this.toptext.desc = null;

	var tl = this;

	var tlinks = listelem.getElementsByTagName("a");
	for( var i = 0; i < tlinks.length; i++ )
	{
		tlinks[i].onclick = function(){ return !tl.getText( this.href ); };
	}
}


TopList.prototype.getText = function( uri )
{
	var tl = this;
	var xreq = GetXmlHttpObject();
	if ( !xreq ) return false;

	xreq.onreadystatechange = function(){ tl.updateText( xreq ); };
	xreq.open( "GET", addGetData( uri, "bare" ), true );
	xreq.send( null );

	return true;
}

TopList.prototype.updateText = function( xreq )
{
	if( ( xreq.readyState != 4 ) && ( xreq.readyState != "complete" ) ){ return true; }

	var tl = this;
	var top = tl.topelem;
	if( !top ) return false;
	eval( "var res = { " + xreq.responseText + " };" );

	var closer = this.closeimg;
	if( !closer && ( closer = add_closer() ) )
	{
		top.insertBefore( closer, top.firstChild );
		this.closeimg = closer;
		closer.onclick = function(){ tl.closeText(); };
	}

	var ttext = this.toptext.title;
	var dtext = this.toptext.desc;
	if( !ttext && ( ttext = createElement( "div" ) ) &&
	    !dtext && ( dtext = createElement( "p" ) ) &&
	    document.createTextNode )
	{
		ttext.className = "title";
		ttext.appendChild( document.createTextNode( res.title ) );
		dtext.appendChild( document.createTextNode( res.desc ) );
		this.toptext.title = ttext;
		this.toptext.desc = dtext;
		top.appendChild( ttext );
		top.appendChild( dtext );
	}
	else
	{
		ttext.replaceChild( document.createTextNode( res.title ), ttext.firstChild );
		dtext.replaceChild( document.createTextNode( res.desc ), dtext.firstChild );
	}

	if( !closer || !ttext || !dtext )
	{
		this.closeimg = this.toptext.title = this.toptext.desc = null;
		top.innerHTML = "<img src='images/close.png' id='t_closer' class='lnk' alt='X' />" +
		                '<span class="title">' + res.title + '</span><p>' + res.desc + '</p>';
		closer = getElementById( "t_closer" );
		closer.onclick = function(){ tl.closeText(); };
	}

	top.style.display = "block";

	return true;
}

TopList.prototype.closeText = function()
{
	if( this.topelem )
		this.topelem.style.display = "none";
}

function add_closer()
{
	var closer = createElement( "img" );

	if( closer )
	{
		closer.className = "lnk";
		closer.alt = "Close Section";
		closer.src = "images/close.png";
	}

	return closer;
}

