var backgrounds_path = '/template/common/images/backgrounds/';
var backgrounds = [
	{low:'lilly1.jpg', medium:'lilly2.jpg', high:'lilly3.jpg'},
	{low:'pink1.jpg', medium:'pink2.jpg', high:'pink3.jpg'},
	{low:'sun1.jpg', medium:'sun2.jpg', high:'sun3.jpg'},
	{low:'blue1.jpg', medium:'blue2.jpg', high:'blue3.jpg'},
	{low:'butter1.jpg', medium:'butter2.jpg', high:'butter3.jpg'},
	{low:'snow1.jpg', medium:'snow2.jpg', high:'snow3.jpg'},
	{low:'white1.jpg', medium:'white2.jpg', high:'white3.jpg'},
	{low:'yellow1.jpg', medium:'yellow2.jpg', high:'yellow3.jpg'},
];

var current_bg = Math.floor(Math.random() * backgrounds.length);
var bgload_step = 0;
var BackgroundCache = new Image();
BackgroundCache.src = backgrounds_path + backgrounds[current_bg].low;

window.onload = function() {
	document.getElementById('HomeBg').style.backgroundImage = 'url(' + BackgroundCache.src + ')';
	bgload_step++;
	BackgroundCache.src = backgrounds_path + backgrounds[current_bg].medium;
}
BackgroundCache.onload = function() {
	if(bgload_step > 0 && bgload_step < 3) {
		document.getElementById('HomeBg').style.backgroundImage = 'url(' + this.src + ')';
		if(bgload_step < 3) {
			bgload_step++;
			this.src = backgrounds_path + (bgload_step == 1 ? backgrounds[current_bg].medium : backgrounds[current_bg].high);
		}
	}
}
