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

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

CSlideShow.prototype.runSlideShowPrePart = function()
{
        document.getElementById('SlideShowFade').getElementsByTagName('img')[0].src = this.preLoad[this.LastPic].src;
        document.getElementById('SlideShowFade').style.filter = "alpha(opacity=100)";
        document.getElementById('SlideShowFade').style.opacity = "1";
         clearInterval(this.hiddenTimer); 
        
         var _this = this;
         setTimeout(function(){_this.runSlideShow()},50);
}

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

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

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

CSlideShow.prototype.runSlideShowPart3 = function()
{
        document.getElementById('SlideShow').style.left = "0px"; 
    
         var _this = this;
         this.hiddenTimer = setInterval(function(){_this.SlideTick()},50);
         
         this.LastPic = this.CurrentPic;
         this.CurrentPic++;

         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.getElementById('SlideShow').style.filter = "alpha(opacity="+this.fadePercentage+")";
         document.getElementById('SlideShow').style.opacity = (this.fadePercentage/100);
         document.getElementById('SlideShowFade').style.filter = "alpha(opacity="+(100-this.fadePercentage)+")";
         document.getElementById('SlideShowFade').style.opacity = (1-(this.fadePercentage/100));
     } else {
         clearInterval(this.hiddenTimer);
    }
}

CSlideShow.prototype.showImage = function(img)
{
    clearTimeout(this.timer);
    document.getElementById('SlideShow').getElementsByTagName('img')[0].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(regularimg)
{
    img = encodeURI(regularimg);  
    for (var i = 0; i < this.preLoad.length; 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 );
}
