var banner = new Array();
var index = 0;
var isActive = true;
var bannerInterval = setInterval(Next, 4000);

function xmlhttpPost() {
	var xmlHttpReq = false;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		xmlHttpReq = new XMLHttpRequest();
		if (xmlHttpReq.overrideMimeType) {
			xmlHttpReq.overrideMimeType('text/xml');
			// See note below about this line
		}
	// IE
	} else if (window.ActiveXObject) { // IE
		try {
			xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
		}
	}
	if (!xmlHttpReq) {
		alert('ERROR AJAX:( Cannot create an XMLHTTP instance');
		return false;
	}   
	xmlHttpReq.open('GET', './webfiles/banners/banners.txt', true);
	xmlHttpReq.setRequestHeader('Content-Type', 
		'application/x-www-form-urlencoded');        
	xmlHttpReq.onreadystatechange = function() { 
		var file = xmlHttpReq.responseText;
		if (xmlHttpReq.readyState == 4)
		{
			var temp = new Array();
			var acum = 0;
			temp[acum] = "";
			for (var counter=0; counter<file.length; counter++)
			{
				if (file[counter] != null && file[counter] != "\n")
				{
					temp[acum] += file[counter];
				}
				else
				{
					temp[++acum] = "";
				}
			}
			acum=-1;
			for (var i in temp)
			{
				if (temp[i].length > 3)
					banner[++acum] = temp[i];
			}
			
			document.getElementById('banner').style.backgroundImage = "url(./webfiles/banners/"+banner[index]+")";
		}
	
	}
	xmlHttpReq.send("");
}

function Next() {
	if (index == banner.length - 1) { index=0; } else { index++; }
	document.getElementById('banner').style.backgroundImage = "url(./webfiles/banners/"+banner[index]+")";
	clearInterval(bannerInterval);
	bannerInterval = setInterval(Next, 4000);
}

function Previous() {
	if (index == 0) { index=banner.length - 1; } else { index--; }
	document.getElementById('banner').style.backgroundImage = "url(./webfiles/banners/"+banner[index]+")";
	clearInterval(bannerInterval);
	bannerInterval = setInterval(Next, 4000);
}

function Pause() {
	if (isActive)
	{
		isActive = false;
		clearInterval(bannerInterval);
		document.getElementById('pauseImage').src='./webimages/play.png';
	}
	else
	{
		isActive = true;
		bannerInterval = setInterval(Next, 4000);
		document.getElementById('pauseImage').src='./webimages/pause.png';
	}
}

xmlhttpPost();
