function [theta, counts, status] = init_priors(theta0, counts0)
    if nargin < 1
        theta0.mu_min = 0;
        theta0.mu_max = 1;
        theta0.sigma = 0.05;
        theta0.tau = 100;
    end
    if nargin < 2
        counts0.mu = 0.1;
        counts0.sigma = 10;
        counts0.tau = 10;
    end
    function resume(int)
        status = int;
        uiresume();
    end

    function update(par, field, value)
        if nargin < 1
            pars = fieldnames(values);
            for p = 1:length(pars)
                fields = fieldnames(self.edit.(pars{p}));
                for f = 1:length(fields)
                    update(pars{p}, fields{f}, ...
                        num(pars{p}, fields{f})); 
                end
            end
        else
            values.(par).(field) = value;
        end
    end

    function refresh()
        pars = fieldnames(self.edit);
        for p = 1:length(pars)
            fields = fieldnames(self.edit.(pars{p}));
            for f = 1:length(fields)
                try
                    val = ebfret.num_to_str(values.(pars{p}).(fields{f}));
                    set(self.edit.(pars{p}).(fields{f}), 'string', val{1});
                catch
                end
            end
        end
    end 

    function value = num(par, field)
        value = str2num(get(self.edit.(par).(field), 'string'));
    end

    % global vars
    status = 0;
    values = struct('theta', theta0, 'counts', counts0);
    self = struct();

    self.dialog = dialog('name', 'Set Priors', ...
                         'color', [0.95 0.95 0.95], ...
                         'units', 'pixels', ...
                         'CloseRequestFcn', @(varargin) resume(0));
    set(self.dialog, ...
        'DefaultUIPanelBackGroundColor', [0.95 0.95 0.95], ...
        'DefaultUIControlUnits', 'normalized');

    try
        % element sizes (pixels)
        row_height = 18;
        edit_width = 72;
        label_width = 72;

        % vertical and horizontal padding (pixels)
        pad_width = 6;
        pad_height = 6;

        % dialog height and width
        num_rows = 11;
        dialog_height = (num_rows+1) * row_height + (num_rows+2) * pad_height;
        dialog_width = 3 * pad_width + label_width + edit_width;

        % get normalized units
        rh = row_height / dialog_height;
        ew = edit_width / dialog_width;
        lw = label_width / dialog_width;

        ph = pad_height / dialog_height;
        pw = pad_width  /dialog_width;

        % window_pos = get(gcbo(), 'position');
        % dialog_pos(1) = min(1, window_pos(1) + round(0.5 * (window_pos(3) - dialog_height)));
        % dialog_pos(2) = min(1, window_pos(2) + round(0.5 * (window_pos(4) - dialog_width)));
        % dialog_pos(3) = dialog_height;
        % dialog_pos(4) = dialog_width;

        % adjust dialog size
        rect = get(self.dialog, 'position');
        set(self.dialog, 'position', [rect(1) rect(2) dialog_width dialog_height]);

        self.label.analysis ...
            = uicontrol(self.dialog, ...
                'style', 'text', ...
                'backgroundcolor', [0.95 0.95 0.95], ...
                'string', 'Number of Sates', ...
                'horizontalalignment', 'center', ...
                'position', [pw 1-1*(rh+ph) 1-2*pw rh]);

        self.label.theta ...
            = uicontrol(self.dialog, ...
                'style', 'text', ...
                'backgroundcolor', [0.95 0.95 0.95], ...
                'string', 'Expected Parameters', ...
                'horizontalalignment', 'center', ...
                'position', [pw 1-3*(rh+ph) 1-2*pw rh]);

        self.label.q_mu_min ...
            = uicontrol(self.dialog, ...
                'style', 'text', ...
                'backgroundcolor', [0.95 0.95 0.95], ...
                'string', 'Min Center', ...
                'horizontalalignment', 'left', ...
                'position', [pw 1-4*(rh+ph) lw rh]);

        self.label.q_mu_max ...
            = uicontrol(self.dialog, ...
                'style', 'text', ...
                'backgroundcolor', [0.95 0.95 0.95], ...
                'string', 'Max Center', ...
                'horizontalalignment', 'left', ...
                'position', [pw 1-5*(rh+ph) lw rh]);

        self.label.q_sigma ...
            = uicontrol(self.dialog, ...
                'style', 'text', ...
                'backgroundcolor', [0.95 0.95 0.95], ...
                'string', 'Noise', ...
                'horizontalalignment', 'left', ...
                'position', [pw 1-6*(rh+ph) lw rh]);

        self.label.q_tau ...
            = uicontrol(self.dialog, ...
                'style', 'text', ...
                'backgroundcolor', [0.95 0.95 0.95], ...
                'string', 'Dwell', ...
                'horizontalalignment', 'left', ...
                'position', [pw 1-7*(rh+ph) lw rh]);

        self.label.counts ...
            = uicontrol(self.dialog, ...
                'style', 'text', ...
                'backgroundcolor', [0.95 0.95 0.95], ...
                'string', 'Prior Strength', ...
                'horizontalalignment', 'center', ...
                'position', [pw 1-8*(rh+ph) 1-2*pw rh]);

        self.label.c_mu ...
            = uicontrol(self.dialog, ...
                'style', 'text', ...
                'backgroundcolor', [0.95 0.95 0.95], ...
                'string', 'Center', ...
                'horizontalalignment', 'left', ...
                'position', [pw 1-9*(rh+ph) 1-2*pw rh]);

        self.label.c_sigma ...
            = uicontrol(self.dialog, ...
                'style', 'text', ...
                'backgroundcolor', [0.95 0.95 0.95], ...
                'string', 'Noise', ...
                'horizontalalignment', 'left', ...
                'position', [pw 1-10*(rh+ph) 1-2*pw rh]);

        self.label.c_tau ...
            = uicontrol(self.dialog, ...
                'style', 'text', ...
                'backgroundcolor', [0.95 0.95 0.95], ...
                'string', 'Dwell', ...
                'horizontalalignment', 'left', ...
                'position', [pw 1-11*(rh+ph) 1-2*pw rh]);


        self.popup.analysis ...
            = uicontrol(self.dialog, ...
                'style', 'popup', ...
                'string', 'All|Current', ...
                'position', [pw 1-2*(rh+ph) 1-2*ph rh]);

        self.edit.theta.mu_min ...
            = uicontrol(self.dialog, ...
                'style', 'edit', ...
                'string', 0, ...
                'callback', @(source, event) update('theta', 'mu_min', num('theta', 'mu_min')), ...
                'position', [1-(pw+ew) 1-4*(rh+ph) ew rh]);

        self.edit.theta.mu_max ...
            = uicontrol(self.dialog, ...
                'style', 'edit', ...
                'string', 0, ...
                'callback', @(source, event) update('theta', 'mu_max', num('theta', 'mu_max')), ...
                'position', [1-(pw+ew) 1-5*(rh+ph) ew rh]);

        self.edit.theta.sigma ...
            = uicontrol(self.dialog, ...
                'style', 'edit', ...
                'string', 0, ...
                'callback', @(source, event) update('theta', 'sigma', num('theta', 'sigma')), ...
                'position', [1-(pw+ew) 1-6*(rh+ph) ew rh]);

        self.edit.theta.tau ...
            = uicontrol(self.dialog, ...
                'style', 'edit', ...
                'string', 0, ...
                'callback', @(source, event) update('theta', 'tau', num('theta', 'tau')), ...
                'position', [1-(pw+ew) 1-7*(rh+ph) ew rh]);

        self.edit.counts.mu ...
            = uicontrol(self.dialog, ...
                'style', 'edit', ...
                'string', 0, ...
                'callback', @(source, event) update('counts', 'mu', num('counts', 'mu')), ...
                'position', [1-(pw+ew) 1-9*(rh+ph) ew rh]);

        self.edit.counts.sigma ...
            = uicontrol(self.dialog, ...
                'style', 'edit', ...
                'string', 0, ...
                'callback', @(source, event) update('counts', 'sigma', num('counts', 'sigma')), ...
                'position', [1-(pw+ew) 1-10*(rh+ph) ew rh]);

        self.edit.counts.tau ...
            = uicontrol(self.dialog, ...
                'style', 'edit', ...
                'string', 0, ...
                'callback', @(source, event) update('counts', 'tau', num('counts', 'tau')), ...
                'position', [1-(pw+ew) 1-11*(rh+ph) ew rh]);

        self.okButton ...
            = uicontrol(self.dialog, ...
                'style', 'pushbutton', ...
                'string', 'Ok', ...
                'position', [pw ph 0.5-1.5*pw rh], ...
                'callback', @(varargin) resume(1));
                % 'callback', ...
                %     @(source, event) return_values(1), ...
        self.cancelButton ...
            = uicontrol(self.dialog, ...
                'style', 'pushbutton', ...
                'string', 'Cancel', ...
                'position', [0.5+0.5*pw ph 0.5-1.5*pw rh], ...
                'callback', @(varargin) resume(0));

        %methodPopupCallback(0);
        refresh();
        uiwait(self.dialog);
        if status
            status = get(self.popup.analysis, 'value');
            values.theta.mu = [values.theta.mu_min, values.theta.mu_max];
            values.theta.lambda = values.theta.sigma.^-2;
            values.counts.lambda = values.counts.sigma;
            theta = rmfield(values.theta, {'mu_min', 'mu_max', 'sigma'});
            counts = rmfield(values.counts, {'sigma'});
        else 
            theta.mu = [NaN, NaN];
            theta.lambda = NaN;
            theta.tau = NaN;
            counts.mu = NaN;
            counts.lambda = NaN;
            counts.tau = NaN;
        end
        delete(self.dialog);
    catch err
        delete(self.dialog);
        rethrow(err)
    end
end