// JavaScript Document

var currentSlide;
var numberOfSlides = 2;
var currentSlideshow;
function initSlideshow(){
	if($('slideshowContainer')){
		currentSlideshow = setInterval(getNextSlide, 10000, null);	
	}
}

function controlSlideShow(){
	if(currentSlideshow != null){
		clearInterval(currentSlideshow);
		currentSlideshow = null;	
		if($('slideshowController')){
			$('slideshowController').innerHTML = "<img src=\"graphics/start_slideshow.png\" style=\"border:0;\" />";	
		}
	} else {
		initSlideshow();
		if($('slideshowController')){
			$('slideshowController').innerHTML = "<img src=\"graphics/stop_slideshow.png\" style=\"border:0;\" />";	
		}
	}
}

function stopSlideShow(){
	if(currentSlideshow != null){
		clearInterval(currentSlideshow);
		currentSlideshow = null;	
		if($('slideshowController')){
			$('slideshowController').innerHTML = "<img src=\"graphics/start_slideshow.png\" style=\"border:0;\" />";	
		}
	}
}

function getNextSlide(theSlideNumber){
	
	/*if(currentSlide == null){
		currentSlide = 0;	
	}*/
	
	/*if(currentSlide+1 >= numberOfSlides){
		currentSlide = 0;	
	} else {
		currentSlide++;	
	}*/
	//alert(slideNumber);
	
	//alert(theSlideNumber);
	
	
	loadSlide();	
}

function getPrevSlide(){
	
	if(currentSlide == null){
		currentSlide = 0;	
	}
	
	if(currentSlide == 0){
		currentSlide = numberOfSlides -1;	
	} else {
		currentSlide--;	
	}
	
	loadSlide(currentSlide);	
}

function loadSlide(){
	//new Effect.Fade('adaptit_info_inner', 
      // { duration:1});
	//new Effect.Fade('adaptit_info_inner');
	new Effect.Fade('slideshowContainerInner', {
					duration: 1,
					fps: 50,
					afterFinish: function(){
					new Ajax.Updater('slideshowContainerInner', 'front_products.php?prodNumber=' + currentSlide,{
					 asynchronous:true,
					 onSuccess: function(){
						new Effect.Appear('slideshowContainerInner', {
										  duration: 1,
										  fps:50,
										  queue: 'end'
										  }) 
					 }
					 });
					}
					});
	
	//if(theSlideNumber == null || theSlideNumber == "undefined"){
		currentSlide = parseInt($("nextSlideNumber").value);
		//alert(currentSlide);
	//}
	//new Effect.Appear('adaptit_info_inner', 
      // {duration:1, from:1.0, to:1.0});


	
}

function loadPage(url, container){
	var fileLoader = new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {		
	  $(container).innerHTML = transport.responseText;
		}
	  
	});	
}

