var chevron_bc = ' &raquo; ';
var chevron_pn = ' &laquo;---&raquo; ';

site_root=null
site_title=null
page_title=null
page_heading=null

breadcrumbs=null	// string containing html code for breadcrumb navigation link
rel_prev=null
rel_next=null
rel_contents=null

// call this inside <head>
function initHead(sr,st,pt,ph) {
	site_root=sr
	site_title=st
	page_title=pt
	page_heading=ph
	echo('<title>'+getHeadTitle()+'</title>')
	echo('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">')
	echo('<meta http-equiv="Content-Script-Type" content="text/javascript">')
	echo('<meta name="author" content="John McFarlane">')
	echo('<link rel="made" href="http://john.mcfarlane.name/" TITLE="John McFarlane">')
	if (rel_prev)
		echo('<link rel="prev" href="'+rel_prev+'">')
	if (rel_next)
		echo('<link rel="next" href="'+rel_next+'">')
	if (rel_contents)
		echo('<link rel="contents" href="'+rel_contents+'">')
	echo('<link rel="shortcut icon" href="'+getSiteFilename('favicon.ico')+'" type="image/vnd.microsoft.icon">')
	echo('<link rel="stylesheet" href="'+getSiteFilename('site.css')+'" type="text/css">')
	echo('<link rel="stylesheet" href="'+getCommonFilename('site.css')+'" type="text/css">')
	if (isOldIe())
		echo('<link rel="stylesheet" href="'+getCommonFilename('iehack.css')+'" type="text/css">')
	echo('<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>');
}

function beginBody() { 
	echo('<div id="outer"><a name="top"></a><div id="inner">');

	var nav_title = getTopNavTitle();
	if (nav_title)
		addBreadcrumb(null, nav_title);	
	printBreadcrumbs();
	
	echo('<div id="content">')
}

function endBody() {
	printPrevNext();
	echo('</div>');
	printBreadcrumbs(true);
	echo('<div id="footer"><p id="copyright"><a href="http://www.thecayo.com/">The Cayo</a> &copy; 2009 ');
	hivelogic_enkoder_name();
	echo('</p><p id="validation"><a href="http://validator.w3.org/check/referer">HTML</a> - <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a></p>');
	echo('</div></div></div>');
	echo('<script type="text/javascript">_uacct = "UA-2617626-2";urchinTracker();</script>');
}

/////////////////////////////////////////////

function addBreadcrumb(link, descr) {
	if (! breadcrumbs)
		breadcrumbs = '';
	else if (breadcrumbs != '')
		breadcrumbs += chevron_bc;
	if (link) {
		breadcrumbs += '<a class="nav" href="'+link+'">'+descr+'</a>';
		if (! rel_contents)
			rel_contents = link;
	}
	else
		breadcrumbs += '<span class="nav_head">'+descr+'</span>';
}

function printBreadcrumbs(top) {
	if (breadcrumbs == null)
		return;
	echo('<div class="nav"><div style="float:left">'+breadcrumbs+'</div>');
	if(top)
		echo('<div style="float:right"><a href="'+top+'">top</a> ^</div>');
	echo('<div style="clear:left"></div></div>');
}

/////////////////////////////////////////////

function setPrevNext(prev, next) {
	rel_prev = prev;
	rel_next = next;
}

function printPrevNext() {
	var count=0

	if (rel_prev) {
		prev=rel_prev
		++count
	}
	else
		prev=rel_contents
	p=prev?'<a class="nav" href="'+prev+'">Previous</a>':'Previous'

	if (rel_next) {
		next=rel_next
		++count
	}
	else
		next=rel_contents
	n=next?'<a class="nav" href="'+next+'">Next</a>':'Next'

	if (count>0)
		echo('<div style="float:left">'+p+'</div><div style="float:right">'+n+'</div><div style="text-align:center">'+chevron_pn+'</div><br>');
}

/////////////////////////////////////////////

function getHeadTitle() {
	var comp = 0;
	var ret = '';
	if (site_title) {
		++ comp;
		ret += site_title;
	}
	if (page_title) {
		++ comp;
		if (comp == 2)
			ret += ' - ';
		ret += page_title;
	}
	return (comp>0) ? ret : null;
}

function getHeading() {
	if (page_heading)
		return page_heading;
	if (page_title)
		return page_title;
	else if (site_title)
		return site_title;
	else
		return null;
}

function getTopNavTitle() {
	if (page_title)
		return page_title;
	else if (site_title)
		return site_title;
	else
		return null;
}

/////////////////////////////////////////////

function getSiteFilename(fn) {
	return site_root+fn;
}

function getCommonFilename(fn) {
	//return site_root+'../../../thecayo.com/htdocs/common/'+fn;
	return 'http://www.thecayo.com/common/'+fn;
}

function echo(s) {
	document.write(s);
}

function isOldIe() {
	// http://www.codingforums.com/archive/index.php?t-13594.html
	a=navigator.appVersion.split('MSIE')
	return a[1] && parseInt(a[1])<7
}

/////////////////////////////////////////////

function thumb(fn, cap, thumb_fn, alt, ext) { 
	if (! ext) 
		ext = 'jpg'
	if (! thumb_fn) 
		thumb_fn = fn+'Thumb'
	if (! cap)
		cap = fn+'.'+ext
	else
		cap.replace('"', '*')
	if (! alt)
		alt = cap
	
	echo('<div class="thumb">')
	echo('<div class="thumb_image"><a href="'+fn+'.'+ext+'">')
	echo('<img class="thumb_image" src="'+thumb_fn+'.'+ext+'" alt="'+alt+'">')
	echo('</a></div>')
	echo('<div class="thumb_caption">')
	echo('<p class="thumb_caption">'+cap+'</p>')
	echo('</div>')
	echo('<div style="clear:left"></div>')
	echo('</div>')
}

/////////////////////////////////////////////

var stripe = true;
function row(cells, clss)
{
	if (clss) {
		stripe = true;
		cstr = ' class="'+clss+'"';
	}
	else {
		stripe = ! stripe;
		if (stripe)
			cstr = ' class="odd"';
	}

	echo('<tr>')
	foreach (c in cells)
		echo('<td'+cstr+'>'+c+'</td>')
	echo('</tr>')
}

/////////////////////////////////////////////

// http://hivelogic.com/enkoder

function hivelogic_enkoder_email(){
var x="function f(x){var i,o=\"\",ol=x.length,l=ol;while(x.charCodeAt(l/13)!" +
"=47){try{x+=x;l+=l;}catch(e){}}for(i=l-1;i>=0;i--){o+=x.charAt(i);}return o" +
".substr(0,ol);}f(\")87,\\\"meozpo1`r #(d&1&% ,7200\\\\/9S000\\\\730\\\\`^TX" +
"TEWsW~220\\\\_Ic610\\\\BX310\\\\F@IJC500\\\\JB200\\\\ENzM?@&771\\\\ul~b56Of" +
"771\\\\ubz771\\\\m{K4|dcofvq>m120\\\\630\\\\R420\\\\300\\\\030\\\\330\\\\22" +
"0\\\\630\\\\100\\\\4530\\\\310\\\\530\\\\J000\\\\230\\\\100\\\\500\\\\n\\\\" +
"700\\\\K4Z000\\\\000\\\\620\\\\310\\\\B000\\\\\\\\\\\\}v30>.0* x!:6?$3 *\\\""+
"(f};o nruter};))++y(^)i(tAedoCrahc.x(edoCrahCmorf.gnirtS=+o;721=%y;2=*y))y+" +
"87(>i(fi{)++i;l<i;0=i(rof;htgnel.x=l,\\\"\\\"=o,i rav{)y,x(f noitcnuf\")"    ;
while(x=eval(x));}
	
function hivelogic_enkoder_name(){
var x="function f(x,y){var i,o=\"\",l=x.length;for(i=0;i<l;i++){y%=127;o+=St" +
"ring.fromCharCode(x.charCodeAt(i)^(y++));}return o;}f(\"_OU_IWP.a$k<l=1);j\\"+
"\"`\\\"smr}=?i-x;=7=/4q2b\\017\\rY\\024\\014\\014\\n\\002@\\021D\\010\\004\\"+
"014\\034,\\037\\025\\0272\\000]\\032XIJSZAHN)zvq}~~,5q1g'0b4mrsgw}>r1bgfzrl" +
"7I\\034N\\016\\025\\036O\\031\\025\\031\\021B\\001\\000\\007T_\\032\\017K\\" +
"032V^VJxN\\023U\\024\\005B2$666+f(f:?)?9<g`}=?}n+1p{skiq\\002}181- >SWX56'2" +
"Y^_,-DBD)*IJVGNOM\\\"\\\\8614YZ\\1771&;8<QRea'##HI\\\")6E8G@\\\"3m|}\\013\\" +
"027\\024\\025z{@\\000\\025_pqJ\\003\\006P\\036ekeo\\004\\013\\tfghe\\016\\0" +
"14p\\035\\036\\020\\034\\025!vzy\\026\\027\\\"y\\177\\177\\014\\r\\007\\020" +
"\\016\\021\\016dii\\006\\007lln\\003<\\024>?89/$ 9;(=\\0142M,-\\030\\r\\r\\" +
"004\\016\\033\\023QLJL!\\\"r]^145Z[F9-733<\\\" \\\"\\\"OH,9.v%<&%3=p\\020\\" +
"023\\022\\177xS\\n\\013\\022\\006L\\017TLD\\000\\034kxgzy\\002\\005\\010efv" +
"joe\\177\\027\\035\\036\\037\\030\\023\\032e`/7p#m =%%7!)n\\177~sr#s\\002t7" +
"w\\024 \\007\\007\\013&\\024\\006\\000\\nD\\023D\\010\\n\\0003\\003\\023\\0" +
"337\\030\\031\\005\\036W\\035\\025\\025\\017\\nS<)l?2465,s0e0%v9!'.)|>qqb30" +
"7t%s\\034H\\031\\023\\031L\\016UGO\\021CXJ@J\\\\\\037J\\016X\\031j\\025d\\0" +
"33\\007T\\020T\\036M!79j=i>o.i$$%9-!%7pz\",57)"                              ;
while(x=eval(x));}