(function( $ ){

  $.fn.bwtocolor = function( options ) {  

    var settings = {
		taglines:"no"
    };

    return this.each(function() {
	
      if ( options ) 
	  { 
        $.extend( settings, options );
      }
	  
	  $tagline = $("<div class='tagline'/>");
	  
	  $root = $(this).find("div");
	  
	  $root.find("img").each(function(i){
	  	$cloneelement = $(this).clone();
		$cloneelement.insertAfter($(this));
	  })
	  
	  $saturated = $root.find("img:odd").addClass("sat");	  
	  var clonesatimg = $saturated.clone();
	  	  
	  $desaturated = $root.find("img:even").addClass("desat");	  
	  var clonedesatimg = $desaturated.clone();
	  	  
	  //$(".desat").pixastic("desaturate");
	  
	  $root.cycle({
	 	before:onBefore,
		after:onAfter
	  });
	  
	  function onBefore(){
		
		var tagline = this;
		
		if(settings.taglines == "yes"){
			if($(this).attr("class")=="sat")
			{	
		        $root.cycle('pause');
				$tagline.animate({
				    left: '0',
					opacity:1
				  }, 1500, function() {					  
				     $tagline.html(tagline.alt);
					 $tagline.find("p").hide();
					 $tagline.find("p").fadeIn(2000, function(){
						  $root.delay(4000).cycle('resume');
				     });				    
				 });
				$root.parent().append($tagline);
			}
			
			if($(this).attr("class")=="desat")
			{
				$tagline.animate({
				    left: '-=1024',
					opacity:0
				  }, 1500, function() {
					  $tagline.find("p").hide();
				 });
			}
		}	  
		 	
	  	$root.css({
			"background-image":"url("+this.src+")"
		})
	  }
	  
	  function onAfter(){
	  	
	  	//$tagline.css({"left":-$tagline.width()});
	  }
	  
	  
	  
    });
  };
})( jQuery );




