var Slider = Class.create();
Slider.prototype = {
	productWidth: 0,
	containerWidth: 638,
	sliderWidth: 591,
	sliderPosition: 0,
	initialize: function() {
		this.anzahl = $$('.product_list_item').length;
		Slider.prototype.productWidth = (this.anzahl * 163);
		this.productSlider = new Control.Slider('slider', 'slidebar');

		this.productSlider.options.onSlide = function(value) {
			Slider.prototype.animate(value);
		};
		this.productSlider.options.onChange = function(value) {
			Slider.prototype.animate(value);
		};
		Event.observe('slider_left', 'mousedown', function(){
			Slider.prototype.leftClick();
		});
		Event.observe('slider_right', 'mousedown', function(){
			Slider.prototype.rightClick();
		});
	},

	animate: function(value) {
		if(value>1) value=1;
		if(value<0) value=0;

		Slider.prototype.sliderPosition = value;

		$('scrollnav').style.left = (-Slider.prototype.productWidth+Slider.prototype.containerWidth) * value + "px";	
	},

	leftClick: function() {
		var moveTo = (parseInt($('slider').style.left.substring(0, $('slider').style.left.length - 2)) - ((Slider.prototype.sliderWidth-93)/10));
		if(moveTo<0) moveTo=0;
		$('slider').style.left = moveTo + "px";
		this.animate(Slider.prototype.sliderPosition-.1);
	},

	rightClick: function() {
		var moveTo = (parseInt($('slider').style.left.substring(0, $('slider').style.left.length - 2)) + ((Slider.prototype.sliderWidth-93)/10));
		if(moveTo>Slider.prototype.sliderWidth-93) moveTo=Slider.prototype.sliderWidth-93;
		$('slider').style.left = moveTo + "px";
		this.animate(Slider.prototype.sliderPosition+.1);
	}
};

function slider_init() {
	var slider = new Slider();
}

//Event.observe(window, 'load', slider_init);
// TODO:
// check ob weniger als 5 produkte eingetragen sind
// - slider sollte dann nicht benutzbar sein