// <![CDATA[
/**
 * dependency of this plugin:
 *
 * //@var global string http_root
 * //@var global string rp_image_global
 * //@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
        grayscale_tile_image: function(options) {
		
			// Set the default values, use comma to separate the settings, example:
            var defaults = {
				objectParent: '.tile-item', // The object parent.
				tileDescription: '.tile-description', // The tile description.
				objectDelay: 150 // The delay time to animate the object's opacity.
            }
                 
            var options = $.extend(defaults, options);
			
			var $cm = this.each(function(){
				
				var o = options;
				var object = $(this);
				
				var width_img = object.find('img').width();
				var height_img = object.find('img').height();
				var parent_object = object.parent(o.objectParent);
				
				if(object.length > 0)
				{
					grayscale.prepare(object.find('img'));
					grayscale(object.find('img'));
					
					object.find('img').css({opacity:0.4});
					
					object.css({
						width:width_img + 'px',
						height:height_img + 'px'
					});
					
					//alert(typeof(width_img));
					//alert(width_img);
					//alert(width_img-10);
					$(o.tileDescription,parent_object).css({
						width: (width_img - 30) + 'px'
					});
				}

			});
			
			// Set the delay variable.
			var delay = 0;
			
			// Loop each object and animate its opacity.
			var $cm_2 = this.each(function(){
				
				var o = options;
				var object = $(this);
				
				// Set the object opacity to 0.
				object.css({opacity:0});
				
				// Do for every instance(starting at 0).
				object.delay(delay).animate({
					opacity:1
				},500);
				
				delay += o.objectDelay;
			
			});

        }
    });
     
//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);

// ]]>
