var btnHome     = document.getElementById("btnHome");
var btnAuthor   = document.getElementById("btnAuthor");
var btnSeries   = document.getElementById("btnSeries");
var btnEvents   = document.getElementById("btnEvents");
var btnReviews  = document.getElementById("btnReviews");
var btnWriting  = document.getElementById("btnWriting");
var btnWorks    = document.getElementById("btnWorks");
var btnContact  = document.getElementById("btnContact");
var btnLinks    = document.getElementById("btnLinks");

var PG_AUTHOR  = 1;
var PG_SERIES  = 2;
var PG_EVENTS  = 3;
var PG_REVIEWS = 4;
var PG_WRITING = 5;
var PG_WORKS   = 6;
var PG_CONTACT = 7;
var PG_LINKS   = 8;

// Preload Images
var cacheHomeOver    = new Image();
var cacheAuthorOver  = new Image();
var cacheSeriesOver  = new Image();
var cacheEventsOver  = new Image();
var cacheReviewsOver = new Image();
var cacheWritingOver = new Image();
var cacheWorksOver   = new Image();
var cacheContactOver = new Image();
var cacheLinksOver   = new Image();

cacheHomeOver.src    = "/images/btn-home-o.gif";
cacheAuthorOver.src  = "/images/btn-author-o.gif";
cacheSeriesOver.src  = "/images/btn-series-o.gif";
cacheEventsOver.src  = "/images/btn-events-o.gif";
cacheReviewsOver.src = "/images/btn-reviews-o.gif";
cacheWritingOver.src = "/images/btn-writing-o.gif";
cacheWorksOver.src   = "/images/btn-works-o.gif";
cacheContactOver.src = "/images/btn-contact-o.gif";
cacheLinksOver.src   = "/images/btn-links-o.gif";

function setupButtons(currentPage) {

    btnHome.onmouseover = function() { btnHome.className = "btnHomeOver" }
    btnHome.onmouseout  = function() { btnHome.className = "btnHomeOut"  }
    btnHome.onclick     = function() { document.location = "/" }
    
    if (currentPage < 1 || currentPage > 8) return;
    
    if (currentPage == PG_AUTHOR) {
        btnAuthor.className = "btnAuthorActive";
        btnAuthor.style.cursor = "default";
    } else {
        btnAuthor.onmouseover  = function() { btnAuthor.className = "btnAuthorOver" }
        btnAuthor.onmouseout   = function() { btnAuthor.className = "btnAuthorOut"  }
        btnAuthor.onclick      = function() { document.location   = "Author.html"   }
    }
    
    if (currentPage == PG_SERIES) {
        btnSeries.className = "btnSeriesActive";
        btnSeries.style.cursor = "default";
    } else {
        btnSeries.onmouseover  = function() { btnSeries.className = "btnSeriesOver" }
        btnSeries.onmouseout   = function() { btnSeries.className = "btnSeriesOut"  }
        btnSeries.onclick      = function() { document.location   = "Series.html"   }
    }
    
    if (currentPage == PG_EVENTS) {
        btnEvents.className = "btnEventsActive";
        btnEvents.style.cursor = "default";
    } else {
        btnEvents.onmouseover  = function() { btnEvents.className = "btnEventsOver" }
        btnEvents.onmouseout   = function() { btnEvents.className = "btnEventsOut"  }
        btnEvents.onclick      = function() { document.location   = "Events.html"   }
    }
    
    if (currentPage == PG_REVIEWS) {
        btnReviews.className = "btnReviewsActive";
        btnReviews.style.cursor = "default";
    } else {
        btnReviews.onmouseover = function() { btnReviews.className = "btnReviewsOver" }
        btnReviews.onmouseout  = function() { btnReviews.className = "btnReviewsOut"  }
        btnReviews.onclick     = function() { document.location    = "Reviews.html"   }
    }
    
    if (currentPage == PG_WRITING) {
        btnWriting.className = "btnWritingActive";
        btnWriting.style.cursor = "default";
    } else {
        btnWriting.onmouseover = function() { btnWriting.className = "btnWritingOver" }
        btnWriting.onmouseout  = function() { btnWriting.className = "btnWritingOut"  }
        btnWriting.onclick     = function() { document.location    = "Writing.html"   }
    }
    
    if (currentPage == PG_WORKS) {
        btnWorks.className = "btnWorksActive";
        btnWorks.style.cursor = "default";
    } else {
        btnWorks.onmouseover   = function() { btnWorks.className = "btnWorksOver" }
        btnWorks.onmouseout    = function() { btnWorks.className = "btnWorksOut"  }
        btnWorks.onclick       = function() { document.location  = "Works.html"   }
    }
    
    if (currentPage == PG_CONTACT) {
        btnContact.className = "btnContactActive";
        btnContact.style.cursor = "default";
    } else {
        btnContact.onmouseover = function() { btnContact.className = "btnContactOver" }
        btnContact.onmouseout  = function() { btnContact.className = "btnContactOut"  }
        btnContact.onclick     = function() { document.location    = "Contact.html"   }
    }
    
    if (currentPage == PG_LINKS) {
        btnLinks.className = "btnLinksActive";
        btnLinks.style.cursor = "default";
    } else {
        btnLinks.onmouseover   = function() { btnLinks.className = "btnLinksOver" }
        btnLinks.onmouseout    = function() { btnLinks.className = "btnLinksOut"  }
        btnLinks.onclick       = function() { document.location  = "Links.html"   }
    }
}