function Agenda () { 
	this.data = []; 
	this.indexOld = -1;
}

Agenda.prototype.add = function (o) {
	this.data[this.data.length] = o;
}

Agenda.prototype.init = function () {
	this.root = new GetObj("boxesAgendas").obj;
	var tmp = this.root.getElementsByTagName("div");
	var cnt = 0;
	
	for (var i=0;i<tmp.length;i++) {
		if (tmp[i].className.indexOf("box box")!=-1) {
			var boxData = {box:tmp[i]};

			if (tmp[i].className.toLowerCase().indexOf('boxon')!=-1) {
				this.indexOld = cnt;	
			}
			
			cnt++;
			
			var boxLinkNodes = tmp[i].getElementsByTagName("a");
			for (var j=0;j<boxLinkNodes.length;j++) {
			    
				if (boxLinkNodes[j].className=="zoom") {
					boxData.zoom = boxLinkNodes[j];	
														
					boxData.zoomImg = boxLinkNodes[j].parentNode.getElementsByTagName("img")[0];										
																																		
					if (boxData.zoomImg.style.top=="") boxData.zoomImg.style.top = boxData.zoomImg.offsetTop + "px";
				}
				
				else if (boxLinkNodes[j].className=="suite") {
					boxData.suite = boxLinkNodes[j]; 
					new Roll(boxLinkNodes[j]);
				}
				else if (boxLinkNodes[j].className=="close")
				{ 
				    boxData.close = boxLinkNodes[j];
				}
			}
		}
		else if (tmp[i].className=="cont") {
			boxData.cont = tmp[i];
			this.add(boxData);
		}
	}
	
	this.setEvents();
	
	
}

Agenda.prototype.setEvents = function () {
	var o = this;
	for (var i=0;i<this.data.length;i++) {
        
        if(this.data[i].suite && this.data[i].close )
        {
		    this.data[i].suite.id = "agendaEvent"+i;
		    this.data[i].suite.onclick = function () { o.showDetails(this.id.substring(11,this.id.length)); }
		    this.data[i].close.id = "closeEvent"+i;
		    this.data[i].close.onclick = function () { o.closeDetails(this.id.substring(10,this.id.length)); }
        }
        
		if(this.data[i].zoom!=null && this.data[i].zoomImg!=null )
		{
		    this.data[i].zoom.id = this.data[i].zoomImg.id = "zoomImgE_"+i;		    
		    this.data[i].zoom.onclick = this.data[i].zoomImg.onclick = function () { o.zoomImg(this.id.substring(9,this.id.length)); }
	    }
	}
}

Agenda.prototype.showDetails = function (index) {
	if (this.indexOld!=index&&this.indexOld!=-1) {
		this.data[this.indexOld].box.className = "box boxOff";
	}
	this.data[index].box.className = "box boxOn";
	this.indexOld = index;
}

Agenda.prototype.closeDetails = function (index) {
	this.data[index].box.className = "box boxOff";
	if (this.indexOld==index) this.indexOld = -1;
}

Agenda.prototype.zoomImg = function (index) {
	var targDiv = new GetObj("photoZoom").obj;	
	var targImg = targDiv.getElementsByTagName("img")[0];	
	targImg.src = this.data[index].zoomImg.src;
	/*targImg.style.width = (this.data[index].zoomImg.offsetWidth*2) + "px";
	targImg.style.height = (this.data[index].zoomImg.offsetHeight*2) + "px";*/
	targDiv.style.top = this.data[index].box.offsetTop + 50 + "px";
	targDiv.onclick = function () { this.style.display = "none"; }
	targDiv.style.display = "block";
}


var initAgenda = function () {
	oAgenda = new Agenda ();
	oAgenda.init();
}

onLoadGlobal.add(initAgenda);



