// JavaScript Document
function test_win() {
	window.open('/testim.php', null, 'width=800, height=auto');
}

function read_test(id) {

	window.open('/testimonials/'+(id != null ? '?id='+id+'#t'+id : ''), null, 'width=600, height=720, scrollbars=1');
}

function load_test(page) {
	newtext = AJAX('testim.php?page='+page, 'GET');
	document.getElementById('testimonials').innerHTML = newtext;
}

function ticker_load() {
	window.clearTimeout(current_timer);
	div = document.getElementById('test_scroll');
	var loadtext = '<div id="test_loading"><img src="images/ajax-loader.gif" alt="Loading..." width="32" height="32" /><br />Loading testimonials.  Please wait.</div>';
	div.innerHTML += loadtext;
	var text = AJAX('_testim.php?r='+Math.random()+'&page='+testim_page, 'GET');
	setOpacity(div, 0);
	div.innerHTML = text;
	fadein('test_scroll');
	//scrollin('test_scroll');
}

function ticker_left() {
	testim_page--;
	ticker_load();	
}

function ticker_right() {
	testim_page++;
	ticker_load();
}

function AJAX(url, method) {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				return false;
			}
		}
	}

	/*
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			return xmlHttp.responseText;
		}
	}
	xmlHttp.open(method, url, true);
	*/
	xmlHttp.open(method, url, false);
	xmlHttp.send(null);
	
	return xmlHttp.responseText;
}

function fadein (div) {
	fader(div, 1, 0);
}

function fadeout(div) {
	fader(div, -1, 0);
}

function scrollin (div) {
	scroller(div, 1, 0);
}

function fader (div, dir, n) {
	var d = document.getElementById(div);
	if (dir > 0) {
		var x = (n / 100) * (Math.PI / 2);
		var y = 100 * Math.sin(x);
	}
	else {
		var x = Math.PI + (n / 100) * (Math.PI / 2);
		var y = 100 * (1 + Math.sin(x));
	}
	setOpacity(d, y);

	if (n < 100) {
		current_timer = window.setTimeout("fader('"+div+"', "+dir+", "+(n+1)+")", 10);
	}
}

function scroller (div, dir, n) {
	var d = document.getElementById(div);
	if (dir > 0) {
		var t = (n / 100) * (Math.PI / 2);
		var x = 1000 - (1000 * Math.sin(t));
	}
	else {
		var t = Math.PI + (n / 100) * (Math.PI / 2);
		var x = 1000 * (1 + Math.sin(t)) - 1000;
	}
	d.style.left = x + 'px';

	if (n < 100) {
		current_timer = window.setTimeout("scroller('"+div+"', "+dir+", "+(n+1)+")", 10);
	}
}

function setOpacity(obj, value) {
	obj.style.opacity = value/100;
	obj.style.filter = 'alpha(opacity=' + value + ')';
}

var testim_page = 0;
var current_timer;
