﻿
var CurrentBtn = undefined;
var fppDB = new Array();
var fppTone = new Number;

$(document).ready(function() {

  CreatePinyinDB();

  $("#jquery_jplayer").jPlayer({
    ready: function() { },
    customCssIds: true
  })
  .jPlayer("onSoundComplete", function() {
    if (CurrentBtn != undefined) {
      CurrentBtn.className = 'btnPlay';
      CurrentBtn = undefined;
    }
  })

  /*.jPlayer("onSoundComplete", function() {
  alert("Sound Complete");
  })*/
  /*.jPlayer("onProgressChange", function(lp, ppr, ppa, pt, tt) {
  $("#pcent").text(parseInt(ppa) + "%");
  })*/
  ;

  $("#fppt1").click(function() {
    fppSetTone(1);
    fppPlaySound();
    return false;
  });

  $("#fppt2").click(function() {
    fppSetTone(2);
    fppPlaySound();
    return false;
  });

  $("#fppt3").click(function() {
    fppSetTone(3);
    fppPlaySound();
    return false;
  });

  $("#fppt4").click(function() {
    fppSetTone(4);
    fppPlaySound();
    return false;
  });


  $("#fppPlay").click(function() {
    if (fppTone == 0 || fppTone == undefined) {
      alert('You must select a tone between 1 and 4 first');
    }
    fppPlaySound();
    return false;
  });

  function fppStifinder() {
    return "http://www.standardmandarin.com/sounds/" + forvansketSti();
  }

  function fppPlaySound() {
    var pinyin = $("#fppPinyin").val();
    var isValidPinyin = jQuery.inArray(pinyin, fppDB);
    if (isValidPinyin) {
      $("#jquery_jplayer").jPlayer("setFile", fppStifinder() + pinyin + fppTone + ".mp3").jPlayer("play");
    }
    else {
      alert('Please type a valid pinyin syllable');
    }
  }

  function fppSetTone(ToneNo) {
    if (fppTone == 0 || fppTone == undefined) {
    }
    else {
      $("#fppt" + fppTone).addClass('fpp-tone-' + fppTone);
      $("#fppt" + fppTone).removeClass('fpp-tone-' + fppTone + '-active');
    }
    fppTone = ToneNo;

    $("#fppt" + fppTone).addClass('fpp-tone-' + fppTone + '-active');
    $("#fppt" + fppTone).removeClass('fpp-tone-' + fppTone);
  }

  function sfcc(c) {
    return String.fromCharCode(c);
  }

  function forvansketSti() {
    return sfcc(112) + sfcc(105) + sfcc(110) + sfcc(121) + sfcc(105) + sfcc(110) + sfcc(47);
  }

});

/*
function playMp3(phrase) {
$("#jquery_jplayer").jPlayer("setFile", "http://www.standardmandarin.com/sounds/dailywords/" + phrase + ".mp3").jPlayer("play");
}
*/


function playMp3(btn, phrase) {
  if (CurrentBtn == btn) {
    $("#jquery_jplayer").jPlayer("stop");
    CurrentBtn.className = 'btnPlay';
    CurrentBtn = undefined;
  }
  else {
    if (CurrentBtn != undefined) {
      CurrentBtn.className = 'btnPlay';
    }
    CurrentBtn = btn;
    CurrentBtn.className = 'btnStop';
    $("#jquery_jplayer").jPlayer("setFile", "http://www.standardmandarin.com/sounds/dailywords/" + phrase + ".mp3").jPlayer("play");
  }
}


function CreatePinyinDB() {
  fppDB.push("ba");
  fppDB.push("bo");
  fppDB.push("bai");
  fppDB.push("bei");
  fppDB.push("bao");
  fppDB.push("ban");
  fppDB.push("ben");
  fppDB.push("bang");
  fppDB.push("beng");
  fppDB.push("bi");
  fppDB.push("biao");
  fppDB.push("bie");
  fppDB.push("bian");
  fppDB.push("bin");
  fppDB.push("bing");
  fppDB.push("bu");
  fppDB.push("pa");
  fppDB.push("po");
  fppDB.push("pai");
  fppDB.push("pei");
  fppDB.push("pao");
  fppDB.push("pou");
  fppDB.push("pan");
  fppDB.push("pen");
  fppDB.push("pang");
  fppDB.push("peng");
  fppDB.push("pi");
  fppDB.push("piao");
  fppDB.push("pie");
  fppDB.push("pian");
  fppDB.push("pin");
  fppDB.push("ping");
  fppDB.push("pu");
  fppDB.push("ma");
  fppDB.push("mo");
  fppDB.push("mai");
  fppDB.push("mei");
  fppDB.push("mao");
  fppDB.push("mou");
  fppDB.push("man");
  fppDB.push("men");
  fppDB.push("mang");
  fppDB.push("meng");
  fppDB.push("mi");
  fppDB.push("miao");
  fppDB.push("mie");
  fppDB.push("miu");
  fppDB.push("mian");
  fppDB.push("min");
  fppDB.push("ming");
  fppDB.push("mu");
  fppDB.push("fa");
  fppDB.push("fo");
  fppDB.push("fei");
  fppDB.push("fou");
  fppDB.push("fan");
  fppDB.push("fen");
  fppDB.push("fang");
  fppDB.push("feng");
  fppDB.push("fu");
  fppDB.push("da");
  fppDB.push("de");
  fppDB.push("dai");
  fppDB.push("dei");
  fppDB.push("dao");
  fppDB.push("dou");
  fppDB.push("dan");
  fppDB.push("dang");
  fppDB.push("deng");
  fppDB.push("dong");
  fppDB.push("di");
  fppDB.push("diao");
  fppDB.push("die");
  fppDB.push("diu");
  fppDB.push("dian");
  fppDB.push("ding");
  fppDB.push("du");
  fppDB.push("duo");
  fppDB.push("dui");
  fppDB.push("duan");
  fppDB.push("dun");
  fppDB.push("ta");
  fppDB.push("te");
  fppDB.push("tai");
  fppDB.push("tao");
  fppDB.push("tou");
  fppDB.push("tan");
  fppDB.push("tang");
  fppDB.push("teng");
  fppDB.push("tong");
  fppDB.push("ti");
  fppDB.push("tiao");
  fppDB.push("tie");
  fppDB.push("tian");
  fppDB.push("ting");
  fppDB.push("tu");
  fppDB.push("tuo");
  fppDB.push("tui");
  fppDB.push("tuan");
  fppDB.push("tun");
  fppDB.push("na");
  fppDB.push("ne");
  fppDB.push("nai");
  fppDB.push("nei");
  fppDB.push("nao");
  fppDB.push("nou");
  fppDB.push("nan");
  fppDB.push("nen");
  fppDB.push("nang");
  fppDB.push("neng");
  fppDB.push("nong");
  fppDB.push("ni");
  fppDB.push("niao");
  fppDB.push("nie");
  fppDB.push("niu");
  fppDB.push("nian");
  fppDB.push("nin");
  fppDB.push("niang");
  fppDB.push("ning");
  fppDB.push("nu");
  fppDB.push("nuo");
  fppDB.push("nuan");
  fppDB.push("nü");
  fppDB.push("nüe");
  fppDB.push("la");
  fppDB.push("le");
  fppDB.push("lai");
  fppDB.push("lei");
  fppDB.push("lao");
  fppDB.push("lou");
  fppDB.push("lan");
  fppDB.push("lang");
  fppDB.push("leng");
  fppDB.push("long");
  fppDB.push("li");
  fppDB.push("lia");
  fppDB.push("liao");
  fppDB.push("lie");
  fppDB.push("liu");
  fppDB.push("lian");
  fppDB.push("lin");
  fppDB.push("liang");
  fppDB.push("ling");
  fppDB.push("lu");
  fppDB.push("luo");
  fppDB.push("luan");
  fppDB.push("lun");
  fppDB.push("lü");
  fppDB.push("lüe");
  fppDB.push("za");
  fppDB.push("ze");
  fppDB.push("zi");
  fppDB.push("zai");
  fppDB.push("zei");
  fppDB.push("zao");
  fppDB.push("zou");
  fppDB.push("zan");
  fppDB.push("zen");
  fppDB.push("zang");
  fppDB.push("zeng");
  fppDB.push("zong");
  fppDB.push("zu");
  fppDB.push("zuo");
  fppDB.push("zui");
  fppDB.push("zuan");
  fppDB.push("zun");
  fppDB.push("ca");
  fppDB.push("ce");
  fppDB.push("ci");
  fppDB.push("cai");
  fppDB.push("cao");
  fppDB.push("cou");
  fppDB.push("can");
  fppDB.push("cen");
  fppDB.push("cang");
  fppDB.push("ceng");
  fppDB.push("cong");
  fppDB.push("cu");
  fppDB.push("cuo");
  fppDB.push("cui");
  fppDB.push("cuan");
  fppDB.push("cun");
  fppDB.push("sa");
  fppDB.push("se");
  fppDB.push("si");
  fppDB.push("sai");
  fppDB.push("sao");
  fppDB.push("sou");
  fppDB.push("san");
  fppDB.push("sen");
  fppDB.push("sang");
  fppDB.push("seng");
  fppDB.push("song");
  fppDB.push("su");
  fppDB.push("suo");
  fppDB.push("sui");
  fppDB.push("suan");
  fppDB.push("sun");
  fppDB.push("zha");
  fppDB.push("zhe");
  fppDB.push("zhi");
  fppDB.push("zhai");
  fppDB.push("zhei");
  fppDB.push("zhao");
  fppDB.push("zhou");
  fppDB.push("zhan");
  fppDB.push("zhen");
  fppDB.push("zhang");
  fppDB.push("zheng");
  fppDB.push("zhong");
  fppDB.push("zhu");
  fppDB.push("zhua");
  fppDB.push("zhuo");
  fppDB.push("zhuai");
  fppDB.push("zhui");
  fppDB.push("zhuan");
  fppDB.push("zhun");
  fppDB.push("zhuang");
  fppDB.push("cha");
  fppDB.push("che");
  fppDB.push("chi");
  fppDB.push("chai");
  fppDB.push("chao");
  fppDB.push("chou");
  fppDB.push("chan");
  fppDB.push("chen");
  fppDB.push("chang");
  fppDB.push("cheng");
  fppDB.push("chong");
  fppDB.push("chu");
  fppDB.push("chua");
  fppDB.push("chuo");
  fppDB.push("chuai");
  fppDB.push("chui");
  fppDB.push("chuan");
  fppDB.push("chun");
  fppDB.push("chuang");
  fppDB.push("sha");
  fppDB.push("she");
  fppDB.push("shi");
  fppDB.push("shai");
  fppDB.push("shei");
  fppDB.push("shao");
  fppDB.push("shou");
  fppDB.push("shan");
  fppDB.push("shen");
  fppDB.push("shang");
  fppDB.push("sheng");
  fppDB.push("shu");
  fppDB.push("shua");
  fppDB.push("shuo");
  fppDB.push("shuai");
  fppDB.push("shui");
  fppDB.push("shuan");
  fppDB.push("shun");
  fppDB.push("shuang");
  fppDB.push("re");
  fppDB.push("ri");
  fppDB.push("rao");
  fppDB.push("rou");
  fppDB.push("ran");
  fppDB.push("ren");
  fppDB.push("rang");
  fppDB.push("reng");
  fppDB.push("rong");
  fppDB.push("ru");
  fppDB.push("rua");
  fppDB.push("ruo");
  fppDB.push("rui");
  fppDB.push("ruan");
  fppDB.push("run");
  fppDB.push("ji");
  fppDB.push("jia");
  fppDB.push("jiao");
  fppDB.push("jie");
  fppDB.push("jiu");
  fppDB.push("jian");
  fppDB.push("jin");
  fppDB.push("jiang");
  fppDB.push("jing");
  fppDB.push("jiong");
  fppDB.push("ju");
  fppDB.push("jue");
  fppDB.push("juan");
  fppDB.push("jun");
  fppDB.push("qi");
  fppDB.push("qia");
  fppDB.push("qiao");
  fppDB.push("qie");
  fppDB.push("qiu");
  fppDB.push("qian");
  fppDB.push("qin");
  fppDB.push("qiang");
  fppDB.push("qing");
  fppDB.push("qiong");
  fppDB.push("qu");
  fppDB.push("que");
  fppDB.push("quan");
  fppDB.push("qun");
  fppDB.push("xi");
  fppDB.push("xia");
  fppDB.push("xiao");
  fppDB.push("xie");
  fppDB.push("xiu");
  fppDB.push("xian");
  fppDB.push("xin");
  fppDB.push("xiang");
  fppDB.push("xing");
  fppDB.push("xiong");
  fppDB.push("xu");
  fppDB.push("xue");
  fppDB.push("xuan");
  fppDB.push("xun");
  fppDB.push("ga");
  fppDB.push("ge");
  fppDB.push("gai");
  fppDB.push("gei");
  fppDB.push("gao");
  fppDB.push("gou");
  fppDB.push("gan");
  fppDB.push("gen");
  fppDB.push("gang");
  fppDB.push("geng");
  fppDB.push("gong");
  fppDB.push("gu");
  fppDB.push("gua");
  fppDB.push("guo");
  fppDB.push("guai");
  fppDB.push("gui");
  fppDB.push("guan");
  fppDB.push("gun");
  fppDB.push("guang");
  fppDB.push("ka");
  fppDB.push("ke");
  fppDB.push("kai");
  fppDB.push("kei");
  fppDB.push("kao");
  fppDB.push("kou");
  fppDB.push("kan");
  fppDB.push("ken");
  fppDB.push("kang");
  fppDB.push("keng");
  fppDB.push("kong");
  fppDB.push("ku");
  fppDB.push("kua");
  fppDB.push("kuo");
  fppDB.push("kuai");
  fppDB.push("kui");
  fppDB.push("kuan");
  fppDB.push("kun");
  fppDB.push("kuang");
  fppDB.push("ha");
  fppDB.push("he");
  fppDB.push("hai");
  fppDB.push("hei");
  fppDB.push("hao");
  fppDB.push("hou");
  fppDB.push("han");
  fppDB.push("hen");
  fppDB.push("hang");
  fppDB.push("heng");
  fppDB.push("hong");
  fppDB.push("hu");
  fppDB.push("hua");
  fppDB.push("huo");
  fppDB.push("huai");
  fppDB.push("hui");
  fppDB.push("huan");
  fppDB.push("hun");
  fppDB.push("huang");
  fppDB.push("a");
  fppDB.push("o");
  fppDB.push("e");
  fppDB.push("er");
  fppDB.push("ai");
  fppDB.push("ei");
  fppDB.push("ao");
  fppDB.push("ou");
  fppDB.push("an");
  fppDB.push("en");
  fppDB.push("ang");
  fppDB.push("eng");
  fppDB.push("yi");
  fppDB.push("ya");
  fppDB.push("yao");
  fppDB.push("ye");
  fppDB.push("you");
  fppDB.push("yan");
  fppDB.push("yin");
  fppDB.push("yang");
  fppDB.push("ying");
  fppDB.push("yong");
  fppDB.push("wu");
  fppDB.push("wa");
  fppDB.push("wo");
  fppDB.push("wai");
  fppDB.push("wei");
  fppDB.push("wan");
  fppDB.push("wen");
  fppDB.push("wang");
  fppDB.push("weng");
  fppDB.push("yu");
  fppDB.push("yue");
  fppDB.push("yuan");
  fppDB.push("yun");
}

