//<!--

adjs = new Array("deadly","evil","malicious","naked","sinful","deadly","sensual","cruel","sexual",
"lustful","forbidden","sinister","tawdry","guilty","dangerous","body","fatal","bedroom","bare","friendly","double",
"triple","wild","female","twisted","burning","hard","family","scandalous","stripped","night","dark","hot","haunting",
"hidden","basic","random","virtual","human","erotic","intimate","destructive","fleshly","carnal","animal","criminal",
"obsessive","nightly","blue","dangerous","lethal","predatory","wicked","body of","deep","indecent","midnight","private",
"secret","tainted","victim of","final","the last","the color of","cold","illicit","possessed by","fugitive",
"the height of","the point of","return to","perfect","concealed","full","unnatural","trial of","the art of",
"urge for","sultry","inhuman","the heart and the","heavy","violated by"); 

nouns = new Array("lies","games","obsessions","misfortunes","obsession","liasons","heat","malice", "malevolence",
"instincts","intentions","desires","sins","suspicions","suspicion","chemistry","passion","perversions","attraction",
"eyes","seduction","roulette","kiss","crimes","bodies","evidence","requirements","fear","dance","confessions","sweat",
"secrets","affairs","agenda","encounters","touch","emotions","inhibitions","knowledge","inhibitions","deception",
"embrace","vice",".com","night","watch","witness","hunter","exposure","curves","predator","motives","murder","murders",
"awakenings","influence","boundaries","illusions","behavior","temptations","love","beauty","desire","dreams","fire",
"response","justice","pursuit","eden","favours","discretion","weapon","lessons","orchid","relations","bounty",
"interludes","fascination","hunger","sisters","revelations","temptress","aggression"); 
// sins 2: point of seduction","desires 3: the temptress","obsession 2: don't tell"

function TitleGenerator() {
	
	this.getTitle = function() {
		return randElem(adjs) + ' ' + randElem(nouns);
	},
	
	this.getSequelStr = function() {	
		var num = Math.randRange(2,8);
		return num + ': ' + this.getTitle();
	}
	
	this.toggleGroove = function() {
		box = document.getElementById('titlebox');
		if(!document.getElementById('enableGroove').checked) {
			//turn off groove
			box.style.fontStyle = '';
			box.style.fontWeight = '';
			box.style.backgroundColor = 'black';
			box.style.color = 'white';
		} 
		else {
			//turn on groove
			box.style.fontStyle = 'italic';
			box.style.fontWeight = 'bold';
			box.style.backgroundColor = 'purple';
			box.style.color = 'white';
		}
	}
	
	this.populate = function() {
		var result = this.getTitle();
		if(document.getElementById('enableSequels').checked) {
			if(Math.random() < .35) {	// 35% chance of a sequel
				result += ' ' + this.getSequelStr();
			}
		}
		result = result.compress().titleCase();
		document.getElementById('titlebox').innerHTML = '' + result;
		
		this.updateSizebox();
	}
	
	this.updateSizebox = function() {
		document.getElementById('sizebox').innerHTML = '' + this.getSize().commafy();
	}
	
	this.getSize = function() {
		return document.getElementById('enableSequels').checked ? 
			Math.pow(adjs.length * nouns.length, 2) :
			adjs.length * nouns.length;
	}
}

// TODO: define this on Array without breaking titleCase??!
function randElem(arr) {
	var idx = Math.randRange(0, arr.length);
	return arr[idx];
}

// Clean up stuff like "foo .com"	
String.prototype.compress = function () {
	return this.replace(/\b\s(\W)/,"$1");
}	

String.prototype.titleCase = function () {
	var str = "";
	var wrds = this.split(" ");
	for (i in wrds) {
		if (typeof(i) != "string")
			continue;
		var word = wrds[i];
		str += ' ' + word.substr(0,1).toUpperCase() + word.substr(1,word.length);
	}
	return str;
}

Number.prototype.commafy = function () {
	var arr = new Array();
	var str = this.toString();
	for (i=str.length,j=1; i>0; i--,j++) {
		arr.push(str.charAt(i-1));
		if(j%3 == 0)
			arr.push(',');
	}
	var result='';
	while (arr.length>0)
		result += arr.pop();
	return result;
}

Math.randRange = function (min, max) {
	return Math.floor(Math.random()*max + min);
}

//-->