window.addEvent('domready', function() {
	
	var path = '/css/images/'
	var bg = [path+'random.jpg', path+'random1.jpg', path+'fondo3.jpg'];
	
	var ws = window.getScrollSize();
	var div_bg = new Element('div', {
		'class': bg.getRandom(),
		'styles': {
			'position': 'absolute',
			'top': '0',
			'left':'0',
			'width': ws.x+'px',
			'height': ws.y+'px',
			'overflow': 'hidden',
			'z-index':-10
		}
	}).inject(document.body);
	
	var img = new Asset.images(bg);
	img.each(function(el, i) {
		el.setStyles({
			'position': 'absolute',
			'top': '0',
			'left': '0',
			'opacity': '0'
		});
		el.set('morph', { duration: 1200 });
		div_bg.adopt(el);
	});
	var c = img.indexOf(img.getRandom());
	img[c].morph({ opacity: 1 });
	var tot = bg.length;
	var bgChange = function(){
		var prev = c;
		c++;
		if ( c >= tot  ) c = 0;
		img[prev].morph({ opacity: 0 });
		img[c].morph({ opacity: 1 });
	};
	bgChange.periodical(10000);
});