var lpszTitle = new Array();		// Title of the testimonial
var lpszTestimonial = new Array();	// Testimonial text
var lpnHeight = new Array();		// Array of offset heights
var nTCount = 0;			// Count of testimonials.
var bMSIE = false;
var bFFX = false;
var bOpera = false;
var szBrowser = window.navigator.appName;
var bScrolling = false;
var nCurrTestimonial = 0;
var nNextTestimonial = 1;

if(szBrowser.indexOf("Microsoft") != -1)
{
	bMSIE = true;
}
else if(szBrowser.indexOf("Netscape") != -1)
{
	bFFX = true;
}
else if(szBrowser.indexOf("Opera") != -1)
{
	bOpera = true;
}

function AddTestimonial(szTitle, szTestimonial)
{
	// You can use as many variables as you need. Just add them as arrays and fill them with this function.
	lpszTitle[nTCount] = szTitle;
	lpszTestimonial[nTCount] = szTestimonial;
	nTCount++;
}
function Init()
{
	/*var dDebug = document.getElementById("debugPort");
	dDebug.innerHTML += "Test";*/
	if(nTCount < 1)
	{
		// ERROR: No testimonials added.
		// alert("No testimonials to scroll.");
	}
	else
	{
		var dViewPort = document.getElementById("ViewPort");
		if(dViewPort)
		{
			if(bMSIE || bFFX || bOpera)
			{
				var i = 0;
				for(i = 0; i < nTCount; i++)
				{
					var dNewObject = document.createElement('div');
					dNewObject.setAttribute("id", "test" + i);
					dNewObject.className = "testimonial";
					dNewObject.style.position = "absolute";
					if(i == 0)
					{
						dNewObject.style.top = "0px";
					}
					else
					{
						dNewObject.style.top = "" + ((dViewPort.offsetTop / 2) + dViewPort.offsetHeight) + "px";
					}
					dNewObject.style.left = "0px";
					
					// This is the HTML for inside each of the testimonials
					dNewObject.innerHTML = "<p>" + lpszTestimonial[i] + "</p>\n";
					dNewObject.innerHTML += "<p><strong>" + lpszTitle[i] + "</strong></p>\n";
					
					dViewPort.appendChild(dNewObject);
				}
				bScrolling = true;
				setTimeout("Scroll(0)", 5000);
			}
			else
			{
			}
		}
		else
		{
			// ERROR: No viewport to scroll through.
			// alert("No viewport to scroll through.");
		}
	}
}

function Scroll(bNext)
{
	var i = 0;
	var dObj = document.getElementById("test" + nCurrTestimonial);
	var dViewPort = document.getElementById("ViewPort");
	if(bNext)
	{
		nCurrTestimonial = nNextTestimonial;
		nNextTestimonial++;
		if(nNextTestimonial == nTCount)
		{
			nNextTestimonial = 0;
		}
		bScrolling = true;	
	}
	if(bScrolling)
	{
		var dObj2 = document.getElementById("test" + (nNextTestimonial));
		var nDiff = dObj2.offsetTop - 2;
		var nTop;
		if(nDiff <= 0)
		{
			nTop = parseInt(dObj2.style.top)
			nTop += nDiff;
			dObj.style.top = "" + ((dViewPort.offsetTop / 2) + dViewPort.offsetHeight) + "px";
			dObj2.style.top = "" + nTop + "px";
			
			setTimeout("Scroll(1)", 5000);
		}
		else
		{
			nTop = parseInt(dObj2.style.top);
			nTop -= 2;
			//document.getElementById("debugPort").innerHTML += "OBJECT" + nNextTestimonial + " TOP: " + nTop + "<br />\n";
			dObj2.style.top = "" + nTop + "px";
			
			
			nTop = parseInt(dObj.style.top);
			nTop -= 2;
			dObj.style.top = "" + nTop + "px";
			setTimeout("Scroll(0)", 33);
		}
	}
}

AddTestimonial("&ndash; Toby Copeland, Owner, Impact Solutions, LLC.", "&quot;I want to express my appreciation for the quality services that you and your organization have provided to Impact Solutions, LLC. In addition to being a satisfied customer, we are very comfortable recommending Kaian-Wright, Inc. to our customers.  Ibelieve that you offer the highest quality at a fair and reasonable price...&quot;");
AddTestimonial("&ndash; Carin Chambers, Office Manager, Drew Auto of La Mesa", "&quot;We have used Kaian-Wright many times. Most recently we remodeled our Collision Center and they were instrumental in that process for both voice and data wiring. ...Customized cabling solution for your individual business needs: We have a very difficult campus. They have always been able to find a way!&quot;");
AddTestimonial("&ndash; C. Revellese, Link Source", "&quot;Kaian-Wright is second to none in the San Diego area when it comes to any request. Their expertise in the voice & data industry assures me the job will be completed on time, the first time. There is no other contractor I prefer on-site. Kaian-Wright has a great team. We are fortunate to have them representing Link Source in the light that they do.&quot;");
