(function($) {
	$.fn.extend({

		customSelectbox : function(options) {

			var defaults = {
				afterClick : function(){},
				direction  : ''
			};

			var options = $.extend(defaults, options);

			return this.each(function() {
				var o = options;
				var obj = $(this);
				
				obj.click(function(){
					var selectbox 				= $(this);
					var selectbox_selected 		= selectbox.find('.div_selectbox_selected');
					var selectbox_div_option	= selectbox.find('.div_option');	

					if(selectbox_div_option.css('display') == "none"){
						$('.div_selectbox .div_option').each(function(){ $(this).hide(); });
						
						selectbox_selected.css('background-position','top right');	
						switch (o.direction) {
						case 'up':
								console.log('up');
								selectbox_div_option.css({
									'top':34 - selectbox_div_option.height()
								});
							break;
						case 'down':
								selectbox_div_option.css({
								'top':34 - selectbox_div_option.height()
							});
							break;
						default:
				
							break;
						}
						if(o.direction == '')
						{
							selectbox_div_option.slideDown(300);
						}
						else
						{
							selectbox_div_option.fadeIn(300);
						}
					}
					
					selectbox_selected.click(function(){	
						$(this).css('background-position','bottom right');	
						
						if(o.direction == '')
						{
							selectbox_div_option.slideUp(300);
						}
						else
						{
							selectbox_div_option.fadeOut(300);
						}
					});
					
					selectbox_div_option.find('li').click(function(){
						selectbox_selected.text($(this).text());
						selectbox.find('input').val( ($(this).attr('val') ? ($(this).attr('val') == 0 ? '' : $(this).attr('val')) : $(this).text() ) );
						selectbox_selected.css('background-position','bottom right');	
						if(o.direction == '')
						{
							selectbox_div_option.slideUp(300);
						}
						else
						{
							selectbox_div_option.fadeOut(300);
						}
						o.afterClick(this);
					});
				});	
				
			});

		}
	});
})(jQuery);

