var marysMessages = new Array("Dear Madam or Sir,\n As you kindly may" +
	" know, I am trying to figure out what 'red' is. So please" +
	" leave me alone."," Please do not disturb me in my studies.", 
	"I am growing impatient... Please keep to yourself. There is plenty to study" +
	" below me.", "Ay! Ya get yer bloody hands off me, bloody fool! Your"+
	" mother was a" +
	" hamster and your father smelt of elderberries!");
var marysMessageNumber = 0;

// For Spaghetti Monster
var spaghetti;
var leftMov = -2;
var topMov = 2;

//For dynamic content
var current;
var directoryDepth;


function displayMarysMessage() {
	alert(marysMessages[marysMessageNumber]);
	if (marysMessageNumber != 3) {
		marysMessageNumber += 1;
	}
	return;

}

function actionSpaghetti() {
	spaghetti = document.getElementById('spaghetti');
	setInterval('moveSpaghetti(spaghetti)', 15);
	
} 

function moveSpaghetti(spaghetti) {
	var temp = spaghetti.style.left;
	var leftPos = parseInt(temp.replace('px',''));
	temp = spaghetti.style.top;
	var topPos = parseInt(temp.replace('px',''));
	
	if(leftPos <= 0 || leftPos >= 514) {
		leftMov = -leftMov;
	}
	if(topPos <= 182 || topPos >= 456) {
		topMov = -topMov;
	}
	
	leftPos = leftPos + leftMov;
	topPos = topPos + topMov;
	
	spaghetti.style.top = topPos +'px;'
	spaghetti.style.left = leftPos + 'px;'
}


function dynamicContent() {
	var banner = document.getElementById('banner');
	var navbar = document.getElementById('navbar');
	
	findCurrentPageDirDepth();
	
	if(directoryDepth == 0) {
		//Banner
		
		banner.innerHTML =
			'<img src="littlegirl.jpg" onclick="displayMarysMessage();"/>' +
			'<span>...What Mary Didn&#39;t Know...</span>';
			
		//Navigation Bar	
		
		navbar.innerHTML ='<a href="index.html">Home</a>'+
			'<a href="philosophical.html">Philosophical Bits</a>'+
			'<a href="otherwritings.html">Other Writings</a>'+
			'<a href="links.html">Links</a>';
	 navbar.childNodes[current].id = 'current';
	} else if (directoryDepth == 1) {
		banner.innerHTML =
			'<img src="../littlegirl.jpg" onclick="displayMarysMessage();"/>'+
		'<span>...What Mary Didn&#39;t Know...</span>';
		navbar.innerHTML ='<a href="../index.html">Home</a>'+
			'<a href="../philosophical.html">Philosophical Bits</a>'+
			'<a href="../otherwritings.html">Other Writings</a>'+
			'<a href="../links.html">Links</a>';
			navbar.childNodes[current].id = 'current';
	
	}
		
}

function findCurrentPageDirDepth() {

	var first_split = document.URL.split("//");
	var without_resource = first_split[1];
	var second_split = without_resource.split("/");
	
	if(second_split[second_split.length - 1] == 'index.html') {
		current = 0;
		directoryDepth = 0;	
	}else if(second_split[second_split.length - 1] == 'flyspaghetti.html') {
		current = 0;
		directoryDepth = 0;	
	}else if(second_split[second_split.length - 1] == 'philosophical.html') {
		current = 1;
		directoryDepth = 0;
	}else if(second_split[second_split.length - 1] == 'otherwritings.html') {
		current = 2;
		directoryDepth = 0;
	}else if(second_split[second_split.length - 1] == 'links.html') {
		current = 3;
		directoryDepth = 0;
	}else if(second_split[second_split.length - 2] == 'philosophical') {
		current = 1;
		directoryDepth = 1;
	}else if(second_split[second_split.length - 2] == '~cihanb') {
		current = 0;
		directoryDepth = 0;
	}

	
	
}