
RandomMainPageGallery = {
	timeout_time : 5000,
	initGallery : function() {
		$$('#mp_random_gallery .aItem').each(function(elem){ elem.setOpacity(0); elem.setStyle({'zIndex' : 0}); });
		this.currentElement = $('mp_random_gallery').down('.aItem').setOpacity(1).setStyle({'zIndex' : 1});
		this.timeout = setTimeout( "RandomMainPageGallery.nextPhoto();", this.timeout_time );
	},	
	nextPhoto : function() {
		clearTimeout(this.timeout);
		currentElement = this.currentElement;
		nextElement = currentElement.next('.aItem');
		if(!nextElement) {
			nextElement = currentElement.up(0).down('.aItem');
		}
		new Effect.Opacity(currentElement, { from: 1, to: 0, duration: 0.5 });
		currentElement.setStyle({'zIndex': '0'});
		new Effect.Opacity(nextElement, { from: 0, to: 1, duration: 0.5 });
		nextElement.setStyle({'zIndex': '1'});
		this.currentElement = nextElement;
		this.timeout = setTimeout( "RandomMainPageGallery.nextPhoto();",  this.timeout_time );
	},
	prevPhoto : function() {
		clearTimeout(this.timeout);
		currentElement = this.currentElement;
		nextElement = currentElement.previous('.aItem');
		if(!nextElement) {
			elems = currentElement.up(0).select('.aItem');
			nextElement = elems[elems.length-1];
		}
		currentElement.setStyle({'zIndex': '0'});
		new Effect.Opacity(currentElement, { from: 1, to: 0, duration: 0.5 });
		nextElement.setStyle({'zIndex': '1'});
		new Effect.Opacity(nextElement, { from: 0, to: 1, duration: 0.5 });
		this.currentElement = nextElement;
		this.timeout = setTimeout( "RandomMainPageGallery.nextPhoto();",  this.timeout_time );
	}
};
RandomMainPageGallery.initGallery();
