// <![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
        load_form_request_reset_account: function(options) {
		
			// Set the default values, use comma to separate the settings, example:
            var defaults = {
				popupWidth:		600 // The width of the popup.
            }
                 
            var options = $.extend(defaults, options);
            
			// return this.click(function(){ // original
			// "this" is already a jQuery object: 
			// When you create the click function you can assign that element to a variable and reference it within:
			var $cm = this.click(function(e){
				
				// Remove #popup-reset-request first if any of it exisits
				$("#popup-reset-request").remove();
				
				// Append a fresh #popup-reset-request
				$(document.body).prepend("<div id='popup-reset-request' class='popup-outer popup-reset'><div class='popup-inner'><div class='close'><a href='#' class='button-close'>x close</a></div><div id='form-reset-request' class='form-reset form'></div></div></div>");
				
				var o = options;
				var object = $(this);
				
				var object_loadpath = object.attr("href");
				var target_popup = $('#popup-reset-request').width(o.popupWidth).hide();
				
				// Keep the lines below for checking.
				//alert(target_classname);
				//alert($cm.selector);
				//alert(text_editor);
				
				// Make a black-out.
				//make_blackout();
				//$(document).make_blackout();
				$.fn.make_blackout();
				
				// Load the form into the the form area then fade the entire wrapper in
				$('#form-reset-request',target_popup).load(object_loadpath, {}, function(){
					
					// You can call the plugin from here to remove the layer if you like.
					$.fn.make_blackout.remove_blackout();
					
					// Set the pop up to the center of the page
					target_popup.set_center();
					
					// Fade in the pop up
					target_popup.fadeIn('fast', function(){
						
						// Remove the black-out.
						// Must set the clear black out here if you use the function like this - clear_blackout();
						$.fn.make_blackout.remove_blackout();
						
						// Attach other plugins and functions.
						$('form *[title]').inputHint();
						$('.close',target_popup).close_popup({target:'#popup-reset-request'});
						target_popup.post_form_request_reset_account();
						
						
					});
				
				});
				return 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);

// ]]>
