
var template='<table border="0" cellpadding="2" cellspacing="0"><tr>' +
			'<td align="right" valign="top"><img src="[RATING]_stars_blue.jpg" alt="[RATING] Star Rating" width="67" height="14"></td>' +
			'<td align="left" valign="top" class="someclass">[TESTIM]</td>'+
			'</tr></table>';
var scroll_id="bgp";
var scroll_speed=50;
var scroll_delay=4000;
var scroll_direction="up";


// Do not modify below here if you dont know what you are doing
var animtimer;
var scrolltimer;
var scroller_running=false;
function preloader() {
	backHighlight = new Image(); 
	backHighlight.src = "back2.jpg";
}
function initTestims()
{
  getTestim('testimsV');
  scroller();
}
function toggleScroller()
{
  if (scroller_running)
  {
	 clearTimeout(scrolltimer);
	 document.getElementById('playpause').src='pause2.jpg';
	 scroller_running=false;
  }
  else
  {
	 document.getElementById('playpause').src='pause.jpg';
	 scroller();
  }
}
function scrollPause()
{
	document.getElementById('btnPlay').src='play.jpg';
	document.getElementById('btnPause').src='pause2.jpg';
	clearTimeout(scrolltimer);
}
function scrollPlay()
{
	scroll_direction="up";
	document.getElementById('btnPlay').src='play2.jpg';
	document.getElementById('btnPause').src='pause.jpg';
	scroller();
}
function scroller()
{
  scroller_running=true;
  if (scroll_direction=="up")
	 nextTestim();
  else
	 prevTestim();
  scrolltimer=setTimeout("scroller()", scroll_delay);
}
function animate()
{
	if (scroll_direction=="up")
		animateup();
	else
		animatedown();
}
function animateup()
{
  divV=document.getElementById('testimsV');
  divH=document.getElementById('testimsH');
  divH.style.visibility='visible';
  if (parseInt(divH.style.top)>0)
  {
	 divV.style.top=parseInt(divV.style.top)-5+"px";
	 divH.style.top=parseInt(divH.style.top)-5+"px";
	 animtimer=setTimeout("animateup()", 50);
  }
  else
  {
	 clearTimeout(animtimer);
	 divV.innerHTML=divH.innerHTML;
	 divV.style.top="0px";
	 divH.style.visibility='hidden';
  }
}
function animatedown()
{
  divV=document.getElementById('testimsV');
  divH=document.getElementById('testimsH');
  divH.style.visibility='visible';
  if (parseInt(divH.style.top)<0)
  {
	 divV.style.top=parseInt(divV.style.top)+5+"px";
	 divH.style.top=parseInt(divH.style.top)+5+"px";
	 animtimer=setTimeout("animatedown()", 50);
  }
  else
  {
	 clearTimeout(animtimer);
	 divV.innerHTML=divH.innerHTML;
	 divV.style.top="0px";
	 divH.style.visibility='hidden';
  }
}
function nextTestim()
{
  scroll_direction="up";
  divO=document.getElementById('testimsO');
  divV=document.getElementById('testimsV');
  divH=document.getElementById('testimsH');
  divO.style.Height=divH.style.Height;
  var max=Math.max(divV.parentNode.offsetHeight, divV.offsetHeight);
  divH.style.top=max+"px";
  divV.style.top="0px";
  getTestim('testimsH');
}
function prevTestim()
{
  scroll_direction="down";                        // Comment this out if you don't want scroll direction to change
  divO=document.getElementById('testimsO');
  divV=document.getElementById('testimsV');
  divH=document.getElementById('testimsH');
  divO.style.Height=divH.style.offsetHeight;
  var upper=(parseInt(divV.offsetHeight)+10)*-1;
  divH.style.top=upper+"px";
  divV.style.top="0px";
  getTestim('testimsH',-1);                        // Get previous testim into hidden div
  scrollPause();
}
var xmlHttp=null;
function getTestim(divID,mov)
{
  xmlHttp=GetXmlHttpObject()
  var url="scroll.php?id=" + scroll_id;
  var rating="";
  var testim="";
  var testimonial="";
  var node=0;
  if (mov)
	 url += "&idx=" + mov;
  xmlHttp.onreadystatechange= function()
  {
	 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 {
		resp=xmlHttp.responseText;
		var pairs = resp.split("[&]");                // [] Avoids ampersands embeded in testimonial text
		for(var i = 0; i < pairs.length; i++)
		{
		  var pos = pairs[i].indexOf('=');
		  if (pos == -1)
			 continue;
		  var argname = pairs[i].substring(0,pos);
		  var value = pairs[i].substring(pos+1);
		  if (argname == 'RATING')
			 rating=value;                              // Rating of testimonial
		  else if (argname=='TESTIM')
			 testim=decodeURIComponent(value);          // Decode encoded testimonial
		  else if (argname=='Error')                   // Error
		  {
			 alert("Error" + value);
			 break;
		  }
		}
		if (rating && testim)
		{
		  testimonial=template.replace("[RATING]",rating);
		  testimonial=testimonial.replace("[TESTIM]",testim);
		  document.getElementById(divID).innerHTML=testimonial;
		  animate();
		}
	 }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}
function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
  {
	 xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
	 try
	 {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	 }
	 catch (e)
	 {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	 }
  }
  return xmlHttp;
}


