// JavaScript Document

function NewsAppear(id, css, cnt){
	this.start = 0;
	this.cur = 0;
	
	this.id = id;
	this.container = $(id);
	this.container.style.position = 'relative';
	this.container.style.overflow = 'hidden';
	this.container.width = $(id).style.width;
	this.container.height = $(id).style.height;
	
	this.divs = this.container.select('div.' + css);
	this.len = this.divs.length;
	this.divs.each(function(s, index){
					   s.style.display = 'none';
					   s.style.position = 'absolute';
					   s.style.width = $(id).style.width;
					   s.style.height = $(id).style.height;
					   s.style.overflow = 'hidden';
					   s.style.top = $(id).style.height;
					   s.style.left = $(id).style.width;
					   });
	this.divs[this.start].style.display = 'block';
	this.divs[this.start].style.left = '0px';
	this.divs[this.start].style.top = '0px';
	
	this.cnt = $(cnt);
	this.cnt.innerHTML = (this.start + 1)+'/'+this.len;
}

NewsAppear.prototype.goFrwd = function(){
	this.divs[this.cur].style.display = 'none';
	this.divs[this.cur].style.left = this.container.width;
	if(this.cur == this.len - 1){
		this.divs[0].style.top = '0px';
		new Effect.Appear(this.divs[0].id, { duration: 0.3 });
		new Effect.Move (this.divs[0].id, { x: 0, y: 0, mode: 'absolute', duration: 0.3 });
		this.cur = 0;
		this.cnt.innerHTML = (this.cur + 1)+'/'+this.len;
	} else{
		this.divs[this.cur+1].style.top = '0px';
		new Effect.Appear(this.divs[this.cur+1].id, { duration: 0.3 });
		new Effect.Move (this.divs[this.cur+1].id, { x: 0, y: 0, mode: 'absolute', duration: 0.3 });
		this.cur++;
		this.cnt.innerHTML = (this.cur + 1)+'/'+this.len;
	}
}

NewsAppear.prototype.goRwnd = function(){
	this.divs[this.cur].style.display = 'none';
	this.divs[this.cur].style.left = this.container.width;
	if(this.cur == 0){
		this.divs[this.len - 1].style.left = '-' + this.container.width;
		this.divs[this.len - 1].style.top = '0px';
		new Effect.Appear(this.divs[this.len - 1].id, { duration: 0.3 });
		new Effect.Move (this.divs[this.len - 1].id, { x: 0, y: 0, mode: 'absolute', duration: 0.3 });
		this.cur = this.len - 1;
		this.cnt.innerHTML = (this.cur + 1)+'/'+this.len;
	} else{
		this.divs[this.cur - 1].style.left = '-' + this.container.width;
		this.divs[this.cur - 1].style.top = '0px';
		new Effect.Appear(this.divs[this.cur-1].id, { duration: 0.3 });
		new Effect.Move (this.divs[this.cur-1].id, { x: 0, y: 0, mode: 'absolute', duration: 0.3 });
		this.cur--;
		this.cnt.innerHTML = (this.cur + 1)+'/'+this.len;
	}
}

NewsAppear.prototype.goUp = function(){
	this.divs[this.cur].style.display = 'none';
	this.divs[this.cur].style.top = this.container.height;
	if(this.cur == this.len - 1){
		this.divs[0].style.left = '0px';
		new Effect.Appear(this.divs[0].id, { duration: 0.3 });
		new Effect.Move (this.divs[0].id, { x: 0, y: 0, mode: 'absolute', duration: 0.3 });
		this.cur = 0;
		this.cnt.innerHTML = (this.cur + 1)+'/'+this.len;
	} else{
		this.divs[this.cur+1].style.left = '0px';
		new Effect.Appear(this.divs[this.cur+1].id, { duration: 0.3 });
		new Effect.Move (this.divs[this.cur+1].id, { x: 0, y: 0, mode: 'absolute', duration: 0.3 });
		this.cur++;
		this.cnt.innerHTML = (this.cur + 1)+'/'+this.len;
	}
}

NewsAppear.prototype.goDwn = function(){
	this.divs[this.cur].style.display = 'none';
	this.divs[this.cur].style.top = this.container.height;
	if(this.cur == 0){
		this.divs[this.len - 1].style.top = '-' + this.container.height;
		this.divs[this.len - 1].style.left = '0px';
		new Effect.Appear(this.divs[this.len - 1].id, { duration: 0.3 });
		new Effect.Move (this.divs[this.len - 1].id, { x: 0, y: 0, mode: 'absolute', duration: 0.3 });
		this.cur = this.len - 1;
		this.cnt.innerHTML = (this.cur + 1)+'/'+this.len;
	} else{
		this.divs[this.cur - 1].style.top = '-' + this.container.height;
		this.divs[this.cur - 1].style.left = '0px';
		new Effect.Appear(this.divs[this.cur-1].id, { duration: 0.3 });
		new Effect.Move (this.divs[this.cur-1].id, { x: 0, y: 0, mode: 'absolute', duration: 0.3 });
		this.cur--;
		this.cnt.innerHTML = (this.cur + 1)+'/'+this.len;
	}
}


function LibriAppear(num){
	this.cur = 0;
	this.scost = 247;
	this.maxVisible = 4;
	this.numLibri = num;
	this.numHidden = this.numLibri - this.maxVisible;
	
	this.id = 'libriContenteiner';
	this.container = $('libriContenteiner');
	this.content = $('libriContent');
	
	this.cnt = $('countLibri');
	this.cnt.innerHTML = (this.cur + 1)+'-'+(this.cur + this.maxVisible)+' di '+this.numLibri;
}

LibriAppear.prototype.goFrwd = function(){
	if(this.cur == this.numHidden){
		//return false;
	} else{
		this.cur++;
		new Effect.Move (this.content.id, { x: -1 * (this.cur * this.scost), y: 0, mode: 'absolute', duration: 0.3 });
		this.cnt.innerHTML = (this.cur + 1)+'-'+(this.cur + this.maxVisible)+' di '+this.numLibri;
	}
}

LibriAppear.prototype.goRwnd = function(){
	if(this.cur == 0){
		//return false;
	} else{
		this.cur--;
		new Effect.Move (this.content.id, { x: -1 * (this.cur * this.scost), y: 0, mode: 'absolute', duration: 0.3 });
		this.cnt.innerHTML = (this.cur + 1)+'-'+(this.cur + this.maxVisible)+' di '+this.numLibri;
	}
}


