// <![CDATA[
/**
 * dependency of this plugin:
 *
 * //@var global string http_root
 * //@var global string rp_global_image
 * //@var global string image_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_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);
			
			//var $cm = this.each(function(index,element){
			// "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.ready(function(e){
				
				var o = options;
				var object = $(this); // always return #document.
				
				$(document.body).prepend("<div id='popup-account' class='popup-outer'><div class='popup-inner'><div class='close'><a href='#' class='button-close'>x close</a></div><div class='binder-form set-form'></div></div></div>");
	
				var target = $('#popup-account').width(o.popupWidth).hide();
				var path = object.find('form').attr('action');
				var string = object.find('form').serialize();
				var pathname = window.location.pathname; // to get the current URL
				
				//var object_loadpath = object.attr("href");
				//var target_popup = $('#popup-reset-request').width(o.popupWidth).hide();
				
				// Keep the lines below for checking.
				//alert(path);
				//alert(pathname);
				//alert($cm.selector);
				//alert($(location).attr('href'));
				//alert(element);
				//alert(string);
				//alert(object.find('form').attr('action'));
				//alert(object.find('form').serialize());
				//target.css({zIndex:500});
				//alert(object.get(0).nodeName);
				
				// Load the form into the the form area then fade the entire wrapper in.
				$('.binder-form',target).load(http_root+path+'?'+string, {}, function(){
					
					// Set the popup to the center of the page.
					//set_center(target);
					$(target).set_center();
					
					//var $cm = target;
					//alert(target.selector);
					
					target.fadeIn('fast', function(){
						
						// Attach other functions and plugins.
						$('form *[title]').inputHint();
						target.post_form_account();
						close_popup(target);
					});
				
				});
				return false;
				
			});
			
			//alert($cm.selector);
			
        }
    });
     
//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);

// ]]>
