// <![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
        help: function(options) {
		
			// Set the default values, use comma to separate the settings, example:
            var defaults = {
				widthPopup:			500
            }
                 
            var options =  $.extend(defaults, options);
			var o = 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 any previous popup first.
				$(".popup, .popup-outer").remove();
				
				// Append the popup.
				$(document.body).prepend("\
				<div id='popup-help' class='popup-outer'>\
					<div class='popup-inner'>\
						<div class='close'><a href='#' class='button-close'>x close</a></div>\
						<div class='binder-help content-article'></div>\
					</div>\
				</div>\
				");
				
				// Set the varible.
				var object = $(this);
				var object_path = object.attr('href');
				var object_popup = $('#popup-help').width(o.widthPopup).hide();
				var target_load = $('.binder-help');
				//alert(html_parents);
				//alert(html_remained);
				
				// Load the form.
				target_load.load( object_path, function(){
					
					// Set the popup to the center of the page.
					object_popup.set_center();
					
					// Attach close popup plugin to fade out the popup.
					$('.close',object_popup).close_popup({target:object_popup});
			
				});
		
				// Keep the lines below for checking.
				//alert(o.popupEdit);
				//alert(path_rescale);
				//alert(path_edit);
				//alert(item_id);
				//alert(o.top);
				//alert($cm.selector);
					
				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);

// ]]>
