function [sd,out1,out2]=nnslides(route,sd,in1,in2,in3);
%NNSLIDES Helper function called by the NNET slideshow demos.
%	
%	*WARNING*: This function is undocumented as it may be altered
%	at any time in the future without warning.

% Matthew J. Simoneau, December 1997
% Copyright 1992-2000 The MathWorks, Inc.
% $Revision: 1.6 $

switch route
   
case 'start'
   if ~isfield(sd,'FrameOneDone')
      try,set(gcf,'DoubleBuffer','on'),catch, end;
      sd.name=in1;
      sd.fig=gcf;
      set(gcf,'DefaultAxesPosition',get(gca,'Position'));
      sd.buts=findobj(gcf,'style','pushbutton');
      set(sd.fig,'Name',in1);
      sd.textbox=uicontrol('Style','text', ...
         'units','normalized','position',get(gca,'Position'),...
         'string','','backgroundcolor',[0.8 0.8 0.8]);
      sd.FrameOneDone=[];
   end
   set(sd.textbox,'string',in1,'fontsize',20,'HorizontalAlignment','center');
   sd=nnslides('text',sd);
   
case 'text'
   if nargin==3
      set(sd.textbox,'fontsize',10,'string',in1,'HorizontalAlignment','left');
   end;
   set(sd.textbox,'visible','on');
   axs=findobj(sd.fig,'type','axes');
   set(axs,'visible','off');
   axkids=get(axs,'children');
   if iscell(axkids) axkids=cell2mat(axkids); end;
   set(axkids,'visible','off'); 
                                  
case 'wipeaxes'
   axs=findobj(sd.fig,'type','axes');
   axkids=get(axs,'children');
   if iscell(axkids) axkids=cell2mat(axkids); end;
   delete(axkids);
   
case 'axes'
   set(sd.textbox,'visible','off');
   axs=findobj(sd.fig,'type','axes');
   set(axs,'visible','on');
   axkids=get(axs,'children');
   if iscell(axkids) axkids=cell2mat(axkids); end;
   set(axkids,'visible','on');   
   
case 'blank'
   set(sd.textbox,'visible','off');
   axs=findobj(sd.fig,'type','axes');
   set(axs,'visible','off');
   axkids=get(axs,'children');
   if iscell(axkids) axkids=cell2mat(axkids); end;
   set(axkids,'visible','off'); 
   
case 'lock'
   set(sd.buts,'enable','off');
   
case 'unlock'
   set(sd.buts,'enable','on'); 
   
case 'trainlin'
   net=in1;P=in2;T=in3;
   limiting=net.trainParam.epochs;
   limloop=limiting+1;
   net.trainParam.epochs=1;              
   net.trainParam.show=Inf;
   h=plotep(net.IW{1},net.b{1},mse(T-sim(net,P)));     
   [net,tr]=train(net,P,T);                                                    
   r=tr;
   epoch=1; cont=1;
   while (length(r.epoch)<limloop & cont)
      epoch=epoch+1;
      [net,tr]=train(net,P,T);
      if length(tr.epoch)>1
         h=plotep(net.IW{1,1},net.b{1},tr.perf(2),h);
         r.epoch=[r.epoch epoch]; 
         r.perf=[r.perf tr.perf(2)];
         r.vperf=[r.vperf NaN];
         r.tperf=[r.tperf NaN];
      else
         cont=0;
      end;
   end;
   net.trainParam.epochs=limiting;
   out1=net; out2=r;
   
otherwise
   error('method not found in nnslides');
end;
