if(!window.Richfaces) window.Richfaces = {};
Richfaces.InplaceSelectList = Class.create(Richfaces.ComboBoxList, {
	initialize : function($super, listId, parentListId, selectFirstOnUpdate, classes, width, height, itemsText, onlistcall, fieldId, shadowId, showDelay, hideDelay) {
		$super(listId, parentListId, selectFirstOnUpdate, classes, width, height, itemsText, onlistcall, fieldId, shadowId, showDelay, hideDelay);
	},
	
	setPosition : function($super, fieldTop, fieldLeft, fieldHeight) {
		var field = this.fieldElem;
		
		field.show();
		var height = field.offsetHeight;				
		var top = height;
		var docHeight = Richfaces.getDocumentHeight();
		var comBottom = fieldTop + height;
		var listHeight = parseInt(this.list.style.height) + Richfaces.getBorderWidth(this.list.parentNode, "tb");
		
		if (parseInt(listHeight) > (docHeight - comBottom)) {
			if (fieldTop > (docHeight - comBottom)) {
				//opens up
				top = 0 - parseInt(listHeight);
			}
		}
		
		this.listParent.style.top = top + "px";
		this.listParent.style.left = 0 + "px";
		
		if (this.iframe) {
			this.iframe.style.top = top + "px";
			this.iframe.style.left = 0 + "px";
		}
	},
	
	show : function($super) {
		$super();
	},
	
	resetState : function() {
		//var tempList = this.list.cloneNode(false);
		//this.listParent.childNodes[1].firstChild.replaceChild(tempList, this.list);
		//this.list = $(tempList.id);
		this.activeItem = null;
		//this.isList = false;
	},
	
	getEventItem : function(event) {
		var item = Event.findElement(event, "span");
		if (item) {
			if (this.listParent.parentNode.id == item.id) {
				return;
			}
		}	
		return item;
	},
	
	setWidth : function(width) {
		var positionElem = this.listParent.childNodes[1];
		var correction = parseInt(width) - Richfaces.getBorderWidth(positionElem.firstChild, "lr") - Richfaces.getPaddingWidth(positionElem.firstChild, "lr") + "px";
		this.list.style.width = correction;
		if (this.iframe) {
			this.iframe.style.width = correction;			
		}
	},
	
	hide : function() {
		this.resetState();
		if (this.iframe) {
			this.iframe.hide();			
		}
		var component = this.listParent.parentNode;
		this.listParent.hide();
	}
});
