$(document).ready(function() {
 
    //Assign a timer, so it will run periodically
    var pto = setTimeout('newsslider()', speed); 
     
    $('#gallery li:first').addClass('selected');
 
});
 
 
function newsslider() {
 
    //Get the current selected item (with selected class), if none was found, get the first item
    var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');
 
    //Get next sibling
    var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');
    var animSpeed = (current_image.next().length) ? 500 : 100;
        
    //clear the selected class
    $('#gallery li').removeClass('selected');
     
    //reassign the selected class to current items
    next_image.addClass('selected');
 
    //Scroll the items
    $('#mask-gallery').scrollTo(next_image, animSpeed, {
        'onAfter' : setPto()
    });      
    
}

function setPto() {
    pto = setTimeout('newsslider()', speed); 
}

