var Balafia_Textbox = Class.create(
{
	area:	false,
	toggle:	false,
	state:	false,
	
	initialize: function(node){
		this.area = node;
		
		if(!this.area || !this.area.hasClassName("textbox")) return false;
		
		this.toggle	=	this.area.down(".toggle");
		this.state	=	this.toggle.down(".open_desc").getStyle("display") == "none" ? true : false;
		
		this.toggle.down(".content").observe("click",function(){
			if(this.state == true){
				this.closeInformation();
			}else{
				this.openInformation();
			}
		}.bind(this));
		
		Balafia_Textbox.instance = this;
	},
	
	openInformation: function()
	{
		this.state = true;
		
		this.area.down(".info").morph("opacity:1",1);
		this.toggle.down(".open_desc").setStyle({display:"none"});
		this.toggle.down(".close_desc").setStyle({display:"inline-block"});
	},
	
	closeInformation: function()
	{
		this.state = false;
		
		this.area.down(".info").morph("opacity:0",1);
		this.toggle.down(".open_desc").setStyle({display:"inline-block"});
		this.toggle.down(".close_desc").setStyle({display:"none"});
	},
	
	prevItemNumber: function()
	{
		var c = this.area.down(".item_number .current");
		var t = this.area.down(".item_number .total");
		
		if(!c || !t) return 1;
		
		var cv = +(c.innerHTML);
		
		if(--cv == 0) cv = +(t.innerHTML);
		c.update(cv);
		
		return cv;
	},
	
	nextItemNumber: function()
	{
		var c = this.area.down(".item_number .current");
		var t = this.area.down(".item_number .total");
		
		if(!c || !t) return 1;
		
		var cv = +(c.innerHTML);
		
		if(++cv > +(t.innerHTML)) cv = 1;
		c.update(cv);
		
		return cv;
	},
	
	setItemNumber: function(n)
	{
		var tv = +(this.area.down(".item_number .total").innerHTML);
		
		if(n < 1)	n = 1;
		if(n > tv)	n = tv;
		
		this.area.down(".item_number .current").update(n);
		
		return n;
	},
	
	getItemNumber: function()
	{
		return +(this.area.down(".item_number .current").innerHTML);
	}
});

Balafia_Textbox.instance = false;
