froPoemList = Class.create();
froPoemList.prototype = {
		
		itemDisplayFullText: 0,
		
		itemPoem: 0,
		itemPoemLeft:0,
		itemPoemRight:0,
		
		dataPoem: [],
		
		sendData: [],
		
		tabCount: 0,
		
		maxInList: 6,
		
		initialize: function() {
	
	
			this.setupUserButtons();
			
			this.updateList();
	
		},
		
		setupUserButtons: function(){
			
			this.itemDisplayFullText = $("contentBounds");
			
			// target locations
			this.itemPoem = $("poemList");
			this.itemPoemLeft = $("poemLeft");
			this.itemPoemRight = $("poemRight");
			
			Event.observe(this.itemPoemLeft, 'click', this.poemPrev.bind(this));
			Event.observe(this.itemPoemRight,'click', this.poemNext.bind(this));
			
			
		},
		poemPrev: function(){
			
			
			if (this.tabCount <= 0){
				// no further back
				this.tabCount = 0;
			}else{
				this.tabCount -= 1;
			}
			
			this.parsePoemList();
			
		},
		poemNext: function(){
			
			var count = this.dataPoem.length;
			
			var max = (count / this.maxInList);
			
			if (max > 1){
				
				if (this.tabCount < max -1){
					
					this.tabCount += 1;
					
				}
			}
			
			this.parsePoemList();
		},
		// list with per point poem & anek
		updateList: function(){
			
			this.tabCount = 0;
			this.dataPoem = 0;
			
			var self = this;
			
			var fromPage = "(route="+ froRoutePointNumber +")";
			
			
			var url = "/poemList.pxml" + fromPage;
			var request = new softRequest(url, this.sendData, function (data){ self.storePoemData(data); });
			
		},
		storePoemData: function (xmlDoc) {
			//-> print server response
			this.dataPoem = xmlDoc.getElementsByTagName('content');
			
			this.parsePoemList();
			
		},
		parsePoemList: function() {
			
			
			this.itemPoem.innerHTML = "";//  + (this.tabCount * this.maxInList);// clear
			
			var count = this.dataPoem.length;
			// parse poem list
			for (var i = (this.tabCount * this.maxInList);((i < count) && (i < (this.tabCount * this.maxInList)+this.maxInList)); i++){	var row = this.dataPoem[i];
				
				var text = row.firstChild.nodeValue;
				// allowEdit
				var allow = row.getAttribute('allowEdit');
				// id <= poemId
				var poemId = row.getAttribute('id');
				
				if (allow){
					if (publicOptions){
						publicOptions.addToEditList(text, poemId, allow);
					}
				}
				
				var item = this.parsePoemButton(text, poemId, allow);
				this.itemPoem.appendChild(item);
				
			}
			
			//-> parse list width editable poems
			if (publicOptions){
				publicOptions.updateEdit();
				
				var count = this.dataPoem.length;
				for (var i = 0; i < count; i++){	var row = this.dataPoem[i];
				
					var text = row.firstChild.nodeValue;
					// allowEdit
					var allow = row.getAttribute('allowEdit');
					// id <= poemId
					var poemId = row.getAttribute('id');
					
					if (allow == "1"){
						if (publicOptions){
							publicOptions.addToEditList(text, poemId, allow);
						}
					}
					
				}
			}
			
			
		},
		parsePoemButton: function (text, poemId){
			
			if (!text){
				return;
			}
			
			var item = Builder.node('div', {'class': 'selectPoemRow'}, 
								Builder.node('div', {'class':'selectPoemTitle'}, text)
								);
			
			var self = this;
			Event.observe(item, 'click', function(){	self.eventShowPoem(poemId);	}	);
			
			return item;
			
		},
		eventShowPoem: function (id, allow){
			
			var self = this;

			var fromPage = "(route="+ froRoutePointNumber +";contentId=" + id + ")";
			
			var url = "/poemList.pxml" + fromPage;
			var request = new softRequest(url, this.sendData, function (data){ self.showPoemFullText(data); });
			
			
			
			
		},
		showPoemFullText: function (xmlDoc){
			
			this.dataPoem = xmlDoc.getElementsByTagName('content');
			var text = this.dataPoem[0].firstChild.nodeValue;
			this.itemDisplayFullText.innerHTML = text;
			
		},
		formControll: function() {
			
			// nickName
			
			// fullName
			
			
		}
		
	
		
};



