var GEDropDown = function(el) {
	// this.containerEl = null;
	// this.titleEl = null;
	this.ulEl = null;
	// this.items = null;
	this.mouseOn = false;
	this.isOpen = true;
	this.initialize(el);
};

GEDropDown.prototype.initialize = function(el) {
	this.ulEl = el;
	// this.items = $(this.ulEl).children();
	var containerEl = document.createElement('div');
	var titleEl = $(this.ulEl).prev().get(0);
	
	var self = this;
	$(this.ulEl)
		.removeClass('dropdown')
		.addClass('dropdown_list')
		.parent().append( containerEl );
	$(containerEl)
		.addClass('dropdown')
		.append( $(titleEl).addClass('dropdown_title') )
		.append( this.ulEl )
		.click( function() { self.toggleSelect(); } )
		.hover( function() { self.mouseOn = true; },
				function() { self.mouseOn = false; }
		);

   	$(document).click( function() { if(!self.mouseOn && self.isOpen) self.close(); } );
	this.close();
};

GEDropDown.prototype.toggleSelect = function() { this.isOpen ? this.close() : this.open(); };

GEDropDown.prototype.close = function() { $(this.ulEl).hide(); this.isOpen = false; };

GEDropDown.prototype.open = function() { $(this.ulEl).show(); this.isOpen = true; };

$(document).ready( function() { $('.dropdown').each( function(i,el){ var list = new GEDropDown(el); } ); } );

