/**
 * jQuery Spotlight
 *
 * Project Page: http://www.gilbertpellegrom.co.uk/projects/jquery-spotlight
 * Copyright (c) 2009 Gilbert Pellegrom, http://www.gilbertpellegrom.co.uk
 * Licensed under the GPL license (http://www.gnu.org/licenses/gpl-3.0.html)
 * Version 1.0 (12/06/2009)
 */
(function($) {

	$.fn.spotlight = function(options) {
		// Default settings
		settings = $.extend({}, {
			opacity: .5,
			speed: 400,
			color: '#333'
		}, options);
		
		// Add the overlay div
        $('body').append('<div id="spotlight"></div>');

        // Get our elements
        var spotlight = $('#spotlight');

        // Set the CSS styles
        spotlight.css({
            'position':'fixed',
            'background':settings.color,
            'opacity':settings.opacity,
            'top':'0px',
            'left':'0px',
            'height':'100%',
            'width':'100%',
            'z-index':'9998'
        });

        var element = $(this);

        if(!element.get(0)) return;

        // Set element CSS
        var currentPos = element.css('position');

        if(currentPos == 'static'){
            element.css({'position':'relative', 'z-index':'9999'});
        } else {
            element.css('z-index', '9999');
        }

		// Returns the jQuery object to allow for chainability.  
		return this;
	};

})(jQuery);
