/* Labour claims, based solely on the "Daily Mail headline generator script"

 Author: Chris Applegate (www.qwghlm.co.uk)
 Version: 1.1 January 7, 2009
 License: GNU GPL v2 or later
 
 Changelog:
 
   1.1 [Jan 2009]
     - Added past/present tenses
     - Updated with 2009-relevant terms
     - Added sarcastic comments to code
   1.0 [2003]
     - Original version

*/

// A more random random generator
function getRandom(a) {

    if (a.length == 1) {
        return a[0];
    }
    
	var n = new Array(50);

	for (var i=0; i<n.length; i++) {
		n[i] = Math.random();
	}

	var m = n[Math.floor(Math.random() * n.length)];
	var o = Math.floor(m * a.length);

	return a[o];

}

// Objects for nouns, modifier verbs and phrases
function Verb(plural, singular, tense) {
	this.singular = singular;
	this.plural = plural;
	this.tense = tense;
}

function Noun(word,person,number) {
	this.word = word;
	this.person = person;
	this.number = number;
}

function Phrase(present, past, active, object) {
	this.present = present;
	this.past = past;
	this.active = active;
	this.object = object;
}

// Auxiliary verbs (the first word in the sentence)
auxiliary_verbs = [
	new Verb("will", "will", "present"), 
	new Verb("could", "could", "present"),
	new Verb("are", "is", "active"),
	new Verb("have", "has", "past")
];


// Subjects (i.e. bad things)
subjects = [

	new Noun("liberal democrats",3,2),
	new Noun("libdems",3,2),
	new Noun("condem",3,1),
	new Noun("nick clegg",3,1),
	new Noun("vince cable",3,1),
	
	new Noun("Liberals",3,2),
	new Noun("Lib Dims",3,2),
	new Noun("Yellow Tories",3,2),
	new Noun("Quisling Liberals",3,2),
	new Noun("Collaborating Labour MPs",3,2),
	new Noun("ConDems",3,2),
	new Noun("Lib Dems",3,2),
	new Noun("Cleggeron",3,2),
	new Noun("Lib Dums",3,2),
	new Noun("Liar Dems",3,2),
	new Noun("Orange Bookers",3,2),
	new Noun("Judas Liberals",3,2),
	new Noun("Traitor Lib Dems",3,2),
	new Noun("Backstabbing Liberals",3,2),
	new Noun("Power hungry Lib Dems",3,2),
	new Noun("Guardian reading liberals",3,2),
	new Noun("Brokeback coalition",3,1),

];

// Transitive phrases (i.e. bad thing they do)
transitive_phrases = [
	new Phrase("give", "given", "giving", "cancer"),
	new Phrase("infect", "infected", "infecting", "with AIDS"),
	new Phrase("give", "given", "giving", "swine flu"),
	new Phrase("make", "made", "making", "obese"),
	new Phrase("give", "given", "giving", "diabetes"),
	new Phrase("make", "made", "making", "impotent"),

	new Phrase("turn","turned","turning","gay"),

	new Phrase("scrounge off","scrounged off","scrounging off",""),
	new Phrase("tax", "taxed", "taxing", ""),
	new Phrase("cheat", "cheated", "cheating", ""),
	new Phrase("defraud", "defrauded", "defrauding", ""),
	new Phrase("steal from","stolen from","stealing from",""),
	new Phrase("burgle","burgled","burgling",""),
	new Phrase("devalue","devalued","devaluing",""),
	new Phrase("rip off","ripped off","ripping off",""),
	
	new Phrase("molest","molested","molesting",""),
	new Phrase("have sex with","had sex with","having sex with",""),
	new Phrase("impregnate", "impregnated", "impregnating", ""),
	
	new Phrase("steal the identity of","stolen the identity of","stealing the identity of",""),	

	new Phrase("destroy","destroyed","destroying",""),
	new Phrase("kill","killed", "killing",""),
	new Phrase("ruin","ruined","ruining",""),
	new Phrase("hurt","hurt", "hurting",""),
	
	new Phrase("gerrymander","gerrymandered","gerrymander",""),
	new Phrase("betray","betrayed","betraying",""),
	new Phrase("sell out","sold out","selling out",""),
	new Phrase("conspire against","conspired against","conspiring against",""),
	new Phrase("steal British jobs from","stole British jobs from","stealing British jobs from",""),
	new Phrase("disgust","disgust","disgust",""),
	new Phrase("offer a straight choice to","offered a straight choice to","offering a straight choice to",""),
	new Phrase("give a pity nomination to","gave a pity nomination to","giving a pity nomination to",""),
	new Phrase("risk","risked","risking",""),
	new Phrase("impose swingeing cuts on","imposed swingeing cuts on","imposing swingeing cuts on",""),
	new Phrase("flip-flop on","flip-flopped on","flip-flopping on",""),
	new Phrase("u-turn over","u-turned over","u-turning over",""),
	
	new Phrase("snatch","snatched","snatching","milk"),
];

// Objects (i.e. saintly, saintly things)
objects = [
	"the british people",
	"the middle class",
	"middle britain",
	"england",

	"hard-working families",
	"homeowners",
	"pensioners",
	"drivers",
	"taxpayers",
	"taxpayers' money",

	"house prices",
	"property prices",
	
	"britain's farmers",
	"the countryside",

	"british justice",
	"british sovereignty",
	"common sense and decency",

	"the queen",
	"the royal family",
	"the church",

	"you",
	"your mortgage",
	"your pension",
	"your daughters",
	"your children",
	"your house",
	"your pets",

	"the conservative party", 
	"cliff richard",
	"the memory of diana",
	"Britain's swans",

	"brokeback",
	"democracy",
	"the nhs",
	
	"the working classes",
	"hard working families",
	"Forgemasters",
	"the BBC",
	"students",
	"student fees",
	"bigoted women",
	"Thatcher",
	"unions",
	"the historic Labour-union link",
	"our traditions",
	"British workers",
	"the North",
	"Andy Burnham's gorgeous eyelashes",
	"working class credentials",
	"the workers",
	"the people's flag",
	"Diane",
	"VAT",
	"a double dip recession",
	"soft southern scum",
	"Ed Balls",
	"Diane Abbott",
	"Jack Straw",
	"Ed Miliband",
	"David Miliband",
	"Andy Burnham",
	"directly elected police commissioners",
	"human shields",
	"cuts",
	"bar charts",
	"the House of Lords",
	"school buildings",
	"David Cameron",
	"George Osborne",
	"homophobia",
	"no more than thirty lovers",
	"the Alternative Vote",
	"boundary changes",
	"immigrants",
	"asylum seekers",
	"school buildings",	
];

// Matches an auxiliary verb with the subject
function match_verb_and_subject(subject, verb) {
	if (subject.number == 1 && subject.person == 3) {
		 return(verb.singular);
	}
	else {
		 return(verb.plural);
	}
}

// Matchs the transitive verb's tense with that of the verb
function match_verb_and_tense(verb, phrase) {
	if (verb.tense == "present") {
		return phrase.present;
		//return phrase.active;
	}
	else if (verb.tense == "past") {
		return phrase.past;
	}
	else if (verb.tense  == "active") {
		return phrase.active;
	}
}

// Returns a Daily Mail Headline as a string
function getHeadline() {
	var sentence = [];

	var subject = getRandom(subjects);
		
	var phrase = getRandom(transitive_phrases);
	var verb = getRandom(auxiliary_verbs);
	var object = getRandom(objects);

	//sentence[0] = match_verb_and_subject(subject, verb);
	sentence[1] = subject.word;
	sentence[2] = match_verb_and_tense(verb, phrase);
	sentence[3] = object;
	if (phrase.object != "") sentence[4] = phrase.object;

	var s = sentence.join(" ").toUpperCase();
	//s += "?";

	return s;
}

// Sets the content of div or paragraph element called "mail_headline"
function setHeadline() {
	document.getElementById("mail_headline").innerHTML = getHeadline();
}
