\ProvidesPackage{coseoul}
\RequirePackage{ifthen}

\newcommand{\chex}{}

\newcounter{currentlevel}
% part					= 7		chapter				= 6		section				= 5
% subsection		= 4		subsubsection	=	3		paragraph			=	2
% subparagraph	=	1

\ifthenelse{\isundefined{\chapter}}%
	{\renewcommand{\chex}{N}\setcounter{currentlevel}{5}}%
	{\renewcommand{\chex}{Y}\setcounter{currentlevel}{6}}

\newcommand{\findnewlevel}[1]% uppity (-1 down, 0 stay, 1 up, 2-6 multiup
{	\addtocounter{currentlevel}{#1}%
	\ifthenelse{\equal{\chex}{N}}%
	{	\ifthenelse{\value{currentlevel} = 6}%
		{	\ifthenelse{#1 > 1}{\addtocounter{currentlevel}{1}}%
				{\addtocounter{currentlevel}{-1}}}{}}{}%
	\ifthenelse{\value{currentlevel} < 1}{\setcounter{currentlevel}{1}}{}%
	\ifthenelse{\value{currentlevel} > 7}{\setcounter{currentlevel}{7}}{}%
}

\newcommand{\levelchange}[2]% title, uppity
{	\findnewlevel{#2}%
	\ifthenelse{\value{currentlevel} = 1}{\subparagraph{#1}}{}%
	\ifthenelse{\value{currentlevel} = 2}{\paragraph{#1}}{}%
	\ifthenelse{\value{currentlevel} = 3}{\subsubsection{#1}}{}%
	\ifthenelse{\value{currentlevel} = 4}{\subsection{#1}}{}%
	\ifthenelse{\value{currentlevel} = 5}{\section{#1}}{}%
	\ifthenelse{\value{currentlevel} = 6}{\chapter{#1}}{}%
	\ifthenelse{\value{currentlevel} = 7}{\part{#1}}{}%
}

\newcommand{\levelup}[1]{\levelchange{#1}{1}}
\newcommand{\leveldown}[1]{\levelchange{#1}{-1}}
\newcommand{\levelstay}[1]{\levelchange{#1}{0}}
\newcommand{\levelmultiup}[2]{\levelchange{#1}{#2}} %title, uppity	