var SchmuckGallery = Class.create({
	init: function(p_elem, p_height) {
		this.interval      = null;
		this.elem          = p_elem;
		this.maxy          = p_height - p_elem.getHeight();
		this.cury          = 0.0;
		this.lock_movement = false;

		this.elem.observe("mouseout", function(p_ev) {
			if(!this.lock_movement) this.back();
		}.bind(this));
		this.elem.observe("mousemove", function(p_ev) {
			if(!this.lock_movement) this.setY(this.calc_yoffset(p_ev) / this.elem.getHeight());
		}.bind(this));
	},
	tweener: function(p_t) {
		this.setY(Math.sin(0.5 * p_t));
	},
	setY: function(p_t) {
		this.cury = p_t;
		this.elem.setStyle({backgroundPosition: '0px -' + (p_t * this.maxy) + 'px'});
	},
	calc_yoffset: function(p_event) {
		return Event.pointerY(p_event) - this.elem.cumulativeOffset().top;
	},
	back: function() {
		this.lock_movement = true;
		new Effect.Tween(null, 2.0 * Math.asin(this.cury), 5.0, {
			duration:    8.0,
			delay:       1.0,
			queue:       { scope: 'schmuckbild' },
			afterFinish: function() { this.lock_movement = false; }.bind(this)
		}, this.tweener.bind(this));
	},
	start: function() {
		this.lock_movement = true;

		new Effect.Appear(this.elem, {
			from:        0.0,
			to:          1.0,
			duration:    0.5,
			queue:       { scope: 'schmuckbild' }
		});
		new Effect.Tween(null, 0.0, 5.0, {
			duration:    8.0,
			delay:       2.5,
			scope:       'schmuckbild',
			queue:       { scope: 'schmuckbild', position: 'end' },
			afterFinish: function() { this.lock_movement = false; }.bind(this)
		}, this.tweener.bind(this));
	}
});

