var trailShowing = true;

var topicsShowing = true;
var moreTopicsShowing = true;
var topicCount = 0;

var tagsShowing = true;
var moreTagsShowing = true;
var tagCount = 0;

function loadTopicPage() {
shrink();
}
function loadTopicPageTags() {
shrink();
showTags();
showMoreTags();
hideTrail();
hideTopics();
}

function shrink() {
var topicD = document.getElementById('moreTopicsDiv');
var tagD = document.getElementById('moreTagsDiv');
if (topicD != null) {
showLessTopics();
}
if (tagD != null) {
showLessTags();
}
}

function showTrail() {
var trailD = document.getElementById("trailDiv");
var trailA = document.getElementById("trailA");

if (trailD != null && trailA != null) {
trailShowing = true;
trailD.className="nothidden";
trailA.innerHTML = '(hide trail)';
}
return false;
}

function hideTrail() {
var trailD = document.getElementById("trailDiv");
var trailA = document.getElementById("trailA");

if (trailD != null && trailA != null) {
trailShowing = false;
trailD.className="hidden";
trailA.innerHTML = '(show trail)';
}
return false;
}

function showTopics() {
var topicD = document.getElementById("topicsDiv");
var topicA = document.getElementById("topicsA");

if (topicD != null && topicA != null) {
topicsShowing = true;
topicD.className="nothidden";
topicA.innerHTML = '(hide topics)';
hideTags();
}
return false;
}

function hideTopics() {
var topicD = document.getElementById("topicsDiv");
var topicA = document.getElementById("topicsA");

if (topicD != null && topicA != null) {
topicsShowing = false;
topicD.className="hidden";
topicA.innerHTML = '(show topics)';
}
return false;
}
function showMoreTopics() {
var topicD = document.getElementById("moreTopicsDiv");
var topicA = document.getElementById("moreTopicsA");

if (topicD != null && topicA != null) {
moreTopicsShowing = true;
topicD.className="nothidden";
topicA.innerHTML = '(show less topics)';
}
return false;
}

function showLessTopics() {
var topicD = document.getElementById("moreTopicsDiv");
var topicA = document.getElementById("moreTopicsA");

if (topicD != null && topicA != null) {
moreTopicsShowing = false;
topicD.className="hidden";
topicA.innerHTML = '(show more topics [' + topicCount + '])';
}
return false;
}

function showTags() {
var tagsD = document.getElementById("tagsDiv");
var tagsA = document.getElementById("tagsA");

if (tagsD != null && tagsA != null) {
tagsShowing = true;
tagsD.className="nothidden";
tagsA.innerHTML = '(hide tags)';
hideTopics();
hideTrail();
}
return false;
}
function hideTags() {
var tagsD = document.getElementById("tagsDiv");
var tagsA = document.getElementById("tagsA");

if (tagsD != null && tagsA != null) {
tagsShowing = false;
tagsD.className="hidden";
tagsA.innerHTML = '(show tags)';
}
return false;
}
function showMoreTags() {
var tagsD = document.getElementById("moreTagsDiv");
var tagsA = document.getElementById("moreTagsA");

if (tagsD != null && tagsA != null) {
moreTagsShowing = true;
tagsD.className="nothidden";
tagsA.innerHTML = '(show less tags)';
hideTopics();
hideTrail();
}
return false;
}
function showLessTags() {
var tagsD = document.getElementById("moreTagsDiv");
var tagsA = document.getElementById("moreTagsA");

if (tagsD != null && tagsA != null) {
moreTagsShowing = false;
tagsD.className="hidden";
tagsA.innerHTML = '(show more tags [' + tagCount + '])';
}
return false;
}

function moreTopics() {
if (moreTopicsShowing) {
return showLessTopics();
}
return showMoreTopics();
}

function moreTags() {
if (moreTagsShowing) {
return showLessTags();
}
return showMoreTags();
}

function topics() {
if (topicsShowing) {
return hideTopics();
}
return showTopics();
}
function trail() {
if (trailShowing) {
return hideTrail();
}
return showTrail();
}

function tags() {
if (tagsShowing) {
return hideTags();
}
hideTopics();
hideTrail();
return showTags();
}

function writeMoreTopics(totalCount) {
topicCount = totalCount;
document.write('<a id="moreTopicsA" href="#" onclick="return moreTopics();" onkeypress="return moreTopics();" class="hideLink">(show more topics [' + topicCount + '])</a><br/>');
}
function writeMoreTags(totalCount) {
tagCount = totalCount;
document.write('<a id="moreTagsA" href="#" onclick="return moreTags();" onkeypress="return moreTags();" class="hideLink">(show more tags [' + tagCount + '])</a><br/>');
}

function writeTopics() {
document.write('<a id="topicsA" href="#" onclick="return topics();" onkeypress="return topics();" class="hideLink">(hide topics)</a><br/>');
}
function writeTags() {
document.write('<a id="tagsA" href="#" onclick="return tags();" onkeypress="return tags();" class="hideLink">(hide tags)</a><br/>');
}
function writeTrail() {
document.write('<a id="trailA" href="#" onclick="return trail();" onkeypress="return trail();" class="hideLink">(hide trail)</a><br/>');
}

function delicious() {
window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=700,height=400');
return false;
}

function submitSite() {
if (!document.forms['inputForm'].tos.checked == true) {
alert('Please agree to the Terms of Service');
return false;
}
var formName;
if (document.forms['inputForm'].typeSubmit[1].checked) {
formName = document.forms['inputForm'].typeSubmit[1].value;
} else {
formName = document.forms['inputForm'].typeSubmit[0].value;
}
document.forms[formName].os0.value = document.forms['inputForm'].os0.value;
document.forms[formName].os1.value = document.forms['inputForm'].os1.value;
document.forms[formName].submit();
return false;
}
