% Antonio Gomez (agomez@tacc.utexas.edu)
% 4-20-17. Added option to put the footer on the right side



\mode<presentation>

\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{etoolbox}



% This theme accepts the "rightfooter" option
% When used, it will put the TACC logo at the bottom of the slide on the right side
% By default, it goes to the left

\xifaspectratio{
  {169} {
  \pgfdeclareimage[width=\paperwidth]{titlebackground}{./figures/master169.jpg}
  \if@rightfooterOption
	\pgfdeclareimage[width=\paperwidth]{background}{./figures/secondary_right169.jpg}
\else
	\pgfdeclareimage[width=\paperwidth]{background}{./figures/secondary169.jpg}
\fi
} 
}[
\pgfdeclareimage[width=\paperwidth]{titlebackground}{./figures/master.jpg}
 \if@rightfooterOption
	\pgfdeclareimage[width=\paperwidth]{background}{./figures/secondary_right.jpg}
\else
	\pgfdeclareimage[width=\paperwidth]{background}{./figures/secondary.jpg}
\fi
]

\setbeamertemplate{background canvas}{%
\xifaspectratio{
  	{169} {
  	 	\ifnum\c@framenumber=1 %
  			\begin{picture}(0,0)
            	\put(-3,-256){%
                \pgfuseimage{titlebackground}
                }
            \end{picture}
         \else%
         	\begin{picture}(0,0)
 				\put(-3,-260){%
                \pgfuseimage{background}
            }
           \end{picture}
         \fi
  	}
  	{43} {
  		\ifnum\c@framenumber=1 %
  			\begin{picture}(0,0)
            	\put(-4,-274){%
                \pgfuseimage{titlebackground}
                }
            \end{picture}
         \else%
         	 \begin{picture}(0,0)
 				\put(-4,-274){%
                \pgfuseimage{background}
            }
           \end{picture}
         \fi
  	}
}
}
  			


%\setbeamertemplate{background canvas}{%
%	% On title page
%    \ifnum\c@framenumber=1 %
%  			\begin{picture}(0,0)
%            	\put(0,-253){%
%                \pgfuseimage{titlebackground}
%                }
%            \end{picture}
%
%    \else%
%    	\xifaspectratio{
%  			{169} {
%            % Other frames background
%            \begin{picture}(0,0)
% 				\put(-4,-260){%
%                \pgfuseimage{background}
%            }
%           \end{picture}
%           }
%           }[
%            % Other frames background
%            \begin{picture}(0,0)
% 				\put(-4,-274){%
%                \pgfuseimage{background}
%            }
%           \end{picture}
%           ]
%    \fi%
%}


\setbeamertemplate{title page}{
\vspace{40pt}
\begin{center}
\usebeamerfont{title} {\huge \inserttitle}\par
\vspace{4ex}
\usebeamerfont{author} {
    \insertauthor 
}\par
\vspace{2ex}
\usebeamerfont{institute}{
    \insertinstitute
} \par
\vspace{2ex}
\usebeamerfont{date}{
    \insertdate
}
\end{center}
}


\setbeamertemplate{frametitle}[default][center]
\setbeamertemplate{frametitle}{
  \makeatletter
  \regexpatchcmd{\insertframetitle}
    {(\c{usebeamertemplate}.*)\c{fi}}
    {\c{NoCaseChange}\cB\{\1\cE\}\c{fi}}
    {}{}%
  \makeatother
  \vskip1ex
  \insertframetitle
}

% Here we define what appears at the bottom of each slide: the "footline".
\setbeamertemplate{footline}{%
  \leavevmode%

  % Horizontal line dividing the rest of the slide from the footer?
  % hrule goes all the way across...
  % \hrule height.3pt%
  % With \rule, you can specify the thickness
  % \rule[raise-height]{width}{thickness}
 % \hspace{.025\textwidth}\rule{.95\textwidth}{.5pt}

  \hbox{%
  \ifnum \thepage>1
    \if@rightfooterOption
    	\begin{minipage}{.2\textwidth}%
      		\hskip .05\textwidth%Give horizontal space else this will set on the left edge of the slide!
    	\end{minipage}
    \else
    	\begin{minipage}{.4\textwidth}%
      		\hskip .05\textwidth%Give horizontal space else this will set on the left edge of the slide!
    	\end{minipage}
    \fi
    
 
    \begin{minipage}{\textwidth}%
     % \vskip .023\textheight%
      \raggedleft%
      \setlength{\rightskip}{\textwidth}
		\if@rightfooterOption
      		\hbox{%
      			\begin{beamercolorbox}[wd=0.7\textwidth,ht=2.25ex,dp=1ex,left]{author in head/foot}%
	         		\insertshorttitle{} \hskip .01\textwidth | \hskip .01\textwidth \insertdate{} \hskip .01\textwidth  | \hskip .01\textwidth  \insertframenumber{}
  				\end{beamercolorbox}%
			}
		\else
			\hbox{%
      			\begin{beamercolorbox}[wd=0.5\textwidth,ht=2.25ex,dp=1ex,left]{author in head/foot}%
	         		\insertshorttitle{} \hskip .01\textwidth | \hskip .01\textwidth \insertdate{} \hskip .01\textwidth  | \hskip .01\textwidth  \insertframenumber{}
  				\end{beamercolorbox}%
			}
		\fi
		
    \end{minipage}%
    \begin{minipage}{.05\textwidth}%
    \end{minipage}%
    \fi %\thepage>1
  }%
  \vskip .023\textheight%
   
}




\ifTACCheadernav

\usesectionheadtemplate
{\hfill\insertsectionhead}
{\hfill\color{fg!50!bg}\insertsectionhead}

% Head
\ifbeamer@compress

% Here we define how the top of the frame looks, the "headline".
\setbeamertemplate{headline}
{%
  \ifnum \thepage>1
    \leavevmode%
    \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex]{%
        section in head/foot}%
      \insertsectionnavigationhorizontal{.5\paperwidth}{\hskip0pt plus1filll}{}%
    \end{beamercolorbox}%
    \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex]{%
        subsection in head/foot}%
      \insertsubsectionnavigationhorizontal{%
        .5\paperwidth}{}{\hskip0pt plus1filll}%
    \end{beamercolorbox}%
  \fi %\thepage>1
}

\else% Not compressed

\setbeamertemplate{headline}
{%
  \ifnum \thepage>1
    \leavevmode%
    \@tempdimb=2.4375ex%
    \ifnum\beamer@subsectionmax<\beamer@sectionmax%
      \multiply\@tempdimb by\beamer@sectionmax%
    \else%
      \multiply\@tempdimb by\beamer@subsectionmax%
    \fi%
    \ifdim\@tempdimb>0pt%
      \advance\@tempdimb by 1.125ex%
      \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb]{%
          section in head/foot}%
        \vbox to\@tempdimb{\vfil\insertsectionnavigation{.5\paperwidth}\vfil}%
      \end{beamercolorbox}%
      \begin{beamercolorbox}[wd=.5\paperwidth,ht=\@tempdimb]{%
          subsection in head/foot}%
        \vbox to\@tempdimb{\vfil\insertsubsectionnavigation{.5\paperwidth}\vfil}%
      \end{beamercolorbox}%
    \fi%
  \fi % \thepage>1
}

\fi % end if compressed
\fi % TACCheadernav


\ifTACCheadertree

\setbeamertemplate{headline}
{
 \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt]{upper separation line head}
 \end{beamercolorbox}
 %
 % Place short title
 %
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
    leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}
    \usebeamerfont{title in head/foot}\insertshorttitle
  \end{beamercolorbox}

 %
 % Place section
 %
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
    leftskip=.3cm,rightskip=.3cm plus1fil]{section in head/foot}
   \usebeamerfont{section in head/foot}%
   %\ifbeamer@tree@showhooks
   \setbox\beamer@tempbox=\hbox{\insertsectionhead}%
   \ifdim\wd\beamer@tempbox>1pt%
   \hskip2pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
   \hskip1pt%
   \fi
   \insertsectionhead
  \end{beamercolorbox}

%
% Place subsection
%
\begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,%
  leftskip=.3cm,rightskip=.3cm plus1fil]{subsection in head/foot}
  \usebeamerfont{subsection in head/foot}%
  %\ifbeamer@tree@showhooks
  \setbox\beamer@tempbox=\hbox{\insertsubsectionhead}%
  \ifdim\wd\beamer@tempbox>1pt%
  \hskip9.4pt\raise1.9pt\hbox{\vrule width0.4pt height1.875ex\vrule width 5pt height0.4pt}%
  \hskip1pt%
  \fi
  \insertsubsectionhead
\end{beamercolorbox}

%
% Place final separation box
%
 \begin{beamercolorbox}[wd=\paperwidth,colsep=1.5pt
   ]{lower separation line head}
 \end{beamercolorbox}

 %
 % Another matching rule which helps to frame the content
 %
 \hspace{.025\textwidth}\rule{.95\textwidth}{.5pt}
}
\fi % TACCheadertree


% The following command suppresses all navigation symbols.  This is
% necessary in the TACC theme, since it overlaps where we want the
% logo to be.
\setbeamertemplate{navigation symbols}{}


\mode
<all>
