/*
var txpos = 20;
var typos = 0;
var twidth = 320;
var theight = 400;
var sashspeed = 500;
var tclass = 'testimonial';
var tdefault = 'testimonial1'; //default initially visible testimonial
var useRandomSlide = true; //start on random testimonial
var tvis = 999; //visible testimonial
var tlist = new Array();
var runSlideshow = true;
var slideDelay = 10000;
*/


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 initTestimonials(){
	//adjust sash speed for initial loading of page
	var s = sashspeed;
	sashspeed = 0;
    tlist = getElementsByClass(tclass,null,null);
	closeTestimonials( tdefault );
	
	//generate random starting testimonial
	

	if ( useRandomSlide ){
		tvis=Math.floor(Math.random()*tlist.length);
	}else{

		//set 'start slide' based on initial testimonial position in array
		for (i = 0; i < tlist.length; i++) {
			if ( tlist[i].id == tdefault)  { tvis = i-1; break; }
		}
	}
	slideshow();
	sashspeed = s;
}

function slideshow(){
	tvis++;
	if (tvis >= tlist.length){ tvis=0; }
	showTestimonial(tlist[tvis].id);
	
	if( runSlideshow ){ var t = setTimeout('slideshow()', slideDelay);}
}

function closeTestimonials( target ){
	for (i = 0; i < tlist.length; i++){
		if( tlist[i].id != target){ closeSpecificTestimonial(tlist[i].id); 	}
	}
}

function closeSpecificTestimonial(elementId){
	var element = document.getElementById(elementId);
	animate(elementId, txpos, typos, 0, theight, sashspeed, null);
    element.up = true;
    element.down = false;	
}

function showTestimonial(elementId){
	closeTestimonials(elementId);
	var t = setTimeout('openTestimonial("'+elementId+'")', sashspeed);
}

function openTestimonial(elementId){
	var element = document.getElementById(elementId);
	animate(elementId, txpos, typos, twidth, theight, sashspeed, null);
    element.up = false;
    element.down = true;
}
