/**
 * Scroller
 * jochen vandendriessche
 * 
 */

function Scroller(o){
	this.obj = $(o);
	// get all the items
	this.nodes = $$('item');
	//window.alert(this.nodes.length);
	this.heights = [];
	this.obs	= [];
	this.fbs	= [];
	this.storeHeights();
	this.visible = 0;
	
	// get the top left pos
	pos = findPos(this.obj);
	var right = pos[0] + 460;
	var top   = pos[1] + 7;
	var bottom= top + 207;
	
	// draw the next / previous
	var next = document.createElement('div');
    next.id = 'scrollNext';	
	next.className = 'scrollNext';
	next.style.left = right + 'px';
	next.style.top = bottom + 'px';
	next.title = 'next'
	next.onclick = bind(this, this.showNext);
	var previous = document.createElement('div');
	previous.id = 'scrollPrevious';
	previous.className = 'scrollPrevious';
	previous.style.left = right + 'px';
	previous.style.top = top + 'px';	
	previous.title = 'previous';
	previous.style.display = 'none';
	previous.onclick = bind(this, this.showPrevious);
	document.body.appendChild(next);
	document.body.appendChild(previous);
	
}

Scroller.prototype={
	
	storeHeights:function(){
		for (var a = 0;a < this.nodes.length;a++){
			var h = this.nodes[a].offsetHeight;
//			this.nodes[a].style.height = h + 'px';
			this.obs[a] = new joinkFX(this.nodes[a], 'outCubic', 30, 'height', ''+h, '-'+h, true);
			//this.obs[a].setFunc(bind(this, this.alterValues));
			this.fbs[a] = new Fader(this.nodes[a], 0, 100, 10);
			this.fbs[a].fadeIn();
		}
	}
	
	,
	
	showNext:function(){
		if (this.visible < (this.nodes.length - 1)){
			$('scrollNext').style.display = 'block';
			$('scrollPrevious').style.display = 'block';			
	//		window.alert(this.obs[this.visible].obj);
			this.obs[this.visible].move();
			this.fbs[this.visible].fadeOut();
			this.visible++;
			//window.alert('news' + this.visible);
		}
		if (this.visible == (this.nodes.length -1)){
			$('scrollNext').style.display = 'none';
		}
		
	}
	
	,
	
	showPrevious:function(){
		if (this.visible > 0){
			$('scrollNext').style.display = 'block';
			$('scrollPrevious').style.display = 'block';
			this.visible--;
			this.obs[this.visible].move();
			this.fbs[this.visible].fadeIn();
			//window.alert('news' + this.visible);			
		}
		if (this.visible == 0){
			$('scrollPrevious').style.display = 'none';
		}
	}	
	
}