function SelectSet(options)
{
	var i;
	this.selectDiv = null;
	this.arrowDiv = null;
	this.valueDiv = null;
	this.dropdownDiv = null;
	this.optionDiv = null;
	this.clearDiv = null;
	this.input = null;
	this._container = null;
	this.isHidden = null;
	this.onchange = null;
	this.value = '';
	this._hover = false;
	this.text = '';	
	this._theme = 'default';
	this._options = [];
	
	if(!!options.container)
		this._container = document.getElementById(options.container);
	else
		throw('NoContainerException');

	if(!!options.onchange)
		this.onchange = options.onchange;

	if(!!options.theme)
		this._theme = options.theme;
	
	this.setTheme(this._theme);
	
	this.selectDiv = document.createElement('div');
	this.selectDiv.className = 'SelectSet_select';
	
	this.arrowDiv = document.createElement('div');
	this.arrowDiv.className = 'SelectSet_arrow';
	this.selectDiv.onselectstart = function(){return false;}
	
	this.selectDiv.onmouseover = function()
	{
		this._hover	= true;
	}.bind(this);
	this.selectDiv.onmouseout = function()
	{
		this._hover = false;
	}.bind(this);
	this.selectDiv.onmousedown = function()
	{
		if(this.isHidden)
			this.show();
		else
			this.hide();
		return false;
	}.bind(this)
	
	this.input = document.createElement('input');
	this.input.type = 'hidden';
	if(!!options.name)
		this.input.name=options.name;
	
	this.valueDiv = document.createElement('div');
	this.valueDiv.className = 'SelectSet_value';
	
	this.dropdownDiv = document.createElement('div');
	this.dropdownDiv.className = 'SelectSet_dropdown';
	this.dropdownDiv.style.display = 'none';
	this.dropdownDiv.onmouseover = function()
	{
		this._hover = true;
	}.bind(this);
	this.dropdownDiv.onmouseout = function()
	{
		this._hover = false;
	}.bind(this);
	this.isHidden = true;
	
	this.optionDiv = document.createElement('div');
	this.optionDiv.className = 'SelectSet_option';
	
	this.clearDiv = document.createElement('div');
	this.clearDiv.style.clear = 'both';
	
	this.selectDiv.appendChild(this.valueDiv);
	this.selectDiv.appendChild(this.arrowDiv);
	this._container.appendChild(this.selectDiv);
	this._container.appendChild(this.clearDiv);
	this._container.appendChild(this.dropdownDiv);
	this._container.appendChild(this.input);
		
	for(i=0; i<options.items.length; i++)
	{
		this.addOption(options.items[i].innerHTML, options.items[i].value);
		
		if(typeof(options.items[i].selected)!='undefined' && options.items[i].selected==true)
		{
			this.value = options.items[i].value;
			this.text = options.items[i].innerHTML;
			this.input.value = this.value;
			this.valueDiv.innerHTML = this.text;
		}
	}
	
	addEvent(document, 'mousedown', function()
	{
		if(!this._hover)
			this.hide();
	}.bind(this));
	return this;
}

SelectSet.prototype.addOption = function(txt, val)
{
	this._options.push( 
	{
		innerHTML: txt,
		value: val
	});
	var optionDiv = this.optionDiv.cloneNode(true);
	optionDiv.innerHTML = txt;
	optionDiv.onmouseup = this.select.partial(this._options.length-1).bind(this);
	this.dropdownDiv.appendChild(optionDiv);
}

SelectSet.prototype.clear = function()
{
	while(this.dropdownDiv.childNodes.length>0)
		this.dropdownDiv.removeChild(this.dropdownDiv.childNodes[0]);
}

SelectSet.prototype.show = function()
{
	this.dropdownDiv.style.display = '';	
	this.isHidden = false;
	
	return false;
}

SelectSet.prototype.hide = function()
{
	this.dropdownDiv.style.display = 'none';	
	this.isHidden = true;
	
	return false;
}

SelectSet.prototype.select = function(index)
{
	this.valueDiv.innerHTML = this._options[index].innerHTML;	
	this.value = this._options[index].value;
	this.text = this._options[index].innerHTML;
	
	if(this.input.value != this._options[index].value && !!this.onchange)
	{
		this.onchange();
	}
	
	this.input.value = this._options[index].value;
	this.hide();
}

SelectSet.prototype.setTheme = function(theme)
{
	if(!!this._themeLink)
		document.getElementsByTagName('head')[0].removeChild(this._themeLink);
	
	fileref=document.createElement('link');
	fileref.setAttribute('rel', 'stylesheet');
	fileref.setAttribute('type', 'text/css');
	fileref.setAttribute('href', '/themes/SelectSet/'+theme+'/theme.css');
	
	this._themeLink = document.getElementsByTagName('head')[0].appendChild(fileref);
}
