document.observe('dom:loaded', init);

var lmove = null;
var rmove = null;
var lcounter = 3;
var rcounter = 3;

function init() {
	$('bla_left').observe('click', slide);
	$('bla_right').observe('click', slide);
	$('bra_left').observe('click', slide2);
	$('bra_right').observe('click', slide2);
}


function slide() {
	var div = $$('#blc_images div')[0];
	var button = this.id;
	$('bla_left').stopObserving();
	$('bla_right').stopObserving();
	
	if(button == 'bla_right') {
	 	if(lcounter == $$('#blc_images div img').length) { lmove = 0; } 
		else {
			lcounter++;
			lmove = -($$('#blc_images div img')[0].getWidth());
		}
	} else if (button == 'bla_left') {
		if(lcounter > 3) {
			lcounter--;
			lmove = $$('#blc_images div img')[0].getWidth();
		} else { lmove = 0; }
	}
	
	
	new Effect.Move(div, {
		y:0,
		x:lmove,
		transition:Effect.Transitions.spring,
		afterFinish:init
	});
}

function slide2() {
	var div = $$('#brc_images div')[0];
	var button = this.id;
	$('bra_left').stopObserving();
	$('bra_right').stopObserving();	
	
	if(button == 'bra_right') {
	 	if(rcounter == $$('#brc_images div img').length) { rmove = 0; } 
		else {
			rcounter++;
			rmove = -($$('#brc_images div img')[0].getWidth());
		}
	} else if (button == 'bra_left') {
		if(rcounter > 3) {
			rcounter--;
			rmove = $$('#brc_images div img')[0].getWidth();
		} else { rmove = 0; }
	}
	
	
	new Effect.Move(div, {
		y:0,
		x:rmove,
		transition:Effect.Transitions.spring,
		afterFinish:init
	});
}
