function CSlideShow (crossFadeDuration,slideShowSpeed)
{
	this.crossFadeDuration = crossFadeDuration;
	this.slideShowSpeed = slideShowSpeed;
	
	this.timer;
	this.CurrentPic = 0;
	this.LastPic = 0;
	this.AantalPics = Pic.length;
	this.preLoad = new Array()
	
	this.fadePercentage = 0;
}

CSlideShow.prototype.startPreload = function()
{
	for (i = 0; i < this.AantalPics; i++){
	   this.preLoad[i] = new Image()
	   this.preLoad[i].src = Pic[i]
	}
}

CSlideShow.prototype.runSlideShowPrePart = function()
{
		document.images.SlideShowFade.src = this.preLoad[this.LastPic].src;
		document.images.SlideShowFade.style.filter = "alpha(opacity=100)";
		document.images.SlideShowFade.style.opacity = "1";

		
		 var _this = this;
		 setTimeout(function(){_this.runSlideShow()},50);
}

CSlideShow.prototype.runSlideShow = function()
{
		document.images.SlideShow.style.left = "9999px"; 
		document.images.SlideShow.style.filter = "alpha(opacity=0)";
		document.images.SlideShow.style.opacity = "0"; 

		
		 var _this = this;
		 setTimeout(function(){_this.runSlideShowPart2()},50);
}

CSlideShow.prototype.runSlideShowPart2 = function()
{
		var tsource = this.preLoad[this.CurrentPic].src;
		document.images.SlideShow.src = this.preLoad[this.CurrentPic].src;	
		clearInterval(this.hiddenTimer);
	
		this.fadePercentage = 0;
		
		 var _this = this;
		 setTimeout(function(){_this.runSlideShowPart3()},50);
}

CSlideShow.prototype.runSlideShowPart3 = function()
{
		document.images.SlideShow.style.left = "0px"; 
	
		 var _this = this;
		 this.hiddenTimer = setInterval(function(){_this.SlideTick()},50);
		 
		 this.LastPic = this.CurrentPic;
		 this.CurrentPic++;
		 this
		 if (this.CurrentPic > (this.AantalPics-1)) this.CurrentPic=0
		 var _this = this;
		 this.timer = setTimeout(function(){_this.runSlideShowPrePart()}, this.slideShowSpeed)
}

CSlideShow.prototype.SlideTick = function()
{
  this.fadePercentage = this.fadePercentage + 5;
  if(this.fadePercentage < 101) {
	  document.images.SlideShow.style.filter = "alpha(opacity="+this.fadePercentage+")";
	 	document.images.SlideShow.style.opacity = (this.fadePercentage/100);
	 	document.images.SlideShowFade.style.filter = "alpha(opacity="+(100-this.fadePercentage)+")";
	 	document.images.SlideShowFade.style.opacity = (1-(this.fadePercentage/100));
	 } else {
	 	clearInterval(this.hiddenTimer);
	}
}

CSlideShow.prototype.showImage = function(img)
{
	clearTimeout(this.timer);
	document.SlideShow.src = img;
	this.CurrentPic = this.findImage(img);
	 this.LastPic = this.CurrentPic;
	 this.CurrentPic++;
	 if (this.CurrentPic > (this.AantalPics-1)) { this.CurrentPic=0 }
}

CSlideShow.prototype.findImage = function(img)
{
	for (var i = 0; i < this.AantalPics; i++){
	   if(this.preLoad[i].src.indexOf(img) > -1){
	   		return i;
	   	}
	}
	return 0;
}

CSlideShow.prototype.resumeSlideShow = function()
{
	clearTimeout(this.timer);
	var _this = this;
	this.timer = setTimeout(function(){_this.runSlideShowPrePart()}, this.slideShowSpeed );
}
