oMain.Select = function(oParams){
	this.eSelect = document.createElement('ins');
	this.eSelect.className = 'select_navigation';
	this.eOptions = document.createElement('ins');
	this.eOptions.className = 'select_navigation_options';
	this.eScroll = document.createElement('ins');
	this.eScroll.className = 'select_navigation_scroll';
	Common.Dom.setStyle(
		this.eScroll,
		'display: none; position: absolute; width: 100%; height: 20px; background: red; left: 0; top: 0;'
	);
	var oThis = this;
	setTimeout(
		function(){oThis.create(oParams);}
		, 0
	);
};

oMain.Select.prototype = {
	create: function(oParams){
		var oThis = this;
		oParams.eOn.parentNode.insertBefore(this.eSelect, oParams.eOn);

		this.eSelected = Common.Dom.getElementsByClassName(oParams.eOn, 'selected')[0];
		this.eSelect.innerHTML = this.eSelected.innerHTML + '<ins class="button"></ins>';
		oMain.make_pseudo(this.eSelect);
		Common.Event.add(this.eSelect, 'click', function(oEvent){
			oThis.open();
			Common.Event.cancel(oEvent);
		});
		Common.Event.add(document, 'click', function(){
			if(!oThis.bDont_close){
				oThis.close();
			}else{
				oThis.bDont_close = false;
			}
		});

		this.eOptions.appendChild(oParams.eOn);
		this.eOptions.style.position = 'absolute';
		this.eOptions.style.zIndex = 999;
		var eOverflow = document.getElementById('layout');
		if(!eOverflow){
			eOverflow = document.body;
		}
		eOverflow.appendChild(this.eOptions);
		Common.Event.add(this.eOptions, 'click', function(oEvent){
			oThis.bDont_close = true;
		});

		this.eOptions.appendChild(this.eScroll);
		Common.Event.add(this.eScroll, 'mouseover', function(){
			oThis.start_scroll();
		});
		Common.Event.add(this.eScroll, 'mouseout', function(){
			oThis.stop_scroll();
		});
		this.close();
	}

	, open: function(){
		if(oMain.oPopup){
			oMain.oPopup.close();
		}
		oMain.oPopup = this;
		this.eOptions.style.display = 'block';
		this.set_position();
		Common.Class.add(this.eSelect, 'hidden');
	}

	, close: function(){
		oMain.oPopup = null;
		Common.Class.remove(this.eSelect, 'hidden');
		this.eOptions.style.display = 'none';
		this.eOptions.style.left = '0px';
		this.eOptions.style.top = '0px';
	}

	, set_position: function(){
		var oSelect_coords = Common.Dom.getAbsoluteCoords(this.eSelect);
		var oOptions_selected_coords = Common.Dom.getAbsoluteCoords(this.eSelected);
		this.iTop = oSelect_coords.iTop - oOptions_selected_coords.iTop;
		this.eOptions.style.left = oSelect_coords.iLeft + 'px';
		this.eOptions.style.top = this.iTop + 'px';
		if(this.iTop < 0){
			this.eScroll.style.display = 'block';
			this.eScroll.style.top = this.iTop * -1 + 'px';
		}
	}

	, start_scroll: function(){
		this.bScroll = true;
		this.scroll();
	}

	, stop_scroll: function(){
		this.bScroll = false;
	}

	, scroll: function(){
		this.iTop += 5;
		this.eOptions.style.top = this.iTop + 'px';
		this.eScroll.style.top = this.iTop * -1 + 'px';
		if(this.iTop < 0){
			setTimeout('oMain.oPopup.scroll()', 0);
		}else{
			this.eScroll.style.display = 'none';
		}
	}
};