var abcEditor = null;
var abcEditArea = null;

YUI().use('node', function(Y) {
	function show_tune() {
		var tune_name = this._node.innerHTML;
		var old_selections = Y.all(".tune_selected");
		old_selections.removeClass('tune_selected');
		this.addClass('tune_selected');
		tune_name = tune_name.replace(/\W/g,'_').toLowerCase();
		var abc = Y.one("#"+tune_name+ ' code');
		if (abc) {
			abc = abc._node.innerHTML;
			abc = abc.replace(/<br>/g, '');

			if (abcEditArea === null) {
				function StaticArea() {
					this.abc = "";
					this.getSelection = function() {return null;};
					this.setSelection = function() { };
					this.getString = function() {return this.abc;};
					this.setString = function(str) {
						var canvas = Y.one("#canvas")._node;
						canvas.innerHTML = "<center><img src='/wp-content/themes/renownedmint/images/progress_transparent.gif' alt='Please wait' /></center>";
						this.abc = str;
						if (this.changelistener)
							this.changelistener.fireChanged();
					};
					this.addSelectionListener = function(listener) { };
					this.addChangeListener = function(listener) {this.changelistener = listener;};
				}
				abcEditArea = new StaticArea();
			}
			abcEditArea.setString(abc);
			if (abcEditor === null)
				abcEditor = new ABCEditor(abcEditArea, {canvas_id: "canvas", midi_id:"midi"});
		}
	}

	Y.on("click", show_tune, ".dots_menu li");
});


