(function($) {

    $.fn.ImageOverlay = function(options) {

        // Options.
        var opts = $.extend({}, $.fn.ImageOverlay.defaults, options);

        return this.each(function() {

            // Allows metadata options to be set on the field level that override plugin options
            // if the metadata plugin is installed. http://docs.jquery.com/Plugins/Metadata
            var thisOpts = $.metadata ? $.extend({}, opts, $(this).metadata()) : opts;

            // Move the overlays below the images, so they are hidden by default.
            $('.offer', this).each(function() {

                var hrefOpts = $.metadata ? $.extend({}, thisOpts, $(this).metadata()) : thisOpts;

                var overlayHeight = $('.overlay', this).height() + 20;

                // Set the CSS properties of the overlay.
                $('.overlay', this).css({
                    top: -overlayHeight + 'px'
                });


                if (hrefOpts.animate) {
                    $(this).hover(function() {
                        $('.overlay', this).stop().animate({ top: '13px' }, { queue: false, duration: hrefOpts.overlay_speed });
                    }, function() {
                        if (hrefOpts.overlay_speed_out != null)
                            $('.overlay', this).stop().animate({ top: -overlayHeight + 'px' }, { queue: false, duration: hrefOpts.overlay_speed_out });
                        else
                            $('.overlay', this).stop().animate({ top: -overlayHeight + 'px' }, { queue: false, duration: hrefOpts.overlay_speed });
                    });
                }
                else {
                    $(this).hover(function() {
                        $('.overlay', this).css('top', '13px');
                    }, function() {
                        $('.overlay', this).css('top', -overlayHeight + 'px');
                    });
                }

            });

            $(this).after('<p style="clear: both; height: 0;">&nbsp;</p>');
        });
    };

    $.fn.ImageOverlay.defaults = {
        animate: true,
        overlay_origin: 'bottom',
        overlay_speed: 'normal'
    };

})(jQuery);

jQuery(document).ready(function() {
    // JavaScript for the Image Overlay galleries.
    $("#shop").ImageOverlay();
});