\NeedsTeXFormat{LaTeX2e}
\def\filedate{2005/10/07}
\def\fileversion{0.1}
\ProvidesClass{topfield}[\filedate\ for Topfield's manuals]

\newif\if@deeperpath\@deeperpathfalse

\newif\if@satellite\@satellitefalse
\newif\if@terrestrial\@terrestrialfalse
\newif\if@cable\@cablefalse

\newif\if@OSDEight\@OSDEightfalse
\newif\if@OSDTwo\@OSDTwofalse
\newif\if@RemoteSix\@RemoteSixfalse
\newif\if@RemoteThirteen\@RemoteThirteenfalse
\newif\if@RemoteFourteen\@RemoteFourteenfalse

\newif\if@normalmargin\@normalmarginfalse
\newif\if@playout\@playouttrue
\newif\if@palatino\@palatinofalse

\newcommand\thisreceiver{}
\newcommand\setthisreceiver[1]{\renewcommand\thisreceiver{#1}}
\newcommand\receivertype{}

\newcommand\manualname{}
\newcommand\setmanualname[1]{\renewcommand\manualname{#1}}
\newcommand\covername{User Manual}
\newcommand\setcovername[1]{\renewcommand\covername{#1}}
\newcommand\certificationmarks{CertificateMarks}
\newcommand\setcertificationmarks[1]{\renewcommand\certificationmarks{#1}}
\newcommand\productimage{NoneImage}
\newcommand\setproductimage[1]{\renewcommand\productimage{#1}}
\newcommand\productinformation{}
\newcommand\setproductinformation[1]{\renewcommand\productinformation{#1}}
\newcommand\manufacturer{\LARGE\sffamily\bfseries TOPFIELD}
\newcommand\setmanufacturer[1]{\renewcommand\manufacturer{\LARGE\sffamily\bfseries#1}}

\newcommand\manualnumber{}
\newcommand\setmanualnumber[1]{\renewcommand\manualnumber{#1}}
\newcommand\destination{English}
\newcommand\setdestination[1]{\renewcommand\destination{#1}}
\newcommand\manufacturerurl{http://www.i-topfield.com}
\newcommand\setmanufacturerurl[1]{\renewcommand\manufacturerurl{#1}}
\newcommand\manufacturerfirm{TOPFIELD Co., Ltd.}
\newcommand\setmanufacturerfirm[1]{\renewcommand\manufacturerfirm{#1}}
\newcommand\buyerinformation{}
\newcommand\warrantyinformation{}

\newcommand\LocalPath{Fig/}
\newcommand\ParentPath{../Fig/}
\newcommand\CommonPath{../../TFCommon/}
\newcommand\ConnectPath{../../TFCommon/Connect/Satellite/}  
\newcommand\OSDPath{../../TFCommon/OSD8/Satellite/}    
\newcommand\OSDCommonPath{../../TFCommon/OSD8/Satellite/}    
\newcommand\RemotePath{../../TFCommon/Remote/TP013/}

\DeclareOption{normalmargin}{
\@normalmargintrue
}

\DeclareOption{deeperpath}{
\@deeperpathtrue
\renewcommand\CommonPath{../../../TFCommon/}
}

\DeclareOption{satellite}{
\renewcommand\receivertype{satellite}
\@satellitetrue
\@terrestrialfalse
\@cablefalse
}

\DeclareOption{terrestrial}{
\renewcommand\receivertype{terrestrial}
\@satellitefalse
\@terrestrialtrue
\@cablefalse
}

\DeclareOption{cable}{
\renewcommand\receivertype{cable}
\@satellitefalse
\@terrestrialfalse
\@cabletrue
}

\DeclareOption{OSD2}{
\@OSDTwotrue
\@OSDEightfalse
}

\DeclareOption{OSD8}{
\@OSDTwofalse
\@OSDEighttrue
}

\DeclareOption{TP006}{
\@RemoteSixtrue
\@RemoteThirteenfalse
\@RemoteFourteenfalse
}

\DeclareOption{TP013}{
\@RemoteSixfalse
\@RemoteThirteentrue
\@RemoteFourteenfalse
}

\DeclareOption{TP014}{
\@RemoteSixfalse
\@RemoteThirteenfalse
\@RemoteFourteentrue
}

\DeclareOption{elayout}{\@playoutfalse}

\DeclareOption{australian}{
\renewcommand\buyerinformation{\include{AustralianDBA}}
\setdestination{Australian}
\renewcommand\warrantyinformation{\include{AustralianWarranty}}
}

\DeclareOption{narrowsec}{
%\setbeforesecskip{-3.5ex \@plus -1ex \@minus -.2ex}
%\setaftersecskip{2.3ex \@plus .2ex}
%\setbeforesubsecskip{-3.25ex \@plus -1ex \@minus -.2ex}
%\setaftersubsecskip{1.5ex \@plus .2ex}
%\setbeforesubsubsecskip{-3.25ex \@plus -1ex \@minus -.2ex}
%\setaftersubsubsecskip{1.5ex \@plus .2ex}
\setbeforesecskip{-2.5ex \@plus -1ex \@minus -.5ex}
\setaftersecskip{1.5ex \@plus .1ex}
\setbeforesubsecskip{-2ex \@plus -1ex \@minus -.5ex}
\setaftersubsecskip{1.ex \@plus .1ex}
\setbeforesubsubsecskip{-2.ex \@plus -1ex \@minus -.5ex}
\setaftersubsubsecskip{1.ex \@plus .1ex}
%spaces
\setlength\alerttopsep{.25\baselineskip}
\setlength\alertbotsep{.25\baselineskip}
\setlength\entitytopsep{.75\floatsep}
\setlength\entitybotsep{.75\floatsep}
}

\DeclareOption{palatino}{\@palatinotrue}

\DeclareOption*{}
\ExecuteOptions{satellite,OSD8}
\ProcessOptions

\RequirePackage{ragged2e}

\@ifpackageloaded{palatino}{}{
\if@palatino \RequirePackage{palatino} \fi
}

\if@deeperpath

\if@satellite
 \renewcommand\ConnectPath{../../../TFCommon/Connect/Satellite/}   
\fi
\if@terrestrial
 \renewcommand\ConnectPath{../../../TFCommon/Connect/Terrestrial/}  
\fi
\if@cable
 \renewcommand\ConnectPath{../../../TFCommon/Connect/Cable/}  
\fi

\if@OSDTwo
  \if@satellite
   \renewcommand\OSDPath{../../../TFCommon/OSD2/Satellite/}  
  \fi
  \if@terrestrial
      \renewcommand\OSDPath{../../../TFCommon/OSD2/Terrestrial/}  
   \fi
   \if@cable
      \renewcommand\OSDPath{../../../TFCommon/OSD2/Cable/}  
   \fi
\fi

\if@OSDEight
  \if@satellite
   \renewcommand\OSDPath{../../../TFCommon/OSD8/Satellite/}  
  \fi
  \if@terrestrial
      \renewcommand\OSDPath{../../../TFCommon/OSD8/Terrestrial/}  
   \fi
   \if@cable
      \renewcommand\OSDPath{../../../TFCommon/OSD8/Cable/}  
   \fi
\fi

\if@OSDEight
 \renewcommand\OSDCommonPath{../../../TFCommon/OSD8/Satellite/}    
\fi

\if@OSDTwo
 \renewcommand\OSDCommonPath{../../../TFCommon/OSD2/Satellite/}    
\fi

\if@RemoteSix
 \renewcommand\RemotePath{../../../TFCommon/Remote/TP006/}
\fi

\if@RemoteThirteen
 \renewcommand\RemotePath{../../../TFCommon/Remote/TP013/}
\fi

\if@RemoteFourteen
 \renewcommand\RemotePath{../../../TFCommon/Remote/TP014/}
\fi

\expandafter\def\csname Ginput@path\endcsname{
{\csname LocalPath\endcsname}
{\csname ParentPath\endcsname}
{\csname OSDPath\endcsname}
{\csname OSDCommonPath\endcsname}
{\csname ConnectPath\endcsname}
{\csname RemotePath\endcsname}
{\csname CommonPath\endcsname}
}

\else

\if@satellite
 \renewcommand\ConnectPath{../../TFCommon/Connect/Satellite/}   
\fi
\if@terrestrial
 \renewcommand\ConnectPath{../../TFCommon/Connect/Terrestrial/}  
\fi
\if@cable
 \renewcommand\ConnectPath{../../TFCommon/Connect/Cable/}  
\fi

\if@OSDTwo
 \if@satellite
   \renewcommand\OSDPath{../../TFCommon/OSD2/Satellite/}  
  \fi
  \if@terrestrial
      \renewcommand\OSDPath{../../TFCommon/OSD2/Terrestrial/}  
   \fi
   \if@cable
      \renewcommand\OSDPath{../../TFCommon/OSD2/Cable/}  
  \fi
\fi

\if@OSDEight
 \if@satellite
   \renewcommand\OSDPath{../../TFCommon/OSD8/Satellite/}  
  \fi
  \if@terrestrial
      \renewcommand\OSDPath{../../TFCommon/OSD8/Terrestrial/}  
   \fi
   \if@cable
      \renewcommand\OSDPath{../../TFCommon/OSD8/Cable/}  
  \fi
\fi

\if@OSDEight
 \renewcommand\OSDCommonPath{../../TFCommon/OSD8/Satellite/}    
\fi

\if@OSDTwo
 \renewcommand\OSDCommonPath{../../TFCommon/OSD2/Satellite/}    
\fi

\if@RemoteSix
 \renewcommand\RemotePath{../../TFCommon/Remote/TP006/}
\fi

\if@RemoteThirteen
 \renewcommand\RemotePath{../../TFCommon/Remote/TP013/}
\fi

\if@RemoteFourteen
 \renewcommand\RemotePath{../../TFCommon/Remote/TP014/}
\fi

\expandafter\def\csname Ginput@path\endcsname{
{\csname LocalPath\endcsname}
{\csname OSDPath\endcsname}
{\csname OSDCommonPath\endcsname}
{\csname RemotePath\endcsname}
{\csname ConnectPath\endcsname}
{\csname CommonPath\endcsname}
}

\fi

\if@playout
\setstocksize{250mm}{176mm}%B5
\settrimmedsize{200mm}{150mm}{*}%TOPFIELD
\else
%\settrimmedsize{210mm}{148mm}{*}%A5
\setstocksize{200mm}{150mm}
\settrimmedsize{200mm}{150mm}{*}
\fi

%Table
\renewenvironment{spec}
{\setlength\tabcolsep{3pt}
 \vspace{\entitytopsep}\par\noindent\startgrayrow
 \begin{minipage}{\linewidth}
 \if@fltab \else\centering\fi\specfont 
 \begin{tabular}{p{\speciwidth}p{\specdwidth}}\toprule 
}{%
 \bottomrule\end{tabular}
 \end{minipage}\vspace{\entitybotsep}\par
 } 

\renewenvironment{capspec}[2][\@empty]{
\setlength\tabcolsep{3pt}
\vspace{\entitytopsep}\par\noindent\startgrayrow
\begin{minipage}{\linewidth}
 \if@fltab\captionstyle{\raggedright}\else\centering\fi
 \if@shortcap\ifx#1\@empty\tabcaption{#2}\else\tabcaption[#1]{#2}\fi
 \else \tabcaption{#2}  \ifx #1\@empty \else \label{tab:#1}\fi\fi%  
 \specfont\startgrayrow% 
 \renewcommand\baselinestretch{1}
 \begin{tabular}{p{\speciwidth}p{\specdwidth}}\toprule
}{%
 \bottomrule\end{tabular}
 \end{minipage}\vspace{\entitybotsep}\par
}

%Illustration
\setlength\interwidth{.75em plus .25em minus .25em}

\renewcommand{\illustfig}[3][\@empty]{%
\settowidth{\leftboxwidth}{\includegraphics[scale=\figscale]{#2}}% 
\if@figframe\addtolength\leftboxwidth{2\figframesep}\fi%  
\setlength{\rightboxwidth}{\linewidth-\leftboxwidth-\extrawidth}% 
\addtolength\rightboxwidth{\marginparwidth}
\vspace{\entitytopsep}\par\noindent % 
 \begin{minipage}[t]{\paperwidth}%
 \hspace*{-\marginparwidth}%
 \begin{minipage}[\boxalign]{\leftboxwidth}%
  \figalign%
  \if@figframe%
  \setlength\fboxsep{\figframesep}% 
  \fbox{\includegraphics[scale=\figscale]{#2}}
  \else\includegraphics[scale=\figscale]{#2}\fi% 
  \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
  \ifx#1\@empty\else\legend{\legendfont#1}\fi% 
 \end{minipage}\hspace{\interwidth}%
 \begin{minipage}[\boxalign]{\rightboxwidth}
  \illustjustify  #3  %
 \end{minipage}
\end{minipage}
 \vspace{\entitybotsep}\par% 
}

\renewcommand{\illustcapfig}[4][\@empty]{%  illustration with caption and label
\settowidth{\leftboxwidth}{\includegraphics[scale=\figscale]{#2}}% 
\if@figframe\addtolength\leftboxwidth{2\figframesep}\fi% 
\setlength{\rightboxwidth}{\linewidth-\leftboxwidth-\extrawidth}%  
\addtolength\rightboxwidth{\marginparwidth}
\vspace{\entitytopsep}\par\noindent %
 \begin{minipage}[t]{\paperwidth}% 
 \hspace*{-\marginparwidth}%
 \begin{minipage}[\boxalign]{\leftboxwidth}
  \figalign% 
  \if@figframe
  \setlength\fboxsep{\figframesep}% 
  \fbox{\includegraphics[scale=\figscale]{#2}}
  \else\includegraphics[scale=\figscale]{#2}\fi% 
  \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}%    
  \if@flfig\captionstyle{\raggedright}\else\centering\fi% 
   \illustcaptionstyle% 
   \if@shortcap\ifx#1\@empty\figcaption{#3}\else\figcaption[#1]{#3}\fi\label{fig:#2}% 
   \else \figcaption{#3}\ifx#1\@empty\label{fig:#2}\else\label{fig:#1}\fi\fi% 
 \end{minipage}\hspace{\interwidth}
 \begin{minipage}[\boxalign]{\rightboxwidth}% \small
 \illustjustify  #4
 \end{minipage}
 \end{minipage}\vspace{\entitybotsep}\par% 
}

\newcommand{\oillustfig}[3][\@empty]{%
\settowidth{\leftboxwidth}{\includegraphics[scale=\figscale]{#2}}% 
\if@figframe\addtolength\leftboxwidth{2\figframesep}\fi%  
\setlength{\rightboxwidth}{\linewidth-\leftboxwidth-\extrawidth}% 
\vspace{\entitytopsep}\par\noindent % 
 \begin{minipage}[t]{\paperwidth}%
 \begin{minipage}[\boxalign]{\leftboxwidth}%
  \figalign%
  \if@figframe%
  \setlength\fboxsep{\figframesep}% 
  \fbox{\includegraphics[scale=\figscale]{#2}}
  \else\includegraphics[scale=\figscale]{#2}\fi% 
  \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}% 
  \ifx#1\@empty\else\legend{\legendfont#1}\fi% 
 \end{minipage}\hspace{\interwidth}%
 \begin{minipage}[\boxalign]{\rightboxwidth}
  \illustjustify  #3  %
 \end{minipage}
\end{minipage}
 \vspace{\entitybotsep}\par% 
}

\newcommand{\oillustcapfig}[4][\@empty]{%  illustration with caption and label
\settowidth{\leftboxwidth}{\includegraphics[scale=\figscale]{#2}}% 
\if@figframe\addtolength\leftboxwidth{2\figframesep}\fi% 
\setlength{\rightboxwidth}{\linewidth-\leftboxwidth-\extrawidth}%  
\vspace{\entitytopsep}\par\noindent %
 \begin{minipage}[t]{\paperwidth}% 
 \begin{minipage}[\boxalign]{\leftboxwidth}
  \figalign% 
  \if@figframe
  \setlength\fboxsep{\figframesep}% 
  \fbox{\includegraphics[scale=\figscale]{#2}}
  \else\includegraphics[scale=\figscale]{#2}\fi% 
  \ifthenelse{\boolean{@dispffn}}{\dispfigfile{#2}}{}%    
  \if@flfig\captionstyle{\raggedright}\else\centering\fi% 
   \illustcaptionstyle% 
   \if@shortcap\ifx#1\@empty\figcaption{#3}\else\figcaption[#1]{#3}\fi\label{fig:#2}% 
   \else \figcaption{#3}\ifx#1\@empty\label{fig:#2}\else\label{fig:#1}\fi\fi% 
 \end{minipage}\hspace{\interwidth}
 \begin{minipage}[\boxalign]{\rightboxwidth}% \small
 \illustjustify  #4
 \end{minipage}
 \end{minipage}\vspace{\entitybotsep}\par% 
}

\renewcommand\normalmargin{% 
 \setlength\trimtop{\stockheight}
 \addtolength\trimtop{-\paperheight}
 \setlength\trimedge{\stockwidth}
 \addtolength\trimedge{-\paperwidth}
 \settrims{.5\trimtop}{.5\trimedge}
 \setulmarginsandblock{.115\paperheight}{.11\paperheight}{*}
 \setheadfoot{.045\paperheight}{.045\paperheight}
 \setlrmarginsandblock{.125\paperwidth}{.125\paperwidth}{*} 
 \checkandfixthelayout
}

\renewcommand\vartwomargin{% 
\@vartwotrue
\setlength\trimtop{\stockheight}
\addtolength\trimtop{-\paperheight}
\setlength\trimedge{\stockwidth}
\addtolength\trimedge{-\paperwidth}
\settrims{.5\trimtop}{.5\trimedge}
\setulmarginsandblock{.115\paperheight}{.11\paperheight}{*}
\setlrmarginsandblock{.3\paperwidth}{.125\paperwidth}{*}
\setmarginnotes{.05\paperwidth}{.125\paperwidth}{0pt}
\setheadfoot{.045\paperheight}{.045\paperheight}
\checkandfixthelayout
\let\evensidemargin\oddsidemargin
}

\if@normalmargin
  \normalmargin
  \normalfolio
  \let\illustfig\oillustfig
\else
 \vartwomargin
 \vartwofolio
\fi

% Menus
\makeatletter
\newcommand\menu[2][\@empty]{%
\ifx #1\@empty the \else #1\fi
\uii{#2} menu}

\newcommand\submenu[3][\@empty]{%
\ifx #1\@empty the \else #1\fi 
\uii{#2} $>$ \uii{#3} menu}

\newcommand\subsubmenu[4][\@empty]{%
\ifx #1\@empty the \else #1\fi 
\uii{#2} $>$ \uii{#3} $>$ \uii{#4} menu}

\newcommand\prmt[2][\@empty]{%
\ifx #1\@empty the \else #1\fi 
\uii{#2} parameter}

% Boxes
\newlength\tempwidth

% Buttons
\newcommand\leftbutton{\raisebox{-.5ex}{\FilledTriangleLeft}}
\newcommand\rightbutton{\raisebox{-.5ex}{\FilledTriangleRight}}
\newcommand\upbutton{\raisebox{-.5ex}{\FilledTriangleUp}}
\newcommand\downbutton{\raisebox{-.5ex}{\FilledTriangleDown}}

%% Signature
\newcommand\signature[2]{%
\settowidth\tempwidth{#1}\vspace{2\baselineskip}
\par\hfill\parbox{\tempwidth}{#2}
}

%% Message Box
\newcommand\messagebox[1]{%
\vspace{.5\baselineskip}\par%
\settowidth\tempwidth{#1}%
\addtolength\tempwidth{.25em}%
\fbox{\parbox{\tempwidth}{#1}}%
\vspace{.5\baselineskip}\par
}

% Covers
\newcommand\frontcover{
\thispagestyle{empty}
\ifthenelse{\boolean{@pdfbookmark}}{\pdfbookmark[0]{Front Cover}{FrontCover}}{}
\ifthenelse{\boolean{@vartwo}}{
 \begin{adjustwidth}{-\vartwosecindent}{0pt}
 \ProductInfo
 \end{adjustwidth}
}{%
 \ProductInfo
}
\buyerinformation
\if@openright\cleartorecto\else\clearpage\fi
}

\newcommand\ProductInfo{%
\settowidth\leftboxwidth{\manufacturer}%
\setlength{\rightboxwidth}{\linewidth-\leftboxwidth-\extrawidth}% 
\colorbox{backgray}{%
\parbox[b][.95\textheight][t]{\leftboxwidth}{\manufacturer}
}\hspace{\interwidth}
\parbox[b][.95\textheight][t]{\rightboxwidth}{%
\vspace*{-3pt}
{\color{textgray}\rule{\linewidth}{1cm}}
\vspace{1cm}\par
\begin{flushright}\sffamily
{\Huge\bfseries \manualname}\bigskip\\
{\huge \covername}
\vspace{1cm}\par
{\slshape\productinformation}
\end{flushright}
\vfill
\begin{center}
\includegraphics[scale=\figscale]{\productimage}
\end{center}
\vfill
\hfill\includegraphics[scale=\figscale]{\certificationmarks}
}}

\newcommand{\backcover}{%
\include{WEEE}
\warrantyinformation
\if@openright
 \newpage\thispagestyle{empty}\null
 \cleartoverso\thispagestyle{empty}
\else
 \newpage\thispagestyle{empty}\null
\fi
\null\vfill
\ifthenelse{\boolean{@pdfbookmark}}{\pdfbookmark[0]{Back Cover}{BackCover}}{}
\ifthenelse{\boolean{@vartwo}}{
 \begin{adjustwidth}{-\vartwosecindent}{0pt} 
 \ManuInfo
 \end{adjustwidth}
}{%
 \ManuInfo
}}

\newcommand\ManuInfo{%
Copyright \copyright\ \number\year, \manufacturerfirm \hfill {\footnotesize \destination\ Version}
\\[-1.5ex] \mbox{}\hrulefill\\
\url{\manufacturerurl}\hfill\manualnumber
}

\if@openright\else\aliaspagestyle{plain}{vartwo}\fi
\renewcommand\buttonfont{\uifont\footnotesize}

\makeindex 
    
\AtBeginDocument{
\renewcommand\illustjustify{\RaggedRight}
\trimLmarks
\let\emph\textsl
\illusthangcaptionoff
\setdeflabelfont{\sffamily}{}
}