%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Copyright 2011 by Fiandrino Claudio
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\mode<presentation>

% Logo to use in the title page
\def\beamer@torinoth@titlepagelogo{}
\DeclareOptionBeamer{titlepagelogo}{\def\beamer@torinoth@titlepagelogo{#1}}

% Second optional logo to use in the title page
\DeclareOptionBeamer{secondlogo}[true]{\def\beamer@torinoth@secondlogo{#1}}
\ExecuteOptionsBeamer{secondlogo=false}

% Third optional logo to use in the title page
\DeclareOptionBeamer{thirdlogo}[true]{\def\beamer@torinoth@thirdlogo{#1}}
\ExecuteOptionsBeamer{thirdlogo=false}

% Language
\DeclareOptionBeamer{language}[italian]{\def\beamer@torinoth@language{#1}}
\ExecuteOptionsBeamer{language=english}

% Second candidate
\DeclareOptionBeamer{secondcandidate}[true]{\def\beamer@torinoth@secondcandidate{#1}}
\ExecuteOptionsBeamer{secondcandidate=false}

% Second supervisor
\DeclareOptionBeamer{secondsupervisor}[true]{\def\beamer@torinoth@secondsupervisor{#1}}
\ExecuteOptionsBeamer{secondsupervisor=false}

% Assistant supervisor
\DeclareOptionBeamer{assistantsupervisor}[true]{\def\beamer@torinoth@assistantsupervisor{#1}}
\ExecuteOptionsBeamer{assistantsupervisor=false}

% Second assistant supervisor
\DeclareOptionBeamer{secondassistantsupervisor}[true]{\def\beamer@torinoth@secondassistantsupervisor{#1}}
\ExecuteOptionsBeamer{secondassistantsupervisor=false}

% Bullet shape
\DeclareOptionBeamer{bullet}{\def\beamer@torinoth@bullet{#1}}
\ExecuteOptionsBeamer{bullet=circle}

\ProcessOptionsBeamer

% Definition of second logo if request
\def\beamer@torinoth@secondlogotext{true}%
\ifx\beamer@torinoth@secondlogo\beamer@torinoth@secondlogotext%
  \def\titlepagesecondlogo#1{\gdef\@titlepagesecondlogo{#1}}%

  % Definition of third logo if request
    \def\beamer@torinoth@thirdlogotext{true}%
    \ifx\beamer@torinoth@thirdlogo\beamer@torinoth@thirdlogotext%
        \def\titlepagethirdlogo#1{\gdef\@titlepagethirdlogo{#1}}%
    \fi%

\fi%

% Ateneo
\providecommand{\ateneo}{\institute}%
\providecommand{\insertateneo}{\insertinstitute}%

% Supervisor
\def\rel#1{\gdef\@rel{#1}}

% Second supervisor
  \def\beamer@torinoth@secondsuptext{true}%
  \ifx\beamer@torinoth@secondsupervisor\beamer@torinoth@secondsuptext%
     \def\secondsupervisor#1{\gdef\@secondsupervisor{#1}}%
  \fi

% Second candidate
\def\beamer@torinoth@secondcandtext{true}%
\ifx\beamer@torinoth@secondcandidate\beamer@torinoth@secondcandtext%
   \def\secondcandidate#1{\gdef\@secondcandidate{#1}}%
\fi

% Assistant supervisor
\def\beamer@torinoth@assistantsupervisortext{true}%
\ifx\beamer@torinoth@assistantsupervisortext\beamer@torinoth@assistantsupervisor%
   \def\assistantsupervisor#1{\gdef\@assistantsupervisor{#1}}%
   % Second assistant supervisor
   \def\beamer@torinoth@secondassistantsuptext{true}%
   \ifx\beamer@torinoth@secondassistantsupervisor\beamer@torinoth@secondassistantsuptext%
      \def\secondassistantsupervisor#1{\gdef\@secondassistantsupervisor{#1}}%
   \fi
\fi

% Margins
\newlength{\beamer@torinoth@normalmargin}
\setlength{\beamer@torinoth@normalmargin}{.065\paperwidth}
\setbeamersize{text margin left=\beamer@torinoth@normalmargin}
\setbeamersize{text margin right=\beamer@torinoth@normalmargin}
\setlength\leftmargini{.6\beamer@torinoth@normalmargin}
\setlength\leftmarginii{.6\beamer@torinoth@normalmargin}
\setlength\leftmarginiii{.6\beamer@torinoth@normalmargin}

% Thesis title page
\defbeamertemplate*{title page}{torinoth}[1][]
{

   % Logo & Ateneo
   \begin{centering}
     \begin{beamercolorbox}[rounded=true,shadow=true,ht=2.5ex,wd=.9\paperwidth,sep=3pt,center,#1]{ateneo page header}%
       \usebeamerfont{ateneo}\insertateneo\par%
     \end{beamercolorbox}
     \vskip0.5em%
     % Check-second-logo
     \def\beamer@torinoth@secondlogotext{true}%
     \ifx\beamer@torinoth@secondlogo\beamer@torinoth@secondlogotext%
        % Check-third-logo
        \def\beamer@torinoth@thirdlogotext{true}%
        \ifx\beamer@torinoth@thirdlogo\beamer@torinoth@thirdlogotext%
            \hbox{
            % First-column
            \begin{beamercolorbox}[wd=0.3\paperwidth,center]{}
            \includegraphics[height=.2\paperheight]{\@titlepagesecondlogo}%
            \end{beamercolorbox}
            % Second-column
            \begin{beamercolorbox}[wd=0.25\paperwidth,center]{}
            \includegraphics[height=.2\paperheight]{\beamer@torinoth@titlepagelogo}%
            \end{beamercolorbox}
            % Third-column
            \begin{beamercolorbox}[wd=0.275\paperwidth,center]{}
            \includegraphics[height=.2\paperheight]{\@titlepagethirdlogo}%
            \end{beamercolorbox}

            }
        \else%
        \hbox{
            % First-column
            \begin{beamercolorbox}[wd=0.475\paperwidth,center]{}
            \includegraphics[height=.2\paperheight]{\beamer@torinoth@titlepagelogo}%
            \end{beamercolorbox}
            % Second-column
            \begin{beamercolorbox}[wd=0.325\paperwidth,center]{}
            \includegraphics[height=.2\paperheight]{\@titlepagesecondlogo}%
            \end{beamercolorbox}}
        \fi%
     \else%
        \includegraphics[height=.2\paperheight]{\beamer@torinoth@titlepagelogo}%
     \fi%
     \vfill%
   \end{centering}
  \vskip0.25em%
  % Title
  \begin{centering}
     \begin{beamercolorbox}[wd=\paperwidth,sep=8pt,center,#1]{title page header}
       \usebeamerfont{title}\inserttitle\par% 
     \end{beamercolorbox}%
  \end{centering}

  \vskip0.75em\par%  

  % definitions
  \def\beamer@torinoth@italiantext{italian}%
  \begin{columns}
%%%%%%%%%%%%%%%%%%%
    % First column
    \column{.5\paperwidth}%
    % Definition of labels
	    % Supervisor-number-check
	    \ifx\beamer@torinoth@secondsupervisor\beamer@torinoth@secondsuptext%
	            % Supervisor-language-check
		    \ifx\beamer@torinoth@language\beamer@torinoth@italiantext%
			    \def\beamer@torinoth@superv{Relatori}%
		    \else%
			    \def\beamer@torinoth@superv{Supervisors}%
		    \fi%
	    \else%
                    % Supervisor-language-check
		    \ifx\beamer@torinoth@language\beamer@torinoth@italiantext%
			    \def\beamer@torinoth@superv{Relatore}%
		    \else%
			    \def\beamer@torinoth@superv{Supervisor}%
		    \fi%
	    \fi%
            % Assistant Supervisor-number-check
           \ifx\beamer@torinoth@secondassistantsupervisor\beamer@torinoth@secondassistantsuptext%
		    % Assistant-supervisor-language-check
		    \ifx\beamer@torinoth@language\beamer@torinoth@italiantext%
			    \def\beamer@torinoth@assistantsupervisorlabel{Correlatori}%
		    \else%
			    \def\beamer@torinoth@assistantsupervisorlabel{Assistant Supervisors}%
		    \fi%
	    \else%
		    % Assistant-supervisor-language-check
		    \ifx\beamer@torinoth@language\beamer@torinoth@italiantext%
			    \def\beamer@torinoth@assistantsupervisorlabel{Correlatore}%
		    \else%
			    \def\beamer@torinoth@assistantsupervisorlabel{Assistant Supervisor}%
		    \fi%
	     \fi%
    %%%%%%%%%%%%%%%%%
    % Placement of labels
    % Assistant-supervisor-check
    \ifx\beamer@torinoth@assistantsupervisor\beamer@torinoth@assistantsupervisortext%
            % Number assistant supervisor check
            \ifx\beamer@torinoth@secondassistantsupervisor\beamer@torinoth@secondassistantsuptext%
                    \begin{beamercolorbox}[ht=0.075\paperheight,sep=8pt,center,#1]{rel}
		    \usebeamerfont{definition}\beamer@torinoth@superv%
		    \end{beamercolorbox}
                    \vskip-0.25em%
		    \ifx\beamer@torinoth@secondsupervisor\beamer@torinoth@secondsuptext%
			    \begin{beamercolorbox}[ht=0.065\paperheight,sep=8pt,center,#1]{rel}%
			    \usebeamerfont{person}\@rel%
			    \end{beamercolorbox}
			    \vskip-0.25em%
			    \begin{beamercolorbox}[ht=0.065\paperheight,sep=8pt,center,#1]{rel}%
			    \usebeamerfont{person}\@secondsupervisor%
			    \end{beamercolorbox}
			    \vspace{\stretch{0.6}}%
		    \else
			    \begin{beamercolorbox}[ht=0.065\paperheight,sep=8pt,center,#1]{rel}%
			    \usebeamerfont{person}\@rel%
			    \end{beamercolorbox}
			    \vspace{\stretch{0.6}}%
		    \fi
		    \begin{beamercolorbox}[ht=0.075\paperheight,sep=8pt,center,#1]{rel}
		    \usebeamerfont{definition}\beamer@torinoth@assistantsupervisorlabel%
		    \end{beamercolorbox}
		    \begin{beamercolorbox}[ht=0.06\paperheight,sep=8pt,center,#1]{rel}%
		    \usebeamerfont{person}\@assistantsupervisor%
		    \end{beamercolorbox}
                    \begin{beamercolorbox}[ht=0.05\paperheight,sep=8pt,center,#1]{rel}%
		    \usebeamerfont{person}\@secondassistantsupervisor%
		    \end{beamercolorbox}
		    \vskip-1.75em%
            \else%
                    \vspace{\stretch{0.6}}%
		    \begin{beamercolorbox}[ht=0.075\paperheight,sep=8pt,center,#1]{rel}
		    \usebeamerfont{definition}\beamer@torinoth@superv%
		    \end{beamercolorbox}
		    \ifx\beamer@torinoth@secondsupervisor\beamer@torinoth@secondsuptext%
			    \begin{beamercolorbox}[ht=0.065\paperheight,sep=8pt,center,#1]{rel}%
			    \usebeamerfont{person}\@rel%
			    \end{beamercolorbox}
			    \vskip-0.25em%
			    \begin{beamercolorbox}[ht=0.065\paperheight,sep=8pt,center,#1]{rel}%
			    \usebeamerfont{person}\@secondsupervisor%
			    \end{beamercolorbox}
			    \vspace{\stretch{0.6}}%
		    \else%
                           
			    \begin{beamercolorbox}[ht=0.075\paperheight,sep=8pt,center,#1]{rel}%
			    \usebeamerfont{person}\@rel%
			    \end{beamercolorbox}
			    \vspace{\stretch{0.6}}%
		    \fi
		    \begin{beamercolorbox}[ht=0.07\paperheight,sep=8pt,center,#1]{rel}
		    \usebeamerfont{definition}\beamer@torinoth@assistantsupervisorlabel%
		    \end{beamercolorbox}
		    \begin{beamercolorbox}[ht=0.06\paperheight,sep=8pt,center,#1]{rel}%
		    \usebeamerfont{person}\@assistantsupervisor%
		    \end{beamercolorbox}
		    %\vskip-2em%
            \fi%
    \else%
            \vspace{\stretch{0.25}}%
	    \begin{beamercolorbox}[ht=0.075\paperheight,sep=8pt,center,#1]{rel}
	    \usebeamerfont{definition}\beamer@torinoth@superv%
	    \end{beamercolorbox}
	    
	    \ifx\beamer@torinoth@secondsupervisor\beamer@torinoth@secondsuptext%
		    \begin{beamercolorbox}[ht=0.065\paperheight,sep=8pt,center,#1]{rel}%
		     \usebeamerfont{person}\@rel%
		     \end{beamercolorbox}
		     \vspace{\stretch{0.5}}%
		     \begin{beamercolorbox}[ht=0.065\paperheight,sep=8pt,center,#1]{rel}%
		     \usebeamerfont{person}\@secondsupervisor%
		     \end{beamercolorbox}
		    \vspace{\stretch{0.75}}%
	    \else%
		    \begin{beamercolorbox}[ht=0.065\paperheight,sep=8pt,center,#1]{rel}%
		    \usebeamerfont{person}\@rel%
		    \end{beamercolorbox}
		    \vspace{\stretch{1}}%
	    \fi%
    \fi%

    % Second column
    \column{.5\paperwidth}%
    % Definitions
    % Number-candidates-check
	    \def\beamer@torinoth@secondcandtext{true}%
	    \ifx\beamer@torinoth@secondcandidate\beamer@torinoth@secondcandtext%
		     % Candidate-language-check
		    \ifx\beamer@torinoth@language\beamer@torinoth@italiantext%
			    \def\beamer@torinoth@cand{Candidati}%
		    \else%
			    \def\beamer@torinoth@cand{Candidates}%
		    \fi%
	    \else%
		     % Candidate-language-check
		    \ifx\beamer@torinoth@language\beamer@torinoth@italiantext%
			    \def\beamer@torinoth@cand{Candidato}%
		    \else%
			    \def\beamer@torinoth@cand{Candidate}%
		    \fi%
	    \fi%
    %%%%%%%%%%%%%%%%%
    % Placement of labels
            \vskip-0.5em%
	    \ifx\beamer@torinoth@secondcandidate\beamer@torinoth@secondcandtext%
		    \begin{beamercolorbox}[ht=0.075\paperheight,sep=8pt,center,#1]{author}
		    \usebeamerfont{definition}\beamer@torinoth@cand%
		     \end{beamercolorbox}
		     \vskip-0.5em%
		     % First-candidate
		     \begin{beamercolorbox}[sep=8pt,center,#1]{author}
		     \usebeamerfont{person}\insertauthor%
		     \end{beamercolorbox}
		     \vskip-0.5em%
		      % Second-candidate
		     \begin{beamercolorbox}[sep=8pt,center,#1]{author}
		     \usebeamerfont{person}\@secondcandidate%
		     \end{beamercolorbox}
	     \else%
		     \begin{beamercolorbox}[ht=0.075\paperheight,sep=8pt,center,#1]{author}
		     \usebeamerfont{definition}\beamer@torinoth@cand%
		     \end{beamercolorbox}
		      \vskip-0.5em%
		      % First-candidate
		     \begin{beamercolorbox}[sep=8pt,center,#1]{author}
		     \usebeamerfont{person}\insertauthor%
		     \end{beamercolorbox}
	     \fi
  \end{columns}
  % Selection of space to skip for the date label
  \def\beamer@torinoth@assistantsupervisortextf{false}%
  \ifx\beamer@torinoth@assistantsupervisor\beamer@torinoth@assistantsupervisortextf%
    \vskip1.5em%
  \else
   \vskip-1.35em%
  \fi

  % Date
  \begin{centering}
    \begin{beamercolorbox}[sep=8pt,center,#1]{date}%
      \usebeamerfont{date}\insertdate{}%
    \end{beamercolorbox}%\vskip0.5em
    \end{centering}
  \vfill
}

% Itemize environment thesis-modifications

% Advantages mode
\newenvironment{adv}%
{\begin{list}{\color{\beamer@torinoth@color}{\ding{51}}}{}}%
{\end{list}}%

% Disadvantages mode
\newenvironment{disadv}%
{\begin{list}{\color{\beamer@torinoth@color}{\ding{55}}}{}}%
{\end{list}}%

% Square mode
\defbeamertemplate{itemize item}{squarem}%
{\tiny\raise.5ex\hbox{\donotcoloroutermaths$\blacksquare$}}
\defbeamertemplate{itemize subitem}{squarem}%
{\tiny\raise.4ex\hbox{\donotcoloroutermaths$\square$}}
\defbeamertemplate{itemize subsubitem}{squarem}%
{\tiny\raise.3ex\hbox{\donotcoloroutermaths$\blacksquare$}}

% Diamond mode
\defbeamertemplate{itemize item}{diamondm}%
{\tiny\raise.5ex\hbox{\donotcoloroutermaths$\blacklozenge$}}
\defbeamertemplate{itemize subitem}{diamondm}%
{\tiny\raise.4ex\hbox{\donotcoloroutermaths$\lozenge$}}
\defbeamertemplate{itemize subsubitem}{diamondm}%
{\tiny\raise.3ex\hbox{\donotcoloroutermaths$\blacklozenge$}}

% Triangle mode
\defbeamertemplate{itemize item}{trianglem}%
{\tiny\raise.5ex\hbox{\donotcoloroutermaths$\blacktriangleright$}}
\defbeamertemplate{itemize subitem}{trianglem}%
{\tiny\raise.4ex\hbox{\donotcoloroutermaths$\vartriangleright$}}
\defbeamertemplate{itemize subsubitem}{trianglem}%
{\tiny\raise.3ex\hbox{\donotcoloroutermaths$\blacktriangleright$}}

% Circle mode
\defbeamertemplate{itemize item}{circlem}%
{\small\raise.2ex\hbox{\donotcoloroutermaths$\bullet$}}
\defbeamertemplate{itemize subitem}{circlem}%
{\small\raise.1ex\hbox{\donotcoloroutermaths$\circ$}}
\defbeamertemplate{itemize subsubitem}{circlem}%
{\scriptsize\raise.1ex\hbox{\donotcoloroutermaths$\bullet$}}

\def\options{square}
\def\optiond{diamond}
\def\optiont{triangle}
\def\optionc{circle}

\ifx\beamer@torinoth@bullet\options
  \setbeamertemplate{items}[squarem]
\fi
\ifx\beamer@torinoth@bullet\optiond
  \setbeamertemplate{items}[diamondm]
\fi
\ifx\beamer@torinoth@bullet\optiont
  \setbeamertemplate{items}[trianglem]
\fi
\ifx\beamer@torinoth@bullet\optionc
  \setbeamertemplate{items}[circlem]
\fi

\mode<all>

