$(document).ready(function(){
  setTimeout("makeVisible();",500);
  rotateAds(-1);
  rotatePhotos(-1);
});
function makeVisible()
{
	document.getElementById('face').style.visibility="visible";
	document.getElementById('ad').style.visibility="visible";
}
function rotateAds(currentAd) {
  var numberOfAds = $('#ad .ads').length;
  currentAd = currentAd % numberOfAds;
  $('#ad .ads').eq(currentAd).fadeOut(function() {
		// re-order the z-index
    $('#ad .ads').each(function(i) {
      $(this).css(
        'zIndex', ((numberOfAds - i) + currentAd) % numberOfAds
      );
    });
    $(this).show();
    setTimeout(function() {rotateAds(++currentAd);}, 5000);
  });
}
function rotatePhotos(currentPhoto) {
  var numberOfPhotos = $('#face .faces').length;
  currentPhoto = currentPhoto % numberOfPhotos;
  $('#face .faces').eq(currentPhoto).fadeOut(function() {
		// re-order the z-index
    $('#face .faces').each(function(i) {
      $(this).css(
        'zIndex', ((numberOfPhotos - i) + currentPhoto) % numberOfPhotos
      );
    });
    $(this).show();
    setTimeout(function() {rotatePhotos(++currentPhoto);}, 5000);
  });
}

