var featuredGallery = {
  total: 0,
  current: 0,
  task : null,
  images : [],
  slideshow: function() {
	$(featuredGallery.images[featuredGallery.current]).fadeOut(1000);
	if(featuredGallery.current+1 >= featuredGallery.total) {
		featuredGallery.current = 0;
	}
    featuredGallery.current++;
	$(featuredGallery.images[featuredGallery.current]).fadeIn(1000);
  },
  shuffle: function() {
	featuredGallery.images.sort( function() { return 0.5 - Math.random(); } );
  }
}

$(function() {
  featuredGallery.total = $('#top_content a').length;
  featuredGallery.images = $('#top_content a img').toArray();
  $('#top_content a img').hide();
  featuredGallery.shuffle();
  $(featuredGallery.images[featuredGallery.current]).show();

  if(featuredGallery.total > 1) {
    featuredGallery.task = window.setInterval(featuredGallery.slideshow, 5000);
  }
});
