var swiper = new Swiper('.swiper-container', {
  	loop: true,
    speed:300,
    observer: true,	
    observerParents: true,
    autoplayDisableOnInteraction: false,
	  autoplay : {
	    delay:4000
	  },
	   onSlideChangeEnd: function(swipers){ 
        swipers.update(); //swiper更新
    },
    pagination: {
    el: '.swiper-pagination',
  },
});

var langList = [
	//中文 英文 阿拉伯文
	{
		foot1:'儲值',
		foot2:'https://footseen.com/img/img1_cn.png',
		foot3:'https://footseen.com/img/img2_cn.png',
		foot4:'https://footseen.com/img/img3_cn.png',
		foot5:'下載APP',
		foot6:'邀請碼:',
		foot7:'複製成功',
	},
	{
		foot1:'Top-up',
		foot2:'https://footseen.com/img/img1_en.png',
		foot3:'https://footseen.com/img/img2_en.png',
		foot4:'https://footseen.com/img/img3_en.png',
		foot5:'Download APP',
		foot6:'Invitation code:',
		foot7:'Copy success',
	},
	{
		foot1:'شحن',
		foot2:'https://footseen.com/img/img1_ar.jpg',
		foot3:'https://footseen.com/img/img2_ar.jpg',
		foot4:'https://footseen.com/img/img3_ar.jpg',
		foot5:'تحميل التطبيق',
		foot6:'شفرة الدعوة:',
		foot7:'تم النسخ بنجاح',
	}
]
var langType = 0;
var langStr =(navigator.language || navigator.browserLanguage).toLowerCase();
if(sessionStorage.lang == undefined || sessionStorage.lang == 'undefined'){
	if(langStr.indexOf('ar')>=0){
		sessionStorage.lang = 7;
		$('.langTitle font').html('العربية');
		langType = 2;
		$('.langList p').eq(2).addClass('check');
	} else if(langStr.indexOf('zh')>=0){
		sessionStorage.lang = 2;
		$('.langTitle font').html('繁體中文');
		langType = 0;
		$('.langList p').eq(0).addClass('check');
	} else {
		sessionStorage.lang = 1;
		$('.langTitle font').html('English');
		langType = 1;
		$('.langList p').eq(1).addClass('check');
	}
} else {
	 if(sessionStorage.lang == 7){
		langType = 2;
		$('.langTitle font').html('العربية');
		$('.langList p').eq(2).addClass('check');
	} else if(sessionStorage.lang == 2){
		langType = 0;
		$('.langTitle font').html('繁體中文');
		$('.langList p').eq(0).addClass('check');
	} else {
		langType = 1;
		$('.langTitle font').html('English');
		$('.langList p').eq(1).addClass('check');
	}
}

$(function(){
	lang();
	$('.langTitle').on('click',function(e){
		$('.langList').show();
		$('.langTitle img').attr('src','https://footseen.com/img/up2.png');
		e.stopPropagation();
	})
	$('.langList p').on('click',function(e){
		$(this).addClass('check').siblings().removeClass('check');
		$('.langTitle font').html($(this).html());
		$('.langList').hide();
		$('.langTitle img').attr('src','https://footseen.com/img/down2.png');
		sessionStorage.lang = $(this).attr('data-lang');
		lang();
		e.stopPropagation();
	})
	$(document).on('click',function(e){
		$('.langList').hide();		
		$('.langTitle img').attr('src','https://footseen.com/img/down2.png');

		e.stopPropagation();
	})
})

function lang(){
	if(sessionStorage.lang == 1){
		langType = 1;
	} else if(sessionStorage.lang == 2){
		langType = 0;
	} else if(sessionStorage.lang == 7){
		langType = 2;
	}
	$('.code span').html(langList[langType].foot6+getRequest().agentCode);
	$('.swiper-container').removeClass('hide');
	var str = '';
	str += '<div class="swiper-wrapper">';
	str += '	<div class="swiper-slide">';
	str += '		<img src="'+langList[langType].foot2+'"/>';
	str += '	</div>';
	str += '	<div class="swiper-slide">';
	str += '		<img src="'+langList[langType].foot3+'"/>';
	str += '	</div>';
	str += '	<div class="swiper-slide">';
	str += '		<img src="'+langList[langType].foot4+'"/>';
	str += '	</div>';
	str += '</div>';
	str += '<div class="swiper-pagination"></div>';
	$('.swiper-container').html(str);
		this.swiper.destroy(false);
		this.swiper = new Swiper('.swiper-container', {
	  	loop: true,
	    speed:300,
	    observer: true,	
	    observerParents: true,
	    autoplayDisableOnInteraction: false,
		  autoplay : {
		    delay:4000
		  },
		   onSlideChangeEnd: function(swipers){ 
	        swipers.update(); //swiper更新
	    },
	    pagination: {
		    el: '.swiper-pagination',
		  },
	});
	$('.topUp').html(langList[langType].foot1);
	$('.iosDown').html(langList[langType].foot5);
}

function getRequest() {
		  var url = location.href;
		  var theRequest = new Object();
		  if (url.indexOf("?") != -1) {
		      var str = url.substr(url.indexOf("?") + 1);
		      strs = str.split("&");
		      for (var i = 0; i < strs.length; i++) {
		          theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		      }
		  }
		  return theRequest;
		}