var mySwiper = null,
	mySwiper2 = null;
var mask1 = null,
	mask2 = null; //彈窗
var interval1 = null,
	interval2 = null,
	interval3 = null;
var flag1 = true,
	flag2 = true,
	flag3 = true;


var _url = 'http://ceshi.yabolive.tv/web';
var _url2 = 'http://test.ybact.yazhaiyabo.com/';
var _url3 = 'http://ceshi.yabolive.tv';


if(location.href.indexOf('activity.yazhaiyabo.com') > -1) {
	_url = 'https://webserver.yabolive.net';
	_url2 = 'https://activity.yazhaiyabo.com/';
	_url3 = 'https://webserver.yabolive.net';
}
var cdn = 'https://big.bgp.ourpow.com/comm';

function $ajax(opt) {
	return new Promise(function(resolve, reject) {
		opt = opt || {};
		opt.method = opt.type || 'POST';
		opt.url = _url + opt.url || '';
		opt.async = opt.async || true;
		opt.data = opt.data || null;
		opt.dataType = opt.dataType || 'json';
		opt.success = opt.success || function() {};
		var xmlHttp = null;
		if(XMLHttpRequest) {
			xmlHttp = new XMLHttpRequest();
		} else {
			xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
		}
		var params = ['uid=' + getRequest().uid, 'cid=web_gw', 'os=WEB', 'token=' + getRequest().token, 'lang=' + (getRequest().lang || 2)];
		for(var key in opt.data) {
			params.push(key + '=' + (opt.data[key] || ''));
		}

		var postData = params.join('&');
		if(opt.method.toUpperCase() === 'POST') {
			xmlHttp.open(opt.method, opt.url, opt.async);
			xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
			xmlHttp.send(postData);
		} else if(opt.method.toUpperCase() === 'GET') {
			xmlHttp.open(opt.method, opt.url + '?' + postData, opt.async);
			xmlHttp.send(null);
		}
		xmlHttp.onreadystatechange = function() {
			var res;
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				res = xmlHttp.responseText;
				if(opt.dataType == 'json') {
					res = JSON.parse(res);
				}
				resolve(res);
			}
		};
	})
}

var currencyUnit = ''; //寶石 貨幣單位
var currencyImg = ''; //寶石圖片
var incomeUnit = ''; //螢火 收益單位
var incomeImg = ''; //螢火圖片
var headUrl = ''; //默認頭像url
var currencyImg2 = ''; //寶石圖片 小
var giftObjImg = '';
			
function getInit() {
	return new Promise(function(resovle, reject) {
		$ajax({
			url: '/active201904/getUserInfo.html',
		}).then(function(res) {
			if(res.vest == 41) {
				if(url_get_params().appversion < 5960) {
					currencyUnit = '樱花'; //貨幣單位
					incomeUnit = '花瓣'; //收益單位
					headUrl = 'https://app.ixiulive.com/static/images/headc.png';
					currencyImg = '<img class="current2" src="https://app.ixiulive.com/static/images/current2.png" />';
					currencyImg2 = 'https://app.ixiulive.com/static/images/current2s.png';
					incomeImg = '<img class="income2" src="https://app.ixiulive.com/static/images/income2.png" />';
					giftObjImg = 'https://app.ixiulive.com/static/images/current2.png';
				} else {
					currencyUnit = '寶石'; //貨幣單位
					incomeUnit = '羽毛'; //收益單位
					headUrl = 'https://app.ixiulive.com/static/images/head2.png';
					currencyImg = '<img class="current4" src="https://app.ixiulive.com/static/images/current4.png" />';
					currencyImg2 = 'https://app.ixiulive.com/static/images/current4s.png';
					incomeImg = '<img  class="income4" src="https://app.ixiulive.com/static/images/income4.png" />';
					giftObjImg = 'https://app.ixiulive.com/static/images/current4.png';
				}
			} else if(res.vest == 40) {
				currencyUnit = '金幣'; //貨幣單位
				incomeUnit = '金豆'; //收益單位
				headUrl = 'https://app.ixiulive.com/static/images/headp.png';
				currencyImg = '<img class="current3" src="https://app.ixiulive.com/static/images/current3.png" />';
				currencyImg2 = 'https://app.ixiulive.com/static/images/current3s.png';
				incomeImg = '<img class="income3" src="https://app.ixiulive.com/static/images/income3.png" />';
				giftObjImg = 'https://app.ixiulive.com/static/images/current3.png';
			} else if(res.vest == 50 || res.vest == 60) {
				currencyUnit = '寶石'; //貨幣單位
				incomeUnit = '羽毛'; //收益單位
				headUrl = 'https://app.ixiulive.com/static/images/head2.png';
				currencyImg = '<img class="current4" src="https://app.ixiulive.com/static/images/current4.png" />';
				currencyImg2 = 'https://app.ixiulive.com/static/images/current4s.png';
				incomeImg = '<img  class="income4" src="https://app.ixiulive.com/static/images/income4.png" />';
				giftObjImg = 'https://app.ixiulive.com/static/images/current4.png';
			} else {
				currencyUnit = '寶石'; //貨幣單位
				incomeUnit = '螢火'; //收益單位
				headUrl = 'https://zhibocdn.yabolive.net/comm/user/boy.png';
				currencyImg = '<img class="current1" src="https://app.ixiulive.com/static/images/current1.png" />';
				currencyImg2 = 'https://app.ixiulive.com/static/images/current1s.png';
				incomeImg = '<img class="income1" src="https://app.ixiulive.com/static/images/income11.png" />';
				giftObjImg = 'https://app.ixiulive.com/static/images/current1.png';
			}
			resovle(res);
		})
	})
}

//跳转到规则

document.getElementsByClassName('rule')[0].onclick = function(){
	window.location.href = 'rule.html' + location.search;
}

//关闭弹窗
function closeMasking(){
	layer.closeAll();
}

function getTime(time) {
	var timezone = 8; //目标时区时间,东八区
	var offset_GMT = new Date(time).getTimezoneOffset(); // 本地时间和格林威治的时间差,单位为分钟
	var nowDate = new Date(time).getTime(); // 本地时间距 1970 年 1 月 1 日午夜(GMT 时间)之间的毫秒数
	var data = new Date(nowDate + offset_GMT * 60 * 1000 + timezone * 60 * 60 * 1000);

	var year = data.getFullYear();
	var month = data.getMonth() + 1;
	var day = data.getDate();
	var hour = data.getHours();
	var minute = data.getMinutes();
	var sec = data.getSeconds();

	var obj = {
		"year": year,
		"month": add0(month),
		"day": add0(day),
		"hour": add0(hour),
		"minute": add0(minute),
		"sec": add0(sec),
	}

	return obj;
}

//加0
function add0(m) {
	return m < 10 ? '0' + m + "" : m + ""
}

//获取url参数
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;
}

function close() {
	var obj = {
		"cid": 14,
		"reqCode": new Date().getTime(),
		"data": {
			"msg": '關閉半屏網頁',
		}
	}
	var obj2 = JSON.stringify(obj);
	appCollaboration(obj2);
}

function appCollaboration(msg) {
	var sUserAgent = navigator.userAgent.toLowerCase();
	var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
	var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
	var bIsMidp = sUserAgent.match(/midp/i) == "midp";
	var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
	var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
	var bIsAndroid = sUserAgent.match(/android/i) == "android";
	var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
	var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
	if(!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM)) {} else if(bIsAndroid) {
		window.yazhai.appCollaboration(msg);
	} else if(bIsIphoneOs || bIsIpad) {
		window.webkit.messageHandlers.appCollaboration.postMessage(msg);
	}
}
//客户端回调结果
function appCallback(msg) {
	console.log(msg);
}