
var MangiarottiGalleryControll;
function MG__scrollGallery(dir){
	if(!MangiarottiGalleryControll){
		MangiarottiGalleryControll = new MG_GalleryControll();
	}
	if(dir=='up'){
		MangiarottiGalleryControll.scrollUp();
	}else{
		MangiarottiGalleryControll.scrollDown();
	}
}
/**
 * Class Mangiarotti Gallery Controll
 * created by Alkadia di adm for Mangiarotti S.p.A.
 * 
 * @return GalleryControll Object
 */
var MG_GalleryControll=Class.create({
	initialize: function() {
		this.visibles = 2;
		this.minScroll = 180;
		this.initialized = false;
		this.maxScroll = 0;
		this.scroll = 0;
		this.setUpGallery();	
	 }, 
	setUpGallery:function(){
		var num = $('mangiarotti_examples').select('.image_row');
		if (num.length > 0) {
			this.initialized = true;
		}
		this.maxScroll = ((num.length - this.visibles) > 0) ? (num.length - this.visibles) : 0;
	},
	setMinimumScroll:function(value){
		this.minScroll = value;
	},
	scrollUp: function(){
		if (this.initialized) {
			this.scroll++;
			if (this.scroll <= this.maxScroll) {
				var newY = -(this.scroll * this.minScroll);
				new Effect.Move('gallery-content', {
					x: 0,
					y: newY,
					mode: 'absolute',
					transition: Effect.Transitions.spring
				});
				
			}
			else {
				this.scroll = this.maxScroll;
			}
		}else{
			return false;
		}
	},
	scrollDown: function(){
		if (this.initialized) {
			this.scroll--;
			if (this.scroll < 0) {
				this.scroll = 0;
			}
			else {
				var newY = -(this.scroll * this.minScroll);
				new Effect.Move('gallery-content', {
					x: 0,
					y: newY,
					mode: 'absolute',
					transition: Effect.Transitions.spring
				});
				
			}
		}else{
			return false;
		}
	},
	showImage: function(element){
		var imgID = $(element).select('img')[0].id.split('img_id_')[1];
		window.open('http://www.mangiarotti.it/externalPopup/index.php?img_id='+imgID,'mangiarotti_popup','width=20, height=20,left=0, top=0, resizable=no, scrollbars=no, status=no, menubar=no');
	}
	
})

