
RandomMainPageGallery = {
	timeout_time : 4000,
	initGallery : function() {
		$$('#mp_random_gallery a.mp_photo').each(function(elem){ elem.setOpacity(0); elem.setStyle({'zIndex' : 0}); });
		this.currentElement = $('mp_random_gallery').down('a.mp_photo').setOpacity(1).setStyle({'zIndex' : 1});
		this.timeout = setTimeout( "RandomMainPageGallery.nextPhoto();", this.timeout_time );
	},	
	nextPhoto : function() {
		clearTimeout(this.timeout);
		currentElement = this.currentElement;
		nextElement = currentElement.next('.mp_photo');
		if(!nextElement) {
			nextElement = currentElement.up(0).down('.mp_photo');
		}
		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('.mp_photo');
		if(!nextElement) {
			elems = currentElement.up(0).select('.mp_photo');
			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();


updateBannerMainPageOffset = function() {
	document_width = document.viewport.getWidth();
	if(document_width > 980) {
		$$('#banner_main_page_left_offset, #banner_main_page_right_offset').invoke('show');
		offset_width = (document_width - 980) / 2;
		$('banner_main_page_left_offset').setStyle( { marginLeft: '-'+offset_width+'px', width : offset_width+'px' } );
		$('banner_main_page_right_offset').setStyle( { marginLeft: (980+offset_width)+'px', width : offset_width-10+'px' } );		
	} else {
		$$('#banner_main_page_left_offset, #banner_main_page_right_offset').invoke('hide');
	}
}
updateBannerMainPageOffset();

