var Nest=Class.create();
var NestTimer=null;

Nest.prototype={
	initialize:function(nest_area,bgcolor) {
		this._index=0;
		this.m_Div=new Array();

		this._nest_area=nest_area;

		this._width=nest_area.getWidth();
		this._height=nest_area.getHeight();
		if (bgcolor) this._background=bgcolor;
	},

	addNest:function(div) {
		this.m_Div[this.m_Div.length]=div;

		div.setStyle({
			width:this._width+'px',
			height:this._height+'px',
			position:'absolute',
			background:this._background,
			zIndex:100
		});

		div.hide();

		this._nest_area.insert(div);
	},

	addNestAjax:function(div,url) {
		this.m_Div[this.m_Div.length]=div;

		div.setStyle({
			width:this._width+'px',
			height:this._height+'px',
			position:'absolute',
			background:this._background,
			zIndex:100
		});

		div.hide();

		new Ajax.Request(url,{
			method:'get',
			onSuccess: function(transport) {
				div.innerHTML="";
				div.innerHTML=transport.responseText;
			},
			onFailure: function() {
				alert("fail");
			}
		});

		this._nest_area.insert(div);
	},

	activeNest:function(i) {
		this.unselectTab();

		this.m_Div[i].setStyle({
			left:this._nest_area.cumulativeOffset().left+'px',
			top:this._nest_area.cumulativeOffset().top+'px'
		});

		this.m_Div[i].show();
	},

	unselectTab:function(i) {
		for (i=0;i<this.m_Div.length;i++) {
			this.m_Div[i].hide();
		}
	},

	Next:function() {
		this._index++;

		if (this._index>this.m_Div.length-1) {
			this._index=0;
		}

		this.activeNest(this._index);

		return false;
	},

	Pre:function() {
		this._index--;
	
		if (this._index<0) {
			this._index=this.m_Div.length-1;
		}

		this.activeNest(this._index);

		return false;
	}
}

function NestAutoStart(n) {
	if (NestTimer==null) NestTimer=setInterval(n+'.Next()',5000);
}

function NestAutoStop() {
	clearInterval(NestTimer);
	NestTimer=null;
}

