$(function() { $(".dropdown-toggle").on("mouseenter", function() { $(this).css("cursor", "pointer"); var menu = $(this).parent().find(".dropdown-menu"); if (!menu.is(":visible")) { menu.show(); } }); $(".dropdown-toggle").on("click", function() { var menu = $(this).parent().find(".dropdown-menu"); if (menu.is(":visible")) { menu.hide(); $(this).blur(); } else { menu.show(); } }); $(".dropdown").on("mouseleave", function() { var menu = $(this).find(".dropdown-menu"); $(this).blur(); if (menu.is(":visible")) { menu.hide(); } }); var swapTimer = 5000; // must be >= 2500 var maxImages = 15; var current = 2; // change background-image every swapTimer ms function nextBackground() { var nextImage = rand(1, maxImages); if (nextImage == current) { // no change if (nextImage > 1) { nextImage = rand(1, nextImage - 1); } else { nextImage = rand(nextImage + 1, maxImages); } } var image = "../images/bg/" + nextImage + ".jpg"; $(".whole-screen").css("background-image", 'url("' + image + '")').animate({opacity: 1}); current = nextImage; setTimeout(nextBackground, swapTimer); } setTimeout(nextBackground, swapTimer * 8); function rand(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } });