var divtodo =new Array();
var original_fontsize=new Array;
var original_lineheight=new Array;
var original_offsetheight=new Array();
var textexpanded=new Array();
var litcoltext="Collapse Text . . .";

function expandtextonhover(anchor, textdivname, explode_0_scroll_1, index){
	if(anchor.innerHTML!=litcoltext){
		if(!textexpanded[index]){
			expandtext(anchor, textdivname, explode_0_scroll_1);
			textexpanded[index]=1;
		}
	} else {
	 	expandtext(anchor, textdivname, explode_0_scroll_1);
		textexpanded[index]=0;
	}

}

function expandtext(anchor, textdivname, explode_0_scroll_1){
	var no_of_steps=10;	
	var no_of_secs=1;
	
	if(anchor.innerHTML!=litcoltext){
		if(!explode_0_scroll_1){
			explode_div(textdivname,no_of_steps, 1, no_of_secs);
		} else {
			scrollout_div(textdivname ,no_of_steps, 1, no_of_secs);	
		}
		anchor.innerHTML=litcoltext;
	} else {
		if(!explode_0_scroll_1){
			explode_div(textdivname,no_of_steps, 0, no_of_secs);
		} else {
			scrollout_div(textdivname ,no_of_steps, 0,  no_of_secs);	
		}
		anchor.innerHTML="More . . .";
	
	}
}
		




function explode_div(div_id, no_of_steps, explode_1_implode_0, speed_in_secs){
	var divindex=-1;
	
	if(divtodo.length){
		for(var i =0;i<divtodo.length;i++){
			if(divtodo[i].id==div_id){
				divindex=i;
				break;
			}
		}
	}
	if(divindex==-1){
		divindex=divtodo.length;
		divtodo[divindex]=getexpObj(div_id);	
		
		original_fontsize[divindex]=get_original_fslh(divtodo[divindex],"fontSize");
		original_lineheight[divindex]=get_original_fslh(divtodo[divindex],"lineHeight");
	}
	
	if(explode_1_implode_0==-1){
		original_offsetheight[divindex]=divtodo[divindex].offsetHeight;
		divtodo[divindex].style.height="0px";
	} else {
		if(explode_1_implode_0){
			doexplodestep(divindex, 1,  no_of_steps, explode_1_implode_0, speed_in_secs);	
		} else {
			doexplodestep(divindex, no_of_steps,  no_of_steps, explode_1_implode_0, speed_in_secs);	
			
		}
	}
}


function scrollout_div(div_id, no_of_steps, explode_1_implode_0, speed_in_secs){
	var divindex=-1;
	
	if(divtodo.length){
		for(var i =0;i<divtodo.length;i++){
			if(divtodo[i].id==div_id){
				divindex=i;
				break;
			}
		}
	}
	if(explode_1_implode_0){
		doscrollstep(divindex, 1,  no_of_steps, explode_1_implode_0, speed_in_secs);	
	} else {
		doscrollstep(divindex, no_of_steps,  no_of_steps, explode_1_implode_0, speed_in_secs);	
			
	}
}

function doscrollstep(divindex, current_step,  no_of_steps, explode_1_implode_0, speed_in_secs){
	
	divtodo[divindex].style.height=Math.round(original_offsetheight*(current_step/no_of_steps))+"px";
	if(explode_1_implode_0){
		var nextstep=current_step+1;	
	} else {
		var nextstep=current_step-1;
	}
	if((nextstep<=no_of_steps)&&(nextstep>-1)){
		window.setTimeout("doscrollstep("+divindex+","+nextstep+", "+no_of_steps+", "+explode_1_implode_0+", "+speed_in_secs+")", speed_in_secs/no_of_steps*1000); 
	} 
	return true;



}
function get_original_fslh(divobj, stype){
	
	var ret="100%";

		
		
	var tryparent=1;
	if(divobj.style){
		if(eval("divobj.style."+stype)){
			tryparent=0;
			ret=	eval("divobj.style."+stype);
		}
	}
	if(tryparent){
		 if(divobj.parentNode){
	
			ret=get_original_fslh(divobj.parentNode, stype);		
		 }
	}
	
	
	return ret;
}

function doexplodestep(divindex, current_step,  no_of_steps, explode_1_implode_0, speed_in_secs){

	if(!current_step){
		divtodo[divindex].style.display="none";	
		return true;
		
	}
	var fsnum="";
	var fstype="";
	var lhnum="";
	var lhtype="";
	var NumChars="0123456789.-";
	
	for(var i=0; i<original_fontsize[divindex].length; i++){
     	Char = original_fontsize[divindex].charAt(i); 
      	if (NumChars.indexOf(Char) == -1) {
			fstype+=Char;
		} else {
			fsnum+=Char;	
		}
	}	

	for(i=0; i<original_lineheight[divindex].length; i++){
     	Char = original_lineheight[divindex].charAt(i); 
      	if (NumChars.indexOf(Char) == -1) {
			lhtype+=Char;
		} else {
			lhnum+=Char;	
		}
	}
	var fsnumf=parseFloat(fsnum);
	var lhnumf=parseFloat(lhnum);
	for(i=current_step; i<no_of_steps; i++){
		fsnumf=fsnumf*0.9;
		lhnumf=lhnumf*0.9;
	}

	divtodo[divindex].style.fontSize=(Math.round(fsnumf*10)/10)+fstype;
	divtodo[divindex].style.lineHeight=(Math.round(lhnumf*10)/10)+lhtype;
	var padding=((no_of_steps-current_step)*8)+"px ";
	divtodo[divindex].style.padding="0px "+padding+" 0px "+padding;

	if(explode_1_implode_0&&(current_step==1)){
		divtodo[divindex].style.display="block";	
	}
	
	if(explode_1_implode_0){
		var nextstep=current_step+1;	
	} else {
		var nextstep=current_step-1;
	}
	if(nextstep<=no_of_steps){
		window.setTimeout("doexplodestep("+divindex+","+nextstep+", "+no_of_steps+", "+explode_1_implode_0+", "+speed_in_secs+")", speed_in_secs/no_of_steps*1000); 
	} 
	return true;
}

function getexpObj(name){
	  if (document.getElementById)  {
	  	return document.getElementById(name);
		
	  } else if (document.all)  {
		return document.all[name];
		
	  }  else if (document.layers)  {
		return getexpObjNN4(document,name);
		
	  }
	}

function getexpObjNN4(obj,name){
	var x = obj.layers;
	var thereturn;
	for (var i=0;i<x.length;i++)	{
	if (x[i].id == name)
	 	thereturn = x[i];
	else if (x[i].layers.length)
		var tmp = getexpObjNN4(x[i],name);
		if (tmp) thereturn = tmp;
	}
	return thereturn;
}

function Checkstylesheet(){
	
//  I'll come back to this as it's a bit complicated	
	if(document.styleSheets){
		for(i=0;i<document.styleSheets.length;i++){
			if(document.styleSheets[i].cssRules){
				startCSSSizes[i]=new Array(document.styleSheets[i].cssRules.length);
				startCSSHeights[i]=new Array(document.styleSheets[i].cssRules.length);
			} else if(document.styleSheets[i].rules) {
				startCSSSizes[i]=new Array(document.styleSheets[i].rules.length);
				startCSSHeights[i]=new Array(document.styleSheets[i].rules.length);
			
			
			} else {
				return false;
			
			
			}

			for(j=0;j<startCSSSizes[i].length;j++){
				if(document.styleSheets[i].cssRules){
					if(document.styleSheets[i].cssRules[j].style){
						vStrS=document.styleSheets[i].cssRules[j].style.fontSize;
						vStrH=document.styleSheets[i].cssRules[j].style.lineHeight;
					}
				} else if(document.styleSheets[i].rules) {	
					if(document.styleSheets[i].rules[j].style){
						vStrS=document.styleSheets[i].rules[j].style.fontSize;
						vStrH=document.styleSheets[i].rules[j].style.lineHeight;
					}
				}
				vSize=eval(vStrS.substring(0,vStrS.indexOf("p")));
				startCSSSizes[i][j]=vSize;
				vSize=eval(vStrH.substring(0,vStrH.indexOf("p")));
				startCSSHeights[i][j]=vSize;
			}
		}
	
	}
}