/**
 * 
 * @authors Your Name (you@example.org)
 * @date    2017-08-02 17:23:52
 * @version $Id$
 */

var langInit = function () {
	var langObj = {
		cn: '简体',
		gb: '繁体',
		en: 'EN'
	};
	var currentLang = TD.util.getQuery('lang');

	// 根据当前语言设置导航栏的语言显示
	if (currentLang !== '') {
		$('.nav-lang-current').html('<div class="nav-lang-item">' + langObj[currentLang] + '</div>')
		$('.lang-' + currentLang).hide();
	} else {
		$('.lang-cn').hide();
	};

	// 事件委托
	$('.nav-lang-hidden').on('click', function () {
		var target = window.event.target || window.event.srcElement;

		if (target.nodeName.toLowerCase() === 'li') {
			// 识别选取的语言并转换成xx格式
			var nextLang = $(target).attr('class').match(/lang\-(cn|gb|en)/g).toString().replace('lang-', '');

			TD.util.setCookie('lang',nextLang,7);

			if (currentLang !== '') {
				location.href = location.href.replace('lang=' + currentLang, 'lang=' + nextLang);
			} else if (TD.util.getQuery('=')) {
				location.href += '&lang=' + nextLang;
			} else {
				location.href += '?lang=' + nextLang;
			};
		};
	});
};

var pageInit = function () {
	langInit();

	$('.m-maofm').fullpage({
		easingcss3: 'cubic-bezier(.62,.01,0,1)'
		// scrollOverflow: true
	});

	TD.imgPreload(function () {
		$('.m-loading').fadeOut(300);
	})
}

$(document).ready(function () {
	pageInit();
})
