// Speed of the automatic slideshow var slideshowSpeed = 5000; // Variable to store the images we need to set as background // which also includes some text and url's. var photos = [ { "title" : "", "image" : "http://images.catholic.org/carousel/news/2015032347father_norm_easter_banner_1200__x550.jpg", "url" : "/carouselClicks.php?t=%A8%95%1CT%28q%ABm%EF%EF%CB%81K%09d%D4", "firstline" : "", "secondline" : "" }, { "title" : "", "image" : "http://images.catholic.org/carousel/news/20141233461200.jpg", "url" : "/carouselClicks.php?t=%DF%8E%C1%EE%0A%16S%0F%FDu%9B%BD%1C%5Dp%D4", "firstline" : "", "secondline" : "" }, { "title" : "", "image" : "http://images.catholic.org/carousel/news/201502534141-catholic-faith-1200x550.gif", "url" : "/carouselClicks.php?t=%25%29%AE%9D-%ED%85%1D%DCE%22br%04%BB%C4", "firstline" : "", "secondline" : "" }, { "title" : "", "image" : "http://images.catholic.org/carousel/news/2014070034serve-1200x550-rev2.jpg", "url" : "/carouselClicks.php?t=Bx%A0%D4%1B%F6%09%9F%A8%DB%9F%2CS%177%DE", "firstline" : "", "secondline" : "" }, { "title" : "", "image" : "http://images.catholic.org/carousel/news/2014101234carb-trappistcaskets-carouselad-story-1200x550cross.jpg", "url" : "/carouselClicks.php?t=%81Srg%16%3D%F1%0C%D7e%B29%10%B4%B4%89", "firstline" : "", "secondline" : "" }, { "title" : "", "image" : "http://images.catholic.org/carousel/news/2014095923bible-ad_1200x550.jpg", "url" : "/carouselClicks.php?t=%2C%0D%27%24%96%CF%3A%DBo%B8%0E%C3%AE%F1u%7F", "firstline" : "", "secondline" : "" }, { "title" : "", "image" : "http://images.catholic.org/carousel/news/20141032141200.jpg", "url" : "/carouselClicks.php?t=%0C%D2%1E-%7E%BB%E8%FA%8D%A4%B5%FE%2Aa%40%5E", "firstline" : "", "secondline" : "" }, { "title" : "", "image" : "http://images.catholic.org/carousel/news/2015022322weisscarousel.jpg", "url" : "/carouselClicks.php?t=%7C%29%C0%E8q%A1%1D%F9%0Dr%5C%DB%B8%1Fq%D2", "firstline" : "", "secondline" : "" }, { "title" : "", "image" : "http://images.catholic.org/carousel/news/20150141281200x550.jpg", "url" : "/carouselClicks.php?t=d%C0%DFH%AB%C4%18%5B+%B1J%8A%A5w%C4G", "firstline" : "", "secondline" : "" } ]; $(document).ready(function() { // Backwards navigation $("#back").click(function() { stopAnimation(); navigate("back"); }); // Forward navigation $("#next").click(function() { stopAnimation(); navigate("next"); }); var interval; $("#control").toggle(function(){ stopAnimation(); }, function() { // Change the background image to "pause" $(this).css({ "background-image" : "url(/images/carousel-pause1.png)" }); // Show the next image navigate("next"); // Start playing the animation interval = setInterval(function() { navigate("next"); }, slideshowSpeed); }); var activeContainer = 1; var currentImg = 0; var animating = false; var navigate = function(direction) { // Check if no animation is running. If it is, prevent the action if(animating) { return; } // Check which current image we need to show if(direction == "next") { currentImg++; if(currentImg == photos.length + 1) { currentImg = 1; } } else { currentImg--; if(currentImg == 0) { currentImg = photos.length; } } // Check which container we need to use var currentContainer = activeContainer; if(activeContainer == 1) { activeContainer = 2; } else { activeContainer = 1; } showImage(photos[currentImg - 1], currentContainer, activeContainer); }; var currentZindex = 20000; var showImage = function(photoObject, currentContainer, activeContainer) { animating = true; // Make sure the new container is always on the background currentZindex--; // Set the background image of the new active container $("#headerimg" + activeContainer).css({ "background-image" : "url(" + photoObject.image + ")", "border" : "0px solid #ccc", "cursor" : "pointer", "display" : "block", "z-index" : currentZindex }); $("div#headerimg" + activeContainer).click(function(){ window.location=photoObject.url; }); // Hide the header text $("#headertxt").css({"display" : "none"}); // Set the new header text $("#firstline").html(photoObject.firstline); $("#secondline") .attr("href", photoObject.url) .html(photoObject.secondline); $("#pictureduri") .attr("href", photoObject.url) .html(photoObject.title); // Fade out the current container // and display the header text when animation is complete $("#headerimg" + currentContainer).fadeOut(function() { setTimeout(function() { $("#headertxt").css({"display" : "block"}); animating = false; }, 500); }); }; var stopAnimation = function() { // Change the background image to "play" $("#control").css({ "background-image" : "url(/images/carousel-play1.png)" }); // Clear the interval clearInterval(interval); }; // We should statically set the first image navigate("next"); // Start playing the animation interval = setInterval(function() { navigate("next"); }, slideshowSpeed); });