var kvStyle = document.getElementById('key_visual');
var r_img = new Array ();
r_img[0] = "images/backMain.png";
r_img[1] = "images/backMain2.png";
r_img[2] = "images/backMain3.png";
r_img[3] = "images/backMain4.png";

// Remember, JavaScript arrays are zero indexed (the first element of an array in JavaScript 
// has an index of 0). Our array r_img consists of four elements. The 
// Math.random() method returns a value between 0 and 1. We have to convert this value to an 
// integer between 0 to 3 so that it can be used as an index to retrieve the string from the 
// r_img array. We store the final value in a variable i.

var i = Math.round(3*Math.random());
kvStyle.style.backgroundImage = "url(" + r_img[i] + ")";