/**
 * news script jquery
 * Examples and documentation at: http://benjaminsterling.com/jquery-jqgalscroll-photo-gallery/
 *
 * @author: Philippe Symons
 * @copyright (c) 2010 Philippe Symons, Inventis Web Architects
*/

var maxNews=0;
var currentIndex=0;
var firstTime=true;

$(document).ready(function(){
    maxNews=$('.main').size();
    //don't even start when there's only one item
    if(maxNews > 1){
        var config=
            {
                interval: 15000,
                repeat: true,
                callback: update
            };//end config
        jQuery.timerDelayCall(config);
    }//end if

});

var update=function(){
    if(firstTime){
        firstTime=false;
    }//end if
    else{
        //first of all remove the class 'first' from all elements.
        $('.main:first-child').css('display', 'none');

        //remove the previous news message and set a new one
        var item=$('.main').get(currentIndex);
        $(item).hide();

        currentIndex++;
        //when we reached the last item, start over.
        if(currentIndex > maxNews -1){
            currentIndex=0;
        }//end if

        item=$('.main').get(currentIndex);
        $(item).fadeIn('slow');
    }//end else
}//end update

var removeFirst=function(index){
    $(this).removeClass('first');
}//end removeFirst
