$(
    function () {
        ProductImage_Quick_Preview.init();
    }
);


/**
 * Handles the product image quick (mouse over) preview
 */
var ProductImage_Quick_Preview = {

    /**
     * The identifier to find the images
     *
     * @type String
     */
    IDENTIFER: '.productimage-preview img',



    /**
     * Initializes the component
     */
    init: function () {
        var $handler = $(this.IDENTIFER);
        this._registerHandler($handler);
    },



    /**
     * Registers the handlers
     *
     * @private
     * @param $handler jQuery
     */
    _registerHandler: function ($handler) {

        var self = this;

        $handler.hover (

            function () { // enter
                self._onMouseEnter( $(this) );
            },

            function () { // leave
                self._onMouseLeave( $(this) );
            }
        );
    },



    /**
     * Callback for mouse enter event
     *
     * @private
     * @param $image jQuery
     */
    _onMouseEnter: function($image) {
        var $currentImageGroup = $image.closest(".productimage-preview").find("a");

        if ($currentImageGroup.length <= 1)
        {
            return;
        }

        $currentImageGroup.filter(".first").hide();
        $currentImageGroup.not(".first").show();
    },



    /**
     * Callback for mouse leave event
     *
     * @private
     * @param $image jQuery
     */
    _onMouseLeave: function ($image) {
        var $currentImageGroup = $image.closest(".productimage-preview").find("a");

        if ($currentImageGroup.length <= 1)
        {
            return;
        }

        $currentImageGroup.filter(".first").show();
        $currentImageGroup.not(".first").hide();
    }
};
