Here is a link to the JSfiddle.
Javascript:
var headerCount;
var timeDelay;
$(document).ready(function () {
headerCount = $('.headerlink').length;
timeDelay = $('.current').attr('ref');
if (undefined != timeDelay) {
timeDelay = "5000"
}
setTimeout("advance()", timeDelay);
});
function advance() {
$('.current').next('.headerlink').addClass('current2');
$('.current').removeClass("current");
$('.current2').addClass('current').removeClass('current2');
if (headerCount == $(".current").index('.headerlink')) {
$('.current').removeClass('current');
$('.headerlink:nth-child(1)').addClass('current');
}
timeDelay = $('.current').attr('ref');
if (undefined != timeDelay) {
timeDelay = "5000"
}
setTimeout("advance()", timeDelay);
}
HTML:
<a ref="5000" class="headerlink current" href="http://www.raceramps.com/12-4thqtr-twenty-five-dollar-rebate.aspx"> <img class="headerimg" src="http://www.raceramps.com/images/promos/4thQTR[25_rebateCheck].jpg" /> </a>
<a class="headerlink" href="http://www.raceramps.com/2012-3rdqtr-25-visa.aspx"> <img class="headerimg" src="http://www.raceramps.com/images/promos/3rdQTR[25VISA_rebate].jpg" /> </a>
<a class="headerlink" href="http://www.raceramps.com/12-4thqtr-twenty-five-dollar-rebate.aspx"> <img class="headerimg" src="http://www.raceramps.com/images/promos/4thQTR[25_rebateCheck].jpg" /> </a>
<a class="headerlink" href="http://www.raceramps.com/12-4thqtr-twenty-five-dollar-rebate.aspx"> <img class="headerimg" src="http://www.raceramps.com/images/promos/4thQTR[25_rebateCheck].jpg" /> </a>
Problem: The goal is for the code to add .current to the next('.headerlink'), then remove .current from the original. But for some reason, it just removes .current (it appears to add/remove to all the matching elements very quickly).
What am I missing?
This does the job:
http://jsfiddle.net/carlosmartinezt/Erw8y/29/
The code is the following:
It is a simplified version, removing irrelevant lines of code.