/*
 * @package AJAX_Chat
 * @author Sebastian Tschan
 * @copyright (c) 2007 Sebastian Tschan
 * @license http://creativecommons.org/licenses/by-sa/
 * @link https://blueimp.net/ajax/
 */

// Overriding client side functionality:

/*
// Example - Overriding the replaceCustomCommands method:
ajaxChat.replaceCustomCommands = function(text, textParts) {
	return text;
}
 */

// Return replaced text for custom commands
// text contains the whole message, textParts the message split up as words array
ajaxChat.replaceCustomCommands = function(text, textParts) {
   switch(textParts[0]) {
      case '/myip':
         return '<span class="chatBotMessage">' + this.lang['myip'].replace(/%s/, textParts[1]) + '</span>';
      case '/myname':
         return '<span class="chatBotMessage">' + this.lang['myname'].replace(/%s/, textParts[1]) + '</span>';
      default:
         return text;
   }
}

//Sounds
ajaxChat.customInitialize = function() {
   try {
      soundManager.url = 'soundmanager/soundmanager2.swf';
      soundManager.debugMode = false;
      soundManager.onload = function(){
         soundManager.createSound({
            id: 'chatbot',
            url: 'soundmanager/chatbot.mp3'
         });
         soundManager.createSound({
            id: 'incoming',
            url: 'soundmanager/incoming.mp3'
         });
         soundManager.createSound({
            id: 'outgoing',
            url: 'soundmanager/outgoing.mp3'
         });
         soundManager.createSound({
            id: 'welcome',
            url: 'soundmanager/welcome.mp3'
         });
         soundManager.createSound({
            id: 'notify',
            url: 'soundmanager/notify.mp3'
         });

         soundManager.play('welcome');
      }
   } catch (e) {
   }
}

ajaxChat.onNewMessage = function(dateObject, userID, userName, userRoleClass, messageID, messageText, ip) {
   try {
	if(document.getElementById('toggleMute').checked == false) {
      		if(userID == this.chatBotID) {
			if(messageText.search(/login/) > 0 || messageText.search(/logout/) > 0 || messageText.search(/channelEnter/) > 0 || messageText.search(/channelLeave/) > 0 || messageText.search(/\/query/) > 0 || messageText.search(/error/) > 0) {
				soundManager.play('notify');
			} else {
				soundManager.play('chatbot');
			}
      		}
      		else if(userID != this.userID) {
         		soundManager.play('incoming');
      		} else {
         		soundManager.play('outgoing');
      		}
	}
   } catch (e) {
   }
   
   return true;
}

