
/* Script taken from http://www.leemessenger.co.uk - Please do not remove this line */
function ChangeCSSBgImg() {
	if (!document.getElementById) return false;
	
	var MyElement = "bg_fotos" //The ID of the element you want to change
	var ImgPath = "imagens/" //The file path to your images
	
	if (!document.getElementById(MyElement)) return false;
	
	var random_images = new Array ();
	random_images[0] = "bg_01.jpg"; // Don't forget to increase the array number each time
	random_images[1] = "bg_02.jpg"; // Don't forget to increase the array number each time
	random_images[2] = "bg_03.jpg"; // Don't forget to increase the array number each time
	random_images[3] = "bg_04.jpg"; // Don't forget to increase the array number each time
	random_images[4] = "bg_07.jpg"; // Don't forget to increase the array number each time
	random_images[5] = "bg_08.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) {
		changeBgImg(MyElement, ImgURL);
		//$header.style.backgroundImage = ImgURL;	
	}
	
	movement = setTimeout("ChangeCSSBgImg()",45000);
}

function changeBgImg(MyElement, ImgURL) {
    var myFx = new Fx.Tween($(MyElement));
    
    fadeColor(MyElement, "out");
    
    setTimeout('fadeImg("'+MyElement+'", "'+ImgURL+'");', 500);    
}

function fadeColor(MyElement, color) {
    var myFx = new Fx.Tween($(MyElement));
    //myFx.set('background-color', color);
    //myFx.start('background-color', color);
    $('bg_fotos').fade(color);
}

function fadeImg(MyElement, ImgURL) {
    var myFx = new Fx.Tween($(MyElement));
    myFx.start('background-image', ImgURL);
    fadeColor(MyElement, "in");
}

/* 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);