
$('.dp-select-checkbox').each( function() {
    //var selectedList = parseInt($(this).data('selectedList'));
    var linkInfo = {};
    var noneSelectedText = $(this).data('textsPlaceholder');

    if ($(this).data('textsSelectAll')) {
	var textsSelectAll = $(this).data('textsSelectAll');
	linkInfo.checkAll ={text: textsSelectAll, title: textsSelectAll};
    }
    if ($(this).data('textsUnselectAll')) {
	var textsUnselectAll = $(this).data('textsUnselectAll');
	linkInfo.uncheckAll = {text: textsUnselectAll, title: textsUnselectAll};
    }    
    if ($(this).data('textsClose')) {
	var textsClose = $(this).data('textsClose');
	linkInfo.close = {text: textsClose, title: textsClose};
    }    
    var multiselect = $(this).multiselect({
	//selectedList: 2,
	/*
	columns  : parseInt($(this).data('columns')),
	search   : parseInt($(this).data('search')),
	selectAll: parseInt($(this).data('selectAll')),
	linkInfo    : {
            //placeholder:  $(this).data('textsPlaceholder'),
	    //search: $(this).data('textsSearch'),
	    checkAll: {text: $(this).data('textsSelectAll'), title: 'Check All foos'},
	    uncheckAll: {text: $(this).data('textsUnselectAll'), title: 'Check All foos'}
	},
*/
/*	faIcons: {
    open: {icon: '<i class="fa fa-caret-down" aria-hidden="true"></i>'},
	    close: {icon: '<i class="fa fa-close" aria-hidden="true"></i>'}
	},
	*/
	linkInfo    : linkInfo,
	noneSelectedText: noneSelectedText,
	classes: $(this).attr('class') + ($(this).data('classes') ? ' ' + $(this).data('classes') : ''),
	selectedText: $(this).data('selectedText') ? $(this).data('selectedText') : null,
	selectedList: $(this).data('selectedList') ? $(this).data('selectedList') : null,
	selectedListSeparator: $(this).data('selectedListSeparator') ? $(this).data('selectedListSeparator') : null,
	maxSelected: $(this).data('maxSelected') ? $(this).data('maxSelected') : null,
	menuWidth: $(this).data('menuWidth') ? $(this).data('menuWidth') : null,
	menuHeight: $(this).data('menuHeight') ? $(this).data('menuHeight') : null,
	buttonWidth: $(this).data('buttonWidth') ? $(this).data('buttonWidth') : null,
	header: $(this).data('header') ? $(this).data('header') : false,
/*	position: {
	    my: 'left top',
	    at: 'left top'
	},*/
	htmlText: [],
	/*
	beforeUncheckAll:  function(event, ui) {
	    var button = $(event.target).multiselect('getButton');
	    button.removeClass('selected');
	},
*/
	maxselected:  function(event, ui) {
	    var checked = $(event.target).multiselect('getChecked');
	    var msg = $(event.target).data('textsMaxSelected').replace('#', checked.length - 1);
	    $(event.target).multiselect('buttonMessage','<center><b>' + msg + '</b></center>');
	    return false;
	},
	checkAll:  function(event, ui) {
	    var button = $(event.target).multiselect('getButton');
	    if (!button.hasClass('selected')) {
		button.addClass('selected');
	    }
	},
	uncheckAll:  function(event, ui) {
	    var button = $(event.target).multiselect('getButton');
	    button.removeClass('selected');
	},
	click: function(event, ui) {
	    var button = $(event.target).multiselect('getButton');
	    var checked = $(event.target).multiselect('getChecked');
	    if (ui.checked && !button.hasClass('selected')) {
		button.addClass('selected');
	    } else {
		// uncheckAll not working with filter
		if (checked.length==0) {
		    button.removeClass('selected');
		}
	    }
	    /*
	    if (checked.length) {
		if (!button.hasClass('selected')) {
		    button.addClass('selected');
		}
	    } else {
		button.removeClass('selected');
	    }
	    */
	},
    });
    if ($(this).data('filter')==1) {
	$(this).multiselectfilter({
	    //label: 'Filter',
	    placeholder: $(this).data('textsFilterPlaceholder'),
	});
	//$(this).multiselect().multiselectfilter();
    }

});

