(function($){
    $.fn.sort = function(params){
        var $this = $(this),
            cant = 0;

        var settings = $.extend({
            messageWell: null,
            messageWrong: null
        }, params);

        main.call(this);

        function main(){
            cant =  $('.item', $this).length;
            $this.on('click','.fn_btncheck',check);
            setEventSort();
            checkSizeScreen();
            $(window).resize(function() {
                checkSizeScreen();
            });
        }

        function setEventSort() {
            $( ".fn_sort", $this).sortable({
                placeholder: "ui-state-highlight" ,
                containment: $this,
                axis:"y"
            });
        }

        function check(){
            var counter = 0;

           $('.item', $this).each(function(i,e){
                if([parseInt($(e).data('value')) - 1] == i)
                    counter++;
           });

            if(counter == cant)
            {
                $('#retro > .content-retro').html($('#'+settings.messageWell).html());
                $('#retro').fadeIn();
            }
            else{
                $('#retro > .content-retro').html($('#'+settings.messageWrong).html());
                $('#retro').fadeIn();
            }
        }

        function checkSizeScreen() {
            if(window.innerWidth < 768)
                openModal('size_screen');
            else{
                $('#modal').removeClass().addClass('zoomOut animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){             $(this).removeClass().hide();         });}
        }
    }
})(jQuery);