var typing = {
    init : function(ele) {
	this.out.target = ele;
    },

    out : {
	target : null,
	text : "",
	write : function(typeWord) {
	    if(typeWord == "\n") typeWord = "</br>";
	    this.target.innerHTML = typeWord + "<b style='background-color:#ffff66'>_</b>";
	},
	clear : function() {
	    this.target.value = "";
	}
    },

    run : function(str) {
	this.originWord = str;
	this.wordIndex = 0;
	this.out.text = "";
	this.out.clear();
	this.typing();
    },

    typing : function() {
	var typeChar = typing.originWord.substr(typing.wordIndex, 1);
	if(typeChar == "") return;
	if(enTypeChar = typing.jpTypeTable[typeChar]) {
	    if(typing.typingIndex ==  (enTypeChar.length-1)) {
		typing.out.text = typing.originWord.substr(0, ++typing.wordIndex);
		typing.out.write(typing.out.text);
		typing.typingIndex = 0;
	    } else {
		typing.out.write(typing.out.text += enTypeChar.substr(typing.typingIndex++, 1));
	    }
	} else {
	    typing.out.write(typing.out.text += typeChar);
	    typing.wordIndex++;
	}

	var typingTime = 100;
	if({'、' : true, '。' : true}[typeChar]) {
	    typingTime = 500;
	}
	setTimeout(typing.typing, typingTime);
	return;
    },
    
    originWord : "",

    typingIndex : 0,

    wordIndex : 0,

    jpTypeTable : {
	    'か' : 'ka', 'き' : 'ki', 'く' : 'ku', 'け' : 'ke', 'こ' : 'ko', 'さ' : 'sa', 'し' : 'si', 'す' : 'su', 'せ' : 'se', 'そ' : 'so',
	    'た' : 'ta', 'ち' : 'ti', 'つ' : 'tu', 'て' : 'te', 'と' : 'to', 'な' : 'na', 'に' : 'ni', 'ぬ' : 'nu', 'ね' : 'ne', 'の' : 'no',
	    'は' : 'ha', 'ひ' : 'hi', 'ふ' : 'fu', 'へ' : 'he', 'ほ' : 'ho', 'ま' : 'ma', 'み' : 'mi', 'む' : 'mu', 'め' : 'me', 'も' : 'mo',
	    'や' : 'ya', 'ゆ' : 'yo', 'よ' : 'yo', 'わ' : 'wa', 'を' : 'wo', 'ん' : 'nn', 'ぁ' : 'xa', 'ぃ' : 'xi', 'ぅ' : 'xu', 'ぇ' : 'xe',
	    'ぉ' : 'xo', 'ゃ' : 'xya', 'ゅ' : 'xyu', 'ょ' : 'xyo', 'が' : 'ga', 'ぎ' : 'gi', 'ぐ' : 'gu', 'げ' : 'ge', 'ご' : 'go', 'ざ' : 'za', 
	    'じ' : 'zi', 'ず' : 'zu', 'ぜ' : 'ze', 'ぞ' : 'zo', 'だ' : 'da', 'ぢ' : 'di', 'づ' : 'du', 'で' : 'de', 'ど' : 'do', 'ば' : 'ba',
	    'び' : 'bi', 'ぶ' : 'bu', 'べ' : 'be', 'ぼ' : 'bo', 'ぱ' : 'pa', 'ぴ' : 'pi', 'ぷ' : 'pu', 'ぺ' : 'pe', 'ぽ' : 'po', 'っ' : 'xtu'
    }
};
