CD.Syllabics = new Class({
	swiff: null,
	soundImg: null,
	initialize: function() {
		CD.PS = new CD.SyllabicSound();
		var cells = document.body.getElements('td');
		if (cells.length > 0) {
			$each(cells, function(cell){
				if ($chk(cell.getProperty('id'))) {
					cell.addEvent('click', this.playSound.bind(cell));
				}
			}.bind(this));
		}
		var soundImg = $('switchsound');
		if ($defined(soundImg)) {
			this.soundImg = soundImg;
			soundImg.getParent().addEvent('click', this.switchSound.bind(this));
		}
	},
	playSound: function(e) {
		var charKeys = this.getProperty('id').split('-');
		CD.PS.playSound(charKeys[0], charKeys[1]);
	},
	switchSound: function(e) {
		new Event(e).stop();
		if ('On' == CD.Conf.syllabicTableSound) {
			CD.Conf.syllabicTableSound = 'Off';
			this.soundImg.setProperties({
				src: CD.Conf.pathImg + 'chartable/sound-off.gif',
				alt: 'Sound Off'
			});
			new CD.Setting('syllabicTableSound', 'Off').save();
		} else {
			CD.Conf.syllabicTableSound = 'On';
			this.soundImg.setProperties({
				src: CD.Conf.pathImg + 'chartable/sound-on.gif',
				alt: 'Sound On'
			});
			new CD.Setting('syllabicTableSound', 'On').save();
		}
	}
});

window.addEvent('onAppReady', function(){
	new CD.Syllabics();
});