var images;
var num = 0;
var container;
var t;

function initGallery(selector, imgList)
{
    container = $(selector);
    if (!container)
        return;
    if (imgList.length < 2)
        return;
    images = imgList;
    num = 1;
    t = setTimeout('onTimer()', 2000);
}

function onTimer()
{
    $(container).append(
        $('<img>').css({ opacity: 0, display: 'block' }).addClass('newGalleryImage').load(
            function() {
            $(this).animate({ opacity: 1 }, 1000, 'linear', function(){
                $(container).find('.galleryImage').each(function(){ $(this).remove(); });
                $(this).removeClass('newGalleryImage').addClass('galleryImage');
                if (images.length == num + 1)
                    num = 0;
                else
                    num = num + 1;
                t = setTimeout('onTimer()', 5000);
                });
            }).attr({ src: images[num].src })
        );
}



