awselect_count = 0;
(function ( $ ) {
	$(document).mouseup(function (e)
		{
		    var awselect = $(".awselect");
		    if (!awselect.is(e.target) // if the target of the click isn't the container...
		        && awselect.has(e.target).length === 0) // ... nor a descendant of the container
		    {
		        deanimate()
		    }
		});
		
	$.fn.awselect = function(options){
		var element = $(this);
		var opts = $.extend({}, $.fn.awselect.defaults, options)
		
		element.each(function(){
			awselect_count += 1
			build($(this), opts);
		})
		
		this.on('click', function(){
			animate(getawselectElement($(this)));
		})
		this.on('change', function(){
			setValue(this);
		})
		console.log(element.attr('id'))
	
		return {
			blue: function(){
				element.css('color', 'blue')
			}
		}
	};
	$.fn.awselect.defaults = {
		background: "#e5e5e5",
		active_background: "#fff",
		placeholder_color: "#000",
		placeholder_active_color: "#000",
		option_color: "#000",
		vertical_padding: "15px",
		horizontal_padding: "40px"
	}
	function getawselectElement(select){
		return $('.awselect[data-select="' + select.attr('id') + '"]')
	}
	function build(element, opts){
		var placeholder = element.attr('data-placeholder')
		var id = element.attr('id')
		var options = element.children('option')
		var selected = false;
		var classes = "awselect";
		var options_html = '';
		var background = opts["background"]
		var active_background = opts["active_background"]
		var placeholder_color = opts["placeholder_color"]
		var placeholder_active_color = opts["placeholder_active_color"]
		var option_color = opts["option_color"]
		var vertical_padding = opts["vertical_padding"]
		var horizontal_padding = opts["horizontal_padding"]
		options.each(function(){
			if ( $(this).attr('selected') == "selected") {
				selected = $(this).text()
			}
			options_html += '
'+ $(this).text() +'';
		})
		if ( selected !== false ) {
			classes += ' hasValue';
		}
		if (typeof id !== typeof undefined && id !== false) {
			id_html = id
		} else {
			id_html = 'awselect_' + awselect_count;
			$(element).attr('id', id_html)
		}
		var awselect_html = '';
			awselect_html += '
'
				awselect_html += '
'
				awselect_html += '
'
					if ( selected !== false ) {
						awselect_html += ''+ selected +'';
					}
					awselect_html += ''+ placeholder +''
					awselect_html += ''+ icon(placeholder_color) +''
				awselect_html += '
'
			awselect_html += '
';
			awselect_html += '
'
				awselect_html += options_html
			awselect_html += '
';
		awselect_html += '