/* generated javascript */
if (!window.skin) {
	var skin = 'monaco';
	var stylepath = 'http://images.wikia.com/common/releases_200911.4/skins';
}

/* MediaWiki:Common.js */
/* Any JavaScript here will be loaded for all users on every page load. */

//YAHOO.util.Event.onDOMReady(chords); 

function chords() {
        var chords = YAHOO.util.Dom.getElementsByClassName('chords'); 
        for (c=0; c<chords.length; c++) {
                doChords(chords[c]);
        }
}

function doChords(chord) {
        chord.style.fontFamily = 'Courier';

	var notes = new Array();
	var lyrics = new Array();
	var order = new Array();
	var tempNotes = '';
	var tempLyrics = '';
	var offset = '';
	
	for (i=0; i<chord.childNodes.length; i++) {
		var thisNode = chord.childNodes[i];
		
  	if (thisNode.nodeType == 3) {
  		if (thisNode.nodeValue.indexOf("\n") > -1) {
  			valueArray = thisNode.nodeValue.split("\n");
  			for (k=0; k<valueArray.length; k++) {
  				tempLyrics += valueArray[k];
	  			addSpaces(valueArray[k].length - offset);
	  			offset = '';
  				if (k != valueArray.length - 1) {
  					if (valueArray[k] == '') {
  						tempLyrics += "\n";	
  					}
	  				pushArrays();	
  				}
  			}
  		} else {
				tempLyrics += thisNode.nodeValue;	
	  		addSpaces(thisNode.nodeValue.length - offset);
	  		offset = '';
  		}
  	}
  	if (thisNode.nodeType == 8) {
  		tempNotes += thisNode.nodeValue;
  		offset = thisNode.nodeValue.length;
  	}
	}
	writeChords();

	function writeChords() {
                alert(order);	
		chord.innerHTML = '';

		var notesCount = 0;
		var lyricsCount = 0;

		for (i=0; i<order.length; i++) {
			if (order[i] == 'notes') {
				if (i>0) {
					chord.innerHTML += "\n";	
				}
				chord.innerHTML += notes[notesCount];
				notesCount++;
			}	else if (order[i] == 'lyrics') {
				chord.innerHTML += lyrics[lyricsCount];	
				lyricsCount++;
			}
		}
	}

	function addSpaces(num) {
		for (j=0; j<num; j++) {
			tempNotes += ' ';
		}	
	}
	
	function pushArrays() {
		if (tempNotes) {
			testNotes = tempNotes.replace(/(^\s*|\s*$)/, "");
			if (testNotes) {
				order.push('notes');
				tempNotes += "\n";
				notes.push(tempNotes);
			}
		}
		if (tempLyrics) {
			tempLyrics += "\n";
			order.push('lyrics');	
			lyrics.push(tempLyrics);
		}
		tempNotes = tempLyrics = '';	
	}
}

/* MediaWiki:Monaco.js */
