/*
Copyright 2007 by orange8 interactive ag
all rights reserved
www.orange8.com
Realized by matthias jaeggli (matthias [ D_O_T ] jaeggli [ A_T ] orange8 [ D_O_T ] com)

droplist generates a dropdownmenu from a inputfield, a list and a drop-downButton
*/
function DropList(inputfield, downButton, list, options){

	//construct
	this.inputfield = $(inputfield);
	this.downButton = $(downButton);
	this.list = $(list);
	
	options = options?options:{};
	this.listLeft = options.left? options.left : 1;
	this.listTop = options.top? options.top : 20;
	this.width = options.width? options.width : 200;
	
	$(this.list).style.marginLeft = this.listLeft+'px';
	$(this.list).style.marginTop = this.listTop+'px';
	$(this.list).style.width = this.width+'px';
	
	addEvent($(downButton), "click", function(){ this.toggle(); }.bind(this));	
	
  var list = $(list);
  var ahref = list.getElementsByTagName('a');
  for(var i = 0; i<ahref.length; i++){
		ahref[i].href = 'javascript:updateValueNHide("'+inputfield+'", "'+(ahref[i].firstChild.nodeValue)+'", "'+list.id+'")';
  }
	
	this.show = function(){
		this.list.style.display = '';
	}
	
	this.hide = function(){
		this.list.style.display = 'none';
	}
	
	this.toggle = function(){
		if(this.list.style.display == 'none'){
			this.show();
		}
		else{
			this.hide();
		}
	}

}

function updateValueNHide(elem, sub, hide){
	elem = $(elem);
	hide = $(hide);
	if(elem && elem.value){
		elem.value = sub;
	}
	hide.style.display = 'none';
}