$(document).ready(function(){

	var config = ajax({"action":"config"});
	//基本信息
	$(".getName").html(config.webName);
	$(".getCompany").html(config.webCompany);
	$(".getPhone").html(config.webPhone);
	$(".getMobile").html(config.webMobile);
	$(".getAddress").html(config.webAddress);
	$(".getEmail").html(config.webEmail);
	$(".getBa").html(config.webBa);
	$(".getGa").html(config.webGa);

	//首先将#btn隐藏
	$(".backTop").hide();
	//当滚动条的位置处于距顶部50像素以下时，跳转链接出现，否则消失
	$(function() {
	  $(window).scroll(function() {
		if ($(window).scrollTop() > 50) {
		  $(".backTop").fadeIn(200);
		} else {
		  $(".backTop").fadeOut(200);
		}
	  });
	  //当点击跳转链接后，回到页面顶部位置
	  $(".backTop").click(function() {
		$('body,html').animate({
		  scrollTop: 0
		},
		500);
		return false;
	  });
	});

	//首先将#btn隐藏
	$(".backTop").hide();
	//当滚动条的位置处于距顶部50像素以下时，跳转链接出现，否则消失
	$(function() {
	  $(window).scroll(function() {
		if ($(window).scrollTop() > 50) {
		  $(".backTop").fadeIn(200);
		} else {
		  $(".backTop").fadeOut(200);
		}
	  });
	  //当点击跳转链接后，回到页面顶部位置
	  $(".backTop").click(function() {
		$('body,html').animate({
		  scrollTop: 0
		},
		500);
		return false;
	  });
	});
	//图片放大
	$(document).on("click", ".maxImg", function(){
		$("body").append("<div class='maxImgBox' style='width:100%;height:100%;z-index:9999;background:rgba(0,0,0,0.5);background:#000 9;filter:Alpha(opacity=50);text-align:center;position:fixed;top:0;left:0;'><p class='closeMaxImg' style='text-align:center;font-size:15px;margin-top:40px;background:#ffffff;color:#666666;cursor:pointer;padding:6px;display:block;width:60px;margin:0 auto;margin-top:20px;border-radius:30px;'>关闭</p><img style='max-width:80%;margin-top:20px;border:1px solid #aaaaaa;background:#ffffff;padding:10px;' src='"+ $(this).attr("src") +"'></div>");
	});
	//关闭图片
	$(document).on("click", ".closeMaxImg", function(){
		$(".maxImgBox").remove();
	});
	//免费在线试用
	$(".gnsy .sy").click(function(){
		window.open("http://www.deerpu.cn/demo.php?code=" + $(this).attr("data-code"));
	});
});


//手机菜单
$(document).on("click", ".mobileNav", function(){
	$(".nav").toggle();
});


//判断手机访问
function isMobile(){
	var userAgentInfo = navigator.userAgent;
	var mobileAgents = [ "Android", "iPhone", "SymbianOS", "Windows Phone", "iPad","iPod"];
	var mobile_flag = false;
	//根据userAgent判断是否是手机
	for (var v = 0; v < mobileAgents.length; v++) {
		if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
			mobile_flag = true;
			break;
		}
	}
	var screen_width = window.screen.width;
	var screen_height = window.screen.height;   
	//根据屏幕分辨率判断是否是手机
	if(screen_width < 500 && screen_height < 800){
		mobile_flag = true;
	}
	return mobile_flag;
}


//电脑端打开QQ
$(document).on("click", ".goQq", function(){
	if(isMobile()){
		window.location.href = "mqqwpa://im/chat?chat_type=wpa&uin=1092399928&version=1&src_type=web&web_src=oicqzone.com";
	}else{
		window.open('http://wpa.qq.com/msgrd?V=1&uin=1092399928&Site=deerpu&Menu=yes');
	}
	
});


//ajax
function ajax(data, type = "GET", datatype = "json", url = "control.php"){
	var result;
	var mydata = typeof(data) == "object" ? data : eval("("+ data +")") ;
	$.ajax({
		url: url,
		data: mydata,
		dataType: datatype,
		async: false,
		type: type,
		success: function(data){
			result = data;
		},
		error: function(data){
			//alert(JSON.stringify(data));
			alert("AJAX执行失败");
		},
		error : function(e) {
    	   //alert(e.responseText);
		}
	});
	return result;
}