var slideShowCount = 0;
var ssTo = '';

var myimages = new Array();

function preloadImages(dir, count) {
	for (x=1; x<=count; x++) {
		myimages[x] = new Image();
		myimages[x].src = "images/" + dir + "/" + x + ".jpg";
	}
}

function setBG(dir) {
	//document.getElementById("bg").src = "images/" + dir + "/1.jpg";
	//document.getElementById("container").style.backgroundImage = "url('images/" + dir + "/1.jpg')";
}

function slideShow(dir, count) {
	slideShowCount++;
	if (slideShowCount>count) { slideShowCount = 1; }

	//document.getElementById("container").style.backgroundImage = "url('images/" + dir + "/" + slideShowCount + ".jpg')";
	//document.getElementById("bg").src = "images/" + dir + "/" + slideShowCount + ".jpg";
	document.getElementById("imge").src = "images/" + dir + "/" + slideShowCount + ".jpg";

	ssTo = setTimeout("slideShow ('" + dir + "', '" + count + "')", 2000);
}

function clear_time() {
	if (ssTo != '') { clearTimeout(ssTo); }
}

function lastPic(dir, maxPic) {
	if (ssTo != '') { clearTimeout (ssTo); }
	if (slideShowCount <= 1) { slideShowCount = (parseInt(maxPic) + 1); }
	slideShowCount = (slideShowCount - 1);

	//document.getElementById("container").style.backgroundImage = "url('images/" + dir + "/" + slideShowCount + ".jpg')";
	//document.getElementById("bg").src = "images/" + dir + "/" + slideShowCount + ".jpg";
	document.getElementById("imge").src = "images/" + dir + "/" + slideShowCount + ".jpg";
}

function nextPic(dir, maxPic) {
	if (ssTo != '') { clearTimeout (ssTo); }
	if (slideShowCount == 0) { slideShowCount = 1; }
	if (slideShowCount >= maxPic) { slideShowCount = 0; }
	slideShowCount = (slideShowCount + 1);

	//document.getElementById("container").style.backgroundImage = "url('images/" + dir + "/" + slideShowCount + ".jpg')";
	//document.getElementById("bg").src = "images/" + dir + "/" + slideShowCount + ".jpg";
	document.getElementById("imge").src = "images/" + dir + "/" + slideShowCount + ".jpg";
}

function change_img(dir, i) {
	clear_time();
	document.getElementById("imge").src = "images/" + dir + "/" + i + ".jpg";
}

function getHTTPObject() {
	if (window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		return new XMLHttpRequest();
	else {      
		alert("Your browser does not support AJAX.");
		return null;   
	}
}

function get_slideshow(d) {
	httpObject = getHTTPObject();
    	    	
    	if (httpObject != null) {
		var now = new Date();
				
		var fullURL = d + '/index.php?ts=' + now.getTime();
    			
		httpObject.open("GET", fullURL, true);
		httpObject.send(null);
		httpObject.onreadystatechange = get_slideshow_handler;
	}
}

function get_slideshow_handler() {
	if (httpObject.readyState == 4) {
		document.getElementById("slideshow").innerHTML = httpObject.responseText;
	}
}


