oldonload_textpage=window.onload;
window.onload=function()
{
	if(typeof oldonload_textpage == 'function')
		oldonload_textpage();
		
	var divs=document.getElementsByTagName('div');
	pagers=[];
	for(var i=0;i<divs.length;i++)
	{
		var op=divs[i];
		if(op.className == 'pager')
			pagers.push(new Pager(op,'pagers',pagers.length));
		else if(op.className == 'readmore')
			pagers.push(new Readmore(op,'pagers',pagers.length));
	}
}

function Readmore(readmorediv,collective,alpha)
{
	this.txtlink=collective+'['+alpha+']';
	
	this.more=true;
	
	this.parentnode=readmorediv.parentNode;
	
	this.morediv=readmorediv.cloneNode(true);
	this.morediv.style.display='block';
	this.parentnode.removeChild(readmorediv);
	
	// add the read more button
	var readmore=document.createElement('a');
	readmore.appendChild(document.createTextNode('Read More'));
	readmore.className='readmore';
	readmore.href='javascript:'+this.txtlink+'.toggle();';
	this.parentnode.appendChild(readmore);
	// add the back button
	var readless=document.createElement('a');
	readless.appendChild(document.createTextNode('Back'));
	readless.className='readless';
	readless.href='javascript:'+this.txtlink+'.toggle();';
	this.morediv.appendChild(readless);
	
	this.lessdiv=this.parentnode.cloneNode(true);
//	this.toggle();
	
	while(this.parentnode.firstChild!=null)
		this.parentnode.removeChild(this.parentnode.firstChild);
	this.parentnode.appendChild(this.lessdiv);
}
$pr=Readmore.prototype;
$pr.toggle=function()
{
	this.more=!this.more;
		
	if(this.more)
		this.go('morediv');
//		this.parentnode.appendChild(this.morediv);
	else
		this.go('lessdiv');
//		this.parentnode.appendChild(this.lessdiv);
}
$pr.go=function(divname)
{
	this.divname=divname;
	this.div=this.parentnode.getElementsByTagName('div')[0];

	this.killanimator();
	
	var begin=100;
	var change=-100;
	var time=5;
	var type='outCirc';
	
	this.animator=new phocus.Animator('','',begin,change,time,type);
	this.animator.object=this;
	this.animator.method='setopacity';
	this.animator.round=true;
	this.animator.addListener(this,'pageup');
	this.animator.run();
}
$pr.pageup=function()
{
	while(this.parentnode.firstChild!=null)
		this.parentnode.removeChild(this.parentnode.firstChild);

	this.divname=this.divname == 'lessdiv' ? 'morediv' : 'lessdiv';
	this.parentnode.appendChild(this[this.divname]);
	this.div=this.parentnode.getElementsByTagName('div')[0];
	
	
	this.killanimator();
	
	var begin=0;
	var change=100;
	var time=5;
	var type='outCirc';
	
	this.animator=new phocus.Animator('','',begin,change,time,type);
	this.animator.object=this;
	this.animator.method='setopacity';
	this.animator.round=true;
	this.animator.run();
}
$pr.setopacity=function(value)
{
	this.div.style.opacity = value/100;
//	this.div.style.filter = 'alpha(opacity=' + value + ')';
}
$pr.killanimator=function()
{
	if(typeof this.animator != 'undefined')
	{
		this.animator.kill();
		this.animator=null;
	}
}

function Pager(pagingdiv,collective,alpha)
{
	this.txtlink=collective+'['+alpha+']';
	
	this.div=pagingdiv;
	this.childer=[];
	this.height=this.div.offsetHeight;
	
	if(typeof(this.div.title) != 'undefined' && this.div.title.indexOf('height:')!=-1)
	{
		this.idealheight=this.div.title.split(':')[1];
		this.div.title='';
	}
	
	this.init();
	this.pages=this.getpagenum();
	this.page(1);
}
$pr=Pager.prototype;
$pr.idealheight=220;
$pr.pages=0;
$pr.curpage=0;
$pr.viewableelements=0;
$pr.removedelements=[];

$pr.init=function()
{
	var childer=this.div.childNodes;
	for(var i=0;i<childer.length;i++)
	{
		var op=childer[i];
		var extra='null';
		var indocflow=true;
		// error check the node to make sure it's not whitespace or plaintext
		if(op.nodeType!=1)
			continue;
		// if we don't want to count this toward the overall height (ie. it's floated or otherwise removed from doc flow)
		if(typeof op.className != 'undefined' && op.className.indexOf('offflow')>=0)
			indocflow=false;
		// if this element is one of the element types that we want to remove from the height calculation
		for(var j in this.removedelements)
			if(op.nodeName.toLowerCase()==this.removedelements[j])
				indocflow=false;		
		// If we want constand elements, we need to count them toward overall height, but not remove them from flow
		// NOTE: constant elements will ALWAYS appear before other content
		if(typeof op.className != 'undefined' && op.className.indexOf('constant')>=0)
			extra='constant';
			
		this.childer.push([indocflow ? op.offsetHeight : 1,op.cloneNode(true),extra]);
	}
}
$pr.gopage=function(pagenum)
{
	this.curpage=pagenum;
	
	this.killanimator();
	
	var begin=100;
	var change=-100;
	var time=5;
	var type='outCirc';
	
	this.animator=new phocus.Animator('','',begin,change,time,type);
	this.animator.object=this;
	this.animator.method='setopacity';
	this.animator.round=true;
	this.animator.addListener(this,'pageup');
	this.animator.run();
}
$pr.pageup=function()
{
	this.page(this.curpage);
	
	this.killanimator();
	
	var begin=0;
	var change=100;
	var time=5;
	var type='outCirc';
	
	this.animator=new phocus.Animator('','',begin,change,time,type);
	this.animator.object=this;
	this.animator.method='setopacity';
	this.animator.round=true;
	this.animator.run();
}
$pr.setopacity=function(value)
{
	this.div.style.opacity = value/100;
//	this.div.style.filter = 'alpha(opacity=' + value + ')';
}
$pr.killanimator=function()
{
	if(typeof this.animator != 'undefined')
	{
		this.animator.kill();
		this.animator=null;
	}
}
$pr.page=function(pagenum)
{
	this.curpage=pagenum;
	// clear the div
	this.div.innerHTML='';
	// add any constant elements first
	for(var i=0;i<this.childer.length;i++)
	{
		var op=this.childer[i];
		if(op[2]=='constant')
		{
			this.div.appendChild(op[1]);
		}
	}
	// add other elements up to the specified height
	var curheight=0;
	for(var i=0;i<this.childer.length;i++)
	{
		var op=this.childer[i];
		if(op[2]=='constant' || op[3]!=this.curpage)
			continue;
		curheight+=op[0];
		this.div.appendChild(op[1].cloneNode(true));
/*		if(curheight>=this.idealheight)
			break;*/
	}
	// add the pager to the bottom
	// container
	if(this.pages>1)
	{
		var pul=document.createElement('ul');
		pul.className='pagercontrol';
		// label
			var l=document.createElement('li');
			var a=document.createElement('a');
			a.className='nohover leftbutton';
			var txt=document.createTextNode('Page');
			a.appendChild(txt);
			l.appendChild(a);
		pul.appendChild(l);
		// previous page
			if(this.curpage>1)
			{
				var l=document.createElement('li');
				var a=document.createElement('a');
				a.href='javascript:void(0);';
				a.href='javascript:'+this.txtlink+'.gopage('+(this.curpage-1)+');';
				a.className='page_prev';
				var txt=document.createTextNode('Prev');
				a.appendChild(txt);
				l.appendChild(a);
			pul.appendChild(l);
			}
		// pages
			for(var i=1;i<=this.pages;i++)
			{
				var l=document.createElement('li');
				var a=document.createElement('a');
				a.href='javascript:void(0);';
				a.href='javascript:'+this.txtlink+'.gopage('+i+');';
				if(this.curpage==i)
					a.className='current';
				var txt=document.createTextNode(i);
				a.appendChild(txt);
				l.appendChild(a);
			pul.appendChild(l);
			}
		// next page
			if(this.curpage<this.pages)
			{
				var l=document.createElement('li');
				var a=document.createElement('a');
				a.href='javascript:void(0);';
				a.href='javascript:'+this.txtlink+'.gopage('+(this.curpage+1)+');';
				a.className='page_next';
				var txt=document.createTextNode('Next');
				a.appendChild(txt);
				l.appendChild(a);
			pul.appendChild(l);
			}
		this.div.appendChild(pul);
		this.div.appendChild(document.createElement('p'));
	}
}
$pr.getpagenum=function()
{
	var pages=1;
	var curheight=0;
	for(var i=0;i<this.childer.length;i++)
	{
		var op=this.childer[i];
		if(op[2]=='constant')
			continue;
		curheight+=op[0];
		op[3]=pages;
		if(curheight>=this.idealheight && i<this.childer.length-1)
		{
			pages++;
			curheight=0;
		}
	}	
	return pages;
}