function spm_SVMCrossVal


%  Initialize and hide the GUI as it is being constructed.
    frameWidth=450;
    frameHeight=600;
    frame = figure('Visible','off','Position',[0,0,frameWidth,frameHeight]);
    movegui(frame,'west'); % get this thing visible on smaller displays.
    
    set(frame,'Name','SVMCrossVal Decode Performance 4 SPM');
    set(frame,'NumberTitle','off');
    set(frame,'MenuBar','none');
    set(frame,'Color',get(0,'defaultUicontrolBackgroundColor'));
    set(frame,'Resize','off');
    set(frame,'Units','normalize');
    
    
    model.subjectMap = SubjectRoiMapping;
    nElementRows = 24;
    optionLineHeight = 1.0/nElementRows;
    controlElementHeight=optionLineHeight*(1.0/1.5)*frameHeight;
    pSubject     = uipanel(frame,'Title','Subject',          'Position',[0 optionLineHeight*22 frameWidth optionLineHeight*2]);
    pPSTH        = uipanel(frame,'Title','PSTH Options',     'Position',[0 optionLineHeight*17 frameWidth optionLineHeight*5]); 
    pCLASS       = uipanel(frame,'Title','Class Definitions','Position',[0 optionLineHeight*11 frameWidth optionLineHeight*6]); 
    pVOXEL       = uipanel(frame,'Title','Voxel Selector',   'Position',[0 optionLineHeight*3  frameWidth optionLineHeight*8]); 
    pSVM         = uipanel(frame,'Title','SVM Options',      'Position',[0 optionLineHeight*1  frameWidth optionLineHeight*2]); 
    btnRunButton = uicontrol(frame,'Tag','run','String','run decode-performance visualiser','Position',[2 optionLineHeight*0  frameWidth controlElementHeight*1.6]);


    % Subject
    firstColumn  =  5.00;
    firstRow     =  1.00 * controlElementHeight;
    
    model.subjectSelector = uicontrol(pSubject,'Style','popupmenu',...
                    'String',getSubjectCellList(model.subjectMap),...
                    'Value',5,...
                    'Position',[firstColumn firstRow 0.66*frameWidth controlElementHeight]);
    set(model.subjectSelector,'BackgroundColor','w');

    % PSTH
    firstColumn  = 5.00;
    secondColumn = 0.33*frameWidth;
    thirdColumn  = 0.66*frameWidth;
%     fourthColumn = 0.84*frameWidth;
    
    firstRow    = 5.5*controlElementHeight;
    secondRow   = 4.5*controlElementHeight;
    thirdRow    = 3.5*controlElementHeight;
    fourthRow   = 2.5*controlElementHeight;
    fifthRow    = 1.0*controlElementHeight;
    
    lStart      = createLabel(pPSTH, [secondColumn firstRow  0.33*frameWidth controlElementHeight],'Start [sec]');
    lEnd        = createLabel(pPSTH, [thirdColumn  firstRow  0.33*frameWidth controlElementHeight],'End [sec]');
    lPSTH       = createLabel(pPSTH, [firstColumn  secondRow 0.33*frameWidth controlElementHeight],'PSTH Range');
    lBaseline   = createLabel(pPSTH, [firstColumn  thirdRow  0.33*frameWidth controlElementHeight],'Baseline');
    lFrameShift = createLabel(pPSTH, [firstColumn  fourthRow 0.33*frameWidth controlElementHeight],'SVM Frame Shift');
    lFramsSize  = createLabel(pPSTH, [firstColumn  fifthRow  0.33*frameWidth controlElementHeight],'SVM Frame Size');
    
    
    model.txtBaselineStart   = createTextField(pPSTH,[secondColumn thirdRow  0.25*frameWidth controlElementHeight],'-22.0');
    model.txtBaselineEnd     = createTextField(pPSTH,[thirdColumn  thirdRow  0.25*frameWidth controlElementHeight],'-20.0');
    model.txtPSTHStart       = createTextField(pPSTH,[secondColumn secondRow 0.25*frameWidth controlElementHeight],'-25.0');
    model.txtPSTHEnd         = createTextField(pPSTH,[thirdColumn  secondRow 0.25*frameWidth controlElementHeight],' 20.0');
    model.txtFrameShiftStart = createTextField(pPSTH,[secondColumn fourthRow 0.25*frameWidth controlElementHeight],'-20.0');
    model.txtFrameShiftEnd   = createTextField(pPSTH,[thirdColumn  fourthRow 0.25*frameWidth controlElementHeight],' 15.0');
    model.txtFrameShiftDur   = createTextField(pPSTH,[secondColumn fifthRow  0.25*frameWidth controlElementHeight],' 0');

                
    %Classes
    nClassRows = 6;
    firstColumn  = 5.00;
    
    firstRow    = (nClassRows-0.5)*controlElementHeight;
    secondRow   = (nClassRows-4.5)*controlElementHeight;

    lClassDef = createLabel(pCLASS, [firstColumn firstRow  0.66*frameWidth controlElementHeight],'<Label>,<[Event,Event,..]>,<SVM-Value>;');
    model.txtClassDef = createTextField(pCLASS,[firstColumn secondRow 0.98*frameWidth 4*controlElementHeight],sprintf('<,\t[ 9,11,13],\t-2 ;\n>,\t[10,12,14],\t-1;'));
    set(model.txtClassDef,'HorizontalAlignment','left');
    set(model.txtClassDef,'Max',20);
    set(model.txtClassDef,'Min',0);
    set(model.txtClassDef, 'FontName', 'FixedWidth')
    
    %Voxel
    nVoxelRows = 8;
    firstColumn  = 5.00;
    
    firstRow    = (nVoxelRows-0.5)*controlElementHeight;
    secondRow   = (nVoxelRows-7.5)*controlElementHeight;

    lVoxelDef = createLabel(pVOXEL, [firstColumn firstRow  0.66*frameWidth controlElementHeight],'<ROI Name>,<ROI Modifier>;');
    model.txtVoxelDef = createTextField(pVOXEL,[firstColumn secondRow 0.98*frameWidth 6*controlElementHeight],...
        sprintf('M1 l,\t[ 0, 0, 0];\nM1 l,\t[ 1, 0, 0];\nM1 l,\t[ 0, 1, 0];\nM1 l,\t[ 0, 0, 1];\n'));
    set(model.txtVoxelDef,'HorizontalAlignment','left');
    set(model.txtVoxelDef,'Max',20);
    set(model.txtVoxelDef,'Min',0);
    set(model.txtVoxelDef, 'FontName', 'FixedWidth')
                
    % SVM
    firstColumn  =  5.00;
    firstRow     =  1.00 * controlElementHeight;

    model.txtSVMopts = createTextField(pSVM,[firstColumn firstRow  0.66*frameWidth controlElementHeight],'-t 0 -s 0 -v 6');
    set(model.txtSVMopts,'Enable','inactive');
    set(model.txtSVMopts,'HorizontalAlignment','left');

    set(btnRunButton,'Callback',{@cbRunSVM,model}); % set here, because of model.    
    set(frame,'Visible','on');
end
    
function label = createLabel(parent,  pos, labelText)
    label = uicontrol(parent,'Style','text','String',labelText,'Position',pos);
    set(label,'HorizontalAlignment','left');
    set(label,'Units','characters');
%     set(label,'BackgroundColor','r');
end

function btn = createButton(parent,pos,tag,labelText,cbArgs)
    btn = uicontrol(parent,'Position',pos,'String',labelText,'tag',tag);
     set(btn,'Callback',{@cbParseVariable,cbArgs});
%     set(btn,'BackgroundColor','b');
end

function txt = createTextField(parent,pos,model)
    txt = uicontrol(parent,'Style','edit','String',model,'Position',pos);
    set(txt,'BackgroundColor','w');
end

function drpField = createDropDown(parent,pos,selectionModel)
 drpField = uicontrol(parent,'Style','popupmenu','Position',pos);
  set(drpField,'String',selectionModel.Strings);
  set(drpField,'BackgroundColor','w');
end

function sane = isSane(model)
    sane = 1;
end


function cbRunSVM(src,evnt,model)

    display('RUN');

    % TODO test parameter values
    
    if isSane(model)
        set(0,'userdata',model);
%         set(src,'Enable','off');
        assignin('base','guiParams',model);
        classify(model)
%         set(src,'Enable','on');
    else
        %todo error beep!
        error('spmtoolbox:SVMCrossVal:paramcheck','please verify all parameters');
    end
                                        
end