\ProvidesPackage{harn}

%% Use \renewcommand{\author}{foo} to give proper
%% copyright notice.
%% Use \section{bar} to get a "bar" heading.
%% Use \titlepage to get a separate title page
%% Use \biginitial{2} to get a two-line initial
%% letter.
%% Use \newrgbcolor{titlegradbegin}{r g b}
%% and \newrgbcolor{titlegradend}{r g b}
%% to obtain colorful headings and titlepages;
%% can be used throughout document, defaults are
%% {1 1 1} for both.

\RequirePackage{ifthen}
\RequirePackage{calc}
\RequirePackage{fancyheadings}
\RequirePackage{fancybox}
\RequirePackage{pst-grad}
\RequirePackage{wrapfig}

\newrgbcolor{titlegradbegin}{1 1 1}
\newrgbcolor{titlegradend}{1 1 1}
\newrgbcolor{grey}{.75 .75 .75}

\newcommand{\Colorovalbox}[2][1pt]{
  \psdblframebox[fillstyle=gradient,
    gradmidpoint=0.5,
    gradbegin=titlegradbegin,
    gradend=titlegradend,
    framearc=.4,
    linewidth=#1]{#2}
}

\renewcommand{\titlepage}{
  \pagestyle{empty}
  \vspace*{\stretch{2}}
  \settowidth{\htw}{\textsc{\title}}
  \setlength{\htfs}{20pt*\ratio{\textwidth}{3\htw}}
  \Colorovalbox[3pt]{
    \makebox[\textwidth]{%
      \fontsize{\htfs}{0cm}\selectfont%
      \settoheight{\hth}{\textsc{\textbf{\title}}}%
      \rule[-.1\hth]{0mm}{1.2\hth}%
      \textsc{\textbf{\title}}%
      \rule[-.1\hth]{0mm}{1.2\hth}%
    }%
  }%
  \vspace*{\stretch{3}}
  
  \cleardoublepage
  \pagestyle{fancy}
  \setcounter{page}{1}
}

\renewcommand{\section}[2][1]{
  \setcounter{page}{#1}
  \markboth{#2}{#2}
  \renewcommand{\title}{#2}
}

\newcommand{\biginitial}[2][u]{
  \settowidth{\biw}{\Huge\textbf{#2}}
  \begin{wrapfigure}[2]{l}{\biw}
    \ifthenelse{\equal{#1}{u}}{
      \raisebox{-1.2ex}[0ex][0ex]{
        \Huge\textbf{#2}
      }
    }
    {
      \raisebox{-3.6ex}[0ex][0ex]{
        \Huge\textbf{#2}
      }
    }
  \end{wrapfigure}
}

\newcommand{\harnhead}[3]{
  \makebox[#1\headwidth][#2]{\Huge\textbf{\textsc{#3~\thepage}}}
}

\newcommand{\marginline}{
  \raisebox{-\headheight/2-\textheight}[0ex][0ex]{\rule{.4pt}{\textheight}}
}
\newlength{\biw}
\newlength{\hth}
\newlength{\htw}
\newlength{\htfs}
\newboolean{classic}
\setboolean{classic}{false}

\DeclareOption{classic}{\setboolean{classic}{true}}
\ProcessOptions

\pagestyle{fancy}

\cfoot[]{}
\chead[]{}

\setlength{\headheight}{.75cm}

\ifthenelse{\boolean{classic}}{
  \lfoot[]{}
  \rfoot[]{}
  \lhead[]{\harnhead{1}{r}{\leftmark}}
  \rhead[\harnhead{1}{l}{\rightmark}]{}
}
{
  \setlength{\headrulewidth}{0mm}
  \setlength{\footrulewidth}{1mm}
  \lfoot[H\^arnworld]{\copyright~\author,~N.~Robin Crossby~\&~Columbia Games Inc.}
  \rfoot[\copyright~\author,~N.~Robin Crossby~\&~Columbia Games Inc.]{H\^arnworld}

  \ifthenelse{\boolean{@twocolumn}}{
    \lhead[]{\Colorovalbox{\harnhead{.97}{r}{\leftmark}}}
    \rhead[\Colorovalbox{\harnhead{.97}{l}{\rightmark}}]{}
  }
  {
    \addtolength{\evensidemargin}{-\marginparwidth}
    \addtolength{\headwidth}{\marginparwidth+\marginparsep}
    \setlength{\textwidth}{.667\textwidth+.667\marginparwidth}
    \setlength{\marginparwidth}{.5\textwidth}
    \addtolength{\evensidemargin}{\marginparwidth}
    \lhead[\fancyplain{}{\makebox[\marginparwidth+.5\marginparsep-.2pt][r]{\marginline}}]{\Colorovalbox{\harnhead{.97}{r}{\leftmark}}}
    \rhead[\Colorovalbox{\harnhead{.97}{l}{\rightmark}}]{\fancyplain{}{\makebox[\marginparwidth+.5\marginparsep-.2pt][l]{\marginline}}}
  }
}
