(function () {

  var langs = ['zh','ar','fr','de','it','ja','ko','pt','ru','es','nl'];

  var strs = ["400GB空间，长期保存",
  						"免费会员200KB/秒",
  						"多文件可同时下载",
  						"VIP会员不限速下载",
  						"下载次数越多，文件保存越久",
  						"超高佣金超级赚钱",
  						"单文件最大4GB",
  						"VIP文件可直接外链"];
  var index = 0;
  var container = document.getElementById('homepage-welcome');

  var COLOR_START = 240;
  var COLOR_END = 40;
  var FONT_START = .1;

  var color;
  var font;

  var fiTimer;
  var foTimer;

  var STEP = 40;
  var COLOR_STEP_IN = -5;
  var COLOR_STEP_OUT = 10;
  var FONT_STEP = 0.015;

  function welcome_go() {
    var str = '欢迎使用CTDISK网络硬盘';
    strs.push(str);
    displayCurrent();
   // for (l in langs) {
      //var destLang = langs[l];
      //google.language.translate(str, 'en', destLang, translated);
    //}
  }
	
  function translated(result) {
    if (!result.error && result.translation) {
      strs.push(result.translation);
      if (strs.length == 4) {
        displayCurrent();
      }
    }
  }

  function displayCurrent() {
    color = COLOR_START;
    font = FONT_START;

    container.style.display = 'none';
    container.style.fontSize = font + 'em';
    container.style.color = 'rgb('+color+','+color+','+color+')';
    container.innerHTML = strs[index];
    container.style.display = '';

    fiTimer = window.setInterval(fadeIn, STEP);
    if ((++index) >= strs.length) index=0;
  }

  function fadeOut() {
    color = Math.min(255, color + COLOR_STEP_OUT);
    container.style.color = 'rgb('+color+','+color+','+color+')';
    if (color == 255) {
      clearInterval(foTimer);
      displayCurrent();
    }
  }

  function fadeIn() {
    color += COLOR_STEP_IN;
    font = Math.min(1, font+FONT_STEP);
    container.style.fontSize = font + 'em';
    container.style.color = 'rgb('+color+','+color+','+color+')';
    if (color <= COLOR_END) {
      clearInterval(fiTimer);
      foTimer = window.setInterval(fadeOut, STEP);
    }
  }

  // expose
  window['start_welcome'] = welcome_go;

}) ();
