document.observe("dom:loaded", function() {
    $$('.b-scale a').each(function(noteLink) {
        var noteOptions = noteLink.onclick instanceof Function ? noteLink.onclick() : {};

        // Заметаем следы - обнуляем onclick
        noteLink.onclick = null;
        noteLink.removeAttribute('onclick');

        noteLink.observe('click', function(evt) {
            var el = evt.element();
            // Навешиваем обработчик onclick для показа попапа
            showChart(noteOptions.chart, el);
        });
    });
});
    

    function showChart(chart, element) { //e.g. F# for whistle: xxxxoo
        var chart = chart;
        var el = element;
        var i = 0;

        $$('.note').invoke('removeClassName', 'active');
        el.up('.note').addClassName('active');
        $('currentNote').update(el.up('.note').down('.note-title').innerHTML)

        $$('#instrumentScheme .hole').each(function(e) {
            $w('closed open half-open').each(function(s) {
                e.removeClassName(s);
            });
            switch ($A(chart)[i]) {
                case 'x':
                    e.addClassName('closed');
                    break;
                case 'o':
                    e.addClassName('open');
                    break;
                case '/':
                    e.addClassName('half-open');
                    break;
                default:
            }
            i++;
        });
        //document.cookie = this.type + "Scheme=" + chart + ";max-age=" + (60 * 60 * 24 * 365);
        //alert(document.cookie);
    }


