function [brainlv, s, designlv, brainscores, designscores, lvintercorrs, ...
	design, perm_result, boot_result] = rri_taskpls_norotate(datamat_lst, ...
	design, num_subj_lst, num_cond_lst, num_boot, num_perm);

    % Init
    %
    brainlv = [];
    s = [];
    designlv = [];
    brainscores = [];
    designcores = [];
    lvintercorrs = [];
    perm_result = [];
    boot_result = [];

    stacked_datamat = [];
    stacked_data = [];
    stacked_design = [];
    stacked_designdata = [];

    num_groups = length(datamat_lst);

    progress_hdl = rri_progress_ui('initialize');

    msg = 'Working on PLS ...';
    rri_progress_ui(progress_hdl, '', msg);

    %  actually, all the groups must have the same condition number
    %
    num_cond = num_cond_lst(1);

    % loop accross the groups, and
    % calculate datamatcorrs for each group
    %
    for i = 1:num_groups

        rri_progress_ui(progress_hdl,'',2/10+5/10*(i-1)/(num_groups)+1/(10*num_groups));

        k = num_cond_lst(i);
        n = num_subj_lst(i);

        datamat = datamat_lst{i};
        data = rri_task_mean(datamat, n);

        rri_progress_ui(progress_hdl,'',2/10+5/10*(i-1)/(num_groups)+3/(10*num_groups));

	% if more than one group, stack data together
	%
        stacked_datamat = [stacked_datamat; datamat];
        stacked_data = [stacked_data; data];
%        stacked_design = [stacked_design; rri_expandvec(design, n)];
        span = [((i-1)*num_cond+1) : i*num_cond];
        stacked_designdata = [stacked_designdata; design(span,:)];

        rri_progress_ui(progress_hdl,'',2/10+5/10*(i-1)/(num_groups)+5/(10*num_groups));

    end		% for

    %  instead of SVD
    crossblock = rri_normalize(stacked_designdata)'*stacked_data;
    brainlv = crossblock';
    s = sqrt(sum(crossblock.^2, 2));
    designlv = stacked_designdata;
    normalized_brainlv = rri_normalize(brainlv);
    lvintercorrs = normalized_brainlv'*normalized_brainlv;

    rri_progress_ui(progress_hdl,'',9/10);

    brainscores = stacked_datamat * brainlv;
    designscores = [];

    num_col = size(designlv, 2);

    for i = 1:num_groups
        k = num_cond_lst(i);
        n = num_subj_lst(i);

        tmp = reshape(designlv((i-1)*k+1:(i-1)*k+k,:), ...
		[1, num_col*k]);
        tmp = repmat(tmp, [n, 1]);		% expand to num_subj
        tmp = reshape(tmp, [n*k, num_col]);

        designscores = [designscores; tmp];	% stack by groups
    end

    rri_progress_ui(progress_hdl,'',1);

    if num_perm > 0

        %  Begin permutation loop
        %
        permcount = zeros(size(s));
        reorder = rri_perm_order(num_subj_lst,num_cond_lst(1),num_perm);

        for p = 1:num_perm

            msg = ['Working on Permutation:  ',num2str(p),' out of ',num2str(num_perm)];
            rri_progress_ui(progress_hdl, '', msg);
            rri_progress_ui(progress_hdl,'',p/num_perm);

            data_p = stacked_datamat(reorder(:,p),:);

            stacked_data_p = [];

            for g=1:num_groups

                k = num_cond_lst(g);
                n = num_subj_lst(g);
                span = sum(num_subj_lst(1:g-1)) * num_cond;

                if num_groups == 1
                    data = rri_task_mean(data_p, n);
                else
                    data = rri_task_mean(data_p(1+span:n*k+span,:), n);
                end

                stacked_data_p = [stacked_data_p; data];

            end		% for num_groups

            crossblock = rri_normalize(stacked_designdata)'*stacked_data_p;
            s_perm = sqrt(sum(crossblock.^2,2));
            permcount = permcount + (s_perm >= s);;

        end		% for num_perm

        perm_result.sprob = permcount / num_perm;
        perm_result.num_perm = num_perm;
        perm_result.permsamp = reorder;
        perm_result.sp = permcount;

    end

    if num_boot > 0

        %  Begin bootstrap loop
        %
        brainlv_sq = brainlv.^2;
        brainlv_sum = brainlv;

        boot_progress = rri_progress_ui('initialize');
        [reorder, new_num_boot] = rri_boot_order(num_subj_lst, num_cond_lst(1), num_boot, 0, boot_progress);

        if isempty(reorder)
            return;
        end;

        if new_num_boot ~= num_boot
            num_boot = new_num_boot;
            h0 = findobj(0,'tag','PermutationOptionsFigure');
            h = findobj(h0,'tag','NumBootstrapEdit');
            set(h,'string',num2str(num_boot));
        end

        max_subj_per_group = 8;
        if (sum(num_subj_lst <= max_subj_per_group) == num_groups)
            is_boot_samples = 1;
        else
            is_boot_samples = 0;
        end

        if isempty(reorder)
           return;
        end

        for p=1:num_boot

            msg = ['Working on Bootstrap:  ',num2str(p),' out of ',num2str(num_boot)];
            rri_progress_ui(progress_hdl, '', msg);
            rri_progress_ui(progress_hdl,'',p/num_boot);

            data_p = stacked_datamat(reorder(:,p),:);
            stacked_data_p = [];

            for g=1:num_groups

                k = num_cond_lst(g);
                n = num_subj_lst(g);
                span = sum(num_subj_lst(1:g-1)) * num_cond;	% group length

                if num_groups == 1
                    data = rri_task_mean(data_p, n);
                else
                    data = rri_task_mean(data_p(1+span:n*k+span,:), n);
                end

                stacked_data_p = [stacked_data_p; data];

            end		% for num_groups

            crossblock = rri_normalize(stacked_designdata)'*stacked_data_p;
            brainlv_sq = brainlv_sq + (crossblock.^2)';
            brainlv_sum = brainlv_sum + crossblock';

        end		% for num_boot

        boot_result.num_boot = num_boot;
        boot_result.bootsamp = reorder;
        brainlv_sum2 = (brainlv_sum.^2) / (num_boot + 1);
        boot_result.brainlv_se=sqrt((brainlv_sq - brainlv_sum2)/num_boot);

        %  check for zero standard errors - replace with ones
        %
        test_zeros=find(boot_result.brainlv_se<=0);
        if ~isempty(test_zeros);
            boot_result.brainlv_se(test_zeros)=1;
        end

        boot_result.compare = brainlv ./ boot_result.brainlv_se;

        %  for zero standard errors - replace bootstrap ratios with zero
        %  since the ratio makes no sense anyway
        %
        if ~isempty(test_zeros);
            boot_result.compare(test_zeros)=0;
        end

    end

    return;						% rri_taskls_norotate

