/* uses jqurey */

function lcSlideshow(divID, showtime, transitiontime){
    this.divID = divID;
    this.showtime = showtime * 1000;
    this.transitiontime = transitiontime * 1000;
    this.trans;
    this.maxtrans;
    this.imgcount;
    this.nextimg;
    this.imgDivs = new Array(); 
    this.index = 1;  
    this.numLoops = -1; 
    this.loopsCount = 0;  

    this.addImg = function(imgSrc){
        var divhtml = "";
        divhtml += '<div id="' + this.divID + 'ssdiv' + this.index + '" style="position:absolute;">';
        divhtml += '<img id="' + this.divID + 'ssimg' + this.index + '" src="' + imgSrc + '" />';
        divhtml += '</div>';
        this.imgDivs = this.imgDivs.concat(divhtml);  
        this.index++;  
    }
    
    this.addText = function(text){
        var divhtml = "";
        divhtml += '<div id="' + this.divID + 'ssdiv' + this.index + '" style="position:absolute;" class="sstextdiv">';
        divhtml += '<div id="' + this.divID + 'ssimg' + this.index + '" class="sstext">' + text + '</div>';
        divhtml += '</div>';
        this.imgDivs = this.imgDivs.concat(divhtml);    
        this.index++; 
    }
    
    this.setNumLoops = function(newNumLoops){
        this.numLoops = newNumLoops;        
    }

    this.initslideshow = function(){         
        this.imgcount = this.imgDivs.length;
        var slidshowhtml = "";

        for(var i=1; i<=this.imgcount; i++){
              slidshowhtml += this.imgDivs[i - 1];
        }

        $('#' + this.divID).html(slidshowhtml); 
        $('#' + this.divID + 'ssdiv1').show(0,function(){   
            $('#' + this.divID + 'ssimg1').show();
        });                                     

        for(var i=2; i<=this.imgcount; i++){
            ($('#' + this.divID + 'ssimg' + i)).show();
            ($('#' + this.divID + 'ssdiv' + i)).hide();
        }
                                    
        this.currentimg = this.imgcount;
        this.nextimg = (this.currentimg + 1) % this.imgcount;

        this.advanceslideshow();
    }

    this.advanceslideshow = function(){   
        var elm = $('#' + this.divID + 'ssdiv' + this.nextimg + ' .sstext');
        var lastelm = $('#' + this.divID + 'ssdiv' + this.currentimg + ' .sstext');
        var elmistext = (elm.size() > 0);
        var lastelmistext = (lastelm.size() > 0);
        if (elmistext){
            elm.css('margin-top','0px');
            elm.css('opacity','0');   
        }
        $('#' + this.divID + 'ssdiv' + this.currentimg).fadeOut(this.transitiontime);     
        $('#' + this.divID + 'ssdiv' + this.nextimg).fadeIn(this.transitiontime);     
        if (elmistext){
            elm.animate({ 
                marginTop: '110px',
                opacity: 1
              }, this.transitiontime );   
        }
        if (lastelmistext){
            lastelm.animate({ 
                marginTop: '249px',
                opacity: 0
              }, this.transitiontime ); 
        }
        
        this.currentimg = this.nextimg;
        this.nextimg = (this.nextimg) % this.imgcount + 1;
        var thisObj = this;
        if(this.nextimg == 1){
            this.loopsCount++;    
        }
        if ((this.nextimg != 1) || (this.numLoops != this.loopsCount)){ 
            setTimeout(function() {thisObj.advanceslideshow()}, this.showtime + this.transitiontime);
        }
    }
    var thisObj = this;
    
    $(function(){   
        var img = new Image();                  
        $(img)
            .load(function (){                                                       
                thisObj.initslideshow(); 
            })
            .attr('src','../../classes/phpThumb/phpThumb.php?src=../../img/template/blackbox.jpg&fltr[]=ric|10|10&w=395&h=249&far=1&zc=1');  
    });                                                                     
}