var asobject = new Class({
	initialize: function(asoitm, asoevnts){
		this.asoevents = $extend({"change" : function(){}}, asoevnts);
		this.asocontainer = $(asoitm);
		
		if((typeof(this.asocontainer) == "object") && ($type(this.asocontainer) == "element")){
			if(this.asocontainer.tagName == "SELECT"){
				$(window).addEvent("resize", this.asoreinitialize.bindWithEvent(this));
				this.asodraw();
				}
			}
		}, 

	asodraw: function(){
		this.asomenuehelper = null;
		this.asomenueselect = null;
		this.asomenueoption = this.asocontainer.getElements("option");
		this.asocoordinates = this.asocontainer.getCoordinates();
		this.asocontainer.setStyle("visibility", "hidden");
		this.asofakeinput = new Element("div", {
			"styles" : {
				"display"		: "block", 
				"position"		: "absolute", 
				"width"			: this.asocontainer.getStyle("width"), 
				"height"		: this.asocontainer.getStyle("height"), 
				"top"			: this.asocoordinates.top, 
				"left"			: this.asocoordinates.left, 
				"padding"		: 0, 
				"margin"		: 0, 
				"border-width"	: this.asocontainer.getStyle("border-width"), 
				"border-style"	: this.asocontainer.getStyle("border-style"), 
				"border-color"	: this.asocontainer.getStyle("border-color"), 
				"overflow"		: "hidden", 
				"z-index"		: 512, 
				"background-color"		: this.asocontainer.getStyle("background-color"), 
				"background-image"		: this.asocontainer.getStyle("background-image"), 
				"background-position"	: this.asocontainer.getStyle("background-position"), 
				"background-repeat"		: this.asocontainer.getStyle("background-repeat") 
				} 
			});
		
		this.asofakeinput.onclick = function(){
			this.asohelper_select.asoopen();
			this.asohelper_select.asolisten();
			}
			
		this.asofakeinput.asohelper_select = this;
		this.asoselectedopt = new Element("span", {
			"styles"	: {
				"display"				: "block", 
				"width"					: (this.asocontainer.getStyle("width") - 16), 
				"background-position"	: "left center", 
				"background-repeat"		: "no-repeat", 
				"overflow"				: "hidden" 
				}
			});
		
		this.asofakeinput.grab(this.asoselectedopt);
		
		$(document.body).grab(this.asofakeinput);
		
		if(this.asocontainer.selectedIndex < 0){
			this.asocontainer.selectedIndex = 0;
			}
				
		this.asoselect($(this.asocontainer.options[this.asocontainer.selectedIndex]));
		}, 

	asolisten: function(){
		(function(){$(document.body).addEvent("click", this.asoclose.bindWithEvent(this));}).delay(200, this);
		}, 
	
	asoopen: function(){
		this.asomenuehelper = new Element("div", {
			"class"		: "input-select-hlpr", 
			"styles"	: {
				"display"		: "block", 
				"position"		: "absolute", 
				"overflow"		: "hidden", 
				"z-index"		: 1024, 
				"width"			: this.asocontainer.getStyle("width"), 
				"top"			: (this.asocoordinates.top +  this.asocoordinates.height), 
				"left"			: this.asocoordinates.left, 
				"border"		: "1px solid #777", 
				"background-color"	:  this.asocontainer.getStyle("background-color") 
				}
			});
		
		if((typeof(this.asomenueoption) == "object") && ($type(this.asomenueoption) == "array")){
			this.asomenueoption.each(function(itm, idx){
				var _tmp = new Element("a", {
					"href"		: "javascript://", 
					"text"		: itm.get("text"), 
					"styles"	: { 
						"display"			: "block", 
						"overflow"			: "hidden", 
						"background-image"	: itm.getStyle("background-image") 
						} 
					});
				_tmp.onclick = function(){
					this.asohelper_select.asochange(this.asohelper_option);
					}
				_tmp.asohelper_select = this;
				_tmp.asohelper_option = itm;
				_tmp.inject(this.asomenuehelper);
				}, this);
			}
		
		this.asomenuehelper.asohelper_select = this;
		$(document.body).grab(this.asomenuehelper);
		}, 
	
	asochange: function(obj){
		this.asoselect(obj);
		this.asoevents.change(this.asocontainer);
		this.asoclose();
		}, 
	
	asoselect: function(obj){
		for(var i=0;i<this.asomenueoption.length;i++){
			if(obj == this.asomenueoption[i]){
				this.asocontainer.selectedIndex = i;
				}
			}

		this.asoselectedopt.set("text", obj.get("text"));
		this.asoselectedopt.setStyle("background-image", obj.getStyle("background-image"));
		this.asoselectedopt.setStyle("padding", obj.getStyle("padding"));
		}, 

	asoreinitialize: function(obj){
		this.asodestroy();
		this.asodraw();
		},

	asodestroy: function(obj){
		this.asoclose();
		this.asocontainer.setStyle("visibility", "visible");
		this.asofakeinput.destroy();
		this.asofakeinput = null;
		}, 
		
	asoclose: function(){
		$(document.body).removeEvents("click");
		$(document.body).onclick=null;
		if((typeof(this.asomenuehelper) == "object") && ($type(this.asomenuehelper) == "element")){
			this.asomenuehelper.destroy();
			this.asomenuehelper = null;
			}
		}
	});