$(document).ready(function(){ /* this code is executed after the dom has been completely loaded */ var totwidth=0; var positions = new array(); $('#slides .slide').each(function(i){ /* traverse through all the slides and store their accumulative widths in totwidth */ positions[i]= totwidth; totwidth += $(this).width(); /* the positions array contains each slide's commulutative offset from the left part of the container */ if(!$(this).width()) { alert("please, fill in width & height for all your images!"); return false; } }); $('#slides').width(totwidth); /* change the cotnainer div's width to the exact width of all the slides combined */ $('#menu ul li a').click(function(e,keepscroll){ /* on a thumbnail click */ $('li.menuitem').removeclass('act').addclass('inact'); $(this).parent().addclass('act'); var pos = $(this).parent().prevall('.menuitem').length; $('#slides').stop().animate({marginleft:-positions[pos]+'px'},450); /* start the sliding animation */ e.preventdefault(); /* prevent the default action of the link */ // stopping the auto-advance if an icon has been clicked: if(!keepscroll) clearinterval(itvl); }); $('#menu ul li.menuitem:first').addclass('act').siblings().addclass('inact'); /* on page load, mark the first thumbnail as active */ /***** * * enabling auto-advance. * ****/ var current=1; function autoadvance() { if(current==-1) return false; $('#menu ul li a').eq(current%$('#menu ul li a').length).trigger('click',[true]); // [true] will be passed as the keepscroll parameter of the click function on line 28 current++; } // the number of seconds that the slider will auto-advance in: var changeevery = 4; var itvl = setinterval(function(){autoadvance()},changeevery*1000); /* end of customizations */ });