%==========================================================================
% Script to display the instructions
%
% Hanneke den Ouden,
% start:        16-08-2009
% last changes  02-08-2011
%
% Jennifer Swart,
% start:        03-02-2014
% last changes  23-04-2015
%
% Jessica Määttä,
% start:        20-04-2015
% last changes  20-04-2015
%==========================================================================

% setup.
spacing     = 3; % distance between lines.
wrap        = 90; % breaks line if more than this amount of characters.

tx = 1;
while tx <= numel(img.instructions)
    switch tx
        case 0
            tx = 1;
            Screen('DrawTexture',wd,img.instructions{tx},[],[0 0 wdw wdh])
        case prep.par.pract.page
            iSes = find(tx == cell2mat(prep.par.pract.page));
            iResp = mod(sID+iSes,prep.par.pract.nStim)+1;
            iPage = prep.par.pract.page{iResp};
            Screen('DrawTexture',wd,img.instructions{iPage},[],[0 0 wdw wdh])
        otherwise
            Screen('DrawTexture',wd,img.instructions{tx},[],[0 0 wdw wdh])
    end
    
    Screen('Flip',wd);
        
    % wait for response.
    if prep.par.keymode == 1
        WaitSecs(.5)
        B.clearResponses(); 
        resp = B.getResponse(10*60,true);
        if resp == prep.par.key.left; tx = tx-1;
        else tx = tx + 1;
        end
    elseif prep.par.keymode == 2
        [~,keyCode,~] = KbWait([],3);
        if find(keyCode) == prep.par.key.left; tx = tx-1;
        else tx = tx + 1;
        end
    end
    
    switch tx-1; case prep.par.pract.page; pavPractice; end
    
end % end while-loop.

Screen('FillRect',wd,backgroundCol);
Screen('Flip', wd);
WaitSecs(1);
