window.TopKarusel = {

	endstop : false,
	process : false,
	block : 'top_karusel',
	block_bg : 'top_karusel_bg',
	onePos : -899,
	duration : 500,
	pos : 0,
	maxPos : 2,

	next : function(e, event){
		if(this.process == false) {

			this.process = true;
			var duration = this.duration;
			var current_pos = this.pos * this.onePos;
			var after_pos = current_pos + this.onePos;
			var pos = this.pos+1;
			var maxPos = this.maxPos;

			if(pos > maxPos) {
				if(this.endstop) {
					window.TopKarusel.process = false;
					return false;
				}
				else {
					pos = 0;
					after_pos = 0;
					duration = 0;
				}
			}

			this.pos = pos;

			var effect = this.block.effect('left', {duration: duration, transition: Fx.Transitions.Quint.easeOut});
			//var effect_bg = this.block_bg.effect('background-position', {duration: duration, transition: Fx.Transitions.Quint.easeOut});

			if(this.endstop) {
				if((pos+1) > maxPos) {
					$('k_next').addClass('noactive');
				}
				else {
					$('k_next').removeClass('noactive');
				}
				$('k_prev').removeClass('noactive');
			}

			effect.addEvent('onComplete', function() {window.TopKarusel.process = false;});
			effect.start(current_pos, after_pos);
			//effect_bg.start(current_pos, after_pos);
		}
		return false;
	},

	prev : function(e){

		if(this.process == false) {

			this.process = true;
			var duration = this.duration;
			var current_pos = this.pos * this.onePos;
			var after_pos = current_pos - this.onePos;
			var pos = this.pos-1;
			var maxPos = this.maxPos;

			if(pos < 0 ) {
				if(this.endstop) {
					window.TopKarusel.process = false;
					return false;
				}
				else {
					pos = this.maxPos;
					after_pos = this.onePos * this.maxPos;
					duration = 0;
				}
			}

			this.pos = pos;

			var effect = this.block.effect('left', {duration: duration, transition: Fx.Transitions.Quint.easeOut});
			//var effect_bg = this.block_bg.effect('background-position', {duration: duration, transition: Fx.Transitions.Quint.easeOut});

			if(this.endstop) {
				if((pos-1)<0) {
					$('k_prev').addClass('noactive');
				}
				else {
					$('k_prev').removeClass('noactive');
				}
				$('k_next').removeClass('noactive');
			}

			effect.addEvent('onComplete', function() {window.TopKarusel.process = false;});
			effect.start(current_pos, after_pos);
			//effect_bg.start(current_pos, after_pos);
		}
		return false;
	},

	init : function(){
		this.block = $(this.block);
		//this.block_bg = $(this.block_bg);
	}
};