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


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


// 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",
"Pedal Faster, or Move Over!",
"Puritanical Thoughts",
"I Do Stupid Things, Too!",
"The Rise of Fashion-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...",
"As Opposed to the &#8220;Moronic Dregs?&#8221;",
"The Wizard of Ooze",
"Everything Old is New Again...",
"Happy Greed-Head Day!!!",
"Liberal Thinking...",
"The Most Important Meal of the Day",
"The King of Comedy!",
"Shocked, shocked, I Tell you...",
"Language is a Virus...",
"Damn Dirty Apes!",
"Spring Break 2006!",
"Me and my Big Mouth...",
"Hoppy Eostre!",
"Math for Dummies!",
"People Will Believe Anything!!",
"See You in the Funny Pages!",
"Are You Now, or Have You Ever...",
"The Creative Process",
"Too Much Information!",
"You Are Getting Sheepy...",
"You Say it's Your Birthday!",
"Pater Patter...",
"NeoCons = A Buncha Wussies",
"Words from the Wise...",
"Let's Play Doctor!",
"Conversational Ploy...",
"Politics are Alien to Me...",
"Cinema Paradiso",
"Comic Book Presidency",
"Driving Me Nuts!",
"Fundamental Truths...",
"In the Nick of Time...",
"A Century of Grumbles...",
"Lest We Forget...",
"The Call of the Chicken-hawk!",
"Selfish, Inconsiderate Pigs!",
"The Whispering Campaign...",
"Hoodwinked",
"7 Silent, but Deadly Sins.",
"You Sir, Are an Asterisk!",
"Boooooo!",
"A Cutting Remark.",
"It's Feeding Time!!",
"I'll Say Grace...",
"Homophobia is So Gay!",
"Call Me an Iconoclast!",
"The Long Wait...",
"A Trip to Angryland!",
"Ghosts of Christmas Past...",
"New Year's E-vil!",
"Sick Leave...",
"Polls say: We Crazy!",
"The Unwelcome Guest...",
"The Thin Line...",
"A Visit to Whiteville...",
"The Sad Decline...",
"Mesopotamia",
"Cartoon Politics",
"Collecting Candidates...",
"Tales from the Crypt!",
"A Glimpse of Infinity...",
"Who's the Boss Here??",
"Busman's Holiday.",
"It's the Great Bunny, Grumbles-Guy!",
"A Visit from St. Dick...",
"Racism, Northern Style...",
"Pictures Fail me...",
"Buncha Fakers!",
"For All You Mothers Out There.",
"R.I.P., Jerry Falwell...",
"Timelines of Non-History...",
"Comic Conventional Wisdom",
"It Could Be Worse!",
"How it All Started...",
"The Cost of Free Speech.",
"Liar! Liar!",
"Pardon me???",
"God Agrees with Me.",
"Cashing In On Crazy...",
"Weighty Matters...",
"Bring the Whole Family!",
"Call me, Irresponsible.",
"Buncha Losers!",
"Flagging a Dead Horse.",
"Confederacy of Dunces.",
"Flying Off the Handle...",
"...Yearning To Breathe Free...",
"Hydra-In-Chief!",
"Baby Magnet.",
"Funniest Logo Ever!",
"Real Scary Problems...",
"Buncha Scary Monsters!",
"Domo Arigato...",
"Mr. Saturday Night!",
"A Traditional Thanksgiving.",
"Praying for Rationality...",
"All the World's a Stage...",
"The Excuse of a Lifetime!",
"Shoe? Meet Other Foot...",
"The Santa/Satan Conundrum.",
"Dead Reckoning.",
"Right on the Mark.",
"... or Forever Hold Your Peace...",
"It's Not a Game...",
"Time Marches On...",
"Taken Aback...",
"Drawing Conclusions...",
"Geezer Alert!",
"Spam! Spam! Spam! Spam!",
"NewsFlash: War Costs Money",
"Sorry to Bring It Up...",
"... It'll Last Longer!",
"If Only He Could've Served...",
"Mortgaging Your Future.",
"Der Kegler",
"A Pathetic Plea for Attention.",
"What Do You Call It?",
"Monkey See, Monkey Drive",
"A Mother of an Idea.",
"Idiots Guide to Irony.",
"Lightning Strikes Twice!",
"A History Lesson.",
"In Loco Parentis",
"It Doesn't Add up...",
"Truth or Scare...",
"Habeas Corpus Rules!",
"Political Literacy.",
"Christian Presidency",
"Torturous Logic.",
"The United States of Denial",
"The Other Credit Crunch...",
"Snake-Oil Salesmen",
"Tin-Hat Time!",
"Youth is Wasted on the Young.",
"Drilling for the Truth.",
"Everybody Run...",
"Grand Old Prevaricators.",
"High-Definition Politics.",
"...Doomed to Repeat it...",
"Signs of Unrest...",
"The Only Explanation.",
"A Moment of Sanity...",
"The Dark Tea-Time of the Soul.",
"Lowering the Bar...",
"At Loose Ends...",
"One Step Forward, Two Back...",
"A Grateful Nation...",
"Cough, Please...",
"Waste Not...",
"Flagging an Offense...",
"The Greatest Story Ever Sold...",
"The Big Night...",
"Retirement Planning.",
"Consumed...",
"The Legacy.",
"Polite Conversation.",
"Joe the Slummer.",
"Yes, We Do...",
"Birth of a Nation.",
"Told Ya So...",
"Questionable Acts.",
"21st Century Skills...",
"Head of the Party...",
"The Free Market...",
"The Blame Game...",
"Television 2.0...",
"The Continuum of Crazy.",
"Hypocritical Right...",
"Heroism 101",
"I Blame England.",
"News for Idiots.",
"Torturous Morality...",
"A Turn for the Verse...",
"World-class Crazy...",
"Pot... Kettle.. Black...",
"Picturing Middle Age.",
"Sound Familiar?",
"The Circus Is In Town!",
"...Not As I Do...",
"Keeping Up With the News...",
"Quit Making my Head Explode!",
"Burning Issues.",
"Nutjob Central",
"Spammy Goodness.",
"Time Trippin'",
"The Bush Legacy",
"Unfairly Unbalanced",
"Labor of Love...",
"Whose Country?",
"Mr. Smarty-Pants...",
"Five Freakin' Years!",
"A Lack of Civility.",
"My Kinda God...",
"Teachin' to the Converted!",
"Memory Loss...",
"Ooooh! Scary!!",
"You Do That Voodoo...",
"Shooting Their Mouths Off...",
"Gobble Gobble Gobble!",
"The Home of the Brave?",
"Remembrance of Things Past...",
"Cosmic Thoughts.",
"Merry Movie Mashup!",
"Yet Another Year...",
"Hat Crimes...",
"Hypo-Brit-ical.",
"Have a King-a-Long!",
"The devil, You Say?",
"Hidden Assets.",
"You and Your Filthy Mouth...",
"Happy Sappy Day!",
"The Mad Tea Party!",
"It's all a Crazy Game.",
"Hush, Woman!!",
"Sugar-water Shocker!",
"Evil Spawn of Evil!",
"Pre-existing Conditions...",
"Fascism Week.",
"I Blame Steve Jobs...",
"The Party of Nope!",
"The Chosen One...",
"The Day After May Day...",
"Spill Baby Spill",
"What Goes Around...",
"Crazin' Arizona",
"When You Sleep with Dogs...",
"Get Your Hands Dirty!",
"Cut the Cake!",
"A Break from Reality...",
"Barton Fink!",
"Patriot Lames...",
"Realpolitik-al",
"Oh, Boo Hoo Hoo...",
"An Editorial Reply...",
"Remember??",
"Time to Walk the Doggerel.",
"True Celebrity...",
"Religious Ground Zero",
"The Dumbening of America.",
"Restoring Horror...",
"There Shall Be a Reckoning!",
"Marketplace of Ideas...",
"Crazy Ladies.",
"Same Old Song and Dance...",
"A Religious Quiz.",
"U R Not Me.",
"More Like Stupid Design...",
"Their Worst Nightmare...",
"Designing Like Crazy...",
"Mourning in America.",
"Him and Taylor Swift...",
"The Way the Ball Bounces...",
"What lies Ahead...",
"Mark Trail Edition...",
"Krazy Konservatives &trade;",
"Christmas Wish Lists...",
"High Resolution.",
"What's the Hold Up?",
"Gee! What a Surprise!",
"Snowpocalypse Now!",
"Un-Civil War",
"All Good Things..."

);

// parse query string for page number
    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return unescape(pair[1]);
            }
        }
        //alert('Query Variable ' + variable + ' not found');
    }

// 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...

function fadeIt(what){
$(what).fadeOut('fast');

}

function setUpPage()
{
// If we got here without the chapter number being set...
page=getQueryVariable("page");
if ((!page) || (page==undefined))
{
page="01";
}else{

image="strips/grumbles" + page + ".jpg";
}

//hide the image
$('#comic img').hide();

// reset the title
$("#epp").html("Episode " + page + " - " + epList[Number(page)-1]);

// change the image
changeImage();

//set up footer
setUpFooter();
}

function changeImage(){

$('#comic img').fadeOut('fast');
$('#comic').html('<img src=' + image + ' />');
$('#comic img').fadeIn('fast');

}

// Make the footer arrow
function setUpFooter(){

//set up navigation
 next = "strip.html?page=" + padNum(Number(page)+1);
 prev = "strip.html?page=" +padNum(page-1);

if (page == "01"){
back = " Back to the Grumbles index page"
$('td#forward').hide();
} else {
// last strip

if (page=="329"){
back = " <b>Back</b> to the previous strip";
$("td#back a").html(back);
$("td#forward").hide();


}
back = " <b>Back</b> to the previous strip"
fore = "<b>Forward</b> to the next strip "
middle = "<a href='index.html'><b> Back</b> to Grumbles Index page!</a>"

}
// change the type
$("td#back a").html(back);
$("td#forward a").html(fore);
$('td#middle').html(middle);
//change the links
$("td#back a").attr('href', prev);
$("td#forward a").attr('href', next);
}

// 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;
}


