var QZslider = new Class({
	container: null,
	list: null,
	eWidth: 0,
	speed: 32,
	toGo: 0,
	running: false,
	initialize: function(parent, col) {
		this.container = parent;
		this.container.setStyle('position', 'relative');
		this.list = this.container.getChildren('ul')[0];
		this.container = new Element('div').inject(this.list, 'after');
		this.list.injectInside(this.container);
		var lis = this.list.getChildren('li');
		this.eWidth = lis[1].getPosition(this.list).x;
		while(this.list.getChildren('li').length < 6)
			lis.each(function(i){i.clone().injectInside(this.list);}, this);
		this.container.setStyle('position', 'relative');
		this.list.setStyle('width', '10000px');
		this.list.setStyle('position', 'absolute');
		this.list.setStyle('top', '0');
		this.steps = this.speed;
		this.speed = this.eWidth/this.steps;
		this.list.setStyle('left', this.snap(0)+'px');
		parent.setStyle('position', 'relative');
		var top = this.container.getPosition(parent).y+this.container.getSize().y/2-14+'px';
		var butt = new Element('img');
		butt.set('src', '/src/img/button/next_'+col+'.gif');
		butt.setStyle('position', 'absolute');
		butt.setStyle('top', top);
		butt.setStyle('left', this.container.getPosition(parent).x+this.container.getSize().x+5+'px');
		butt.setStyle('margin', 0);
		butt.setStyle('width', 27);
		butt.addEvent('click', this.next.bind(this));
		butt.inject(parent);
		butt = new Element('img');
		butt.set('src', '/src/img/button/prev_'+col+'.gif');
		butt.setStyle('position', 'absolute');
		butt.setStyle('top', top);
		butt.setStyle('left', this.container.getPosition(parent).x-32+'px');
		butt.setStyle('margin', 0);
		butt.setStyle('width', 27);
		butt.addEvent('click', this.prev.bind(this));
		butt.inject(parent);
	},
	snap: function(pos) {
		var off;
		if(pos >= 0) {
			this.list.getLast().inject(this.list, 'top');
			off = pos-this.eWidth;
		} else if(pos <= -2*this.eWidth) {
			this.list.getFirst().inject(this.list);
			off = pos+this.eWidth;
		} else
			off = pos;
		return off
	},
	render: function() {
		this.running = true;
		if(this.toGo == 0) return this.running=false;
		var pos = this.list.getPosition(this.container).x;
		if(this.toGo > 0) {
			pos += this.speed;
			this.toGo--;
		} else {
			pos -= this.speed;
			this.toGo++;
		}
		if(this.toGo%this.steps == 0 || this.toGo == 0) {
			var diff1 = pos%this.eWidth;
			var diff2 = this.eWidth+diff1;
			pos -= (Math.abs(diff1) < Math.abs(diff2))?diff1:diff2;
		}
		this.list.setStyle('left', this.snap(pos)+'px');
		if(this.toGo == 0)
			this.running=false;
		else
			window.setTimeout(this.render.bind(this), 10);
	},
	next: function(e) {
		this.toGo -= this.steps;
		if(!this.running) this.render();
	},
	prev: function(e) {
		this.toGo += this.steps;
		if(!this.running) this.render();
	}
});