(function(jQuery){
    jQuery.fn.extend({ 
        //pass the options variable to the function
        wizard_radio: function(options) {
            //Set the default values, use comma to separate the settings, example:
            var defaults = {
                spritePath: null,
                spriteValues: null
            }
				
            var options =  jQuery.extend(defaults, options);
            return this.each(function() {
            
		var o = options;
		var actualParent = this;

		$('input:radio',this).hide();
		var count = 0;	

		var path = null
		if (options.spritePath != null)
			path = options.spritePath;

		jQuery('input:radio',this).each(function()
		{
			var value = jQuery(this).attr('value');
			var text  = jQuery(this).attr('rel');
							
			var sprite;
			if (options.spriteValues != null)
				sprite = options.spriteValues[value];


			//sprite
			if ( path != null && sprite != null)
			{
				jQuery(this).after('<a rel="'+value+'" class="sprite ' + sprite + '-off">' + text + '</a>');

                                jQuery( 'a:eq(' + count + ')',$(this).parent()).click(function()
                                {
                                    var rcount = 0;
				    for( var item in options.spriteValues )
    				    {
	    			    
                                        jQuery('a:eq(' + rcount + ')',$(this).parent()).removeClass(options.spriteValues[item] + '-on').addClass(options.spriteValues[item] + '-off');
    					rcount++;
    				    }
    				    jQuery(this).removeClass(sprite + '-off').addClass(sprite + '-on');
    				    actualParent.actualValue = $(this).attr('rel');
    				});						
			}
			else
			{
			        jQuery(this).after('<a rel="'+value+'" class="form-button"><span>' + text + '</span></a>');						
				jQuery( 'a:eq(' + count + ')',$(this).parent() )
                                .click(function()
    			        {
    				    actualParent.actualValue = $(this).attr('rel');
    				    jQuery('.form-button', $(this).parent()).removeClass('selected');
    				    jQuery(this).toggleClass('selected');						
    				});						
			}
					
                        obj = $('a:eq(' + count + ')',$(this).parent());
			if (jQuery(this).attr('checked'))
			    jQuery(obj).toggleClass('selected');				
			count++;
		});
			
                this.getValue = function()
                    { return this.actualValue; }
                this.getActualValue = function()
                    { return this.actualValue; }
                this.setActualValue = function(value) 
                {   
                    var valExists = false;
                    this.actualValue = value;
                    jQuery('a',actualParent).each(function(){
                        if( $(this).attr('rel')==value )
                        {
                            $(this).click();
                            valExists = true;
                        }
                        if (valExists == false)
                        {
                            jQuery('.form-button', $(this).parent()).removeClass('selected');
                              var rcount = 0;
                              for( var item in options.spriteValues )
    			      {
    			    
	    		          jQuery('a:eq(' + rcount + ')',$(this).parent()).removeClass(options.spriteValues[item] + '-on').addClass(options.spriteValues[item] + '-off');
    				  rcount++;
    		              }
                        }
                        
                    });
                }
    		});
        }
    });
})(jQuery);
