// <![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
        reveal_tile_text: function(options) {
		
			// Set the default values, use comma to separate the settings, example:
            var defaults = {
				objectParent: '.tile-item', // The object parent.
				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);
				
				// Set the object parent.
				var parent_object = object.parent(o.objectParent);
				
				var width_parent = parent_object.width();
				var height_parent = parent_object.height();
				
				object.css({
					width: width_parent + 'px',
					height: (height_parent - 6) + 'px'
				});
				
				//Get rgb string
				var colour_parent = parent_object.css("background-color");
				var colour_object = object.css("background-color");
				
				//alert(colour_object);
				
				object.css({ backgroundColor: colour_parent });
				
				if(object.length > 0)
				{
					//On hover...	
					object.hover(function() {
						
						//Animate the object background colour to match its parent's.
						$(this).animate({ backgroundColor: colour_parent }, 'fast');
						
						//Change the button's position to the new position.
						$('a',parent_object).css({backgroundPosition: '0px -11px'});
						
						//On hover out...
					}, function() { 
						
						//Animate the object background colour back to its original.
						$(this).animate({ backgroundColor: colour_object }, 'fast');
						
						//Change the button's position back.
						$('a',parent_object).css({backgroundPosition: '0px 0px'});
					});
				}

			});
			
			// Set the variable.
			var delay = 4000;
			
			// Loop each object and animate its opacity.
			var $cm_2 = this.each(function(){
			
				var o = options;
				var object = $(this);
				
				// Do for every instance(starting at 0).
				object.delay(delay).animate({
					backgroundColor: 'rgb(204, 204, 204)'
				},100);
				
				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);

// ]]>
