function prettyup(varargin)
% PRETTYUP  Makes the current figure look nice for slides or papers
%           by changing BackColor, FontColor, FontSize, FontWeight, 
%           FontName, FontAngle and/or LineWidth. 
%
%  Usage:   prettyup(figuretype,'Parameter','choice',...);
%   
%  Inputs:  figuretype = Powerpoint or Paper
%           BackColor = background color (default is [.8 .8 .8]) 
%           FontColor = font and axis color (default is 'y')
%           FontSize  = font size (20 is default)
%           FontWeight= font weight (default is 'normal')
%           FontName = font name (default is 'times')
%           FontAngle = font angle (default is 'normal')
%           LineWidth = line width for axes (default is 2)
%       
%           (with no arguments, figuretype='Paper')
%
% Dave Chapman  (based on code from Rich Signell)

if (nargin < 1)
  figtype = 'paper';
else
  figtype = lower(varargin{1});
end

switch (figtype)
  case 'powerpoint'
    % set defaults (for powerpoint slides)
    font_size=20;
    bg_color=[.8 .8 .8];
    font_weight='normal';
    font_name='times';
    font_angle='normal';
    line_width=2;
    font_color='y';
  case 'paper'
    font_size=16;
    bg_color=[.8 .8 .8];
    font_weight='normal';
    font_name='times';
    font_angle='normal';
    line_width=1;
    font_color='k';
  otherwise
    error(['Unrecognized figure type ' figtype '.'])
end

if (nargin > 1)

paramPairs = varargin(2:end);

% Do some validity checking on param-value pairs
if (rem(length(paramPairs),2) ~= 0)
  error(['Invalid input syntax. Optional parameters and values' ...
                 ' must be in pairs.']);
end

% Process param-value pairs
for k = 1:2:length(paramPairs)
  param = lower(paramPairs{k});
  value = paramPairs{k+1};

  switch (param)
   case 'backcolor'
        bg_color = lower(value);
        if strcmp(bg_color,'none')
          bg_color = [.8 .8 .8];
        end
   case 'linewidth'
        line_width = value;
   case 'fontsize'
        font_size = value;
   case 'fontcolor'
        font_color = lower(value);
   case 'fontweight'
        font_weight = lower(value);
   case 'fontname'
        font_name = lower(value);
   case 'fontangle'
        font_angle = lower(value);
   otherwise
        error(['Unrecognized option ' param '.']);
  end
end
end


ha=get(gcf,'children');
for ax=1:length(ha);
axes(ha(ax));
set(gca,'LineWidth',line_width)
set(gca,'FontWeight',font_weight)
set(gca,'fontsize',font_size)
set(gca,'fontname',font_name)
set(gca,'fontangle',font_angle)

h=get(gca,'title');  % h is the handle to the title
set(h,'fontsize',font_size)
set(h,'FontWeight',font_weight)
set(h,'color',font_color)
set(h,'fontname',font_name)
set(h,'fontangle',font_angle)

h=get(gca,'xlabel');  % h is the handle to the xlabel
set(h,'fontsize',font_size)
set(h,'FontWeight',font_weight)
set(h,'fontname',font_name)
set(h,'fontangle',font_angle)

h=get(gca,'ylabel');  % h is the handle to the ylabel
set(h,'fontsize',font_size)
set(h,'FontWeight',font_weight)
set(h,'fontname',font_name)
set(h,'fontangle',font_angle)

h=get(gca,'zlabel');  % h is the handle to the zlabel
set(h,'fontsize',font_size)
set(h,'FontWeight',font_weight)
set(h,'fontname',font_name)
set(h,'fontangle',font_angle)

% Axis and Axis labels 
 set(gca,'Ycolor',font_color)
 set(gca,'Xcolor',font_color)
 set(gca,'Zcolor',font_color)

%h = get(gca,'Children');
%  for i = 1:length(h)
%  ht = get(h(i),'type');
%  if strcmp(ht,'text')
%   set(h(i),'FontWeight',font_weight)
%   set(h(i),'fontsize',font_size)
%   set(h(i),'color',font_color)
%  end
%  if strcmp(ht,'line')
%   lw = get(h(i),'LineWidth');
%   set(h(i),'LineWidth',line_width)
%  end
%end
end

set(gcf,'color',bg_color)
