var bgs = new Array ( "background-top-ingresso.jpg", "background-top-piscina.jpg", "background-top-piscina1.jpg", "background-top-tenda.jpg" ); var numBgs = bgs.length; var c = 0; // Index of current image. var rnum = Math.round(Math.random()*numBgs); // For the onLoad script function randBg() { changeBg(rnum); } // Loads an image not quite random; based on the time, new every n minutes. function loadBg(n) { Time = new Date(); var Mins = Time.getMinutes(); changeBg((Math.round(Mins/n)) % numBgs); // Next image every n minutes. } // Uncomment to preload images var preload = new Array(); for (var i=0; i < numBgs; i++) { preload[i] = new Image; preload[i].src = bgs[i]; } function changeBg(n) { document.getElementById("switcher").style.background = 'url(ui/s/normale/bgtop/' + bgs[n] + ') top no-repeat'; c = n; } // Direction > 0 == forward, Direction < = 0 == back. function goBg(direction) { var next; if (direction > 0) { if (c+1 == numBgs) next = 0; else next = c+1; } else if (direction <= 0) { if (c == 0) next = numBgs-1; else next = c-1; } changeBg(next); }