% \ProvidesPackage{}

\mode<presentation>

\DeclareOptionBeamer{logo}[true]{\def\beamer@cosec@activate@logo{#1}}
\ExecuteOptionsBeamer{logo=false}
\ProcessOptionsBeamer

%%% \define@key{beamerthemecosec}{logo}[true]{\csname bmb@coseclogo#1\endcsname}
\newif\ifbmb@coseclogo
\csname bmb@coseclogo\beamer@cosec@activate@logo\endcsname

\RequirePackage{bit-logos-plain}
\RequirePackage{beamerbaseboxes}

%%% COLORS CORRESPONDING TO THE CORPORATE DESIGN OF THE UNIVERSITY OF BONN
\definecolor{unigelb}{rgb}{1,.76,.05}%
% \definecolor{uniblau}{rgb}{0,.27,.57}%
\definecolor{uniblau}{rgb}{0,.38,.68}% CoSec blue
\definecolor{unigrau}{rgb}{.54,.54,.5}%

\definecolor{unigelbdarker}{cmyk}{0,.5,1,0}%
%\definecolor{unigelbdarker}{rgb}{1,.76,.05}%
\definecolor{uniblaudarker}{cmyk}{1,.65,0,0}%


\setbeamercolor{frametitle}{bg=uniblau!90!black}
\setbeamercolor{frametitle right}{bg=uniblau!20}

\setbeamercolor*{structure}{bg=white, fg=uniblau}

\setbeamercolor*{palette primary}{use=structure,fg=white,bg=structure.fg!100!white} 
\setbeamercolor*{palette secondary}{use=structure,fg=white,bg=structure.fg!75} 
\setbeamercolor*{palette tertiary}{use=structure,fg=white,bg=structure.fg!75} 
\setbeamercolor*{palette quaternary}{use=structure,fg=white,bg=structure.fg!50}

\setbeamercolor*{palette sidebar primary}{fg=white} 
\setbeamercolor*{palette sidebar secondary}{fg=white} 
\setbeamercolor*{palette sidebar tertiary}{fg=white} 
\setbeamercolor*{palette sidebar quaternary}{fg=white}

\setbeamercolor*{titlelike}{parent=palette primary}

\setbeamercolor*{block title}{fg=uniblau,bg=white}
\setbeamercolor*{block title alerted}{use=unigelbdarker text,bg=white,fg=unigelbdarker text.fg!75!bg} 
\setbeamercolor*{block title example}{use=example text,bg=white,fg=example text.fg!75!bg}
\setbeamercolor*{block body}{parent=normal text,use=block title,bg=block title.bg!30!bg} 
\setbeamercolor*{block body alerted}{parent=normal text,use=block title unigelb,bg=block title unigelb!25!bg} 
\setbeamercolor*{block body example}{parent=normal text,use=block title example,bg=block title example.bg!25!bg}


\setbeamercolor*{separation line}{} 
\setbeamercolor*{fine separation line}{}

\setbeamercolor*{alerted text}{fg=unigelbdarker}
\setbeamercolor*{example text}{fg=unigelbdarker}


\setbeamertemplate{title page}[default][colsep=-4bp,rounded=true,shadow=true]
\setbeamertemplate{part page}[default][colsep=-4bp,rounded=true,shadow=true]
\setbeamertemplate{blocks}[default]

%\setbeamertemplate{items}[ball]
%\setbeamertemplate{sections/subsections in toc}[ball]

\usefonttheme{professionalfonts}
%\useinnertheme{circles}

%\usecolortheme{seahorse}
%\logo{\coseclogoW{2cm}}

\setbeamercovered{transparent}
%\beamertemplatetransparentcovereddynamic

\newcommand{\ignore}[1]{}

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{headline}{}{}
\setbeamertemplate{footline}{}{}

\pgfdeclarehorizontalshading[frametitle.bg,frametitle right.bg]{beamer@frametitleshade}{\paperheight}{%
  color(0pt)=(frametitle.bg);
  color(\paperwidth)=(frametitle right.bg)}

\pgfdeclareverticalshading[lower.bg,upper.bg]{bmb@transition}{200cm}{%
  color(0pt)=(lower.bg); color(2pt)=(lower.bg); color(4pt)=(lower.bg)}

\AtBeginDocument{
  \pgfdeclareverticalshading{beamer@topshade}{\paperwidth}{%
    color(0pt)=(bg);
    color(4pt)=(black!50!bg)}
}

\newdimen\cosecbeamer@logowidth
\newdimen\beamer@tempdimx

\cosecbeamer@logowidth=15mm

\newbox\cosecbeamer@logo
\newbox\cosecbeamer@frametitle

\defbeamertemplate*{frametitle}{cosec theme}
{%
  \nointerlineskip%
  \vskip-2pt%
  \hbox{\leavevmode
    \advance\beamer@leftmargin by -12bp%
    \advance\beamer@rightmargin by -12bp%
    \beamer@tempdim=\textwidth%
    \advance\beamer@tempdim by \beamer@leftmargin%
    \advance\beamer@tempdim by \beamer@rightmargin%
    \beamer@tempdimx=\paperwidth
    %% Construct the logo (or don't).
%    \ifbmb@coseclogo
%    \setbox\cosecbeamer@logo\hbox{%
%      \coseclogoW{\cosecbeamer@logowidth}%
%    }%
%    %% Calculate remaining width
%    \advance\beamer@tempdimx-0.6cm% \leftskip & \rightskip used below!
%    \advance\beamer@tempdimx-\wd\cosecbeamer@logo
%    \else
    \setbox\cosecbeamer@logo\hbox{}%
%    \fi
    \hskip-\Gm@lmargin\hbox{%
      \ifx\insertframesubtitle\@empty%
      \setbox\cosecbeamer@frametitle\hbox{\insertframetitle\strut}%
      \else
      \setbox\cosecbeamer@frametitle\hbox{\insertframetitle}%
      \fi
      \@tempdima\ht\cosecbeamer@logo% logo itself
      \advance\@tempdima\dp\cosecbeamer@logo% logo itself
      \setbox\@tempboxa\hbox{\strut}\advance\@tempdima\dp\@tempboxa%
      %%% \showthe\@tempdima
      \setbox\beamer@tempbox=\hbox{%
        \begin{minipage}[b]{\beamer@tempdimx}%
          \vbox{}\vskip-.75ex%
          \leftskip0.3cm%
          \rightskip0.3cm plus1fil%
          \leavevmode
          \hbox to 0pt{%
            \hskip-\leftskip
            \hskip\beamer@tempdimx%
            \vbox to 0pt{%
              \vskip-\ht\cosecbeamer@frametitle
              \box\cosecbeamer@logo
              \vss}%
            \hss}%
          \insertframetitle%
          \ifx\insertframesubtitle\@empty%
            \strut\par%
          \else
            \par{\usebeamerfont*{framesubtitle}{%
                \usebeamercolor[fg]{framesubtitle}%
                \insertframesubtitle}\strut\par}%
          \fi%
          \nointerlineskip
          \vbox{}%
        \end{minipage}%
      }%
      %%% \showthe\ht\beamer@tempbox
      %%% \showthe\@tempdima
      \ifdim\ht\beamer@tempbox<\@tempdima
      \setbox\beamer@tempbox\vbox to\@tempdima{\box\beamer@tempbox\vfil}%
      \fi
      \beamer@tempdim=\ht\beamer@tempbox%
      \advance\beamer@tempdim by 2pt%
      \begin{pgfpicture}{0pt}{0pt}{\paperwidth}{\beamer@tempdim}
        \usebeamercolor{frametitle right}
        \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{\paperwidth}{\beamer@tempdim}}
        \pgfusepath{clip}
        \pgftext[left,base]{\pgfuseshading{beamer@frametitleshade}}
      \end{pgfpicture}
      \hskip-\paperwidth%
      %%% \tracingall\showboxdepth7\nonstopmode
      %%% \showbox\beamer@tempbox
       \box\beamer@tempbox%
     }%
    \hskip-\Gm@rmargin%
  }%
  \nointerlineskip
    \vskip-0.2pt
    \hbox to\textwidth{\hskip-\Gm@lmargin\pgfuseshading{beamer@topshade}\hskip-\Gm@rmargin}
    \vskip-2pt
}

\defbeamertemplate*{footline}{cosec theme}
{%
  \leavevmode%
  \hbox{%
    \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1.125ex,leftskip=.3cm
      plus1fill,rightskip=.3cm]{white}
      \ifnum\c@framenumber<2\else
      \@tempcnta\inserttotalframenumber
      %%% \advance\@tempcnta\@ne% This would have last page # = 0.
      \advance\@tempcnta-\c@framenumber
      \@arabic\@tempcnta
      %\insertframenumber
      /\inserttotalframenumber
      \fi
    \end{beamercolorbox}}
  \vskip0pt%
}


\mode
<all>
