 /* 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; z-index: 4; '+
         'background-image: url(global/classes/phpThumb/phpThumb.php?new=000000&fltr[]=ric|10|10&f=gif&w=' + $('#' + this.divID).width() + '&h=' + $('#' + this.divID).height() +
        '); width:' + $('#' + this.divID).width() + 'px; height: ' + $('#' + this.divID).height() + 'px;" class="sstextdiv">';
        divhtml += '<div id="' + this.divID + 'ssimg' + this.index + '" class="sstext" style="position:absolute; display:none; z-index: 5; color: #56C74D; font-size: 18px; text-align: center; width: ' +
            $('#' + this.divID).width() + 'px;">' + text + '</div>'; // +
//            '<div id="' + this.divID + 'ssimgbg' + this.index + '" style="width: ' +
//            $('#' + this.divID).width() + 'px; height: ' + $('#' + this.divID).height() + 'px;">' +
//            '</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); 
        
        $('.sstext').css('opacity', '0');
        $('.sstext').css('display', 'block');
        
        $('#' + 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 = 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');   
        }
//        if (!lastelmistext){  
            $('#' + this.divID + 'ssdiv' + this.currentimg).fadeOut(this.transitiontime); 
//        } 
//        else{               
//            $('#' + this.divID + 'ssdiv' + this.currentimg).fadeOut(this.transitiontime);   
//            var thisObj = this;
//            setTimeout(function() {
//                    lastelm.animate({ 
//                        marginTop: $('#' + thisObj.divID).height(),
//                        opacity: 0
//                      }, thisObj.transitiontime );                                                      
//                }, this.showtime);       
//        }                                                                                
        $('#' + this.divID + 'ssdiv' + this.nextimg).fadeIn(this.transitiontime);     
        if (elmistext){       
            //$('#' + this.divID + 'ssimg' + this.currentimg).fadeIn(this.transitiontime);            
            //$('#' + this.divID + 'ssimg' + this.currentimg).css('background-color', '#000000');
            elm.animate({ 
                marginTop: ($('#' + this.divID).height() - 18) / 2,
                opacity: .9
              }, this.transitiontime );            
            //$('#' + this.divID + 'ssimg' + this.currentimg).css('background-color', '');  
        }
        if (lastelmistext){
//            lastelm.animate({ 
//                marginTop: $('#' + this.divID).height(),
//                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(){ 
        thisObj.initslideshow();     
    });  
    
    $(window).load(function(){  
        thisObj.advanceslideshow();
    });                                                                                         
}     