current = 0;
automatic = false;
timeoutID = null;

// seting show lenght
function setShowLength(len) {showLength = len;}

function switchImage(direction) {
   // hiding current picture
   object = document.getElementById('slide' + current);
   object.style.display = 'none';
   
   if (automatic == false){
		if (direction){ // showing next
			current = (current + 1)%showLength;			
		}else{ // showing previous
			current = (current - 1)%showLength;
		}
		updateControls();
   }else{ // automatic is on
   	current = (current + 1)%showLength;
   }

   object = document.getElementById('slide' + current);
   object.style.display = 'block';
   
   // updating status
   // var par = document.getElementById('cntr_status');
   // par.replaceChild(document.createTextNode("Status: "+(current+1)+" of "+showLength),par.firstChild);
   
   // checking if automatic mode is ON
   if (automatic == true){
   	timeoutID = setTimeout(switchImage, 4000);
   }
}

function updateControls()
{
	object = document.getElementById('cntr_next');
	if (current == (showLength-1)){ // showing the last picture
		// disabling the next control
		object.style.display = 'none';
	}else{
		object.style.display = 'inline';
	}
	object = document.getElementById('cntr_prev');
	if (current == 0){
		object.style.display = 'none';
	}else{
		object.style.display = 'inline';
	}
}

function playShow()
{
	automatic = true;
	timeoutID = setTimeout(switchImage, 4000);
	
	// hiding controls
	object = document.getElementById('cntr_prev');
	object.style.display = 'none';
	object = document.getElementById('cntr_next');
	object.style.display = 'none';
	object = document.getElementById('cntr_play');
	object.style.display = 'none';
	// showing controls
	object = document.getElementById('cntr_stop');
	object.style.display = 'inline';
}

function stopShow()
{
	automatic = false;
	if (timeoutID != null)
	{
		clearTimeout(timeoutID);
		timeoutID = null;
	}

	// update controls
	updateControls();
	// showing controls
	object = document.getElementById('cntr_play');
	object.style.display = 'inline';
	// hiding controls
	object = document.getElementById('cntr_stop');
	object.style.display = 'none';
}


