var noteCollection = new Array();
function notes() {
  noteCollection = collectClass('noteView','div');
	for (var i = 0; i < noteCollection.length; i++) {
		var ele = noteCollection[i];
		if (isClassName(ele,"noteView")) {
			ele.id = "note" + i;
		}
	}
	if ( noteCollection.length > 0 ) {
		unloadAllNoteViews();
		prepareNoteViews();
	}
}

function prepareNoteViews() {
	var notes = noteCollection;
	for (var i = 0; i < notes.length; i++) {
		var linkText = notes[i].getElementsByTagName('h3');
		noteElementLink = document.createElement("h3");
	  noteElementLink.innerHTML = '<a href="javascript:showNoteView(' + "'" + notes[i].id + "'" + ')">' + linkText[0].innerHTML + '</a>';
	  notes[i].parentNode.insertBefore(noteElementLink, notes[i]);
		removeElement(notes[i],linkText[0]);
	}
}

function showNoteView(id) {
	if (isLoaded(id)) {
		unloadHTML(id);
	}
	else {
		unloadAllNoteViews();
		loadHTML(id);
	}
}

function unloadAllNoteViews() {
	var notes = noteCollection;
	for (var i = 0; i < notes.length; i++) {
		if (document.getElementById(notes[i].id)) {
			unloadHTML(notes[i].id);
		}
	}
}
