(function( $ ){
	/* funciones del plug-in */
	
	var functions = {
		normal: function( element, color ) {
			
			var properties = styles.base();
			
			$.extend( properties, styles.normal( color ) );
			
			$( element ).css( properties );
		},
		over: function( element, color ) {
			$( element ).css( styles.over( color ) );
		},
		active: function( element, color ) {
			$( element ).css( styles.active( color ) );
		},
		disabled: function( element, color ) {
			$( element ).css( styles.disabled( color ) );
		},
		enabled: function( element, color ) {
			$( element ).css( styles.normal( color ) );
		}
	}

	/* Metodos del Plugin */
	var methods = {
		init: function( element , options ) {
			
			$(element).each(function( ){
				var $this = $(this),
					color = $this.data('color')
				
				if ( ! color ) {
					
					var settings = {
						'color' : 'gray'
					};
					if ( options ) {
						$.extend( settings, options );
					}
					$this.data('color', settings.color);
					
				}
				else {
					var settings = {
						'color' : $this.data('color')
					};
				}
				
				functions.normal( this, settings.color );
				
				$this.bind({
					mouseover: function( ) {
						functions.over(this, settings.color );
					},
					focus: function( ) {
						functions.over(this, settings.color );
					},
					mouseleave: function( ) {
						functions.normal(this, settings.color );
					},
					mouseup: function( ) {
						functions.normal(this, settings.color );
					},
					blur: function( ) {
						functions.normal(this, settings.color );
					},
					mousedown: function( ) {
						functions.active(this, settings.color );
					}
					
				});
				
				
			});
		},
		destroy: function( ) {
			$(arguments).each(function( ){
				var $this = $(this)
				$this.unbind("mouseover focus mouseleave mouseup blur mousedown click");
				$this.removeData('color');
				$this.removeAttr('style');
				
			});
		},
		disabled: function( ) {
			$(arguments).each(function( ){
				var $this = $(this),
					color = $this.data('color')
				if ( color ) {
					functions.disabled( this, color );
					$this.unbind("mouseover focus mouseleave mouseup blur mousedown");
					$this.bind({
						click: function( e ) {
							e.preventDefault();
						}
					});
				}
			});
		},
		enabled: function( ) {
			$(arguments).each(function( ){
				var $this = $(this),
					color = $this.data('color')
				if ( color ) {
					functions.enabled( this, color );
					$this.unbind("click");
					functions.normal( this, color );
				
					$this.bind({
						mouseover: function( ) {
							functions.over(this, color );
						},
						focus: function( ) {
							functions.over(this, color );
						},
						mouseleave: function( ) {
							functions.normal(this, color );
						},
						mouseup: function( ) {
							functions.normal(this, color );
						},
						blur: function( ) {
							functions.normal(this, color );
						},
						mousedown: function( ) {
							functions.active(this, color );
						}
					
					});
					
				}
				
			});
		}
	}
	/* plug-in to jquery */
	$.fn.css3button = function( method ) {
		
		if ( typeof method === 'object' || ! method ) {
			methods.init(this, method);
		}
		else if ( methods[method] ) {
			
			methods[method].apply( method, this );
		}
		return this;
	}
	
		
	/* estilos */
	
	var styles = {
		base: function() {
			return {
				'-moz-border-radius': '4px',
			    '-webkit-border-radius': '4px',
			    '-khtml-border-radius': '4px',
			    'border-radius': '4px',
			    '-moz-box-shadow':'inset 1px 1px 0 rgba(255,255,255,0.3)',
			    '-webkit-box-shadow':'inset 1px 1px 0 rgba(255,255,255,0.3)',
			    'box-shadow':'inset 1px 1px 0 rgba(255,255,255,0.3)',
			    'cursor': 'pointer',
			    'display': 'inline-block',
			    'font': '12px/16px "Lucida Grande", "Lucida Sans Unicode", "Helvetica Neue", Helvetica, Arial, Verdana, sans-serif',
			    'padding': '4px 10px',
			    'outline': 'none !important',
			    'text-align': 'center',
			    'text-decoration': 'none',
			    'position': 'relative',
				'-moz-box-sizing': 'border-box !important'
			}
		},
		normal: function( color ) {
			switch ( color ) {
				case 'orange':
							return {
								'background': '#f78d1d',
							    'background-image': '-webkit-gradient(linear, left top, left bottom, from(#faa51a), to(#f47a20))',
							    'background': '-moz-linear-gradient(top, #faa51a, #f47a20)',
							    '-pie-background': 'linear-gradient(top, #faa51a, #f47a20)',
							    'border': 'solid 1px #dd6611',
							    'color': '#fef4e9',
							    'text-shadow': '0 1px 1px rgba(0,0,0,0.25)'
							}
							break;
				case 'red':
							 return {
								'background': '#C44747',
								'background-image': '-webkit-gradient(linear, left top, left bottom, color-stop(0.1, #DD5F5F), color-stop(0.9, #A92C2C))',
							    'background': '-moz-linear-gradient(top, #DD5F5F 10%, #A92C2C 90%)',
							    '-pie-background': 'linear-gradient(top, #DD5F5F 10%, #A92C2C 90%)',
							    'border': '1px solid #A92C2C',
							    'color': '#fef4e9',
							    'text-shadow': '0 1px 1px rgba(0,0,0,0.25)'
							}
							break;
				case 'blue':
							return {
								'background': '#0095cd',
							    'background-image': '-webkit-gradient(linear, left top, left bottom, from(#00adee), to(#0078a5))',
							    'background': '-moz-linear-gradient(top,  #00adee,  #0078a5)',
							    '-pie-background': 'linear-gradient(top,  #00adee,  #0078a5)',
							    'border': '1px solid #034462',
							    'color': '#ffffff',
							    'text-shadow': '0 1px 1px rgba(0,0,0,0.25)'
								}
							break;
				case 'green':
							return {
								'background': '#8fc857',
							    'background-image': '-webkit-gradient(linear, left top, left bottom, from(#8fc857), to(#5c9425))',
							    'background': '-moz-linear-gradient(top,  #8fc857,  #5c9425)',
							    '-pie-background': 'linear-gradient(top,  #8fc857,  #5c9425)',
							    'border':'1px solid #561',
							    'color': '#ffffff',
							    'text-shadow': '0 1px 1px rgba(0,0,0,0.25)'
							}
							break;
				default:
							 return {
								'background': '#f1f1f1',
							    'background-image': '-webkit-gradient(linear, left top, left bottom, from(#e9e9e9), to(#d1d1d1))',
							    'background': '-moz-linear-gradient(top,  #e9e9e9,  #d1d1d1)',
							    '-pie-background': 'linear-gradient(top,  #e9e9e9,  #d1d1d1)',
							    'border': '1px solid #bbb',
							    'color': '#555',
							    'text-shadow': '0 1px 0 #fff'
							}
							break;
			}

		},
		over: function( color ) {
			switch ( color ) {
				case 'orange':
							return {
								'background': '#f47c20',
							    'background-image': '-webkit-gradient(linear, left top, left bottom, from(#f88e11), to(#f06015))',
							    'background': '-moz-linear-gradient(top,  #f88e11,  #f06015)',
							    '-pie-background': 'linear-gradient(top,  #f88e11,  #f06015)',
							    'border': 'solid 1px #aa5511',
							    'color': '#fef4e9'
							}
							break;
				case 'red':
							return {
								'background': '#C44747',
								'background-image': '-webkit-gradient(linear, left top, left bottom, color-stop(0.1, #DD4141), color-stop(0.9, #A92121))',
							    'background': '-moz-linear-gradient(top, #DD4141 10%, #A92121 90%)',
							    '-pie-background': 'linear-gradient(top, #DD4141 10%, #A92121 90%)',
							    'border': '1px solid #711',
							    'color': '#fef4e9'
							}
							break;
				case 'blue':
							return {
								'background': '#007ead',
							    'background-image': '-webkit-gradient(linear, left top, left bottom, from(#0095cc), to(#00678e))',
							    'background': '-moz-linear-gradient(top,  #0095cc,  #00678e)',
							    '-pie-background': 'linear-gradient(top,  #0095cc,  #00678e)',
							    'border': '1px solid #234',
							    'color': '#fff'
							}
							break;
				case 'green':
							return {
								'border': '1px solid #556611',
							    'background': '#8fbb44',
							    'background-image': '-webkit-gradient(linear, left top, left bottom, from(#8fbb44), to(#5c8825))',
							    'background': '-moz-linear-gradient(top,  #8fbb44,  #5c8825)',
							    '-pie-background': 'linear-gradient(top,  #8fbb44,  #5c8825)',
							    'border': '1px solid #342'
								}
							break;
				default:
							return {
								'border': '1px solid #aaa',
							    'background': '#ececec',
							    'background': '-webkit-gradient(linear, left top, left bottom, from(#e1e1e1), to(#c1c1c1))',
							    'background': '-moz-linear-gradient(top,  #e1e1e1,  #c1c1c1)',
							    '-pie-background': 'linear-gradient(top,  #e1e1e1,  #c1c1c1)',
							    'border': '1px solid #999',
							    'color': '#555'
							}
							break;
			}
		},
		active: function( color ) {
			switch ( color ) {
				case 'orange':
							return {
								'background': '#f47a20',
							    'background-image': '-webkit-gradient(linear, left top, left bottom, from(#f47a20), to(#faa51a))',
							    'background': '-moz-linear-gradient(top,  #f47a20, #faa51a)',
							    '-pie-background': 'linear-gradient(top,  #f47a20, #faa51a)',
							    'border': 'solid 1px #aa5511',
							    'color': '#fef4e9'
							}
							break;
				case 'red':
							return {
								'background': '#C44747',
								'background-image': '-webkit-gradient(linear, left top, left bottom, color-stop(0.1, #A92C2C), color-stop(0.9, #DD5F5F))',
							    'background': '-moz-linear-gradient(top, #A92C2C 10%, #DD5F5F 90%)',
							    '-pie-background': 'linear-gradient(top, #A92C2C 10%, #DD5F5F 90%)',
							    'border': '1px solid #711',
							    'color': '#fef4e9'
							}
							break;
				case 'blue':
							return {
								'background': '#80bed6',
							    'background-image': '-webkit-gradient(linear, left top, left bottom, from(#0078a5), to(#00adee))',
							    'background': '-moz-linear-gradient(top,  #0078a5,  #00adee)',
							    '-pie-background': 'linear-gradient(top,  #0078a5,  #00adee)',
							    'border': '1px solid #234',
							    'color': '#fff'
							}
							break;
				case 'green':
							return {
								'background': '#8fbb44',
							    'background-image': '-webkit-gradient(linear, left top, left bottom, from(#5c8825), to(#8fbb44))',
							    'background': '-moz-linear-gradient(top,  #5c8825,  #8fbb44)',
							    '-pie-background': 'linear-gradient(top,  #5c8825,  #8fbb44)',
							    'border': '1px solid #342'
							}
							break;
				default:
							return {
								'background': '#ddd',
							    'background-image': '-webkit-gradient(linear, left top, left bottom, from(#ccc), to(#e9e9e9))',
							    'background': '-moz-linear-gradient(top,  #ccc,  #e9e9e9)',
							    '-pie-background': 'linear-gradient(top,  #ccc,  #e9e9e9)',
							    'border': '1px solid #999',
							    'color': '#555'
							}
							break;
			}
		},
		disabled: function( color ) {
			switch ( color ) {
				
				case 'orange':
							return { 
								'background': '#f78d1d',
							    'border': 'solid 1px #dd6611',
							    'color': '#fef4e9',
							    'text-shadow': '0 1px 1px rgba(0,0,0,0.25)' 
							}
							break;
				case 'red':
							return {
								'background': '#C44747',
							    'border': '1px solid #A92C2C',
							    'color': '#fef4e9',
							    'text-shadow': '0 1px 1px rgba(0,0,0,0.25)'
							}
							break;
				case 'blue':
							return {
								'background': '#0095cd',
							    'border': '1px solid #034462',
							    'color': '#fff',
							    'text-shadow': '0 1px 1px rgba(0,0,0,0.25)'
							}
							break;
				case 'green':
							return {
								'color': '#fff',
							    'background': '#8fc857',
							    'text-shadow': '0 1px 1px rgba(0,0,0,0.25)',
							    'border': '1px solid #561'
							}
							break;
				default:
							return {
								'background': '#f1f1f1',
							    'border': '1px solid #bbb',
							    'color': '#555',
							    'text-shadow': '0 1px 0 #fff'
							}
							break;
			}
		}
		
	}
	
	
	/**/
})( jQuery );
