I have the code below but I cannot call nextPromo because it is not a function. How can I make this work? I am trying to setup a rotator using object oriented style. I am new to it so i am very confused. I have tried many things but I jsut don’t know and I am very frustrated with it, please help
function promoSlides(s){
this.index = 0;
this.prevIndex = 0;
this.currentVeh = "";
this.t;
this.slides = s;
this.len = this.slides.length;
this.sortWeight = function(){
($('body').hasClass('en')) ? this.slides.sort(SortByWeight) : this.slides.sort(SortByWeightFr);
};
function SortByWeight(a,b) { return b.weight - a.weight; }
function SortByWeightFr(a,b) { return a.frWeight - b.frWeight; }
this.startTimer = function(){ this.t = setTimeout("this.nextPromo()", 3000); }
this.nextPromo = function(){
if(this.index > 0 || this.prevIndex > 0) $(this.slides[this.prevIndex].el).css("display","none");
$(this.slides[this.index].el).css("display","block");
this.prevIndex = this.index;
this.index = (this.index < this.len-1) ? this.index+1 : 0;
this.startTimer();
}
return true;
} ;
EDIT: Here is a simplified example which I have tested. This uses setInterval to periodically advance the slide index. The “next” functionality is contained within an anonymous function.