var href = window.location.href;
if(href.indexOf('?')!=-1){
   href=window.location.href.split('?')[0];
} else {
	if(href.indexOf('#')!=-1){
		href=window.location.href.split('#')[0];
	}
}
href = href + "?";
var isAnswer=false;

$(function() {
	var obj1 = dc("page1"),
    obj2 = dc("page2"),
    obj3 = dc("page3"),
    obj4 = dc("page4"),
    obj5 = dc("page5"),
    obj6 = dc("page6"),
    obj7 = dc("page7"),
    obj8 = dc("page8"),
    obj9 = dc("page9");
    $('.bg_1').append('<div class="top_title"><img src="http://h5.iamberry.com/iamberry/wechat/test/images/2-1.png"><div class="one_1"><img src="http://h5.iamberry.com/iamberry/wechat/test/images/1-1.png"></div></div><div id="action" style="position: relative;text-align: center;"></div></div>');
    document.addEventListener("touchmove", function(b) {
        b.preventDefault()
    }, false);
	$("#page1").on("swipeUp", function() {
	    Mobilebone.transition(obj2, obj1, false)
	});
	$("#page2").on("swipeUp", function() {
	    Mobilebone.transition(obj3, obj2, false)
	});
	$("#page3").on("swipeUp", function() {
	    Mobilebone.transition(obj4, obj3, false)
	});
	$("#page4").on("swipeUp", function() {
	    Mobilebone.transition(obj5, obj4, false)
	});
	$("#page5").on("swipeUp", function() {
	    Mobilebone.transition(obj6, obj5, false)
	});
	$("#page6").on("swipeUp", function() {
	    Mobilebone.transition(obj9, obj6, false)
	});
	$("#page8").off().on("swipeUp", function() {
	    Mobilebone.transition(obj9, obj8, false)
	});
	$("#page9").on("swipeUp", function() {
	    Mobilebone.transition(obj1, obj9, false)
	});
	$("#page1").on("swipeDown", function() {
	    Mobilebone.transition(obj9, obj1, true)
	});
	$("#page2").on("swipeDown", function() {
	    Mobilebone.transition(obj1, obj2, true)
	});
	$("#page3").on("swipeDown", function() {
	    Mobilebone.transition(obj2, obj3, true)
	});
	$("#page4").on("swipeDown", function() {
	    Mobilebone.transition(obj3, obj4, true)
	});
	$("#page5").on("swipeDown", function() {
	    Mobilebone.transition(obj4, obj5, true)
	});
	$("#page6").on("swipeDown", function() {
	    Mobilebone.transition(obj5, obj6, true)
	});
	$("#page8").on("swipeDown", function() {
	    Mobilebone.transition(obj6, obj8, true)
	});
	$("#page9").on("swipeDown", function() {
	    Mobilebone.transition(obj6, obj9, true)
	});
});
window.onload=function(){
    get2WM();
    // getConfig();
    setTimeout(function(){
        $('#action').append('<div class="left1"><img src="http://h5.iamberry.com/iamberry/wechat/test/images/1-2.png"></div><div class="right1"><img src="http://h5.iamberry.com/iamberry/wechat/test/images/1-3.png"></div><div class="left1-2"><img src="http://h5.iamberry.com/iamberry/wechat/test/images/1-4.png"></div><div class="right1-2"><img src="http://h5.iamberry.com/iamberry/wechat/test/images/1-5.png"></div>')
        $('.left1').addClass('smallbig1');
        $('.right1').addClass('smallbig2');
        $('.left1-2').addClass('smallbig3');
        $('.right1-2').addClass('smallbig4');
        $(".loading-bg").hide();
    },300);
};
function dc(objectid) {
    if(document.getElementById && document.getElementById(objectid)) {
        return document.getElementById(objectid);// w3c dom
    } else if (document.all && document.all(objectid)) {
        return document.all(objectid);// msie 4 dom
    } else if (document.layers && document.layers[objectid]) {
        return document.layers[objectid];// nn 4 dom.. note: this won't find nested layers
    } else {
        return false;
    }
}
$(".ul_qes>li").each(function(){
   $(this).click(function(){
    $(this).children().prop("checked",true);
    if(isAnswer){
        $(".btn_submit").off().css('background-color','#c9c9ca');
    }else{
        $(".btn_submit").css('background-color','#d90049');
    }
    });
});
getConfig();
function getConfig(){
    $.ajax({
    type: 'get',
    url: '/iamberry/config/get',
    data: {appid: "", url: window.location.href},
    dataType: 'json',
    timeout: 10000,
    context: $('body'),
    success: function(data){
        setConfig(data);
    },
    error: function(xhr, type){
        console.log('Ajax error!' + xhr)
    }
    });
}
/**配置JS-SDK*/
function setConfig(config){
    wx.config({
      debug: false,
      appId: config.appId,
      timestamp: config.timestamp,
      nonceStr: config.nonceStr,
      signature: config.signature,
      jsApiList: [
        'checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'hideMenuItems',
        'showMenuItems'
        ]
    });
    wx.ready(function(){
    	wxReadySuccess();
    });
}
        
function get2WM(){
    var shareUrl = '';
    var quaryStr = '';
    if(href.indexOf('?')!=-1){
       quaryStr = window.location.href.split('?')[1];
    }
    $.ajax({
        url:'/iamberry/wechat/member/shareDrpUrl?dates=' + new Date().getTime() + '&' + quaryStr,
        dataType: 'json',
        type: 'POST',
        data: {},
        timeout: 15000,
        success: function(dt) {
            console.log(dt);
            if(dt.status) {
                $("#share-2wm-image").attr("src", dt.data.qrcodeUrl);
                if(dt.data.shareUrl.indexOf('?')!=-1){
                   shareUrl = href + dt.data.shareUrl.split('?')[1];
                }
                //console.log("----ture---22--" + shareUrl);
            } else {
                //console.log("----false-");
				var nowHref = window.location.href;
				if(nowHref.indexOf('?')!=-1){
					shareUrl = href + nowHref.split('?')[1];
					if(shareUrl.indexOf('#')!=-1){
						shareUrl = shareUrl.split('#')[0];
					}
				}
                $("#share-2wm-image").attr("src", dt.data.qrcodeUrl);
            }
            // 重新注册分享
			url = shareUrl;
			console.log("url:" + url);
			getConfig();
        },
        error: function(xhr, type, errorThrown) {
            // errorfn(xhr);
        }
    });

}

/** 分享时、分享后调用方法 */
var url;
function shareMessage() {
	url = url || href;
	console.log("configURL:" + url);
	alert(url);
    wx.onMenuShareTimeline({ //分享到朋友圈,只有标题、图标，没有内容简介
        title: "8秒冲好一瓶奶！", link: url, imgUrl: "http://h5.iamberry.com/iamberry/common/shop/images/logo_head.png",
        success: function () {
        },
        cancel: function () {
        }
    });
    wx.onMenuShareAppMessage({ // 分享给好友，有标题、内容简介、图标
        title: "8秒冲好一瓶奶！", desc: "精准配比、精准温度、精准奶量，只需轻轻一按！", link: url, imgUrl: "http://h5.iamberry.com/iamberry/common/shop/images/logo_head.png",
        success: function () {
        },
        cancel: function () {
			// alert("share app error:");
        }
    });
}
function wxReadySuccess() {
    // wx.getNetworkType({success: function (res) {}});
    wx.showMenuItems({
        menuList: [
            "menuItem:share:appMessage",
            "menuItem:share:timeline"
        ] // 要显示的菜单项，所有menu项见附录3
    });
    wx.hideMenuItems({
        menuList: [
            "menuItem:copyUrl",
            "menuItem:openWithSafari",
            "menuItem:originPage",
            "menuItem:share:email",
            "menuItem:dayMode",
            "menuItem:setFont",
            "menuItem:nightMode",
            "menuItem:share:qq",
            "menuItem:dayMode",
            "menuItem:exposeArticle",
            "menuItem:nightMode",
            "menuItem:openWithQQBrowser",
            "menuItem:share:QZone",
            "menuItem:favorite",
            "menuItem:share:facebook"
        ] // 要隐藏的菜单项，所有menu项见附录3
    });
	url = url || href;
	console.log("configURL:" + url);
	// alert(url);
	wx.onMenuShareTimeline({ //分享到朋友圈,只有标题、图标，没有内容简介
        title: "8秒冲好一瓶奶！", link: url, imgUrl: "http://h5.iamberry.com/iamberry/common/shop/images/logo_head.png",
        success: function () {
        },
        cancel: function () {
        }
    });
    wx.onMenuShareAppMessage({ // 分享给好友，有标题、内容简介、图标
        title: "8秒冲好一瓶奶！", desc: "精准配比、精准温度、精准奶量，只需轻轻一按！", link: url, imgUrl: "http://h5.iamberry.com/iamberry/common/shop/images/logo_head.png",
        success: function () {
        },
        cancel: function () {
			// alert("share app error:");
        }
    });
	// shareMessage();
}