
$(document).ready(function(){
     var totWidth=0;
    var positions = new Array();

    $('#slides .slide').each(function(i){

        positions[i]= totWidth;
        totWidth += $(this).width();

        if(!$(this).width())
        {
            alert("Please, fill in width & height for all your images!");
            return false;
        }
    });

    $('#slides').width(totWidth);

    var current=1;

    function autoAdvance(){
        if(current==-1) return false;
        if(current==4) current=0;
        $('#slides').stop().animate({
            marginLeft:-positions[current]+'px'
        },1650);
        // $('#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++;
    }

    var changeEvery = 5;

    var itvl = setInterval(function(){
        autoAdvance()
    },changeEvery*1000);
});
