$(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) {
            positions[i]= totWidth;
            totWidth += $(this).width();

            if(!$(this).width()) {
                return false;
            }
    });
    // Set with
    $('#slides').width(totWidth);


    $('#solutions-menu ul li a').click(function(e,keepScroll) {
        /* On a thumbnail click */

        $('a').removeClass('act').addClass('inact');
        //$(this).parent().addClass('act');
        $(this).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);
    });
    // First element 'a' is active
    $('a:first').addClass('act').siblings().addClass('inact');



    /*****
     *
     *	Enabling auto-advance.
     *
     ****/
    var current=1;
    function autoAdvance() {
            if(current==0) return false;
            $('#solutions-menu ul li a').eq(current%$('#solutions-menu ul li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
            current++;
    }
    // Interval between each slider (in s)
    var changeEvery = 4;
    var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);
});