$('.tab-list').delegate(".build-tab","click",function(event){
	var target = $(event.target);
	$('.tab-list .build-tab').removeClass('active');
	target.addClass('active');
	
})
var players = [];


//var d = JSON.parse(res.content[0].meta.channel);
//	play1 = play(d[0].rtsp,d[0].size)
	
var getListUrl = "/device/device/list";


//区域信息
var areaParam = {
	parentId:"738719738515689472",
	hasSub:false
};
var areaUrl = "/publics/treenode/listNodeByParent";
getData(areaUrl,areaParam).then(res => {
	
	var l = res.length;
	var h = "";
	for(var i=0;i<l;++i){
		h+="<li node-id='"+res[i].id+"'>"+res[i].nodeName+"</li>";
	}
	$("#areaList").html(h);
})

//获取栋舍
function getBuild(id){
	var getNodeParam = {
		parentId:id,
		hasSub:false
	}
	var getNodeUrl = "/publics/treenode/listNodeByParent";
	
	getData(getNodeUrl,getNodeParam).then(res => {
		var l = res.length;
		var h = "";
		for(var i=0;i<l;++i){
			h+="<li node-id='"+res[i].id+"'>"+res[i].nodeName+"</li>";
		}
		$("#deviceList").html(h);
	})
}
//获取栋舍的设备
function getDevice(areaId){
		var getdeviceParam = {
			areaId:areaId
		};
		var getdeviceUrl = "/device/device/listByAreaId";
		getData(getdeviceUrl,getdeviceParam,"GET").then(res => {
			
				var r = res.length;
				var h="";
				var t=0;
				var channel = [];
				for(var j = 0;j<r;++j){
					if(res[j].categoryId=="738713612176855040"){
						
						//监控设备
						//$("#buildmap area").eq(n).attr("device-id",res[j].deviceId);
						var d = JSON.parse(res[j].meta.channel);
						channel.push(d);
						h += showVideo(res[j],t);
						++t;
						continue;
					}
					
				}
				$(".video-windows").html(h);
				for(var j=0;j<t;++j){
					
					if(currIp==loginIp){
						//登录IP和设备IP一致
						videoIp = lanIp
						players.push(play(j,channel[j][0].rtsp,channel[j][0].size));
						
					}else{
						//用普清
						videoIp = currIp;
						console.log(channel[j][1].rtsp,channel[j][1].size)
						players.push(play(j,channel[j][1].rtsp,channel[j][1].size))
					}
					
				}
			//}			
		})
}
	
function showVideo(data,j){
	var d = JSON.parse(data.meta.channel);
	var html = "";
	html+= "<div class='video-play1'><div class='video-play1-container'>"
	html+= "<div class='tab'><span class='tab-title'>"+data.name+"</span></div>"
	html+= "<div class='video'><svg version='1.1' width='37' height='25' class='wide-border-line1'>"
	html+= "<g transform='translate(0.5 0.5)'><polyline points='0,24.5 0,0 37,23.5 ' style='fill:#0E1E51;stroke:#53BAFD;stroke-width:1'/>"
	html+= "</g></svg><svg version='1.1' width='160' height='25' class='wide-border-line2'><g transform='translate(0.5 0.5)'>"
	html+= "<polyline points='160,25 135,0 25,0 -1,23.5' style='fill:#0E1E51;stroke:#53BAFD;stroke-width:1'/></g></svg>"
	html+= "<div id='play-box-"+j+"' class='playerbox'></div></div></div></div>";				
	return html;
}