var curCS2;
var d = document;
var w = window;
var t = true;
var f = false;
var n = null;
var newCS2;
function getOffsets2(obj) {
	var offsetTop = obj.offsetTop;
	var offsetLeft = obj.offsetLeft;
	while ((obj = obj.offsetParent )!=null) {
		offsetTop += obj.offsetTop;
		offsetLeft += obj.offsetLeft;
	}
	return [offsetLeft, offsetTop];
}

function iniCustomSelect2(){
	//var lstSelect = $A(d.getElementsByTagName('select'));
	var lstSelect2 = $A(d.getElementsByClassName('select_nav'));

	lstSelect2.each(function(select2){
		select2.style.display = 'none';
		newCS2 = d.createElement('input');
		newCS2.id = 'new_'+select2.id;
		newCS2.className = 'newCS2';
		newCS2.readOnly = "readOnly";
		newCS2.onclick = function(){
			switchOptions2(this.id);
		}
		newCS2.onmouseover = function(){curCS2 = this.id;}
		newCS2.onmouseout = function(){curCS2 = '';}
		
		var opts2 = d.createElement('div');
		opts2.id = 'opts_new_'+select2.id;
		opts2.className = 'opts2';
		opts2.style.display = 'none';
		opts2.setAttribute('CS2',select2.id);
		opts2.onmouseover = function(){curCS2 = 'new_'+this.getAttribute('CS2');}
		opts2.onmouseout = function(){curCS2 = '';}
		
		var optTab2 = new Array();
		
		var lstOpt2 = $A(select2.getElementsByTagName('option'));
		lstOpt2.each(function(opt2){
			if(opt2.selected) newCS2.value = opt2.innerHTML;
			var tmpOpt2 = d.createElement('div');
			tmpOpt2.setAttribute('value',opt2.value);
			tmpOpt2.setAttribute('CS2',select2.id);
			tmpOpt2.onmouseover=function(){this.className='optHover2';}
			tmpOpt2.onmouseout=function(){this.className='opt2';}
			tmpOpt2.onclick=function(){
				setSelectValue2(this.getAttribute('CS2'), this.getAttribute('value'));
				$('new_'+this.getAttribute('CS2')).value = this.innerHTML;
				$('new_'+this.getAttribute('CS2')).style.backgroundPosition = 'top left';
				new Effect.Fade($('opts_new_'+this.getAttribute('CS2')), {duration:0.3});
			}
			var optContent2 = d.createTextNode(opt2.innerHTML);
			tmpOpt2.appendChild(optContent2);
			optTab2.push(tmpOpt2);
		});
		optTab2.each(function(opt2){
			opts2.appendChild(opt2);
		});
		
		var pN2 = select2.parentNode;
		pN2.appendChild(newCS2);
		pN2.appendChild(opts2);
	});
	Event.observe(d, 'click', hideOpts2, f);
}

function switchOptions2(id){
	if($('opts_'+id).visible()==f){
		hideOpts2();
		$(id).style.backgroundPosition='bottom left';
		var posSelect2 = getOffsets2($(id));
		//$('opts_'+id).style.left = (posSelect[0] - 40)+'px';
		$('opts_'+id).style.left =850+'px';
		$('opts_'+id).style.top = (posSelect2[1] - 10)+$(id).getHeight()+'px';
		new Effect.BlindDown('opts_'+id, {duration:0.3});
	}
}

function hideOpts2(){
	var lstopts2 = $A(d.getElementsByClassName('opts2'));
	lstopts2.each(function(opts2){
		if(opts2.visible() && 'new_'+opts2.getAttribute('CS2')!=curCS2){
			$('new_'+opts2.getAttribute('CS2')).style.backgroundPosition = 'top left';
			new Effect.Fade(opts2, {duration:0.3});
		}
	});
}

function setSelectValue2(targetSelect2, valueSelect2){
	if($(targetSelect2).value!=valueSelect2){
		var ts2 = $(targetSelect2);
		var lstOpts2 = $A(ts2.getElementsByTagName('option'));
		lstOpts2.each(function(opt2){
			if(opt2.value==valueSelect2){
				opt2.selected = 'selected';
				throw $break;
			}
		});
		if($(targetSelect2).onchange!=undefined){
			$(targetSelect2).onchange();
		}
	}
	if($(targetSelect2).onclick!=undefined){
			$(targetSelect2).onclick();
	}
}
