// <![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
        toggle_slide: function(options) {
		
			// Set the default values, use comma to separate the settings, example:
            var defaults = {
				objectClassName:		'clicked',
				targetElement:			'.items-member',
				easingHeight:			'easeOutExpo',
				animateSpeed:			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){
				
				// Set the varible.
				var object = $(this);
				var object_text = object.text();
				var object_target = $(o.targetElement);
				var target_height = object_target.height();
				var actual_height = object_target.css({height: "100%", maxHeight:"100%"}).height(); //var actual_height = object_target.height('100%').height();
				object_target.height(target_height);
				
				// Check if the object has no class name then proceed.
				if (!(object.hasClass(o.objectClassName)))
				{
					// Add the class name to the object.
					object.addClass('clicked');
					
					object_target.animate({
							height:actual_height + 'px'
						}, {
							duration: o.animateSpeed,
							specialEasing: {
							height: o.easingHeight
						},
							complete: function() {
							object.after('<span class="sneaky-height" style="display:none;">'+target_height+'</span>');
						}
					});
					
					// Check if the object contain the keyword, then replace they keyword.
					// or: if($(":contains('More')", this).length > 0)alert('1');
					if (object.is(":contains('More')"))  object.text($(this).text().replace('More','Less')); 
				}
				else
				{
					var sneaky_height = object.next('.sneaky-height').text();
					//alert(sneaky);
					
					// Add the class name to the object.
					object.removeClass(o.objectClassName);
					object.next('.sneaky-height').remove();
					
					object_target.animate({
							height:sneaky_height + 'px'
						}, {
							duration: o.animateSpeed,
							specialEasing: {
							height: o.easingHeight
						},
							complete: function() {
							// do nothing.
							//$(this).after('<span class="sneaky-info">'+target_height+'</span>');
						}
					});
					
					// Check if the object contain the keyword, then replace they keyword.
					// or: if($(":contains('More')", this).length > 0)alert('1');
					if (object.is(":contains('Less')"))  object.text($(this).text().replace('Less','More')); 
				}
					
				// 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);

// ]]>
