
/* Script taken from http://www.leemessenger.co.uk - Please do not remove this line */
function ChangeCSSBgImg() { 
    if (!document.getElementById) return false;
    
    var MyElement = "header" //The ID of the element you want to change
    var ImgPath = "/img/" //The file path to your images
    
    if (!document.getElementById(MyElement)) return false;
    
    var random_images = new Array ();
    random_images[0] = "bg_header_builders1.jpg";
    random_images[1] = "bg_header_builders2.jpg";
    random_images[2] = "bg_header_builders3.jpg";
    //random_images[3] = "bg_header_builders4.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; 
    }
    
    movement = setTimeout("ChangeCSSBgImg()",7000);
}

//Used to set an initial image so there is no initial flicker when the second image loads in
function setInitialImage() {
    if (!document.getElementById) return false;
    
    var MyElement = "header" //The ID of the element you want to change
    var ImgPath = "/img/" //The file path to your images
    
    if (!document.getElementById(MyElement)) return false;
    
    var $header = document.getElementById(MyElement);
    var $backgroundurl = $header.style.backgroundImage;
    var ImgURL = "url(" + ImgPath + "bg_header_builders4.jpg" + ")";
    
    if ($backgroundurl != ImgURL) {
        $header.style.backgroundImage = ImgURL; 
    }
    
    movement = setTimeout("ChangeCSSBgImg()",7000);
}


/* 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(setInitialImage);
