var videoblock;
var recordblock;
//实时播放视频组件
function initBlock(){
	var uuid = $.uniqueId();
	videoblock = $.videoBlock({
		uuid : uuid,
		title : "",
		$baseContainer : $("#video"),
		$content:$("#video"),
		serverConnection : top.serverConnection,
		monid : null,
		isRunning : false,
		onRightClick : $.noop()
	});
	BlockCacher.addBlock(videoblock);
	$("#video video").attr("id",videoblock.videoId);
}
function webrtc_startVideo(sbbh,tdbh,tdmc){
	videoblock.setFdId(sbbh).setChannelId(tdbh).setHideTitle(tdmc).startMonitor();
}
//历史视频播放组件
function initRecordBlock(){
	var uuid = $.uniqueId();
	recordblock = $.recordblock({
		uuid : uuid,
		title : "",
		$baseContainer : $("#record"),
		$content:$("#record"),
		serverConnection : top.serverConnection,
		monid : null,
		isRunning : false,
		onRightClick : $.noop()
	});
	BlockCacher.addBlock(recordblock);
	$("#record video").attr("id",recordblock.videoId);
}
function webrtc_startRecord(sbbh,tdbh,tdmc,startTime,endTime){	
//	console.log("播放时间：",startTime,endTime);
	var playbackurl = "";
	var end_occur = timeChange(endTime);
	var start_occur= timeChange(startTime);
	recordblock.setFdId(sbbh).setChannelId(tdbh).setHideTitle(tdmc).startPlayback(start_occur ,0,end_occur,playbackurl,sbbh,tdbh,0);
}

//毫秒数转换
function timeChange(time){
	return Date.parse(new Date(time.replace(/-/g,"/")))/1000;
}
//事件开始事件，输入字符串时间前10秒
function start_occurTime(time){
	var dt=new Date(time.replace(/-/g,"/"));//将传入的日期格式的字符串转换为date
	var ndt=new Date(dt.getTime()-10000);//将转换之后的时间减去十秒
	//console.log('开始时间为：',ndt);
	return Date.parse(ndt)/1000;
}
//事件开始事件，输入字符串时间后10秒
function end_occurTime(time){
	var dt=new Date(time.replace(/-/g,"/"));//将传入的日期格式的字符串转换为date
	var ndt=new Date(dt.getTime()+10000);//将转换之后的时间减去十秒
	//console.log('结束时间为：',ndt);
	return Date.parse(ndt)/1000;
}

// 关闭录像
function closeRecordvideo(){
	if(recordblock && recordblock.fdId && recordblock.channelId != null){
		//录像关闭
		recordblock.stopPlayback();
		recordblock.setRunning(false).setHideTitle("").setTitle("")
		.setFdId("").setChannelId("").setMonId(null);
		recordblock.setPeerConnection(null);
		recordblock.getVideoComp().src = "";
	}
}

