//form of address for audience
var intro=[
"My fellow Americans",
"Friends",
"Ladies and Gentlemen",
"Workers",
"Comrades",
"Fellow workers",
"Friends, Romans and Countrymen"];

//sentence beginning new paragraph
var paragraphOpener=[
"History is not easily deceived, she will judge us not by our words but by our actions",
"At this time we are faced with stark choices",
"Centuries ago our forefathers gathered on this hallowed soil in the spirit of hope",
"Since the dawn of time man has striven to fulfil his destiny",
"The time has come for us to wield the sword of destiny",
"We find ourselves at the dawn of a new era",
"Future generations will not forgive delays",
"We must steer a true course between inaction and overreaction",
"There is an old saying, true today as it ever was, that you only get what you pay for",
"We find ourselves at a crossroads in history",
"We can always find a thousand good reasons to postpone a vital decision",
"Decision making is as much about timing as about content",
"We should become deflected from our task, neither by seeking the admiration of friends, nor by avoiding the hatred of enemies",
"For every wise choice there are a thousand foolish and compelling alternatives",
"Our forefathers bestowed on us instruments of democracy, not as monuments, but as tools to fight oppression, dictatorship and injustice",
"Are we going to use our heads or yield to our basest instincts?",
"Important questions demand considered responses",
"Nobody is right all of the time",
"Building democracy demands wisdom, courage and faith.  Destroying it takes mere brutality",
"Everyone is entitled to a moment of glory",
"It is easy to choose the popular, but it is sometimes hard to choose that which is just",
"We all have a responsibility, not just to ourselves, not just to our children, but to countless generations to come",
"Declaring the truth is not a passport to popularity",
"The time has come to look deeply into the soul of our nation",
"The choice we make must be the honest choice, the right choice.  It may not be the easy choice",
"A great philosopher once said 'and this too shall pass away'",
"In all things we must not forget common sense"];

//paragraph ending
var paragraphEpilog = [
"For what we do now will be remembered in a thousand years",
"In all these things we remain steadfast",
"And always remember, in the final analysis we can only do what is possible",
"Many a good plan has been spoilt in the execution",
"The quality of the kitchen is gauged by the feast",
"Nothing is finished until the last trump sounds",
"While we may not achieve the impossible, let us at least try",
"And as always, we must keep our feet firmly anchored to the ground",
"If we do not stand for integrity, we stand for nothing",
"We may be forgiven for being wrong, but we will be condemned for not trying",
"If we cannot be supermen, let us at least be men",
"This we choose, not because it is easy, not even because it is desirable, but because it is right",
"This is the least we would demand of an enemy.  We can surely ask no less of a friend",
"And as always, we must never lose our common touch",
"In a stroke we could even now remove this peril for ever",
"I fear that this is not the last time we will need to take drastic action",
"Let us not in our endeavours become blind to the cries of our weakest members",
"In all these things we must heed our conscience and not our wallets",
"If we do not make this choice will we ever be able to face our children?",
"We may be few, while our enemies are strong, but we are resolute and our cause is just",
"A once in a lifetime opportunity.  Let us seize it",
"So to those who say <span style='font-style:italic';>how could we dare</span>, I say <span style='font-style:italic';>how could we dare not</span>",
"In all this we must stay focused",
"As always the message must be 'bide your time'",
"To that we all say Amen"];



//phrases used to build sentence
//phrase1 leads into present tense verb
var phrase1 = [
"How then can we in all honesty and with a clear conscience",
"Our forefathers would not condone it, nor our children thank us were we to",
"We must therefore with all due diligence",
"We dishonour the lessons of our forefathers if we",
"How will the world judge us if we fail to",
"Nothing can stop us if we make it our intention to",
"Why therefore do we find ourselves failing to",
"If I believed that in this Land there was one person who cared not for justice and truth, I would",
"Many would willingly die for their children.  Our country asks not that we die, but that we",
"Is it any wonder then that our enemies",
"Never in a thousand years would we dare to",
"We must not confuse the Public Interest with the Interest of the Public.  This means we must",
"In all things we must have the courage to trust in our feelings to",
"Could we doubt, even for an instant our ability to",
"We can never have certainty, we can sometimes receive encouragement, but we always have the hope that we shall",
"Have we the sense, have we the knowledge, above all have we the courage to",
"Long, long ago - it seems a lifetime now - I had a dream.  A dream to",
"It's been said that our enemy's enemy is our friend, but would you trust a friend trying to",
"Absence of evidence is not evidence of absence.  Accordingly it is not enough that we",
"In all the history books of all the countries in the World, no leader has ever tried to",
"To criticise requires only opportunity, to lead demands courage, integrity and the faith to",
"Is there even one among us who could doubt the necessity to",
"If we are ever again to look at ourselves in the mirror, we must at the very least",
"Perfection will doubtless elude us, but let us not fail to strive for that which is excellent as we",
"How could we ever again have confidence in someone who would, twice in a single generation try to",
"History would not forgive us, if even for a moment we hesitated in our quest to",
"The path to damnation is littered with the bodies of those who had not the sense to",
"Once in every generation there arrives a leader with the courage to",
"Is there any man who, even for a moment would"];

//verb
var phrase2 = [
"ignore",
"embrace",
"extol",
"proscribe",
"encourage",
"implicate",
"unleash",
"pity",
"rejuvenate",
"bestir",
"empower",
"prohibit",
"disinherit",
"denigrate",
"eschew",
"destroy forever",
"triumph over",
"trample underfoot",
"spit upon",
"honour",
"hate",
"admire",
"despise",
"denounce",
"humiliate",
"envy",
"discourage",
"emulate"];


//animate target leading into "to [verb]"
var phrase3 = [
"everyone who tries",
"anyone who dares",
"the very least among us who would aspire",
"the ungodly members of our society in their insane desire",
"that unholy alliance of so-called righteous men and their declared aim",
"those Four Horsemen of the Apocalypse, even now as they try",
"the forces of darkness in their insane rush",
"the great unwashed in their attempt",
"the <span style='font-style: italic;'>hoi polloi</span>, ever seeking",
"the only person ever likely",
"the Evil One who tries",
"those among us who wish",
"the widows and orphans of our unsung heroes, unable",
"those inhabitants of the corridors of power, only too willing",
"the silent majority, with their unvoiced desire",
"the majority of decent people who want only",
"the very leaders who even now desire",
"those thousands of loyal supporters who even as we speak are trying",
"countless thousands of helpless victims, every one of whom desires",
"false prophets of doom, who seek",
"the imperative of destiny determined",
"time's spectre, driven",
"the untold generations of mankind who died without ever having the chance",
"the hostile forces of evil in their quest"];



//infinitive of transitive verb, minus the "to"
var phrase4 = [
"undo",
"ravish",
"destroy",
"perpetuate",
"embrace",
"re-create from the ashes",
"wipe-out completely",
"enshrine the honour of",
"carve in stone",
"bring to fruition",
"hasten the demise of",
"raze to the ground",
"scatter to the four winds",
"uplift",
"atone for",
"consign to oblivion",
"forgo",
"surrender forever",
"entomb forever",
"unleash for all time",
"disfranchise",
"franchise",
"rein in",
"vindicate for ever",
"release",
"abhor",
"repel",
"invite",
"invoke",
"release",
"enchain",
"enslave"];

//inanimate entity
var phrase5 = [
"our noble heritage",
"this eternal country",
"our beloved fatherland",
"our most sacred principals",
"this, our noblest aspiration",
"our worst nightmares",
"our enemies discomfiture",
"our true destiny",
"the cowardice of indecision",
"Fate's winged chariot",
"the one true calling",
"the call of darkness",
"the lure of false glory",
"the riddle of creation",
"Armageddon's final victory",
"vainglorious ignominity",
"the darkness of destiny",
"Kismet's eternal question",
"the last bastion of civilisation",
"the evil of our enemies",
"the aspirations of our ancestors",
"hope's message",
"the sins of our forefathers",
"the eternal question",
"crimes against humanity",
"weapons of mass destruction",
"destiny's warning",
"the lesson of history",
"the pleas of our forefathers",
"the cries of our children",
"eternity's calling",
"civilisation's last hope",
"mankind's lost dream",
"the enigma of eternity",
"the legacy of justice",
"the fulcrum of destiny",
"the lever of fate",
"our very meaning",
"the one attribute that separates the noble from the savage"];

//meaningless profundity
var phrase6 = [
"and thus condemning us forever to the dustbin of history",
"thereby questioning the honour of our forefathers",
"thereby dishonouring the very notion of nationhood",
"ensuring it is we and not our enemies who inhabit the moral high ground",
"endeavouring all the time to balance fairness with urgency",
"never for an instant allowing fear to cloud the judgement",
"in this we strive as long as we have the breath within us",
"to the eternal humiliation of our enemies",
"and we see as always <span style='font-style: italic;'>sic transit gloria mundi</span>",
"until mankind itself is forgotten",
"as long as there is hope",
"while there is still breath in us",
"before greed finally destroys this precious land",
"while the world will still listen",
"is there any one who could doubt this",
"while there is still time",
"and in so doing change history forever",
"increasing both the gravity and the likelihood of disaster",
"enriching for all time the stockpile of noble deeds by our countrymen",
"adding to the sum total of human iniquity",
"to the greater glory of our nation and of mankind"];




//final ending, used once
var ending = [
"We may be few in number, and our enemies strong, but for truth and justice we must take the risk",
"I know I can count on your support",
"The journey may be long, and the path dangerous, but the World will forever thank us for taking it",
"Go now and spread the message.  Our time has come",
"And may God bless us all",
"Remember that alone we are weak, but together we are invincible",
"In supporting our cause you will deserve the respect of generations yet unborn",
"Together we will conquer the fiercest foe",
"We will win through because our cause is just, our intentions pure and our actions honourable"];


//random number in the range 0 .. max-1
function rand(max) {
  var rNum=NaN
  while (isNaN(rNum)) {
    rNum=Math.floor(Math.random()*(max))
  }
  return rNum
}


//random sentence
function sentence() {
 msg=phrase1[a1] + " "; a1 = (a1+1) % phrase1.length;
 msg+=phrase2[a2] + " "; a2 = (a2+1) % phrase2.length;
 msg+=phrase3[a3] + " "; a3 = (a3+1) % phrase3.length;
 msg+="to " + phrase4[a4] + " "; a4 = (a4+1) % phrase4.length;
 msg+=phrase5[a5] + "; "; a5 = (a5+1) % phrase5.length;
 msg+=phrase6[a6] + ".  "; a6 = (a6+1) % phrase6.length;
 n1++;
 return msg;
}


//random paragraph
function paragraph(){
 msg = "<p>";
 n0++;
 msg += paragraphOpener[a0] + ".   "; a0 = (a0+1) % paragraphOpener.length;
 for (k=0;k<2;k++) msg += sentence() + "  ";
 msg += paragraphEpilog[ae] + ".   "; ae = (ae+1) % paragraphEpilog.length;
 msg += "</p>";
 return msg;
}


function introduction(){
 return "<h3>" + intro[rand(intro.length)] + "</h3>"
}


function epilog(){
 msg = "<p>" + ending[rand(ending.length)] + "!</p>"
 return msg;
}


var footnote = "<p style='color:#b33; font-size: 9pt; font-style: italic;'>"
+"This speech has just been automatically generated by a simple algorithm.&nbsp;"
+"Any sense or meaning is coincidental. Try another - the menu is on the left.</p>";

function rhetoric(){
 n0=0;n1=0;nParagraphs = 4;
 a0 = rand(paragraphOpener.length);
 a1 = rand(phrase1.length);
 a2 = rand(phrase2.length);
 a3 = rand(phrase3.length);
 a4 = rand(phrase4.length);
 a5 = rand(phrase5.length);
 a6 = rand(phrase6.length);
 ae = rand(paragraphEpilog.length);
 msg = introduction();
 for (j=0;j<nParagraphs;j++) msg += paragraph();
 msg += epilog() + footnote;
 return msg;
}



//show list of parameters
function params(){
 msg = '<br><p class="tiny">'
 + n0 + "/" + paragraphOpener.length + "p"
 + " " + n1 + "/" + phrase1.length
 + " " + phrase2.length
 + " " + phrase3.length
 + " " + phrase4.length
 + " " + phrase5.length
 + " " + paragraphEpilog.length + "e"
 + "</p>";
 return msg;
}


function initrhetoric(){
  loadMenu(rhetoricmenu);
  writemain(rhetoric());
}


var rhetoricmenu=[
"MENU",
"HOME|go:index.html",
"Another random speech|writemain(rhetoric())"
];
