window.addEvent('domready', function() {

	if(typeof(backimage) !== 'undefined' && backimage != null && backimage != "uploads/tx_ogvimagefield/") {
	
		/*//first remove no-JS background image
		if (browserVersion == "ie6"){
			// -> for IE6
			$(document.body).setStyle('background-image','none');
		}
		else{
			// -> for everything except IE6
			$('background').setStyle('background-image','none');	
		}*/
		
		$(document.body).setStyle('background-color','#D0D1D3');
		
		//load and fade background image
		setTimeout("load_image(backimage)",250);
	}
});


//decide which image should be loaded
/*function get_image_by_hour(){
	
	var img = backimage

	// if there is no image available for this interval: use default
	if(typeof(img) !== 'undefined' && img != null) {
		return img;
	}
	else {
		return backimage_default;
	}
}*/

//load and fade the background image
function load_image(img_src){
	var image = new Image();
	image.onload = function() {
		
		//if (browserVersion == "ie6"){
		if (typeof(browserVersion) !== 'undefined' &&  browserVersion== "ie6") {
			// -> for IE6
			var e = $(document.body);
			e.setStyle('background-image','url(' + this.src + ')');
		}
		else{
			// -> for everything except IE6
			var e = $('background');	
		
			e.setStyle('background-image','url(' + this.src + ')');
			e.setStyle('opacity','0.001');
			
			//e.fx = new Fx.Styles(e, {duration:1600, wait:false});
			//e.fx.start({
			//		'opacity': 1
			//});
			
			//e.fx = new Fx.Morph(e, {duration:1600, onComplete: function() {
            //    new Fx.Morph(e, {duration:1600}).start({opacity:0});
			//}}).start({'opacity':1}); 
			
			e.fx = new Fx.Morph(e, {duration:2000, wait:false});
			e.fx.start({
					'opacity': 1
			});
		}
	};
	image.src =img_src;
}
