// <![CDATA[
/**
 * dependency of this plugin:
 *
 * //@var global string http_root
 * //@var global string rp_global_image
 * //@var global string img_loader
 * //@var global string rp_cms
 *
 * //@function close_popup()
 *
*/

// You need an anonymous function to wrap around your function to avoid conflict
(function($){
 
    // Attach this new method to jQuery
    $.fn.extend({ 
         
        // This is where you write your plugin's name
        replace_checkbox: function(options) {
		
			// Set the default values, use comma to separate the settings, example:
            var defaults = {
				increment: 0 // The increment number.
            }
                 
            var options = $.extend(defaults, options);
			
			var $cm = this.each(function(){
				
				var o = options;
				var object = $(this);
				
				if(object.length > 0)
				{
					object.hide();
					object.after('<span class="button-checkbox-replacement"></span>');
					var $each_check = object.attr('checked');
					
					if($each_check == true)
					{
						$('.button-checkbox-replacement').css({backgroundPosition:'0px -20px'});

						$('.button-checkbox-replacement').click(function(){
							
							var $this_parent = $(this).parent();
							var $this_check = $('.button-checkbox',$this_parent).attr('checked');

							if($this_check == false)
							{
								$('.button-checkbox',$this_parent).attr('checked', true);
								$(this).css({backgroundPosition:'0px -20px'});
							}
							else
							{
								$('.button-checkbox',$this_parent).attr('checked', false);
								$(this).css({backgroundPosition:'0px 0px'});
							}
							
						});
						
					}
					else
					{
						
						$('.button-checkbox-replacement').toggle(
							function (){
								var $this_parent = $(this).parent();
								$(this).css({backgroundPosition:'0px -20px'});
								$('.button-checkbox',$this_parent).attr('checked', true);
							},
							function (){
								var $this_parent = $(this).parent();
								$(this).css({backgroundPosition:'0px 0px'});
								$('.button-checkbox',$this_parent).attr('checked', false);
							}
						);

					}
				}

			});

        }
    });
     
//pass jQuery to the function, 
//So that we will able to use any valid Javascript variable name 
//to replace "$" SIGN. But, we'll stick to $ (I like dollar sign: ) )       
})(jQuery);

// ]]>
