function runajax(objID, serverPage){
	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) {
			alert("Your browser does not support AJAX!");
			 return false;
		  }
		}
	  }
	var obj = document.getElementById(objID);
	  xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4){
		  obj.innerHTML = xmlHttp.responseText;
		  }
	  }
	  xmlHttp.open("GET", serverPage, true);
	  xmlHttp.send(null);
}

	//function to show a loading image
	function updateStatus(){
		document.getElementById("captionDiv").innerHTML = "";
		document.getElementById("captionDiv").innerHTML = "<span class='slideShowCaption'>loading...</span>";
	}
	
	function imageClick(id, ssid, type){
		stopSlideShow();
		if(type == "prev"){
			if(ssid <= 0){
				currentCounter = maxSlides-1;
			}else{
				currentCounter = parseInt(ssid)-1;
			}
		}else{
			if(ssid >= maxSlides-1){
				currentCounter = 0;
			}else{
				currentCounter = parseInt(ssid)+1;
			}
		}
		//updateStatus();
		runajax('slideShowMain', '../dynamicContent/common/slideShowPic.php?id='+id+'&ssid='+ssid+'&type='+type);
	}
	function imageSwap(obj, type, state){
		var newclass = "";
		if(type ==  "prev"){
				if(state == "over"){
					newclass = "ssPrevImageOver";
				}else{
					newclass = "ssPrevImage";
				}
		}else if(type ==  "next"){
				if(state == "over"){
					newclass = "ssNextImageOver";
				}else{
					newclass = "ssNextImage";
				}
		}else if(type ==  "play"){
				if(state == "over"){
					newclass = "ssPlayImageOver";
				}else{
					newclass = "ssPlayImage";
				}
		}else if(type ==  "stop"){
				if(state == "over"){
					newclass = "ssStopImageOver";
				}else{
					newclass = "ssStopImage";
				}
		}
		obj.className=newclass; 
	}
	function animateSlideShow(){
		//updateStatus();
		timer = setTimeout(animateSlideShow, 7000);  //rotate images every 7 seconds
		runajax('slideShowMain', '../dynamicContent/common/slideShowPic.php?id='+slideShowId+'&ssid='+currentCounter+'&isSlideShow=true');
			if(currentCounter  >= maxSlides-1){
				currentCounter = 0;
			}else{
				currentCounter += 1;
			}
	}
	function startSlideShow(){
		var playContainer = document.getElementById("playImage");
		playContainer.style.display='none';
		var stopContainer = document.getElementById("stopImage");
		stopContainer.style.display='block';

		resetSlideShow();
		animateSlideShow();
	}
	function stopSlideShow(){
		var stopContainer = document.getElementById("stopImage");
		stopContainer.style.display='none';
		var playContainer = document.getElementById("playImage");
		playContainer.style.display='block';
		resetSlideShow();
	}
	function resetSlideShow(){
		clearTimeout(timer);
	}
