
function UISelectInput(selectElement, optionsElement, opts){
	this.select = selectElement;
	this.optionsElement = optionsElement;
	this.isOpened = false;
	this.isAnimated = false;
	this.closingTimer = null;
	this.choiceCallback = opts.choiceCallback;
	
	var that = this;
	$(this.select).click(function(){
		that.toggleChoices();
	});
	$(this.select).hover(
		function(){
			$(this).css("cursor","pointer");
		},
		function(){
			$(this).css("cursor","default");
		}
	);
	$(this.optionsElement+" li").click(function(){
		that.choiceWasMade($(this).text(),this);
	});
	
	// handle click outside
	$(document.body).bind('click',function(e) {
		if(that.isOpened == true){
			var parentElement = $(that.select).get(0);
			if($(parentElement+":contains("+e.target+")") === false || parentElement != e.target) {
				that.toggleChoices();
			}
		}
	});
	
	$(this.select+" p:first").text($(this.optionsElement+" li:first").text());
	opts.initCallback.call(this);
}
UISelectInput.implement({
	toggleChoices:function(){
		var that = this;
		this.isAnimated = true;
		if(this.isOpened === false){
			$(this.optionsElement).slideDown('fast',function(){
				that.isAnimated = false;
				that.isOpened = true;
			});
		} else {
			$(this.optionsElement).slideUp('fast',function(){
				that.isAnimated = false;
				that.isOpened = false;
			});
		}
	},
	choiceWasMade:function(text, el){
		$(this.select+" p:first").text(text);
		this.toggleChoices();
		this.choiceCallback.call(this, text, el);
	},
	getValue:function(){
		return $(this.select+" p:first").text();
	}
});
