function select_layer_all(ta){
	if(!ta){ta = document}
	var t = ta.getElementsByTagName('SELECT');
	var temp = null;
	
	for(var i=0,m=t.length;i<m;i++){		
		temp = new select_layer(t[i]);
	}
}


var select_layer = function(ta){
	this.over = false;
	this.used = false;
	this.select = null;
	this.init(ta);	

	this.layout = null;
	this.textbox = null;
	this.button = null;
	this.optionlayer = null;
	this.options = null; 

	this.mk_element();
}
select_layer.prototype.init = function(ta){
	this.used = false;
	
	if(ta.tagName =='SELECT'){
		
		this.select = ta;
	}else{
		var t = document.getElementById(ta);
		if(t&&t.tagName =='SELECT'){
			this.select = t;
		}else{
			alert('ERROR : init()');
			return false;
		}
	}
	this.used = true;
	return true;
}
select_layer.prototype.mk_element = function(){
	if(!this.used)	{alert('ERROR : mk_element()');return false;}

	this.layout = document.createElement('span');
	this.layout.className=this.select.className;
	if(!this.layout.className)	this.layout.className='select_layer';
//	this.layout.style.cssText='position:relative;z-index:999;';
//	alert(this.layout.style.zIndex);
	//======================= 
	if (this.select.nextSibling) 	this.select.parentNode.insertBefore(this.layout,this.select.nextSibling);
	else this.select.parentNode.appendChild(this.layout);		
	this.mk_textbox();	
	this.mk_button();	
	this.layout.appendChild(this.textbox);
	this.layout.appendChild(this.button);	
	this.mk_optionlayer();
	this.layout.appendChild(this.optionlayer);
	this.select.style.display='none';
	this.sync_design();
	this.optionlayer_view(2);
	
}
select_layer.prototype.sync_design = function(){
	var t = (this.button.offsetLeft-this.textbox.offsetLeft)+this.button.clientWidth;
	this.optionlayer.style.width = t+'px';
	this.optionlayer.style.left = this.textbox.offsetLeft+'px';
}
select_layer.prototype.mk_textbox = function(){
	if(!this.used)	{alert('ERROR : mk_textbox()');return false;}
	var this_s = this;
	this.textbox = document.createElement('input');
	this.textbox.type='text';
	this.textbox.value='';
	this.textbox.className ='select_layer_textbox';
	this.textbox.readOnly=true;
	this.textbox.className='textbox';
	this.textbox.style.cssText=this.select.style.cssText;
	with(this.textbox.style){
		if(!this.select.style.width)
			width = this.select.clientWidth+'px';
		textAlign='center';
//		border='1px solid #999999';
		cursor='pointer';
		position='relative';
	}
	this.textbox.onclick=function(){this_s.optionlayer_view(0);}
	this.textbox.onblur=function(){
		if(!this_s.over){
			this_s.optionlayer_view(2);
		}
	}
}
select_layer.prototype.mk_button = function(){
	if(!this.used)	{alert('ERROR : mk_button()');return false;}
	var this_s = this;
	
	this.button = document.createElement('img');	
	this.button.src= "../img/select_icon.gif";
	this.button.style.position = "relative";		
	this.button.style.left = "-15px";
	this.button.style.paddingBottom = "1px";	
	this.button.style.width = "9px";
	this.button.style.height= "5px";
	
	this.button.onfocus=function(){		this_s.textbox.focus();		}
	this.button.onselect=function(){		this_s.textbox.focus();		}	
	this.button.onclick=function(){		this_s.textbox.click();	}
	this.button.onmouseover=function(){		this_s.over=true;	}	
	this.button.onmouseout=function(){		this_s.over=false;	}		

}

select_layer.prototype.optionlayer_view = function(type){
	if(!this.used)	{alert('ERROR : optionlayer_view()');return false;}
	var this_s = this;
	if(type==0){
		if(this.optionlayer.style.display=='none')
			this.optionlayer_view(1);
		else
			this.optionlayer_view(2);
	}else if(type==1){
		this_s.textbox.className='textbox_select';
		this_s.button.className='button_select';
		this.optionlayer.style.display='';
	}else if(type==2){
		this_s.textbox.className='textbox';
		this_s.button.className='button';

		this.optionlayer.style.display='none';	
	}
}
select_layer.prototype.mk_optionlayer = function(){
	if(!this.used)	{alert('ERROR : mk_textbox()');return false;}
	this.optionlayer_span = document.createElement('div');
	this.optionlayer = document.createElement('div');
	this.optionlayer.className='optionlayer';
	with(this.optionlayer.style){
		width = this.textbox.clientWidth+'px';
		position='absolute';
		left = '0px';
		overflow='hidden';
		top = this.textbox.offsetHeight+this.textbox.offsetTop+'px';
		zIndex='9999999';
	}
	this.mk_options();
	for(var i=0,m=this.options.length;i<m;i++){
		this.optionlayer.appendChild(this.options[i]);
	}
}
select_layer.prototype.mk_options = function(){
	this.options = new Array();
	var this_s = this;
	if(!this.used)	{alert('ERROR : mk_options()');return false;}
	//alert(this.select.options.length);
	var over=function(){
		this.className='option_over';
		this_s.over=true;
	}
	var out=function(){
		this_s.over=false;
		if(this.getAttribute('selected')!='false'){
			this.className='option_selected';
		}else{
			this.className='option';
		}
	}
	var click=function(){
		this_s.over=false;
		this_s.select_option(this.getAttribute('index'));
		this_s.select_onchange();
		this_s.optionlayer_view(2);
	}
	var cssText="overflow:hidden;cursor:pointer;white-space:nowrap;";
	for(var i=0,m=this.select.options.length;i<m;i++){
		var op = this.select.options[i];
		var d = document.createElement('div');
		d.innerHTML = op.text;
		d.setAttribute('index',i);
		d.setAttribute('value',op.value);
		d.setAttribute('selected','false');
		d.onmouseover=over;
		d.onmouseout=out;
		d.onclick=click;
		d.style.cssText=cssText;
		d.style.fontSize=this.select.style.fontSize;
		d.className='option';
		this.options.push(d);
	}
	this.select_option(this.select.selectedIndex);
}
select_layer.prototype.select_option = function(sel){
	if(!this.used)	{alert('ERROR : mk_options()');return false;}
	for(var i = 0,m=this.options.length;i<m;i++){
		this.options[i].className='option';
		this.options[i].setAttribute('selected','false');

	}
	if(sel!=-1){
		this.options[sel].className='option_selected';
		this.options[sel].setAttribute('selected','true');
		this.select.selectedIndex = sel;
		this.textbox.value=this.options[sel].innerHTML;
	}
}
select_layer.prototype.select_onchange = function(){
	if(this.select.onchange)
	this.select.onchange();
}