(function($){

    $.fn.blend = function(options, callback) {

	if ($.browser.mozilla && (parseFloat($.browser.version) < 1.9)) { return this; }
	
	var settings = $.extend({}, $.fn.blend.settings, options);
        $(this).each(function(){    
	    var $this = $(this),
		$target = $(settings.target ? settings.target : this),
		$hover,
		target = [],
		i,
		length,
		style = {},
		active = false,
		out = 0,
		opacity = settings.opacity,
		bg = 'background-',
		properties = [
		    bg+'color',
		    bg+'image',
		    bg+'repeat',
		    bg+'attachment',
		    bg+'position',
		    bg+'position-x',
		    bg+'position-y'
		];
	    
	    length = properties.length;
	    
	    if($target[0].style.position !== 'absolute'){
		$target.css({position:'relative'});   
	    }
	    
	    if(!$target.hasClass('hover')){
		$target.wrapInner('<div style="position:relative" />');
	    }
	    
	    for (i=0; i<length; i++){
		target[i] = $target.css(properties[i]);
	    }
	    
	    $target.addClass("hover");
	    
	    style = {};
		style.position='absolute';
		style.top=0;
		style.left=0;
		style.width=$target.width();
		style.height=$target.height();
		for (i=0; i<length; i++){
		    style[properties[i]] = $target.css(properties[i]);
		}
		
	    //checks to see if blend has already been applied to an element.
	    if($target.find(".jsblend").length === 0){
		$hover = $('<div class="jsblend" />').css(style);
		
		if(settings.top){
		    $hover.appendTo($target);
		} else {
		    $hover.prependTo($target);
		}
	    } else {
		$hover = $target.find(".jsblend");
	    }
	    
	    style = {};
	    for (i=0; i<length; i++){
		style[properties[i]] = target[i];
	    }
	    
	    $target.css(style);
	    
	    if(settings.reverse){
		out = settings.opacity;
		opacity = 0;
	    }
	    $hover.css({opacity:out});
	    
	    function pulse(o){
		if(active){
		    $hover.fadeTo(settings.speed, o, function(){
			pulse(o===out?opacity:out);
		    });
		}
	    }
	    
	    if(settings.pulse && settings.active){
		active = true;
		pulse(opacity);
	    } else if(settings.pulse){
		$this.hover(function(){
		    active = true;
		    pulse(opacity);
		}, function(){
		    active = false;
		    $hover.stop(true).fadeTo(settings.speed, out);
		});
	    } else {
		$this.hover(function(){
		    $hover.stop().fadeTo(settings.speed, opacity);
		}, function(){
		    $hover.stop().fadeTo(settings.speed, out);
		});
	    }
	    
	});
        return this;
    };
    
    $.fn.blend.settings = {
        speed : 500,
        opacity : 1,
        target : false,
        reverse : false,
	pulse : false,
	active : false,
	top : false
    };
    
}(jQuery));// JavaScript Document