$(function(){

	if (navigator.userAgent.match(/mobile/i)) { // 移动端访问请求 跳转
		window.location.href = "protal/index.html";
	}

	/*-------------------------------------------------------------------------------*/
	initSwiper = function(){
		$('#nvslider').nivoSlider({
			effect: 'random',
			pauseTime: 5000,
			captionOpacity: 0.7,
			directionNavHide: false
		}); 
	};

	swiperInit = function(postId){ // 轮播广告
		var _path=HTTP_PREFIX+"/advertment/fetch.shtml";
		var params={
				postId:postId
		};
		$.ajax({
			url: _path, 
			type: "post", 
			dataType: "json",
			data:$.toJSON(params),   
			contentType:"application/json",
			success: function(data) { 
				if(data.code=='01'){
					var vhtml = template('advertHtml', data);
					$("#nvslider").html(vhtml);
					initSwiper();
				}
			}
		});
	};

	swiperInit('1');

	/*-------------------------------------------------------------------------------*/

	headerRead = function(){ // 今日头条
		var _path=HTTP_PREFIX+"/article/today.shtml";
		$.ajax({
			url: _path, 
			type: "get", 
			dataType: "json",
			contentType:"application/json",
			success: function(data) { 
				var vhtml = template('todayHtml', data.content);
				$('#today').html(vhtml);
			}
		});
	};

	headerRead();

	/*-------------------------------------------------------------------------------*/
	siteconfig = function(){ // 站点配置等
		var _path=HTTP_PREFIX+"/protal/fetch.shtml";
		$.ajax({
			url: _path, 
			type: "get", 
			dataType: "json",
			contentType:"application/json",
			success: function(data) {
				var config = data.content;
				$(".location").html(config.address);
				$(".phone").html("客服:"+config.tel);
				$(".email").html("<a href='mailto:"+config.email+"'>"+config.email+"</a>");
				$("#webqrcode").attr('src',config.qrcode);
				// 微信公众号
				if(config.wxopen!=null && config.wxopen!=''){
					$("#wxopen").attr('src',config.wxopen);
				}else{
					$("#wxopen").remove();
				}
			}
		});
	};

	siteconfig();

	initYear = function(){
		var d = new Date()
		var vYear = d.getFullYear();
		$("#site_year").html(vYear);
	};
	
	initYear();
});