//-------------------------------------
// DIV list scroller
// Author: Meelis Pärjasaar
// email: meelis (at) wiseman.ee
// date: 6.12.2007
//-------------------------------------
function DivScroller(elem_count, visible_items) //constructor
{
	this.div_count = elem_count; //4
	this.visible_divs = visible_items; //3

	if(this.div_count < this.visible_divs) this.visible_divs = this.div_count;// if less than visible_count

	//hide moveup button
	document.getElementById('lcat_moveup').style.display = 'none';

	//if there are hidden divs then show movedown
	if( this.div_count > this.visible_divs ) {
		setTimeout( "Effect.SlideDown('lcat_movedown', { duration: 0.8 })", 800);
		//document.getElementById('lcat_movedown').style.display = '';
	} else {
		document.getElementById('lcat_movedown').style.display = 'none';
	}

	this.first_div_nr = 0;
	this.last_div_nr = this.visible_divs - 1;

	var i=0;
	this.div_names = new Array(); // html id names are listed here. 'lcat_1','lcat_2' ...
	for (i=0; i<this.div_count; i++) {
		this.div_names[i] = "lcat_"+ (i+1);
	}
	//alert('div_count' + this.div_count + ', first_div_nr' + this.first_div_nr + ', last_div_nr' + this.last_div_nr);

	//-------------------------------------
	this.MoveUp = function () {
		if( this.first_div_nr <= 0 ) return false; //do nothing if already in the beginning of list

		var element1 = this.div_names[this.first_div_nr-1];//item to show
		var element2 = this.div_names[this.last_div_nr];//item to hide
		//alert(this.first_div_nr + ' - ' + element1 + ',' + this.last_div_nr +' - ' + element2);

		this.first_div_nr--;
		this.last_div_nr--;

		new Effect.Parallel(
		 [ new Effect.SlideDown(element1),
			new Effect.SlideUp(element2) ],
		 { duration: 0.5 }
		 //{ duration: 0.5, afterFinish: this.showhide_buttons_up() }
		);

		this.showhide_buttons_up();
	}

	//-------------------------------------
	this.MoveDown = function () {
		if( this.last_div_nr >= this.div_count - 1 ) return false; //do nothing if already in the end of list

		var element1 = this.div_names[this.first_div_nr];//item to hide
		var element2 = this.div_names[this.last_div_nr+1];//item to show
		//alert(this.first_div_nr + ' - ' + element1 + ',' + this.last_div_nr +' - ' + element2);

		this.first_div_nr++;
		this.last_div_nr++;

		new Effect.Parallel(
		 [ new Effect.SlideDown(element2),
			new Effect.SlideUp(element1) ],
		 { duration: 0.5 }
		 //{ duration: 0.5, afterFinish: this.showhide_buttons_down() }
		);

		this.showhide_buttons_down();
	}

	//-------------------------------------
	this.showhide_buttons_up = function () {
		if( this.first_div_nr <= 0 ) { //if in the beginning of list
			document.getElementById('lcat_moveup').style.display = 'none';
			document.getElementById('lcat_movedown').style.display = '';
		} else { //if move up, then make movedown visible
			document.getElementById('lcat_movedown').style.display = '';
		}
	}

	//-------------------------------------
	this.showhide_buttons_down = function () {
		if( this.last_div_nr >= this.div_count - 1 ) { //if in the end of list
			document.getElementById('lcat_movedown').style.display = 'none';
			document.getElementById('lcat_moveup').style.display = '';
		} else { //if move down, then make moveup visible
			document.getElementById('lcat_moveup').style.display = '';
		}
	}
	//-------------------------------------
}

/*
Event.observe(window, 'load', scrollerInit, false);
var scroller = null;
function scrollerInit() {
	scroller = new DivScroller(6, 3);
}
*/