var myTimer;
var clear;
myTimer=null;
function stopShow()
{
clear=clearTimeout(myTimer);
}


function playShowRecursive() {
    var showCookiename = "show=";
	var imageCookiename= "image=";
	var numItemsCookiename= "numItems=";
	var show="";
	var id="";
	var numItems="";
	var ca = document.cookie.split(';');
	
	for(var i=0;i < ca.length;i++) {
	var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1,c.length);
	
	if (c.indexOf(showCookiename) == 0) show = ( c.substring(showCookiename.length,c.length));
	if (c.indexOf(imageCookiename) == 0) id = ( c.substring(imageCookiename.length,c.length));
	if (c.indexOf(numItemsCookiename) == 0) numItems = ( c.substring(numItemsCookiename.length,c.length));
	
		if (id == (numItems-1))
		{
		id= 0;
		}
	}//end while
	
	imageChangerURL="imageChangerURL.php";
    if (navigator.appName == "Microsoft Internet Explorer") {
            http = new ActiveXObject("Microsoft.XMLHTTP");
                } 
              else {
                  http = new XMLHttpRequest();
               }

		http.open("GET", imageChangerURL + '?image=' + id + '&show=' + show, true)
	    http.onreadystatechange = showImageResponse
		http.send(null)
	
}
function pausecomp(millis) {
        var date = new Date();
        var curDate = null;

        do { curDate = new Date(); }
        while(curDate-date < millis);
		
myTimer=setTimeout("playShowRecursive()", 2000);
    } 


function showImageResponse() {

	if (http.readyState == 4) {
		results = http.responseText
		document.getElementById('imageContainer').innerHTML = results
		pausecomp(3000);
	}
}


//functions for non recursive playing 

function showImageFade(show,id,numItems)
{

imageChangerURL="imageChangerURL.php";
 if (navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                else {
                  http = new XMLHttpRequest();
                }
		http.open("GET", imageChangerURL + '?image=' + id + '&show=' + show, true)
		http.onreadystatechange = showImageResponse2
		http.send(null)
							
}



function showImageFadeNext(show,id,numItems)
{
if (id != numItems)
	{
	id++;
	}
	if (id == (numItems-1) || id > numItems)
	{
	id= 0;
	}
	
	
imageChangerURL="imageChangerURL.php";
 if (navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                else {
                  http = new XMLHttpRequest();
                }
		http.open("GET", imageChangerURL + '?image=' + id + '&show=' + show, true)
		http.onreadystatechange = showImageResponse2
		http.send(null)
							
}

function showImageFadePrevious(show,id,numItems)
{
	if (id != numItems )
	{
	id--;
	}
	
	if (id < 0 )
	{
    id= numItems-2;
	}
	
imageChangerURL="imageChangerURL.php";
 if (navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                else {
                  http = new XMLHttpRequest();
                }
		http.open("GET", imageChangerURL + '?image=' + id + '&show=' + show, true)
		http.onreadystatechange = showImageResponse2
		http.send(null)
							
}


function showImageResponse2() {
	if (http.readyState == 4) {
		results = http.responseText
		document.getElementById('imageContainer').innerHTML = results
		
		imgs = new Array(), 
		zInterval = null, 
		current=0, 
		pause=true;
		imgs = document.getElementById("imageContainer").getElementsByTagName("img");
		for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
		imgs[0].style.display = "block";
		imgs[0].xOpacity = .1;
		setTimeout(so_xfade,2);

	}
}

function so_xfade() {

	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade,2000);
	} else {
		setTimeout(so_xfade,50);
	}
	
	function setOpacity(obj) {
		if(obj.xOpacity >.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
}


