// * Liberally adapted from www.nowheregirl.com * //
// *                Original code               * //
// *           written by Justine Shaw          * //
// *    Extensively modified by James Burns     * //


// Some globals
var atsign = "&#64;";
var address = "grumbles"+atsign+"jamesburns"+"design.com";

// Write the email address... 
function mailer(){
document.write ("&#0149;&nbsp;<a href=mailto:"+ address +">Contact me<\/a>");

}

function mailLink(type){
document.write ("<a href=mailto:"+ address + ">" + type + "<\/a>");
}

function thisWeeksEp(text){
document.write ("<a href=\"strips/" + padNum(numberOfChapters)+ ".html\">"+ text +"</a>");
}

// Set up variables and utility routines


// Generalized routine to pad out single digit numbers

function padNum(thingie){
if (thingie < 10) {
	return "0"+thingie;
}else{
	return thingie;
	}
}

// Array to hold weekly titles - update weekly

epList = new Array(
"Darwin was Wrong!",
"Lead, Follow, or Just Get Out of the Way!",
"Meaty, Beaty, Big & Bouncy!",
"Gwarsh! Wouldja' Take a Look-see at That!?!",
"The Survival of the Dumbest!",
"Worst... Convention... Ever...",
"That's Crazy Talk, Man...",
"Rebel Without a Pause",
"Where's my Darn Jetpack??",
"From Beyond the Grave!",
"Rudolph the Dysfunctional Reindeer.",
"There's a Reason Why It's Called \"Grumbles\"",
"BRRRRING! BRRRING! It's for You!",
"A Public Service Announcement...",
"Things Fall Apart...",
"Sell-outs Selling Things!",
"One Nation, Under God ...",
"Scared of Our Own Shadow...",
"One From the Heart",
"Conservative Thought",
"A Cartoon Outing",
"Triumph of the Pin-Heads!",
"Stick with What You Know...",
"The Bald-faced Truth",
"Happy Pagan Fertility Festival!!",
"Spring Break!",
"We Live in Bizarro World!",
"Where There&#8217;s Smoke...",
"Something Fishy&#8217;s Going On...",
"An Ode to Spring",
"I Had Too Much to Dream Last Night...",
"The Sporting Life!",
"Kids and Their Music...",
"I Hate When That Happens!",
"Things I Know...",
"Old Enough to Know Better...",
"Happy Dad Day!",
"Push Away from the Table, America",
"Long May it Wave...",
"The Last of His Nine Lives...",
"The Scary Side of Terrorism",
"Wearing Your Hatred on Your Sleeve...",
"WW'TJD?",
"\"I Shot an Arrow in the Air...\"",
"A Reason to Celebrate!",
"Who&#8217;s Next?",
"&#8220;Higher&#8221; Education",
"Hateful Holy-Rollers!",
"\"Better to Remain Silent...\"",
"Happy Anniversary (to us)!",
"Dreams Come True...",
"Would You Like Fries with That?",
"Contains Racy Dialog...",
"Value-based Dialog",
"The Fickle Finger of Fat!",
"Things that Scare Me",
"Losing Class Warfare",
"Peddle Faster, or Move Over!",
"Puritanical Thoughts",
"I Do Stupid Things, Too!",
"The Rise of Fasion-ism",
"Baby Idiot Box&trade;",
"Parking Lot Fascism",
"A Very Special Grumbly Christmas",
"Not a Good Sign...",
"911 Call of Shame",
"I Spy with My Little Eye..."
);

// figure out some numbers from the array

var numberOfChapters = epList.length;


// function to loop through episode array, to list episodes

function episodeList() {

var episodes = "";
for (x=epList.length-1; x >= 0; x--){
episodes += " <li>Week " + (x+1) + " - <a href=\"strips/" + padNum(x+1)+ ".html\">"+ epList[x] +"</a></li>";
}
myScroll=document.getElementById("scroll");
myScroll.innerHTML=episodes;

}


// set new var 'next' equal to page + 1; set new var 'prev' equal to page - 1 -- 
// these will be used for the functions that need to know what the next and previous page numbers are...
if (chapter){
var next = chapter;
var next = ++next;
var prev = chapter;
var prev = --prev;

next=padNum(next);
prev=padNum(prev);
}

// Make the footer arrow
function footerArrow(){
var arrow = "<div class=\"reverse\">";
if (chapter == "01"){
arrow =  "<table width=\"670\"><tr><td align=\"left\"><a href=\"../index.html\"><img src=\"../images/arrow_prev_off.jpg\" border=\"0\" align=\"top\" alt=\"\"><strong> Back</strong> to Grumbles Index page</a></td>";
arrow += "<td align=\"right\">"
arrow +=  "<a href=" + next + ".html>";
arrow += "<strong> Forward</strong> to the next Grumble. <img src=\"../images/arrow_next_off.jpg\" border=\"0\" align=\"top\" alt=\"\"></a></td></tr></table></div>";
}

else if ((chapter == numberOfChapters) || (chapter > numberOfChapters)) {
arrow =  "<table width=\"670\"><tr><td align=\"left\"><a href=\"../index.html\"><img src=\"../images/arrow_prev_off.jpg\" border=\"0\" align=\"top\" alt=\"\"><strong> Back</strong> to Grumbles Index page</a>";
arrow += "<td align=\"left\">"
arrow +=  "<a href=" + prev + ".html>";
arrow += "<img src=\"../images/arrow_prev_off.jpg\" border=\"0\" align=\"top\" alt=\"\"><strong> Back</strong> to the previous Grumble.</a></td></tr></table></div>";
}

else {
arrow =  "<table width=\"670\"><tr><td align=\"left\"><a href=\"../index.html\"><img src=\"../images/arrow_prev_off.jpg\" border=\"0\" align=\"top\" alt=\"\"><strong> Back</strong> to Grumbles Index page</a></td><td align=\"center\"><a href=" + prev + ".html><img src=\"../images/arrow_prev_off.jpg\" border=\"0\" align=\"top\" alt=\"\"><strong> Back</strong> to previous Grumble.</a></td>";
arrow += "<td align=\"right\">"
arrow +=  "<a href=" + next + ".html>";
arrow += "<strong> Forward</strong> to the next Grumble. <img src=\"../images/arrow_next_off.jpg\" border=\"0\" align=\"top\" alt=\"\"></a></td></tr></table></div>";
}

return arrow
}

// Write the title for the header section
function headerTitle() {
var title = "";
if ((epList[(chapter - 1)])!=undefined){
title = "<strong>Grumbles: </strong>" + epList[(chapter - 1)];
}else{
title = "<strong>Grumbles </strong>";
}
return title;
}

function makePage(){
var page="";

//Start writing HTML page
if (chapter){
document.title= "Grumbles - Week " + (eval(chapter));
}
// write header section

page += "<div id=\"header\"> <table>";
page += "<tr>";
page += "<td>";
page += headerTitle();
page += "</td></table></div>";

// write main section

page += "<div id=\"comic\">";
page += "<img src=\"grumbles" +chapter+ ".jpg\" border=\"0\" alt=\"Grumbles comic image\" />";
page += "</div>";

// write footer

page += "<div id=\"footer\">";
page += "<table><tr>";
page += "<td class=\"reverse\">";
page += footerArrow();
page += "</td></table></div>";

//write it all out
document.write (page);

}