(function( $ ){
	var settings = {'bgColor':'#666'};

	var methods = {
		init:function(options){
			var IR = this;
			
			return this.each(function(){				
				var $this = $(this), 
					data = $this.data(IR.attr('id')),
					myData = {color	: $this.css("color")};
				
				$.extend(myData, settings, options);       		
				// If the plugin hasn't been initialized yet
				if ( ! data ) {
					$(this).data(IR.attr('id'), {
						target 		: $this,
						rollColor	: myData.rollColor,
						color		: myData.color,
						loadCallback: myData.loadCallback,
						delay		: myData.delay
					});
				}
				
				$this.css("cursor","pointer");
				
				$this.mouseenter(function(){
					$this.children('h5').css('color',myData.rollColor);
					var saturated = $this.find('.projectImage').get(0);
					Pixastic.revert(saturated);
				}).mouseleave(function(){
					$this.children('h5').css('color',myData.color);
					curImg = $this.find('.projectImage').pixastic('desaturate');
				});
				
				
				$this.children(".projectImageContainer").imagesLoaded(function(){
					//console.log('imageLoaded');
					/*$this.find('.projectImage').css('display','block');
					$this.find('.projectImage').pixastic('desaturate');
					*/
					
					if(myData.loadCallback != undefined)
					{
						myData.loadCallback.apply($this,[$this]);
					}
				});
			});
		},
		
		desaturate:function(){
			return this.each(function(){
				var $this = $(this);
				$this.find('.projectImage').pixastic('desaturate');
			});
		},
		
		resaturate:function(){
			return this.each(function(){
				var $this = $(this);
				var saturated = $this.find('.projectImage').get(0);
				Pixastic.revert(saturated);
			});
		}
	};
	
	$.fn.projectThumbnail = function(method) {
		// Method calling logic
		if ( methods[method] ) {
			return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
		} else {
			$.error( 'Method ' +  method + ' does not exist on jquery.projectThumbnail' );
		}
	};
})( jQuery );
