// JavaScript Document
function ChangeCSSBgImg() {
	if (!document.getElementById) return false;
	
	var MyElement = "background" //The ID of the element you want to change
	var ImgPath = "image/" //The file path to your images
	
	if (!document.getElementById(MyElement)) return false;
	
	var random_images = new Array ();
	random_images[0] = "1bg.jpg"; // Don't forget to increase the array number each time
	random_images[1] = "2bg.jpg"; // Don't forget to increase the array number each time
	random_images[2] = "3bg.jpg"; // Don't forget to increase the array number each time
	random_images[3] = "4bg.jpg"; // Don't forget to increase the array number each time
	random_images[4] = "5bg.jpg"; // Don't forget to increase the array number each time
	random_images[5] = "6bg.jpg"; // Don't forget to increase the array number each time
	random_images[6] = "7bg.jpg"; // Don't forget to increase the array number each time
	random_images[7] = "8bg.jpg"; // Don't forget to increase the array number each time
	random_images[8] = "9bg.jpg"; // Don't forget to increase the array number each time
	
	var $header = document.getElementById(MyElement);
	var $backgroundurl = $header.style.backgroundImage;
	var ImgURL = "url(" + ImgPath + random_images[rand(random_images.length)] + ")";
	
	if ($backgroundurl != ImgURL) {
		$header.style.backgroundImage = ImgURL;	
	}
	
	
}

/* random number generator */
function rand(n) {
  return ( Math.floor ( Math.random ( ) * n ) );
}

/* Custom onload function */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
/* trigger onload */
addLoadEvent(ChangeCSSBgImg);
