
// resize to reload
AddEventListen(3);
AddEventListen(4);
var videowallX = parseInt($('#VideoWallSizeX').val());
var videowallY = parseInt($('#VideoWallSizeY').val());
VideoWallResolutionSelectNum = 1;
// 像素边距输入监测
$('#BezelTop').on('change',function(){
	if (parseInt($(this).val())>256) {
		$(this).val('256');
	}
	else if ($(this).val()=='') {
		$(this).val('0');
	}	
});
$('#BezelBottom').on('change',function(){
	if (parseInt($(this).val())>256) {
		$(this).val('256');
	}
	else if ($(this).val()=='') {
		$(this).val('0');
	}
});
$('#BezelLeft').on('change',function(){
	if (parseInt($(this).val())>256) {
		$(this).val('256');
	}
	else if ($(this).val()=='') {
		$(this).val('0');
	}
});
$('#BezelRight').on('change',function(){
	if (parseInt($(this).val())>256) {
		$(this).val('256');
	}
	else if ($(this).val()=='') {
		$(this).val('0');
	}
});
$('#BezelTop').blur(function(){
	if ($(this).val()=='') {
		$(this).val('0');
	}
});
$('#BezelBottom').blur(function(){
	if ($(this).val()=='') {
		$(this).val('0');
	}
});
$('#BezelLeft').blur(function(){
	if ($(this).val()=='') {
		$(this).val('0');
	}
});
$('#BezelRight').blur(function(){
	if ($(this).val()=='') {
		$(this).val('0');
	}
});
// 左侧圆形按钮点击事件
$('.VideoWallRxDeviceScrollContDecoder li').each(function(e){
	$(this).on('click',function(){
		$('.VideoWallRxDeviceScrollContDecoder li').removeClass('VideoScrollRxClick');
		$('.IPAV1100VideoWallRxCont').css('top',-(120*e)+'px');
		$(this).addClass('VideoScrollRxClick');
	});
});
$('.VideoWallTxDeviceScrollContEncoder li').each(function(e){
	$(this).on('click',function(){
		var _IPAV1100TxCont = $('.IPAV1100VideoWallTxContScrool').height();
		var _IPAV1100TxContDisplayH = parseInt((_IPAV1100TxCont+12)/120)*120;
		
		$('.VideoWallTxDeviceScrollContEncoder li').removeClass('VideoScrollRxClick');
		$('.IPAV1100VideoWallTxCont').css('top',-(_IPAV1100TxContDisplayH*e)+'px');
		$(this).addClass('VideoScrollRxClick');
	});
});
// PageLoadingVideoWallDevice();
$('#VideoWallRemoveFromGroupRx').on('click',function(){
	if (DecoderConfigurationDeviceNumb==0) return;
	if ($('#VideoWallGroupSelectRx span').html()=='Default') return;
	var groupID = $('#VideoWallGroupRxSelectBox li:eq('+DeviceGroupRxSelectNum+') span:eq(1)').html();
	var grouplist = DecodeGroupDataListArr;
	var  newgrouplist='';
	var _num;
	
	var GroupDataArr = '';
	$.ajax({
            type: 'POST',
            url: 'common/GroupSaveSetting.php',
            data: 'ReadGroupSaveSettingName=VideoWallDecode_'+groupID,
            datatype: 'json',
            async: true,
            success: function(rst) {
            	var _rst = rst.split(',');
            	for (var i = 0; i < _rst.length; i++) {
            		if (_rst[i]!='') {
            			var _rstArr = _rst[i].split(':');
            			var _grouplist = grouplist[DecoderConfigurationDeviceNumb-1].split(':');
            			if (_grouplist[0]==_rstArr[2]) {
            				_rst[i] = '';
            			}
            		}
            	}
            	var _rstTmp;
            	for (var i = 0; i < _rst.length; i++) {//重新拼合数据    
            		if (_rst[i]!='') {
            			_rstTmp += _rst[i]+',';
            		}
				}
				_rstTmp = _rstTmp.substr(0,_rstTmp.length-1);
                GroupAddingDeviceSaveSetting('VideoWallDecode_'+groupID,_rstTmp);

                grouplist[DecoderConfigurationDeviceNumb-1]='';    
				for (var i = 0; i < grouplist.length; i++) {//重新拼合数据         
				    GroupDataArr+= grouplist[i]+',';
				}
				GroupDataArr = GroupDataArr.substr(0,GroupDataArr.length-1);
				var data = 'type=9&id='+groupID+'&deviceMAC='+GroupDataArr+'&devicetype=rx';
				//console.log(data);
				PageAddGroup(data);
				$('.IPAV1100VideoWallRxCont:eq(0) li:eq('+DecoderConfigurationDeviceNumb+')').html('');
				$('.IPAV1100VideoWallRxCont:eq(0) li:eq('+DecoderConfigurationDeviceNumb+')').removeClass('deviceBoxHasDevice');
            } 
        });
				
});
$('#VideoWallRemoveFromGroupTx').on('click',function(){
	if ($('#VideoWallGroupSelectTx span').html()=='Default') return;
	var groupID = $('#VideoWallGroupTxSelectBox li:eq('+DeviceGroupTxSelectNum+') span:eq(1)').html();
	var grouplist = EncodeGroupDataListArr;
	var  newgrouplist='';
	var _num;
		
	var GroupDataArr = '';
	$.ajax({
            type: 'POST',
            url: 'common/GroupSaveSetting.php',
            data: 'ReadGroupSaveSettingName=VideoWallEncode_'+groupID,
            datatype: 'json',
            async: true,
            success: function(rst) {
            	var _rst = rst.split(',');
            	for (var i = 0; i < _rst.length; i++) {
            		if (_rst[i]!='') {
            			var _rstArr = _rst[i].split(':');
            			var _grouplist = grouplist[EncoderConfigurationDeviceNumb].split(':');
            			if (_grouplist[0]==_rstArr[2]) {
            				_rst[i] = '';
            			}
            		}
            	}
            	var _rstTmp;
            	for (var i = 0; i < _rst.length; i++) {//重新拼合数据    
            		if (_rst[i]!='') {
            			_rstTmp += _rst[i]+',';
            		}
				}
				_rstTmp = _rstTmp.substr(0,_rstTmp.length-1);
                GroupAddingDeviceSaveSetting('VideoWallEncode_'+groupID,_rstTmp);
                grouplist[EncoderConfigurationDeviceNumb]='';    
				for (var i = 0; i < grouplist.length; i++) {//重新拼合数据         
				    GroupDataArr+= grouplist[i]+',';
				}
				GroupDataArr = GroupDataArr.substr(0,GroupDataArr.length-1);
				var data = 'type=9&id='+groupID+'&deviceMAC='+GroupDataArr+'&devicetype=tx';
				//console.log(data);
				PageAddGroup(data);
				$('.IPAV1100VideoWallTxCont:eq(0) li:eq('+EncoderConfigurationDeviceNumb+')').html('');
				$('.IPAV1100VideoWallTxCont:eq(0) li:eq('+EncoderConfigurationDeviceNumb+')').removeClass('deviceBoxHasDevice');
            } 
        });
				
});
$('#IPA1100VideoWallParameterContWallUl').html('');
$('#IPA1100VideoWallParameterContWallUl').css('width',(videowallX*40-2)+'px');
for (var j = 0; j < videowallY; j++) {
	PresetDataDetail[j]=[];
	for (var i = 0; i < videowallX; i++) {
		$('#IPA1100VideoWallParameterContWallUl').append('<li>\
																	<div class="IPA1100VideoWallParameterContWallULLIFlag"></div>\
																</li>');
		PresetDataDetail[j][i]='';
	}
	$('#IPA1100VideoWallParameterContWallUl li:eq('+(videowallY*videowallX+videowallX-1)+')').css('border-right','none');
}
$('#VideoWallRemoveBtn').on('click',function(){
	$('#IPA1100VideoWallParameterContWallUl li').each(function(e){
		if ($(this).hasClass('videoWallDecoderClick')) {
			var _num = parseInt($('#VideoWallSizeX').val());
			sendCommand('data=set '+PresetDataDetail[parseInt(e/_num)][parseInt(e%_num)]+' video genlock');
			var _deviceID = PresetDataDetail[parseInt(e/_num)][parseInt(e%_num)];
			PresetDataDetail[parseInt(e/_num)][parseInt(e%_num)]='';
			$(this).removeClass('videoWallDecoderClick');
			$('#IPA1100VideoWallParameterContWallUl li:eq('+e+') div').removeClass('videoWallDecoderBottomClick');
			$('#IPA1100VideoWallParameterContRxDrop').html('');
			$('#VideoWallRemoveFromWall').hide();
			$.ajax({
            type: 'POST',
            url: 'common/readfile.php',
            data: 'firstRecallFromFile=1',
            datatype: 'json',
            async: true,
            success: function(rst) {
            	var _rst = rst.replace(_deviceID,'');
            	ReadDataFromFile('firstsaveToFile=1&savedata='+_rst);
            }});
			
		}
	});
});
$(window).resize(function(){
	if (current_page != 2) {
		return;
	}
	
	PageLoadingVideoWallDevice();
});
var VideoWallMonitorsResolutions=0;
var VideoWallMonitorsResolutionsOver=0;
// pin to this position
$('#VideoWallRxPinToThisPosition').on('click',function(){
	if (DecoderConfigurationDeviceNumb==0) return;
		var _deviceNum=DecoderConfigurationDeviceNumb;
		var _jsonPositionData;
		
		$.ajax({
		    type: 'POST',
		    url: 'common/readfile.php',
		    data: 'PositionInfoFromFile=1',
		    datatype: 'json',
		    async: true,
		    success: function(rst) {
		    	var _arr = _data.videoswitching_decode_arr.split(',');
				_jsonPositionData = rst;
				var _jsonPositionDataArr = _jsonPositionData.split(',');
		    	if (1) {
		    		if ($('.IPAV1100VideoWallRxCont li:eq('+_deviceNum+') .DeviceBoxNavTopLocked').hasClass('DeviceBoxPositionLocked')) {
		    			$('.IPAV1100VideoWallRxCont li:eq('+_deviceNum+') .DeviceBoxNavTopLocked').removeClass('DeviceBoxPositionLocked');
		    			if (_jsonPositionData!='') {        		
				        	var _jsonPositionDataTmp='';
				        	if (_jsonPositionData.indexOf(_arr[_deviceNum-1])>=0) {
				        		for (var i = 0; i < _jsonPositionDataArr.length; i++) {
					        		var _jsonPositionDataArrTmp = _jsonPositionDataArr[i].split(':');
					        		if (_jsonPositionDataArrTmp[0]==_arr[_deviceNum-1]) {
					        			_jsonPositionDataArr[i] = _jsonPositionDataArrTmp[0]+':N';	        				
					        		}
					        	}
					        	_jsonPositionData='';
					        	for (var i = 0; i < _jsonPositionDataArr.length; i++) {
						        	_jsonPositionData += _jsonPositionDataArr[i] + ',';
						        }
						        _jsonPositionData = _jsonPositionData.substr(0,_jsonPositionData.length-1);
				        	}else{
				        		_jsonPositionData += ',' + _arr[_deviceNum-1]+':N';
				        	}
				        }else{
				        	_jsonPositionData = _arr[_deviceNum-1]+':N';
				        }
		    		}
		    		else {		
		    			$('.IPAV1100VideoWallRxCont li:eq('+_deviceNum+') .DeviceBoxNavTopLocked').addClass('DeviceBoxPositionLocked');		        
				        if (_jsonPositionData!='') {        		
				        	var _jsonPositionDataTmp='';
				        	if (_jsonPositionData.indexOf(_arr[_deviceNum-1])>=0) {
				        		for (var i = 0; i < _jsonPositionDataArr.length; i++) {
					        		var _jsonPositionDataArrTmp = _jsonPositionDataArr[i].split(':');
					        		if (_jsonPositionDataArrTmp[0]==_arr[_deviceNum-1]) {
					        			_jsonPositionDataArrTmp[1] = _deviceNum;
					        			_jsonPositionDataArr[i] = _jsonPositionDataArrTmp[0]+':'+_jsonPositionDataArrTmp[1];	        				
					        		}
					        	}
					        	_jsonPositionData='';
					        	for (var i = 0; i < _jsonPositionDataArr.length; i++) {
						        	_jsonPositionData += _jsonPositionDataArr[i] + ',';
						        }
						        _jsonPositionData = _jsonPositionData.substr(0,_jsonPositionData.length-1);
				        	}else{
				        		_jsonPositionData += ',' + _arr[_deviceNum-1]+':'+_deviceNum;
				        	}
				        }else{
				        	_jsonPositionData = _arr[_deviceNum-1]+':'+_deviceNum;
				        }
		    		}
			    	ReadDataFromFile('PositionInfoSetFile=1&PositionInfoData='+_jsonPositionData);
			    	// console.log(_jsonPositionData);
		    	}
			    else {
			    	//DecodeGroupDataListArr
			    	if ($('.IPAV1100VideoWallRxCont li:eq('+_deviceNum+') .DeviceBoxNavTopLocked').hasClass('DeviceBoxPositionLocked')) {
		    			$('.IPAV1100VideoWallRxCont li:eq('+_deviceNum+') .DeviceBoxNavTopLocked').removeClass('DeviceBoxPositionLocked');
		    			for (var i = 0; i < DecodeGroupDataListArr.length; i++) {
				    		if ((_deviceNum-1)==i) {
				    			var _DecodeGroupDataListArrTmp = DecodeGroupDataListArr[i].split(':');
				    			_DecodeGroupDataListArrTmp[1] = _deviceNum;
				    			DecodeGroupDataListArr[i] = _DecodeGroupDataListArrTmp[0]+':N';
				    			break;
				    		}
				    	}
				    	var _temp='';
				    	for (var i = 0; i < DecodeGroupDataListArr.length; i++) {
				    		_temp+=DecodeGroupDataListArr[i]+',';
				    	}
				    	_temp = _temp.substr(0,_temp.length-1);
		    		}
		    		else {
		    			$('.IPAV1100VideoWallRxCont li:eq('+_deviceNum+') .DeviceBoxNavTopLocked').addClass('DeviceBoxPositionLocked');
		    			for (var i = 0; i < DecodeGroupDataListArr.length; i++) {
				    		if ((_deviceNum-1)==i) {
				    			var _DecodeGroupDataListArrTmp = DecodeGroupDataListArr[i].split(':');
				    			_DecodeGroupDataListArrTmp[1] = _deviceNum;
				    			DecodeGroupDataListArr[i] = _DecodeGroupDataListArrTmp[0]+':'+_DecodeGroupDataListArrTmp[1];
				    			break;
				    		}
				    	}
				    	var _temp='';
				    	for (var i = 0; i < DecodeGroupDataListArr.length; i++) {
				    		_temp+=DecodeGroupDataListArr[i]+',';
				    	}
				    	_temp = _temp.substr(0,_temp.length-1);
				    	
		    		}
				    PageAddGroup('type=9&id='+$('#VideoWallGroupRxSelectBox li:eq('+DeviceGroupRxSelectNum+') span:eq(1)').html()+'&deviceMAC='+_temp);
				   	// console.log(_temp);
			    }
		    }
		});
});
$('#VideoWallTxPinToThisPosition').on('click',function(){
		var _deviceNum=EncoderConfigurationDeviceNumb;
		var _jsonPositionData;
		
		$.ajax({
		    type: 'POST',
		    url: 'common/readfile.php',
		    data: 'PositionInfoFromFile=2',
		    datatype: 'json',
		    async: true,
		    success: function(rst) {
		    	var _arr = _data.videoswitching_encode_arr.split(',');
				_jsonPositionData = rst;
				var _jsonPositionDataArr = _jsonPositionData.split(',');
		    	if (1) {
		    		if ($('.IPAV1100VideoWallTxCont li:eq('+_deviceNum+') .DeviceBoxNavTopLocked').hasClass('DeviceBoxPositionLocked')) {
		    			$('.IPAV1100VideoWallTxCont li:eq('+_deviceNum+') .DeviceBoxNavTopLocked').removeClass('DeviceBoxPositionLocked');
		    			if (_jsonPositionData!='') {        		
				        	var _jsonPositionDataTmp='';
				        	if (_jsonPositionData.indexOf(_arr[_deviceNum])>=0) {
				        		for (var i = 0; i < _jsonPositionDataArr.length; i++) {
					        		var _jsonPositionDataArrTmp = _jsonPositionDataArr[i].split(':');
					        		if (_jsonPositionDataArrTmp[0]==_arr[_deviceNum]) {
					        			_jsonPositionDataArr[i] = _jsonPositionDataArrTmp[0]+':N';	        				
					        		}
					        	}
					        	_jsonPositionData='';
					        	for (var i = 0; i < _jsonPositionDataArr.length; i++) {
						        	_jsonPositionData += _jsonPositionDataArr[i] + ',';
						        }
						        _jsonPositionData = _jsonPositionData.substr(0,_jsonPositionData.length-1);
				        	}else{
				        		_jsonPositionData += ',' + _arr[_deviceNum]+':N';
				        	}
				        }else{
				        	_jsonPositionData = _arr[_deviceNum]+':N';
				        }
		    		}
		    		else {		
		    			$('.IPAV1100VideoWallTxCont li:eq('+_deviceNum+') .DeviceBoxNavTopLocked').addClass('DeviceBoxPositionLocked');		        
				        if (_jsonPositionData!='') {        		
				        	var _jsonPositionDataTmp='';
				        	if (_jsonPositionData.indexOf(_arr[_deviceNum])>=0) {
				        		for (var i = 0; i < _jsonPositionDataArr.length; i++) {
					        		var _jsonPositionDataArrTmp = _jsonPositionDataArr[i].split(':');
					        		if (_jsonPositionDataArrTmp[0]==_arr[_deviceNum]) {
					        			_jsonPositionDataArrTmp[1] = _deviceNum;
					        			_jsonPositionDataArr[i] = _jsonPositionDataArrTmp[0]+':'+_jsonPositionDataArrTmp[1];	        				
					        		}
					        	}
					        	_jsonPositionData='';
					        	for (var i = 0; i < _jsonPositionDataArr.length; i++) {
						        	_jsonPositionData += _jsonPositionDataArr[i] + ',';
						        }
						        _jsonPositionData = _jsonPositionData.substr(0,_jsonPositionData.length-1);
				        	}else{
				        		_jsonPositionData += ',' + _arr[_deviceNum]+':'+_deviceNum;
				        	}
				        }else{
				        	_jsonPositionData = _arr[_deviceNum]+':'+_deviceNum;
				        }
		    		}
			    	ReadDataFromFile('PositionInfoSetFile=2&PositionInfoData='+_jsonPositionData);
			    	// console.log(_jsonPositionData);
		    	}
			    else {
			    	//DecodeGroupDataListArr
			    	if ($('.IPAV1100VideoWallTxCont li:eq('+_deviceNum+') .DeviceBoxNavTopLocked').hasClass('DeviceBoxPositionLocked')) {
		    			$('.IPAV1100VideoWallTxCont li:eq('+_deviceNum+') .DeviceBoxNavTopLocked').removeClass('DeviceBoxPositionLocked');
		    			for (var i = 0; i < EncodeGroupDataListArr.length; i++) {
				    		if (_deviceNum==i) {
				    			var _DecodeGroupDataListArrTmp = EncodeGroupDataListArr[i].split(':');
				    			_DecodeGroupDataListArrTmp[1] = _deviceNum;
				    			EncodeGroupDataListArr[i] = _DecodeGroupDataListArrTmp[0]+':N';
				    			break;
				    		}
				    	}
				    	var _temp='';
				    	for (var i = 0; i < EncodeGroupDataListArr.length; i++) {
				    		_temp+=EncodeGroupDataListArr[i]+',';
				    	}
				    	_temp = _temp.substr(0,_temp.length-1);
		    		}
		    		else {
		    			$('.IPAV1100VideoWallTxCont li:eq('+_deviceNum+') .DeviceBoxNavTopLocked').addClass('DeviceBoxPositionLocked');
		    			for (var i = 0; i < EncodeGroupDataListArr.length; i++) {
				    		if (_deviceNum==i) {
				    			var _DecodeGroupDataListArrTmp = EncodeGroupDataListArr[i].split(':');
				    			_DecodeGroupDataListArrTmp[1] = _deviceNum;
				    			EncodeGroupDataListArr[i] = _DecodeGroupDataListArrTmp[0]+':'+_DecodeGroupDataListArrTmp[1];
				    			break;
				    		}
				    	}
				    	var _temp='';
				    	for (var i = 0; i < EncodeGroupDataListArr.length; i++) {
				    		_temp+=EncodeGroupDataListArr[i]+',';
				    	}
				    	_temp = _temp.substr(0,_temp.length-1);
				    	
		    		}
				    PageAddGroup('type=9&id='+$('#VideoWallGroupTxSelectBox li:eq('+DeviceGroupTxSelectNum+') span:eq(1)').html()+'&deviceMAC='+_temp);
				   	// console.log(_temp);
			    }
		    }
		});
});
$('#VideoWallMonitorsResolutions').on('mouseover',function(){
	$('#VideoWallResolution .RxDeviceOptionsRightGenlockScaling').show();

});
$('#VideoWallResolution .RxDeviceOptionsRightGenlockScaling').on('mouseleave',function(){
	$('#VideoWallResolution .RxDeviceOptionsRightGenlockScaling').hide();	
});
$('#VideoWallResolutionSettingBtn').on('click',function(){	
	if (VideoWallMonitorsResolutions==1) {
		$('#VideoWallResolution').hide();
		$('#VideoWallRemoveFromWall').hide();
		VideoWallMonitorsResolutions = 0;
	}
	else {
		var _checkResolution = $('.VideoWallDisplayResolution').html();
		$('#VideoWallResolution .RxDeviceOptionsRightGenlockScaling .RxDeviceOptionsRightNavList .IPAV1100RxDeviceOptionsNavSecL').removeClass('IPAV1100RxDeviceOptionsNavSecLHover');
		VideoWallMonitorsResolutions=1;
		for (var i = 0; i < VideoWallResolutionArr.length; i++) {
			var _resolution = VideoWallResolutionArr[i][0]+'x'+VideoWallResolutionArr[i][1];
			if (_checkResolution.indexOf(_resolution)>=0) {
				$('#VideoWallResolution .RxDeviceOptionsRightGenlockScaling .RxDeviceOptionsRightNavList:eq('+i+') .IPAV1100RxDeviceOptionsNavSecL').addClass('IPAV1100RxDeviceOptionsNavSecLHover');
			}
		}
		$('#VideoWallResolution').show();
		$('#VideoWallRemoveFromWall').hide();
	}
	

});
$('#VideoWallResolutionSettingBtn').on('mouseover',function(){
	VideoWallMonitorsResolutionsOver=1;
});
$('#VideoWallResolutionSettingBtn').on('mouseleave',function(){
	VideoWallMonitorsResolutionsOver=0;
});
$('body').on('click',function(){
	if (VideoWallMonitorsResolutionsOver!=1) {
		$('#VideoWallResolution').hide();
		VideoWallMonitorsResolutions = 0;
		$('#VideoWallResolution .RxDeviceOptionsRightGenlockScaling').hide();
	}
});
// wall size loading
$('#VideoWallSizeX').on('change',function(){
	var videowallX = parseInt($('#VideoWallSizeX').val());
	var videowallY = parseInt($('#VideoWallSizeY').val());
	if (0>=videowallX||videowallX>5) {
		$('#DisplayErrorContent .DeviceSendReceiveInfraredContText').html('Must be a number between 1 and 5');
		$('#DisplayErrorContent').show();
		return;
	}
	$('#IPA1100VideoWallParameterContWallUl').html('');
	$('#IPA1100VideoWallParameterContWallUl').css('width',(videowallX*40-2)+'px');
	for (var j = 0; j < videowallY; j++) {
		PresetDataDetail[j]=[];
		for (var i = 0; i < videowallX; i++) {
			$('#IPA1100VideoWallParameterContWallUl').append('<li>\
																	<div class="IPA1100VideoWallParameterContWallULLIFlag"></div>\
																</li>');
			PresetDataDetail[j][i]='';
		}
		$('#IPA1100VideoWallParameterContWallUl li:eq('+(videowallY*videowallX+videowallX-1)+')').css('border-right','none');
	}
	VideoWallEventListen(1);
});
$('#VideoWallSizeY').on('change',function(){
	var videowallX = parseInt($('#VideoWallSizeX').val());
	var videowallY = parseInt($('#VideoWallSizeY').val());
	if (0>=videowallX||videowallY>5) {
		$('#DisplayErrorContent .DeviceSendReceiveInfraredContText').html('Must be a number between 1 and 5');
		$('#DisplayErrorContent').show();
		return;
	}
	$('#IPA1100VideoWallParameterContWallUl').html('');
	$('#IPA1100VideoWallParameterContWallUl').css('width',(videowallX*40-2)+'px');
	for (var j = 0; j < videowallY; j++) {
		PresetDataDetail[j]=[];
		for (var i = 0; i < videowallX; i++) {
			$('#IPA1100VideoWallParameterContWallUl').append('<li>\
																<div class="IPA1100VideoWallParameterContWallULLIFlag"></div>\
															</li>');
			PresetDataDetail[j][i]='';
		}
		$('#IPA1100VideoWallParameterContWallUl li:eq('+(videowallY*videowallX+videowallX-1)+')').css('border-right','none');
	}
	VideoWallEventListen(1);
});
var VideoWallDecoderDrop = 0;
var VideoWallEncoderDrop = 0;
var VideoWallTxDeviceID;
$('#IPA1100VideoWallParameterContRxDrop').on('mouseup',function(){
	if (VideoWallDecoderDrop==1) {
		$('.IPA1100VideoWallParameterContWallUL li').each(function(e){
			if ($(this).hasClass('videoWallDecoderClick')) {
				var videowallX = parseInt($('#VideoWallSizeX').val());
				var videowallY = parseInt($('#VideoWallSizeY').val());
				var _x = parseInt(e%videowallX);
				var _y = parseInt(e/videowallX);
				PresetDataDetail[_y][_x] = DecodeVideoWallDataArr[DecoderToChangePositionAfterNum-1][1];
				CheckResolutionToChange(DecodeVideoWallDataArr[DecoderToChangePositionAfterNum-1][1],_x,_y);
				VideoWallDecoderDrop=0;
				$('#IPA1100VideoWallParameterContRxDrop').html($('.IPAV1100VideoWallRxCont li:eq('+DecoderToChangePositionAfterNum+')').html());
				VideoWallEventListen(2);
				CheckDeviceInArr();
				VideoWallEventListen(4);
				if ($('#IPA1100VideoWallParameterContTxDrop').html()!='') {
					//VideoWallEncoderDrop=1;
					//$('#IPA1100VideoWallParameterContTxDrop').mouseup();
					var _checkInArr='';
					$('#IPA1100VideoWallParameterContWallUl li').each(function(e){
						if ($('#IPA1100VideoWallParameterContWallUl li:eq('+e+') div').hasClass('videoWallDecoderBottomClick')) {
							_checkInArr += (e+1)+',';
						}
					});
					if (_checkInArr=='') {
						return;
					}
					var presetid = parseInt($('.listHeadLeftContPresetSelect').val())-1;
					var _i,_j;//parameterResolution
					var _dataCommand;
					var _h,_v,_i,_j;
					_h = parseInt($('#VideoWallSizeX').val());
					_v = parseInt($('#VideoWallSizeY').val());
					_checkInArr = _checkInArr.substr(0,_checkInArr.length-1).split(',');
					for (var i = 0; i < _checkInArr.length; i++) {
						(function(ii){
							_i = parseInt((parseInt(_checkInArr[ii])-1)/_h);
							_j = (parseInt(_checkInArr[ii])-1)%_h;
							console.log(_checkInArr[ii]);
							_ResolutionData = returnResolution(_checkInArr[ii],VideoWallTxDeviceID);
							console.log('resolution:'+_ResolutionData);
							_ResolutionData = _ResolutionData.split(',');
							
							_dataCommand = 'join '+VideoWallTxDeviceID+':HDMI:0 '
									+PresetDataDetail[_i][_j]+':HDMI:0 wall size '+parameterResolution[VideoWallResolutionSelectNum]+' fps '+_ResolutionData[8]+' offset '+
									_ResolutionData[0]+' '+_ResolutionData[1]+' keep '+_ResolutionData[2]+' '+_ResolutionData[3]+
									' viewport '+_ResolutionData[4]+' '+_ResolutionData[5]+' '+_ResolutionData[6]+' '+_ResolutionData[7];
							sendCommand('data='+_dataCommand);
							console.log('dataCommand:'+_dataCommand);

							var _arrRx1 = _data.videoswitching_decode_arr.split(',');
							var _arrTx1 = _data.videoswitching_encode_arr.split(',');
							var _numRx1='',_numTx1='';
							for (var i = 0; i <_arrTx1.length; i++) {
								(function(ii){
									if (_arrTx1[ii]==VideoWallTxDeviceID) {
										_numTx1=ii;//匹配设备ID,存储到相应序号设备数据			
									}
								})(i);		
							}
							for (var i = 0; i <_arrRx1.length; i++) {
								(function(ii){
									if (_arrRx1[ii]==PresetDataDetail[_i][_j]) {
										_numRx1=ii;//匹配设备ID,存储到相应序号设备数据
									}
								})(i);		
							}
						
							SystemLogWriteToFileAnother('Video Wall Parameters',EncodeVideoWallDataArr[_numTx1][2]+' >> '+DecodeVideoWallDataArr[_numRx1][2]);
							var _PresetData = "{'x':'"+$('#VideoWallSizeX').val()+
									"','y':'"+$('#VideoWallSizeY').val()+
									"','top':'"+$('#BezelTop').val()+
									"','bottom':'"+$('#BezelBottom').val()+
									"','left':'"+$('#BezelLeft').val()+
									"','right':'"+$('#BezelRight').val()+
									"','tx':'"+VideoWallTxDeviceID+
									"','resolution':'"+parameterResolution[VideoWallResolutionSelectNum]+
									"','data':'"+PresetDataDetail.toString()+"'}";
							ReadDataFromFile('firstsaveToFile=1&savedata='+_PresetData);
							$('.VideoWallDisplayResolution').html('Wall Resolution : '+parameterResolution[VideoWallResolutionSelectNum].replace(' ','x'));
						})(i);
					}
					VideoWallEncoderDrop = 0;
				}
				var _PresetData = "{'x':'"+$('#VideoWallSizeX').val()+
						"','y':'"+$('#VideoWallSizeY').val()+
						"','top':'"+$('#BezelTop').val()+
						"','bottom':'"+$('#BezelBottom').val()+
						"','left':'"+$('#BezelLeft').val()+
						"','right':'"+$('#BezelRight').val()+
						"','tx':'"+VideoWallTxDeviceID+
						"','resolution':'"+parameterResolution[VideoWallResolutionSelectNum]+
						"','data':'"+PresetDataDetail.toString()+"'}";
				ReadDataFromFile('firstsaveToFile=1&savedata='+_PresetData);
			}
		});		
	}	
});
$('#IPA1100VideoWallParameterContTxDrop').on('mouseup',function(){
	if (VideoWallEncoderDrop==1) {
		$('#IPA1100VideoWallParameterContTxDrop').html($('.IPAV1100VideoWallTxCont li:eq('+EncoderChannelNum+')').html());
		VideoWallTxDeviceID = EncodeVideoWallDataArr[EncoderChannelNum][1];
		VideoWallEncoderDrop=0;
		VideoWallEventListen(3);

		if ($('.connectionToServerBtn').html()=='Connect') {
			return;
		}
		var _checkInArr='';
		//VideoWallResolutionSelectNum = 1;
		$('#IPA1100VideoWallParameterContWallUl li').each(function(e){
			if ($('#IPA1100VideoWallParameterContWallUl li:eq('+e+') div').hasClass('videoWallDecoderBottomClick')) {
				_checkInArr += (e+1)+',';
			}
		});
		if (_checkInArr=='') {
			return;
		}
		var presetid = parseInt($('.listHeadLeftContPresetSelect').val())-1;
		var _i,_j;//parameterResolution
		var _dataCommand;
		var _h,_v,_i,_j;
		_h = parseInt($('#VideoWallSizeX').val());
		_v = parseInt($('#VideoWallSizeY').val());
		_checkInArr = _checkInArr.substr(0,_checkInArr.length-1).split(',');
		for (var i = 0; i < _checkInArr.length; i++) {
			(function(ii){
				_i = parseInt((parseInt(_checkInArr[ii])-1)/_h);
				_j = (parseInt(_checkInArr[ii])-1)%_h;
				console.log(_checkInArr[ii]);
				_ResolutionData = returnResolution(_checkInArr[ii],VideoWallTxDeviceID);
				console.log('resolution:'+_ResolutionData);
				_ResolutionData = _ResolutionData.split(',');
				
				// _dataCommand = 'join '+VideoWallTxDeviceID+':HDMI:0 '
				// 	+PresetDataDetail[_i][_j]+':HDMI:0 wall size '+VideoWallResolutionArr[1][0]+' '+VideoWallResolutionArr[1][1]+' fps 60 offset '+
				// 	_ResolutionData[0]+' '+_ResolutionData[1]+' keep '+_ResolutionData[2]+' '+_ResolutionData[3]+
				// 	' viewport '+_ResolutionData[4]+' '+_ResolutionData[5]+' '+_ResolutionData[6]+' '+_ResolutionData[7];
				_dataCommand = 'join '+VideoWallTxDeviceID+':HDMI:0 '
						+PresetDataDetail[_i][_j]+':HDMI:0 wall size '+parameterResolution[VideoWallResolutionSelectNum]+' fps '+_ResolutionData[8]+' offset '+
						_ResolutionData[0]+' '+_ResolutionData[1]+' keep '+_ResolutionData[2]+' '+_ResolutionData[3]+
						' viewport '+_ResolutionData[4]+' '+_ResolutionData[5]+' '+_ResolutionData[6]+' '+_ResolutionData[7];
				sendCommand('data='+_dataCommand);
				console.log('dataCommand:'+_dataCommand);

				var _arrRx1 = _data.videoswitching_decode_arr.split(',');
							var _arrTx1 = _data.videoswitching_encode_arr.split(',');
							var _numRx1='',_numTx1='';
							for (var i = 0; i <_arrTx1.length; i++) {
								(function(ii){
									if (_arrTx1[ii]==VideoWallTxDeviceID) {
										_numTx1=ii;//匹配设备ID,存储到相应序号设备数据			
									}
								})(i);		
							}
							for (var i = 0; i <_arrRx1.length; i++) {
								(function(ii){
									if (_arrRx1[ii]==PresetDataDetail[_i][_j]) {
										_numRx1=ii;//匹配设备ID,存储到相应序号设备数据
									}
								})(i);		
							}
						
							SystemLogWriteToFileAnother('Video Wall Parameters',EncodeVideoWallDataArr[_numTx1][2]+' >> '+DecodeVideoWallDataArr[_numRx1][2]);
				var _PresetData = "{'x':'"+$('#VideoWallSizeX').val()+
						"','y':'"+$('#VideoWallSizeY').val()+
						"','top':'"+$('#BezelTop').val()+
						"','bottom':'"+$('#BezelBottom').val()+
						"','left':'"+$('#BezelLeft').val()+
						"','right':'"+$('#BezelRight').val()+
						"','tx':'"+VideoWallTxDeviceID+
						"','resolution':'"+parameterResolution[VideoWallResolutionSelectNum]+
						"','data':'"+PresetDataDetail.toString()+"'}";
				ReadDataFromFile('firstsaveToFile=1&savedata='+_PresetData);
				$('.VideoWallDisplayResolution').html('Wall Resolution : '+parameterResolution[VideoWallResolutionSelectNum].replace(' ','x'));
			})(i);
		}
	}	
});
// 视频墙改变分辨率
var VideoWallResolutionSelectNum;
$('#VideoWallResolution .RxDeviceOptionsRightGenlockScaling .RxDeviceOptionsRightNavList').each(function(ev){
	$(this).on('click',function(){		
		//if (DecoderConfigurationDeviceNumb==0) return;
		if ($('.connectionToServerBtn').html()=='Connect') {
			return;
		}
		var _checkInArr='';
		VideoWallResolutionSelectNum = ev;
		$('#IPA1100VideoWallParameterContWallUl li').each(function(e){
			if ($('#IPA1100VideoWallParameterContWallUl li:eq('+e+') div').hasClass('videoWallDecoderBottomClick')) {
				_checkInArr += (e+1)+',';
			}
		});
		if (_checkInArr=='') {
			return;
		}
		var presetid = parseInt($('.listHeadLeftContPresetSelect').val())-1;
		var _i,_j;//parameterResolution
		var _dataCommand;
		var _h,_v,_i,_j;
		_h = parseInt($('#VideoWallSizeX').val());
		_v = parseInt($('#VideoWallSizeY').val());
		_checkInArr = _checkInArr.substr(0,_checkInArr.length-1).split(',');
		for (var i = 0; i < _checkInArr.length; i++) {
			(function(ii){
				_i = parseInt((parseInt(_checkInArr[ii])-1)/_h);
				_j = (parseInt(_checkInArr[ii])-1)%_h;
				console.log(_checkInArr[ii]);
				_ResolutionData = returnResolution(_checkInArr[ii],VideoWallTxDeviceID);
				console.log('resolution:'+_ResolutionData);
				_ResolutionData = _ResolutionData.split(',');

				_dataCommand = 'join '+VideoWallTxDeviceID+':HDMI:0 '
						+PresetDataDetail[_i][_j]+':HDMI:0 wall size '+parameterResolution[ev]+' fps '+_ResolutionData[8]+' offset '+
						_ResolutionData[0]+' '+_ResolutionData[1]+' keep '+_ResolutionData[2]+' '+_ResolutionData[3]+
						' viewport '+_ResolutionData[4]+' '+_ResolutionData[5]+' '+_ResolutionData[6]+' '+_ResolutionData[7];

				// _dataCommand = 'join '+VideoWallTxDeviceID+':HDMI:0 '
				// 	+PresetDataDetail[_i][_j]+':HDMI:0 wall size '+VideoWallResolutionArr[ev][0]+' '+VideoWallResolutionArr[ev][1]+' fps 60 offset '+
				// 	_ResolutionData[0]+' '+_ResolutionData[1]+' keep '+_ResolutionData[2]+' '+_ResolutionData[3]+
				// 	' viewport '+_ResolutionData[4]+' '+_ResolutionData[5]+' '+_ResolutionData[6]+' '+_ResolutionData[7];
				sendCommand('data='+_dataCommand);
				var _PresetData = "{'x':'"+$('#VideoWallSizeX').val()+
						"','y':'"+$('#VideoWallSizeY').val()+
						"','top':'"+$('#BezelTop').val()+
						"','bottom':'"+$('#BezelBottom').val()+
						"','left':'"+$('#BezelLeft').val()+
						"','right':'"+$('#BezelRight').val()+
						"','tx':'"+VideoWallTxDeviceID+
						"','resolution':'"+parameterResolution[ev]+
						"','data':'"+PresetDataDetail.toString()+"'}";
				ReadDataFromFile('firstsaveToFile=1&savedata='+_PresetData);
				console.log('dataCommand:'+_dataCommand);
				var _arrRx1 = _data.videoswitching_decode_arr.split(',');
							var _arrTx1 = _data.videoswitching_encode_arr.split(',');
							var _numRx1='',_numTx1='';
							for (var i = 0; i <_arrTx1.length; i++) {
								(function(ii){
									if (_arrTx1[ii]==VideoWallTxDeviceID) {
										_numTx1=ii;//匹配设备ID,存储到相应序号设备数据			
									}
								})(i);		
							}
							for (var i = 0; i <_arrRx1.length; i++) {
								(function(ii){
									if (_arrRx1[ii]==PresetDataDetail[_i][_j]) {
										_numRx1=ii;//匹配设备ID,存储到相应序号设备数据
									}
								})(i);		
							}
						
							SystemLogWriteToFileAnother('Video Wall Parameters',EncodeVideoWallDataArr[_numTx1][2]+' >> '+DecodeVideoWallDataArr[_numRx1][2]);
				$('.VideoWallDisplayResolution').html('Wall Resolution : '+parameterResolution[ev].replace(' ','x'));
			})(i);
		}
		$('#WallParameters span:eq(7)').html(parameterResolutionDisplay[ev]);
	});
});
// Group 
$('.GroupOptionsRight .GroupOptionsRightNavList').each(function(e){
	$(this).on('mouseover',function(){
		$(this).css('background-color','#6797b8');
		$('.GroupOptionsRight .GroupOptionsRightNavList:eq('+e+') .IPAV1100GroupOptionsNavSecL').css('background-color','#006eb8');
	});
	$(this).on('mouseleave',function(){
		$(this).css('background-color','#313d49');
		$('.GroupOptionsRight .GroupOptionsRightNavList:eq('+e+') .IPAV1100GroupOptionsNavSecL').css('background-color','#313d49');
	});
});
// $('#VideoWallPresetList .GroupRxSelectBoxNav li').each(function(e){
// 	$(this).on('mouseover',function(){
// 		$(this).css('background-color','#6797b8');
// 		$('#VideoWallPresetList .GroupRxSelectBoxNav li:eq('+e+') .IPAV1100GroupOptionsNavSecL').css('background-color','#006eb8');
// 		$('#VideoWallPresetList .GroupRxSelectBoxNav li:eq('+e+') .IPAV1100GroupSelectNavIco').css('background-image','url(../images/GroupSelectNavIcoHover.png)');
		
// 	});
// 	$(this).on('mouseleave',function(){
// 		$(this).css('background-color','#23272d');
// 		$('#VideoWallPresetList .GroupRxSelectBoxNav li:eq('+e+') .IPAV1100GroupOptionsNavSecL').css('background-color','#23272d');
// 		$('#VideoWallPresetList .GroupRxSelectBoxNav li:eq('+e+') .IPAV1100GroupSelectNavIco').css('background-image','url(../images/GroupSelectNavIco.png)');
// 	});
// });
// video wall effect ------------------------------------------------------
VideoWallEventListen(1);
$('.VideoWallParameterHoverDevice').on('mouseover',function(){
	$(this).show();
});
$('.VideoWallParameterHoverDevice').on('mouseleave',function(){
	$(this).hide();
});
$('body').on('click',function(){
	if (_VedioWallHideBox==0) {
		// console.log(0);
		$('#VideoWallRemoveFromWall').hide();
	}
		
	if (_VideoWallGroupRxSettingOver==1) {
		if (_VideoWallGroupTxSettingOver==0){
			$('#VideoWallGroupOptionsTx').hide();
			$('#VideoWallTxDeviceRenameBox').css('left','165px');
			_VideoWallGrouopTxSetting=0;
			$('#VideoWallGroupTxSelectBox').hide();
			_VideoWallGrouopTxSelect=0;
		}
		return;
	}
	if (_VideoWallGroupTxSettingOver==1) {
		if (_VideoWallGroupRxSettingOver==0){
			$('#VideoWallGroupOptionsRx').hide();
			$('#VideoWallRxDeviceRenameBox').css('left','165px');
			_VideoWallGrouopRxSetting=0;
			$('#VideoWallGroupRxSelectBox').hide();
			_VideoWallGrouopRxSelect=0;
		}
		return;
	}
	if (PresetDisplayClick==1){
		if (_VideoPresetChangeName==0) {
			$('#VideoWallPresetList').hide();
			PresetDisplayClick=0;
		}			
	}
	if (_VideoWallGrouopTxSetting==1){
		$('#VideoWallGroupOptionsTx').hide();
		$('#VideoWallTxDeviceRenameBox').css('left','165px');
		_VideoWallGrouopTxSetting=0;
	}
	if (_VideoWallGrouopRxSetting==1){
		$('#VideoWallGroupOptionsRx').hide();
		$('#VideoWallRxDeviceRenameBox').css('left','165px');
		_VideoWallGrouopRxSetting=0;
	}
	if (_VideoWallGrouopTxSelect==1){
		$('#VideoWallGroupTxSelectBox').hide();
		_VideoWallGrouopTxSelect=0;
	}
	if (_VideoWallGrouopRxSelect==1){
		$('#VideoWallGroupRxSelectBox').hide();
		_VideoWallGrouopRxSelect=0;
	}
});
var _VideoWallGroupRxSettingOver = 0;
$('#VideoWallGroupOptionSettingRx').on('mouseover',function(){
	_VideoWallGroupRxSettingOver = 1;
});
$('#VideoWallGroupOptionSettingRx').on('mouseleave',function(){
	_VideoWallGroupRxSettingOver = 0;
});
$('#VideoWallGroupOptionsRx').on('mouseover',function(){
	_VideoWallGroupRxSettingOver = 1;
});
$('#VideoWallGroupOptionsRx').on('mouseleave',function(){
	_VideoWallGroupRxSettingOver = 0;
});
// ------------------------------
$('#VideoWallGroupSelectRx').on('mouseover',function(){
	_VideoWallGroupRxSettingOver = 1;
});
$('#VideoWallGroupSelectRx').on('mouseleave',function(){
	_VideoWallGroupRxSettingOver = 0;
});
$('#VideoWallGroupRxSelectBox').on('mouseover',function(){
	_VideoWallGroupRxSettingOver = 1;
});
$('#VideoWallGroupRxSelectBox').on('mouseleave',function(){
	_VideoWallGroupRxSettingOver = 0;
});

var _VideoWallGroupTxSettingOver = 0;
$('#VideoWallGroupOptionSettingTx').on('mouseover',function(){
	_VideoWallGroupTxSettingOver = 1;
});
$('#VideoWallGroupOptionSettingTx').on('mouseleave',function(){
	_VideoWallGroupTxSettingOver = 0;
});
$('#VideoWallGroupOptionsTx').on('mouseover',function(){
	_VideoWallGroupTxSettingOver = 1;
});
$('#VideoWallGroupOptionsTx').on('mouseleave',function(){
	_VideoWallGroupTxSettingOver = 0;
});
// ------------------------
$('#VideoWallGroupSelectTx').on('mouseover',function(){
	_VideoWallGroupTxSettingOver = 1;
});
$('#VideoWallGroupSelectTx').on('mouseleave',function(){
	_VideoWallGroupTxSettingOver = 0;
});
$('#VideoWallGroupTxSelectBox').on('mouseover',function(){
	_VideoWallGroupTxSettingOver = 1;
});
$('#VideoWallGroupTxSelectBox').on('mouseleave',function(){
	_VideoWallGroupTxSettingOver = 0;
});
// Group Rx Setting ---------------------------------
var _VideoWallGrouopRxSetting = 0;
$('#VideoWallGroupOptionSettingRx').on('click',function(){
	$('#VideoWallRemoveFromWall').hide();
	if (_VideoWallGrouopRxSetting==0) {
		$('#VideoWallGroupOptionsRx').show();
		$('#VideoWallGroupRxSelectBox').hide();
		_VideoWallGrouopRxSetting=1;
		_VideoWallGrouopRxSelect=0;
		_VideoWallGrouopTxSelect=0;
	}
	else if (_VideoWallGrouopRxSetting==1){
		$('#VideoWallGroupOptionsRx').hide();
		$('#VideoWallRxDeviceRenameBox').css('left','165px');
		_VideoWallGrouopRxSetting=0;
	}
	
});
// Group Tx Setting
var _VideoWallGrouopTxSetting = 0;
$('#VideoWallGroupOptionSettingTx').on('click',function(){
	$('#VideoWallRemoveFromWall').hide();
	if (_VideoWallGrouopTxSetting==0) {
		$('#VideoWallGroupOptionsTx').show();
		$('#VideoWallGroupTxSelectBox').hide();
		_VideoWallGrouopTxSetting=1;
		_VideoWallGrouopRxSelect=0;
		_VideoWallGrouopTxSelect=0;
	}
	else if (_VideoWallGrouopTxSetting==1){
		$('#VideoWallGroupOptionsTx').hide();
		$('#VideoWallTxDeviceRenameBox').css('left','165px');
		_VideoWallGrouopTxSetting=0;
	}
});
// Group select rx ---------------------------------
var _VideoWallGrouopRxSelect = 0;
$('#VideoWallGroupSelectRx').on('click',function(){
	$('#VideoWallRemoveFromWall').hide();
	if (_VideoWallGrouopRxSelect==0) {
		$('#VideoWallGroupRxSelectBox').show();
		$('#VideoWallGroupOptionsRx').hide();
		$('#VideoWallRxDeviceRenameBox').css('left','165px');
		_VideoWallGrouopRxSelect=1;
		_VideoWallGrouopRxSetting=0;
		_VideoWallGrouopTxSetting=0;
		PageAddGroup('type=11&pagetype=videowall&devicetype=rx');
	}
	else if (_VideoWallGrouopRxSelect==1){
		$('#VideoWallGroupRxSelectBox').hide();
		_VideoWallGrouopRxSelect=0;
	}
});
// Group select tx
var _VideoWallGrouopTxSelect = 0;
$('#VideoWallGroupSelectTx').on('click',function(){
	$('#VideoWallRemoveFromWall').hide();
	if (_VideoWallGrouopTxSelect==0) {
		$('#VideoWallGroupTxSelectBox').show();
		$('#VideoWallGroupOptionsTx').hide();
		$('#VideoWallTxDeviceRenameBox').css('left','165px');
		_VideoWallGrouopTxSelect=1;
		_VideoWallGrouopRxSetting=0;
		_VideoWallGrouopTxSetting=0;
		PageAddGroup('type=11&pagetype=videoswitching&devicetype=tx');
	}
	else if (_VideoWallGrouopTxSelect==1){
		$('#VideoWallGroupTxSelectBox').hide();
		_VideoWallGrouopTxSelect=0;
	}
});
// 场景选择显示
var PresetDisplayClick=0;
var PresetSelectNum=0;
$('#VideoWallPresetSelect').on('click',function(){
	$('#VideoWallRemoveFromWall').hide();
	if (PresetDisplayClick==0) {
		PageAddGroup('type=11&pagetype=videowall&devicetype=rx');
		$('#VideoWallPresetList').show();
		PresetDisplayClick=1;
		_VideoWallGrouopRxSelect=1;
	}
	else if (PresetDisplayClick==1) {
		$('#VideoWallPresetList').hide();
		PresetDisplayClick=0;
		_VideoWallGrouopRxSelect=0;
	}
});
$('#VideoWallPresetSelect').on('mouseover',function(){
	_VideoWallGroupTxSettingOver = 1;
});
$('#VideoWallPresetSelect').on('mouseleave',function(){
	_VideoWallGroupTxSettingOver = 0;
});
// 视频墙名字更改与点击事件
var _VideoPresetChangeName=0;
var _VideoPresetChangeNameTimer;
var _presetSelect;
$('#VideoWallPresetList li').each(function(e){
	$(this).on('mousedown',function(){
		_VideoPresetChangeNameTimer=setTimeout(function(){
			_presetSelect = e;
			_VideoPresetChangeName=1;
			$('.VideoWallPresetRenameBox').css('top',e*22+11+'px');
			$('.VideoWallPresetRenameBox input').val($('#VideoWallPresetList li:eq('+e+') div:eq(1)').html());
			$('.VideoWallPresetRenameBox').show();
		},1000);
	});
	$(this).on('mouseup',function(){
		if (_VideoPresetChangeName==0) {
			clearTimeout(_VideoPresetChangeNameTimer);
			$('#VideoWallPresetSelect span').html($('#VideoWallPresetList li:eq('+e+') div:eq(1)').html());
			PresetSelectNum = e;
		}
	});
});
$('.VideoWallPresetRenameBox .VideoWallPresetRenameBoxYes').on('click',function(){
		PresetNameReadFromFile(_presetSelect,$('.VideoWallPresetRenameBox input').val());
		_VideoPresetChangeName=1;
		$('.VideoWallPresetRenameBox').hide();
	setTimeout(function(){
		_VideoPresetChangeName=0;
	},200);
});
$('.VideoWallPresetRenameBox .VideoWallPresetRenameBoxNo').on('click',function(){
		$('.VideoWallPresetRenameBox').hide();
		_VideoPresetChangeName=1;
	setTimeout(function(){
		_VideoPresetChangeName=0;
	},200);
});
$('#VideoWallPrsetDel').on('click',function(){
	$('#VideoWallPresetDelectCont').show();
	$('#VideoWallPresetDelectCont .DeviceSendReceiveInfraredContText:eq(1)').html($('#VideoWallPresetSelect span').html());
});
$('#VideoWallPresetSaveContClose').on('click',function(){
	$('#VideoWallPresetSaveCont').hide();
});
$('#VideoWallPresetDelectContClose').on('click',function(){
	$('#VideoWallPresetDelectCont').hide();
});
$('#VideoWallPresetDelectContNo').on('click',function(){
	$('#VideoWallPresetDelectCont').hide();
});
$('#VideoWallPresetDelectContYes').on('click',function(){
	ReadDataFromFile('saveToFile='+PresetSelectNum+'&savedata=');
	$('#VideoWallPresetDelectCont').hide();

	$('#VideoWallSizeX').val(_presetArr.x);
    $('#VideoWallSizeY').val(_presetArr.y);

    $('#BezelTop').val(_presetArr.top);
    $('#BezelBottom').val(_presetArr.bottom);
    $('#BezelLeft').val(_presetArr.left);
    $('#BezelRight').val(_presetArr.right);
    if (_presetArr.resolution.indexOf('Wall Resolution')>=0) {
        $('.VideoWallDisplayResolution').html(_presetArr.resolution);
    }
    else {
        $('.VideoWallDisplayResolution').html('Wall Resolution : '+_presetArr.resolution.replace(' ','x'));
    }
                    
    var _presetDataArr = _presetArr.data.split(',');
	var videowallX = parseInt($('#VideoWallSizeX').val());
    var videowallY = parseInt($('#VideoWallSizeY').val());
    //console.log(_presetDataArr);
    $('#IPA1100VideoWallParameterContWallUl').html('');
    $('#IPA1100VideoWallParameterContWallUl').css('width',(videowallX*40-2)+'px');
    PresetDataDetail=[];
    for (var j = 0; j < videowallY; j++) {
        PresetDataDetail[j]=[];
        for (var i = 0; i < videowallX; i++) {
            $('#IPA1100VideoWallParameterContWallUl').append('<li>\
                                                                <div class="IPA1100VideoWallParameterContWallULLIFlag"></div>\
                                                            </li>');
            PresetDataDetail[j][i]='';
        }
        $('#IPA1100VideoWallParameterContWallUl li:eq('+(videowallY*videowallX+videowallX-1)+')').css('border-right','none');
    }
});
$('#VideoWallPresetSave').on('click',function(){
	$('#VideoWallPresetSaveCont').show();
});
// 场景保存按钮
VideoWallTxDeviceID = '';
$('#VideoWallPresetSaveContSave').on('click',function(){
	var _DecodeVideoMode = new Array();
	var _DecodeVideoResolution = new Array();
	var _PresetDataDetail = PresetDataDetail.toString().split(',');
	for (var i = 0; i < _PresetDataDetail.length; i++) {
		if (''!=_PresetDataDetail[i]&&'undefined'!=typeof(_PresetDataDetail[i])) {
			for (var j = 0; j < DecodeVideoWallDataArr.length; j++) {
				if (''!=DecodeVideoWallDataArr[j]&&'undefined'!=typeof(DecodeVideoWallDataArr[j])) {
					if (DecodeVideoWallDataArr[j][1]==_PresetDataDetail[i]) {
						_DecodeVideoMode[i] = DecodeVideoWallDataArr[j][4];
						_DecodeVideoResolution[i] = DecodeVideoWallDataArr[j][7]+' '
													+DecodeVideoWallDataArr[j][8]+' fps '
													+DecodeVideoWallDataArr[j][9];
					}
				}
			}
			//DecodeVideoWallDataArr
		}
	}	
	var _PresetData = "{'x':'"+$('#VideoWallSizeX').val()+
						"','y':'"+$('#VideoWallSizeY').val()+
						"','top':'"+$('#BezelTop').val()+
						"','bottom':'"+$('#BezelBottom').val()+
						"','left':'"+$('#BezelLeft').val()+
						"','right':'"+$('#BezelRight').val()+
						"','tx':'"+VideoWallTxDeviceID+
						"','resolution':'"+$('.VideoWallDisplayResolution').html()+
						"','data':'"+PresetDataDetail.toString()+
						"','DecodeModeData':'"+_DecodeVideoMode.toString()+
						"','DecodeModeResolution':'"+_DecodeVideoResolution.toString()+"'}";
	ReadDataFromFile('saveToFile='+PresetSelectNum+'&savedata='+_PresetData);
	$('#VideoWallPresetSaveCont').hide();
});
// 场景调用按钮
$('#VideoWallPresetSaveContRecall').on('click',function(){
	ReadDataFromFile('RecallFromFile='+PresetSelectNum,'PresetRecall');
	$('#VideoWallPresetSaveCont').hide();
});
// device bottom info
// video change resolution
$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRight1 .RxDeviceOptionsRightNavList').each(function(e){
	$(this).on('mouseover',function(){
		// if (DecoderConfigurationDeviceNumb==0) return;
		//clearTimeout(_settimeoutResolution);
		$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightGenlockScaling').hide();
		$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitch').hide();
		_settimeoutResolution=setTimeout(function(){
			if (_VideoPageResolutionFormats==0) {
				$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitchNav').hide();
			}
		},300);
		
		$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightGroupDisplay').hide();
		if (e==1) {
			CheckBoxIsOverflow(0,3);
			$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightGenlockScaling').show();
		}
		if (e==2) {
			CheckBoxIsOverflow(0,3);
			$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitch').show();
		}
		if (1) {
				if (e==10) {
					CheckBoxIsOverflow(0,3);
					$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightGroupDisplay').show();

				}
		}
	});
});
$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitch').on('mouseover',function(){
	_VideoPageResolutionFormats = 1;
});
$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitch').on('mouseleave',function(){
	_VideoPageResolutionFormats = 0;
});
$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitchNav').on('mouseover',function(){
	_VideoPageResolutionFormats = 1;
});
$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitchNav').on('mouseleave',function(){
	$(this).hide();
	_VideoPageResolutionFormats = 0;
});
$('#VideoWallConfigurationTxDevice .RxDeviceOptionsRight .RxDeviceOptionsRightNavList').each(function(e){
	$(this).on('mouseover',function(){
		// if (DecoderConfigurationDeviceNumb==0) return;
		$('#VideoWallConfigurationTxDevice .RxDeviceOptionsRightGroupDisplay').hide();
		if (1) {
			if (e==9) {
				CheckBoxIsOverflow(0,3);
				$('#VideoWallConfigurationTxDevice .RxDeviceOptionsRightGroupDisplay').show();
			}
		}				
	});		
});
var _videoFastSwitchMode;
$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitch .RxDeviceOptionsRightNavList').each(function(e){
	$(this).on('mouseover',function(){
		// if (DecoderConfigurationDeviceNumb==0) return;
		$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitchNav').show();
		_videoFastSwitchMode = e;

		$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitchNav .IPAV1100RxDeviceOptionsNavSecL').removeClass('IPAV1100RxDeviceOptionsNavSecLHover');
		if ($('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitch .IPAV1100RxDeviceOptionsNavSecL:eq('+e+')').hasClass('IPAV1100RxDeviceOptionsNavSecLHover')) {
			console.log(e);
			$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitchNav .IPAV1100RxDeviceOptionsNavSecL:eq('+_DecoderFastSwitchFullScreen+')').addClass('IPAV1100RxDeviceOptionsNavSecLHover');
		}
		if (e==0) {
			$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitchNav').css('top','91px');
		}
		if (e==1) {
			$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitchNav').css('top','112px');
		}
		if (e==2) {
			$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitchNav').css('top','134px');
		}
		CheckBoxIsOverflow(3,3);
	});
});
// 
// decoder点击弹窗显示-------------------------------
$('#VideoWallSendReceiveRS232').on('click',function(){
	if (DecoderConfigurationDeviceNumb==0) return;
	DecoderOrEncoder = 1;
	$('#DeviceSendReceiveRs232').show();
	loadingDeviceIDRs232();
});
$('#VideoWallSendReceiveIR').on('click',function(){
	if (DecoderConfigurationDeviceNumb==0) return;
	DecoderOrEncoder = 1;
	$('#DeviceSendReceiveInfrared').show();
	loadingDeviceIDInfrared();
	});
$('#VideoWallFactoryReset').on('click',function(){
	DecoderOrEncoder = 1;
	$('#DeviceFactoryReset').show();
});
$('#VideoWallReboot').on('click',function(){
	DecoderOrEncoder = 1;
	$('#DeviceReboot').show();
	});
// encoder点击弹窗显示------------------------------
$('#VideoWallSendReceiveRS232Tx').on('click',function(){
	DecoderOrEncoder = 2;
	$('#DeviceSendReceiveRs232').show();
	loadingDeviceIDRs232();
});
$('#VideoWallSendReceiveIRTx').on('click',function(){
	DecoderOrEncoder = 2;
	$('#DeviceSendReceiveInfrared').show();
	loadingDeviceIDInfrared();
	});
$('#VideoWallFactoryResetTx').on('click',function(){
	DecoderOrEncoder = 2;
	$('#DeviceFactoryReset').show();
});
$('#VideoWallRebootTx').on('click',function(){
	DecoderOrEncoder = 2;
	$('#DeviceReboot').show();
});
// decoder configuration click function  发送指令----------------------------------------------
$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightNavList:eq(0)').on('click',function(){//genlock	
	var _arrRx = _data.videoswitching_decode_arr.split(',');
	var _DecodeRx;
		if (DecoderConfigurationDeviceNumb==0)
			_DecodeRx = 'ALL_RX';
		else
			_DecodeRx = _arrRx[DecoderConfigurationDeviceNumb-1];		
	sendCommand('data=set '+_DecodeRx+' video genlock');
	SystemLogWriteToFileAnother('Video Wall Decoder','Genlock');
});
$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightGenlockScaling .RxDeviceOptionsRightNavList').each(function(e){// genlock scalling
	$(this).on('click',function(){
		var _arrRx = _data.videoswitching_decode_arr.split(',');
		var _DecodeRx;
			if (DecoderConfigurationDeviceNumb==0)
				_DecodeRx = 'ALL_RX';
			else
				_DecodeRx = _arrRx[DecoderConfigurationDeviceNumb-1];
		sendCommand('data=set '+_DecodeRx+' video genlock_scaling size '+_genlockscalling[e]);
		SystemLogWriteToFileAnother('Video Wall Decoder','Genlock Scalling');
	});
});
$('#VideoWallConfigurationRxDevice .RxDeviceOptionsRightFastSwitchNav .RxDeviceOptionsRightNavList').each(function(e){// fast switch
	$(this).on('click',function(){
		var _arrRx = _data.videoswitching_decode_arr.split(',');
		var _DecodeRx;
			if (DecoderConfigurationDeviceNumb==0)
				_DecodeRx = 'ALL_RX';
			else
				_DecodeRx = _arrRx[DecoderConfigurationDeviceNumb-1];
		if (_videoFastSwitchMode == 0) {
			sendCommand('data=set '+_DecodeRx+' video fastswitch size '+_fastswitch[e]);
		}
		else if(_videoFastSwitchMode == 1){
			sendCommand('data=set '+_DecodeRx+' video fastswitch stretch size '+_fastswitch[e]);
		}
		else if(_videoFastSwitchMode == 2){
			sendCommand('data=set '+_DecodeRx+' video fastswitch crop size '+_fastswitch[e]);
		}
		SystemLogWriteToFileAnother('Video Wall Decoder','Fast Switch Full Screen');
	});
});
$('#VideoWallLeaveVideoChannel').on('click',function(){	
	var _arrRx = _data.videoswitching_decode_arr.split(',');
	var _DecodeRx;
		if (DecoderConfigurationDeviceNumb==0)
			_DecodeRx = 'ALL_RX';
		else
			_DecodeRx = _arrRx[DecoderConfigurationDeviceNumb-1];
	sendCommand('data=leave '+_DecodeRx+':HDMI:0');
	SystemLogWriteToFileAnother('Video Wall Decoder','Leave Video Channel');
});
// ----------------------------------
$('#VideoWallConfigurationStartVideo').on('click',function(){
	var _arrRx = _data.videoswitching_encode_arr.split(',');		
	sendCommand('data=start '+_arrRx[EncoderConfigurationDeviceNumb]+':HDMI:0');
});
$('#VideoWallConfigurationStopVideo').on('click',function(){
	var _arrRx = _data.videoswitching_encode_arr.split(',');		
	sendCommand('data=stop '+_arrRx[EncoderConfigurationDeviceNumb]+':HDMI:0');
});
$('#VideoWallConfigurationStopAndFreeChannel').on('click',function(){
	$('#DeviceStopandFreeMulticastaddress').show();
	// var _arrRx = _data.videoswitching_encode_arr.split(',');		
	// sendCommand('data=stop '+_arrRx[EncoderConfigurationDeviceNumb]+':HDMI:0 free');
});
// 分组功能模块rename/////////////////////////////////////////////////////////////////////////////////
$('#VideoWallGroupOptionsRxRename').on('click',function(){
	if ($('#VideoWallGroupSelectRx span').html()!='Default') {
		$('#VideoWallRxDeviceRenameBox input').val($('#VideoWallPresetSelect span').html());
		$('#VideoWallRxDeviceRenameBox').css('left','11px');
	}	
});
$('#VideoWallRxDeviceRenameBoxYes').on('click',function(){
	var groupID = $('#VideoWallPresetList li:eq('+PresetSelectNum+') span').html();
	var name = $('#VideoWallRxDeviceRenameBox input').val();
	if (name=='') {
		$('#DisplayErrorContent .DeviceSendReceiveInfraredContText').html('Invalid Value!');
		$('#DisplayErrorContent').show();
		return;
	}
	var data = 'type=2&id='+groupID+'&rename='+name+'&pagetype=videowall&devicetype=rx';
	_VideoWallGrouopRxSelect = 1;
	PageAddGroup(data);
	$('#VideoWallPresetSelect span').html(name);
	$('#VideoWallRxDeviceRenameBox').css('left','165px');
});
$('#VideoWallRxDeviceRenameBoxNo').on('click',function(){
	$('#VideoWallRxDeviceRenameBox').css('left','165px');
});
$('#VideoWallGroupOptionsTxRename').on('click',function(){
	if ($('#VideoWallGroupSelectTx span').html()!='Default') {
		$('#VideoWallTxDeviceRenameBox input').val($('#VideoWallGroupSelectTx span').html());
		$('#VideoWallTxDeviceRenameBox').css('left','11px');
	}	
});
$('#VideoWallTxDeviceRenameBoxYes').on('click',function(){	
	var groupID = $('#VideoWallGroupTxSelectBox li:eq('+DeviceGroupTxSelectNum+') span:eq(1)').html();
	var name = $('#VideoWallTxDeviceRenameBox input').val();
	var data = 'type=2&id='+groupID+'&rename='+name+'&pagetype=videoswitching&devicetype=tx';
	_VideoWallGrouopTxSelect = 1;
	PageAddGroup(data);
	$('#VideoWallTxDeviceRenameBox').css('left','165px');
});
$('#VideoWallTxDeviceRenameBoxNo').on('click',function(){
	$('#VideoWallTxDeviceRenameBox').css('left','165px');
});
// 删除分组选项功能
$('#VideoWallGroupOptionsRxDelectGroup').on('click',function(){
	if ($('#VideoWallGroupSelectRx span').html()=='Default') {
        $('#DeleteGroupNeedComfirm').hide();
        return;
    }
	DeleteGroupDisplayBox('videowall','rx');
});
$('#VideoWallGroupOptionsTxDelectGroup').on('click',function(){
	if ($('#VideoWallGroupSelectTx span').html()=='Default') {
        $('#DeleteGroupNeedComfirm').hide();
        return;
    }
	DeleteGroupDisplayBox('videowall','tx');
});
// pageloading device box
function PageLoadingVideoWallDevice(){	
	// $('.IPAV1100ContentBottomLeft').css('width','15%');
	// $('.IPAV1100ContentBottomLeft').css('width',(parseInt($('.IPAV1100ContentBottomLeft').width())-1)+'px');
	if (current_page != 2) {
		return;
	}	
	$('.IPAV1100VideoWallRxCont').css('width','100%');
	$('.IPAV1100VideoWallTxCont').css('width','100%');
	var Exp_boxHeight = $('#BottomRightVideoWall').height();
	var Exp_CurrentBoxHeight = Exp_boxHeight-500-24;
	$('.IPAV1100ContentBottomRightVideoWallBottomCont').css('height',Exp_CurrentBoxHeight+'px');
	
	// rx device box reload -----------------------------
	var _EncoderDeviceBoxHeight = (parseInt((Exp_CurrentBoxHeight-42)/108)*120+108)<Exp_CurrentBoxHeight?(parseInt((Exp_CurrentBoxHeight-42)/108)*120+108):(parseInt((Exp_CurrentBoxHeight-42)/108-1)*120+108);
	$('.IPAV1100VideoWallTxContScrool').css('height',_EncoderDeviceBoxHeight+'px');

	var _IPAV1100RxCont = $('.IPAV1100VideoWallRxCont').width();
	var _IPAV1100TxCont = $('.IPAV1100VideoWallTxCont').width();
	var _IPAV1100TxContDisplayH = parseInt((_EncoderDeviceBoxHeight+12)/120);
	var _IPAV1100TxContDisplayH = _IPAV1100TxContDisplayH*3;
	var _x = 3*(parseInt((_IPAV1100RxCont-197)/209)+1);
	var _y = _IPAV1100TxContDisplayH*(parseInt((_IPAV1100TxCont-197)/209)+1);

	if (_IPAV1100RxCont>(_x/3*209+197-12) ) {
		$('.IPAV1100VideoWallRxCont').css('width','99%');
	}
	if (_IPAV1100TxCont>(_y/_IPAV1100TxContDisplayH*209+197-12) ) {
		$('.IPAV1100VideoWallTxCont').css('width','99%');
	}

	//$('.IPAV1100VideoWallTxCont').css('height',($('.IPAV1100VideoWallTxCont').height()-24)+'px');
	if ($('.IPAV1100VideoWallRxCont li').length<_x) {
		var _qidian = $('.IPAV1100VideoWallRxCont li').length;
		for (var i = _qidian; i <_x; i++) {
			$('.IPAV1100VideoWallRxCont').append("<li></li>");
		}
		$('.IPAV1100VideoWallRxCont li').each(function(){
			if ($(this).hasClass('IPAV1100RxContLiRepos')) {
				$(this).removeClass('IPAV1100RxContLiRepos');
			}			
		});
		for (var i = 1; i < 3; i++) {
			$('.IPAV1100VideoWallRxCont li:eq('+((_x/3)*i)+')').addClass('IPAV1100RxContLiRepos');
		}
	}
	if ($('.IPAV1100VideoWallRxCont li').length>_x) {
		$('.IPAV1100VideoWallRxCont li').each(function(){
			if ($(this).hasClass('IPAV1100RxContLiRepos')) {
				$(this).removeClass('IPAV1100RxContLiRepos');
			}
		});
		for (var i = 1; i < 3; i++) {
			$('.IPAV1100VideoWallRxCont li:eq('+((_x/3)*i)+')').addClass('IPAV1100RxContLiRepos');
		}
		
		var _length = $('.IPAV1100VideoWallRxCont li').length;
		for (var i = _length-1; i >= _x; i--) {
			$('.IPAV1100VideoWallRxCont li:eq('+i+')').remove();
		}
	}
	if ($('.IPAV1100VideoWallTxCont li').length<_y) {
		var _qidian = $('.IPAV1100VideoWallTxCont li').length;
		for (var i = _qidian; i <_y; i++) {
			$('.IPAV1100VideoWallTxCont').append("<li></li>");
		}
		$('.IPAV1100VideoWallTxCont li').each(function(){
			if ($(this).hasClass('IPAV1100RxContLiRepos')) {
				$(this).removeClass('IPAV1100RxContLiRepos');
			}			
		});
		for (var i = 1; i < _IPAV1100TxContDisplayH; i++) {
			$('.IPAV1100VideoWallTxCont li:eq('+(_y/_IPAV1100TxContDisplayH)*i+')').addClass('IPAV1100RxContLiRepos');
		}

	}
	if ($('.IPAV1100VideoWallTxCont li').length>_y) {
		$('.IPAV1100VideoWallTxCont li').each(function(){
			if ($(this).hasClass('IPAV1100RxContLiRepos')) {
				$(this).removeClass('IPAV1100RxContLiRepos');
			}
		});
		for (var i = 1; i < _IPAV1100TxContDisplayH; i++) {
			$('.IPAV1100VideoWallTxCont li:eq('+(_y/_IPAV1100TxContDisplayH)*i+')').addClass('IPAV1100RxContLiRepos');
		}
		
		var _length = $('.IPAV1100VideoWallTxCont li').length;
		for (var i = _length-1; i >= _y; i--) {
			$('.IPAV1100VideoWallTxCont li:eq('+i+')').remove();
		}
	}
	AddEventListen(3);
	AddEventListen(4);
}
// decoder configuration setting
function VideoWallDecoderConfigurationSettingBox(){
	var _DecoderConfigurationDeviceNumb = DecoderConfigurationDeviceNumb;
	if (_DecoderConfigurationDeviceNumb==0) return;
	$('#DeviceRxConfigurationBox .DeviceDecoderConfigurationNav span:eq(0)').html('Decoder '+  +' Configuration');
	$('#DeviceRxConfigurationBox .DeviceDecoderConfigurationRightNavCIco').attr('src','images/SettingRadioOff.png');
	// Analog Audio Output
	if (DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][0]==2) {
		$('#DeviceRxConfigurationBox .DeviceDecoderConfigurationRightNavCIco:eq(0)').attr('src','images/SettingRadioOn.png');
	}else if (DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][0]==3) {
		$('#DeviceRxConfigurationBox .DeviceDecoderConfigurationRightNavCIco:eq(1)').attr('src','images/SettingRadioOn.png');
	}
	// HDMI Audio Output
	if (DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][1]==2) {
		$('#DeviceRxConfigurationBox .DeviceDecoderConfigurationRightNavCIco:eq(2)').attr('src','images/SettingRadioOn.png');
	}else if (DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][1]==3) {
		$('#DeviceRxConfigurationBox .DeviceDecoderConfigurationRightNavCIco:eq(3)').attr('src','images/SettingRadioOn.png');
	}else if (DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][1]==6) {
		$('#DeviceRxConfigurationBox .DeviceDecoderConfigurationRightNavCIco:eq(4)').attr('src','images/SettingRadioOn.png');
	}else if (DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][1]==7) {
		$('#DeviceRxConfigurationBox .DeviceDecoderConfigurationRightNavCIco:eq(5)').attr('src','images/SettingRadioOn.png');
	}
	// Display EDID
	$('#DeviceRxConfigurationBox .DeviceDecoderConfigurationRightNavCEDIDTxt').html(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][2]);
	// Network Setting
	$('#DeviceRxConfigurationBox #DecoderHostname').val(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][3]);
	if (DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][4]=='DHCP')
		$('#DeviceRxConfigurationBox #DecoderIPMode').val('0');
	else
		$('#DeviceRxConfigurationBox #DecoderIPMode').val('1');
	
	$('#DeviceRxConfigurationBox #DecoderIPAdress').val(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][5]);
	$('#DeviceRxConfigurationBox #DecoderMask').val(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][6]);
	$('#DeviceRxConfigurationBox #DecoderGateway').val(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][7]);
	if ($('#DeviceRxConfigurationBox #DecoderIPMode').val()=='0') {
		$('#DeviceRxConfigurationBox #DecoderIPAdress').attr('disabled',true);
		$('#DeviceRxConfigurationBox #DecoderMask').attr('disabled',true);
		$('#DeviceRxConfigurationBox #DecoderGateway').attr('disabled',true);
		$('#DeviceRxConfigurationBox #DecoderIPAdress').addClass('textDisabled');
		$('#DeviceRxConfigurationBox #DecoderMask').addClass('textDisabled');
		$('#DeviceRxConfigurationBox #DecoderGateway').addClass('textDisabled');
	}else if($('#DeviceRxConfigurationBox #DecoderIPMode').val()=='1'){
		$('#DeviceRxConfigurationBox #DecoderIPAdress').attr('disabled',false);
		$('#DeviceRxConfigurationBox #DecoderMask').attr('disabled',false);
		$('#DeviceRxConfigurationBox #DecoderGateway').attr('disabled',false);
		$('#DeviceRxConfigurationBox #DecoderIPAdress').removeClass('textDisabled');
		$('#DeviceRxConfigurationBox #DecoderMask').removeClass('textDisabled');
		$('#DeviceRxConfigurationBox #DecoderGateway').removeClass('textDisabled');
	}
	// RS232
	if (DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][8]==2400) {
		$('#DeviceRxConfigurationBox #DecoderRs232BaudRate').val('0');
	}else if(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][8]==4800){
		$('#DeviceRxConfigurationBox #DecoderRs232BaudRate').val('1');
	}else if(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][8]==9600){
		$('#DeviceRxConfigurationBox #DecoderRs232BaudRate').val('2');
	}else if(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][8]==19200){
		$('#DeviceRxConfigurationBox #DecoderRs232BaudRate').val('3');
	}else if(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][8]==38400){
		$('#DeviceRxConfigurationBox #DecoderRs232BaudRate').val('4');
	}else if(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][8]==57600){
		$('#DeviceRxConfigurationBox #DecoderRs232BaudRate').val('5');
	}else if(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][8]==115200){
		$('#DeviceRxConfigurationBox #DecoderRs232BaudRate').val('6');
	}
	if(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][9]==7){
		$('#DeviceRxConfigurationBox #DecoderRs232DataBit').val('0');
	}else if(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][9]==8){
		$('#DeviceRxConfigurationBox #DecoderRs232DataBit').val('1');
	}
	if (DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][10]==1) {
		$('#DeviceRxConfigurationBox #DecoderRs232StopBit').val('0');
	}else if(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][10]==2){
		$('#DeviceRxConfigurationBox #DecoderRs232StopBit').val('1');
	}
	if (DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][11]=='NONE') {
		$('#DeviceRxConfigurationBox #DecoderRs232Parity').val('0');
	}else if(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][11]=='ODD'){
		$('#DeviceRxConfigurationBox #DecoderRs232Parity').val('1');
	}else if(DecodeDetaileDataArr[_DecoderConfigurationDeviceNumb-1][11]=='EVEN'){
		$('#DeviceRxConfigurationBox #DecoderRs232Parity').val('2');
	}
}
// encoder configuration setting
function VideoWallEncoderConfigurationSettingBox(){
	var _EncoderConfigurationDeviceNumb = EncoderConfigurationDeviceNumb;
	if (EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][0]) {
		$('#HDCPSupport').val('0');
		$('#HDCP22Support').attr('disabled',false);		
		$('#HDCP22Support').removeClass('textDisabled');
	}else{
		$('#HDCPSupport').val('1');
		$('#HDCP22Support').attr('disabled',true);

		$('#HDCP22Support').addClass('textDisabled');
	}
	// HDCP 2.2 Support
	if (EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][1]) {
		$('#HDCP22Support').val('0');
	}else{
		$('#HDCP22Support').val('1');
	}
	// Display EDID
	$('#DeviceTxConfigurationBox .DeviceDecoderConfigurationRightNavCEDIDTxt').val(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][2]);
	// Network Setting
	$('#DeviceTxConfigurationBox #EncoderHostname').val(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][3]);
	if (EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][4]=='DHCP')
		$('#DeviceTxConfigurationBox #EncoderIPMode').val('0');
	else
		$('#DeviceTxConfigurationBox #EncoderIPMode').val('1');
	
	$('#DeviceTxConfigurationBox #EncoderIPAdress').val(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][5]);
	$('#DeviceTxConfigurationBox #EncoderMask').val(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][6]);
	$('#DeviceTxConfigurationBox #EncoderGateway').val(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][7]);
	if ($('#DeviceTxConfigurationBox #EncoderIPMode').val()=='0') {
		$('#DeviceTxConfigurationBox #EncoderIPAdress').attr('disabled',true);
		$('#DeviceTxConfigurationBox #EncoderMask').attr('disabled',true);
		$('#DeviceTxConfigurationBox #EncoderGateway').attr('disabled',true);
		$('#DeviceTxConfigurationBox #EncoderIPAdress').addClass('textDisabled');
		$('#DeviceTxConfigurationBox #EncoderMask').addClass('textDisabled');
		$('#DeviceTxConfigurationBox #EncoderGateway').addClass('textDisabled');
	}else if($('#DeviceTxConfigurationBox #EncoderIPMode').val()=='1'){
		$('#DeviceTxConfigurationBox #EncoderIPAdress').attr('disabled',false);
		$('#DeviceTxConfigurationBox #EncoderMask').attr('disabled',false);
		$('#DeviceTxConfigurationBox #EncoderGateway').attr('disabled',false);
		$('#DeviceTxConfigurationBox #EncoderIPAdress').removeClass('textDisabled');
		$('#DeviceTxConfigurationBox #EncoderMask').removeClass('textDisabled');
		$('#DeviceTxConfigurationBox #EncoderGateway').removeClass('textDisabled');
	}
	// RS232
	if (EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][8]==2400) {
		$('#DeviceTxConfigurationBox #EncoderRs232BaudRate').val('0');
	}else if(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][8]==4800){
		$('#DeviceTxConfigurationBox #EncoderRs232BaudRate').val('1');
	}else if(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][8]==9600){
		$('#DeviceTxConfigurationBox #EncoderRs232BaudRate').val('2');
	}else if(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][8]==19200){
		$('#DeviceTxConfigurationBox #EncoderRs232BaudRate').val('3');
	}else if(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][8]==38400){
		$('#DeviceTxConfigurationBox #EncoderRs232BaudRate').val('4');
	}else if(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][8]==57600){
		$('#DeviceTxConfigurationBox #EncoderRs232BaudRate').val('5');
	}else if(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][8]==115200){
		$('#DeviceTxConfigurationBox #EncoderRs232BaudRate').val('6');
	}
	if(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][9]==7){
		$('#DeviceTxConfigurationBox #EncoderRs232DataBit').val('0');
	}else if(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][9]==8){
		$('#DeviceTxConfigurationBox #EncoderRs232DataBit').val('1');
	}
	if (EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][10]==1) {
		$('#DeviceTxConfigurationBox #EncoderRs232StopBit').val('0');
	}else if(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][10]==2){
		$('#DeviceTxConfigurationBox #EncoderRs232StopBit').val('1');
	}
	if (EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][11]=='NONE') {
		$('#DeviceTxConfigurationBox #EncoderRs232Parity').val('0');
	}else if(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][11]=='ODD'){
		$('#DeviceTxConfigurationBox #EncoderRs232Parity').val('1');
	}else if(EncodeDetaileDataArr[_EncoderConfigurationDeviceNumb][11]=='EVEN'){
		$('#DeviceTxConfigurationBox #EncoderRs232Parity').val('2');
	}
}
var _VedioWallHideBox=0;
// video wall event listen
function VideoWallEventListen(num){
	switch(num){
	case 1:
		$('.IPA1100VideoWallParameterContWallUL li').unbind('mouseover');
		$('.IPA1100VideoWallParameterContWallUL li').unbind('mouseleave');
		$('.IPA1100VideoWallParameterContWallUL li').unbind('mousemove');
		$('.IPA1100VideoWallParameterContWallUL li').unbind('mousedown');
		$('.IPA1100VideoWallParameterContWallUL li').each(function(e){
			$(this).on('mouseover',function(event){
				if ($('.IPA1100VideoWallParameterContWallUL li:eq('+e+') .IPA1100VideoWallParameterContWallULLIFlag').hasClass('videoWallDecoderBottomClick')) {
					
					$('.VideoWallParameterHoverDevice').html('');
					var videowallX = parseInt($('#VideoWallSizeX').val());
					var videowallY = parseInt($('#VideoWallSizeY').val());
					
					var _x = parseInt(e%videowallX);
					var _y = parseInt(e/videowallX);
					if (PresetDataDetail[_y][_x]!='') {
						for (var i = 0; i < DecodeVideoWallDataArr.length; i++) {
							if (DecodeVideoWallDataArr[i]!=''&&typeof(DecodeVideoWallDataArr[i])!='undefined') {
								if (DecodeVideoWallDataArr[i][1]==PresetDataDetail[_y][_x]) {
									$('.VideoWallParameterHoverDevice').html(VideoWallParametersDecoder);
									$('.VideoWallParameterHoverDevice .DeviceBoxNavTop span').html(DecodeVideoWallDataArr[i][0]);								
									$('.VideoWallParameterHoverDevice .DeviceBoxCont span:eq(0)').html(DecodeVideoWallDataArr[i][7]+'x'+DecodeVideoWallDataArr[i][8]);
									$('.VideoWallParameterHoverDevice .DeviceBoxCont span:eq(1)').html(DecodeVideoWallDataArr[i][9]+'Hz');
									$('.VideoWallParameterHoverDevice .DeviceBoxCont span:eq(2)').html(DecodeVideoWallDataArr[i][10]+','+DecodeVideoWallDataArr[i][11]+'Bit');

									$('.VideoWallParameterHoverDevice .DeviceBoxBottomDataDetail span:eq(1)').html(DecodeVideoWallDataArr[i][0]);
						            var _device_id = stringToArray(DecodeVideoWallDataArr[i][1],2);

						            $('.VideoWallParameterHoverDevice .DeviceBoxBottomDataDetail span:eq(5)').html((_device_id[0]+'-'+
						            																						_device_id[1]+'-'+
						            																						_device_id[2]+'-'+
						            																						_device_id[3]+'-'+
						            																						_device_id[4]+'-'+
						            																						_device_id[5]).toLocaleUpperCase());
						            $('.VideoWallParameterHoverDevice .DeviceBoxBottomDataDetail span:eq(3)').html(DecodeVideoWallDataArr[i][2]);
						            $('.VideoWallParameterHoverDevice .DeviceBoxBottomDataDetail span:eq(7)').html('v' + DecodeVideoWallDataArr[i][3]);
						            var switchType;
						            if (DecodeVideoWallDataArr[i][4]==0) {		
										switchType = 'Genlock';
									}
									else if(DecodeVideoWallDataArr[i][4]=='FAST_SWITCHED'||DecodeVideoWallDataArr[i][4]=='FAST_SWITCHED_CROP'||DecodeVideoWallDataArr[i][4]=='FAST_SWITCHED_STRETCH'){//fast switch full screen 
										switchType = 'Fast Switch';
									}
									else if(DecodeVideoWallDataArr[i][4]=='GENLOCK_SCALING'){//genlock scaling
										switchType = 'Genlock Scaling';
									}
									else if(DecodeVideoWallDataArr[i][4]=='WALL_GENLOCKED'){
										switchType = 'Wall Genlock';
									}
						            $('.VideoWallParameterHoverDevice .DeviceBoxBottomDataScroll span').html(DecodeVideoWallDataArr[i][2]+'-'+switchType);
									
								}
							}
								
						}
					}
					$('.VideoWallParameterHoverDevice').show();
				}
				else {

				}			
				$(this).css('background-color','#006eb8');
				$('.IPA1100VideoWallParameterContWallUL li:eq('+e+') .IPA1100VideoWallParameterContWallULLIFlag').css('background-color','#42ff00');
				
				
			});
			$(this).on('mouseleave',function(event){				
				$(this).css('background-color','#3c4752');
				$('.VideoWallParameterHoverDevice').hide();
				$('.IPA1100VideoWallParameterContWallUL li:eq('+e+') .IPA1100VideoWallParameterContWallULLIFlag').css('background-color','#c5def0');
			});
			$(this).on('mousemove',function(event){
				//console.log(event.pageY+':'+event.pageX);
				$('.VideoWallParameterHoverDevice').css('top',event.pageY-$('.IPAV1100ContentHead').height()+6+'px');
				$('.VideoWallParameterHoverDevice').css('left',event.pageX-$('.IPAV1100ContentBottomLeft').width()-6+'px');
				//$('.VideoWallParameterHoverDevice .DeviceBoxNavTop span').html('Classroom'+(e+1));
			});
			$(this).on('mousedown',function(){
				var videowallX = parseInt($('#VideoWallSizeX').val());
				var videowallY = parseInt($('#VideoWallSizeY').val());
				$('#IPA1100VideoWallParameterContRxDrop').html('');
				if ($(this).hasClass('videoWallDecoderClick')) {
					
					$(this).removeClass('videoWallDecoderClick');
					$('.IPA1100VideoWallParameterContWallUL li:eq('+e+') .IPA1100VideoWallParameterContWallULLIFlag').removeClass('videoWallDecoderBottomClick');
					
				}
				else{
					$('.IPA1100VideoWallParameterContWallUL li').removeClass('videoWallDecoderClick');
					$('.IPA1100VideoWallParameterContWallUL li div').removeClass('videoWallDecoderBottomClick');
					$(this).addClass('videoWallDecoderClick');
					$('.IPA1100VideoWallParameterContWallUL li:eq('+e+') .IPA1100VideoWallParameterContWallULLIFlag').addClass('videoWallDecoderBottomClick');
					var _x = parseInt(e%videowallX);
					var _y = parseInt(e/videowallX);
					if (PresetDataDetail[_y][_x]!='') {
						for (var i = 0; i < DecodeVideoWallDataArr.length; i++) {
							if (DecodeVideoWallDataArr[i]!=''&&typeof(DecodeVideoWallDataArr[i])!='undefined') {
								if (DecodeVideoWallDataArr[i][1]==PresetDataDetail[_y][_x]) {
									$('#IPA1100VideoWallParameterContRxDrop').html(VideoWallParametersDecoder);
									$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxNavTop span').html(DecodeVideoWallDataArr[i][0]);								
									$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxCont span:eq(0)').html(DecodeVideoWallDataArr[i][7]+'x'+DecodeVideoWallDataArr[i][8]);
									$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxCont span:eq(1)').html(DecodeVideoWallDataArr[i][9]+'Hz');
									$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxCont span:eq(2)').html(DecodeVideoWallDataArr[i][10]+','+DecodeVideoWallDataArr[i][11]+'Bit');

									$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxBottomDataDetail span:eq(1)').html(DecodeVideoWallDataArr[i][0]);
						            var _device_id = stringToArray(DecodeVideoWallDataArr[i][1],2);

						            $('#IPA1100VideoWallParameterContRxDrop .DeviceBoxBottomDataDetail span:eq(5)').html((_device_id[0]+'-'+
						            																						_device_id[1]+'-'+
						            																						_device_id[2]+'-'+
						            																						_device_id[3]+'-'+
						            																						_device_id[4]+'-'+
						            																						_device_id[5]).toLocaleUpperCase());
						            $('#IPA1100VideoWallParameterContRxDrop .DeviceBoxBottomDataDetail span:eq(3)').html(DecodeVideoWallDataArr[i][2]);
						            $('#IPA1100VideoWallParameterContRxDrop .DeviceBoxBottomDataDetail span:eq(7)').html('v' + DecodeVideoWallDataArr[i][3]);
						            var switchType;
						            if (DecodeVideoWallDataArr[i][4]==0) {		
										switchType = 'Genlock';
									}
									else if(DecodeVideoWallDataArr[i][4]=='FAST_SWITCHED'||DecodeVideoWallDataArr[i][4]=='FAST_SWITCHED_CROP'||DecodeVideoWallDataArr[i][4]=='FAST_SWITCHED_STRETCH'){//fast switch full screen 
										switchType = 'Fast_Switch';
									}
									else if(DecodeVideoWallDataArr[i][4]=='GENLOCK_SCALING'){//genlock scaling
										switchType = 'Genlock_Scaling';
									}
									else if(DecodeVideoWallDataArr[i][4]=='WALL_GENLOCKED'){
										switchType = 'Wall_Genlock';
									}
						            $('#IPA1100VideoWallParameterContRxDrop .DeviceBoxBottomDataScroll span').html(DecodeVideoWallDataArr[i][2]+'-'+switchType);
									VideoWallEventListen(2);
									VideoWallEventListen(4);
								}
							}
								
						}
					}
				}
				CheckDeviceInArr();	
				$('#VideoWallRemoveFromWall').hide();
				
			});
		});
	break;
	case 2://注册TX/RX点击显示隐藏设备信息事件
		$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxBottom').unbind('click');
		$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxBottom').on('click',function(){
			if ($(this).height()==80) {
				$(this).css('height','13px');
				$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxBottomDataScroll').show();
				$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxBottomDataDetail').hide();
			}
			else {
				$(this).css('height','80px');
				$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxBottomDataScroll').hide();
				$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxBottomDataDetail').show();
			}
		});			
	break;
	case 3:
		$('#IPA1100VideoWallParameterContTxDrop .DeviceBoxBottom').unbind('click');
		$('#IPA1100VideoWallParameterContTxDrop .DeviceBoxBottom').on('click',function(){
			if ($(this).height()==80) {
				$(this).css('height','13px');
				$('#IPA1100VideoWallParameterContTxDrop .DeviceBoxBottomDataScroll').show();
				$('#IPA1100VideoWallParameterContTxDrop .DeviceBoxBottomDataDetail').hide();
			}
			else {
				$(this).css('height','80px');
				$('#IPA1100VideoWallParameterContTxDrop .DeviceBoxBottomDataScroll').hide();
				$('#IPA1100VideoWallParameterContTxDrop .DeviceBoxBottomDataDetail').show();
			}
		});			
	break;
	case 4://注册rx remove setting按钮点击事件
		$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxNavTopSetting').unbind('click');
		$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxNavTopSetting').unbind('mouseover');
		$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxNavTopSetting').unbind('mouseleave');
		$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxNavTopSetting').on('click',function(){
			_VedioWallHideBox = 1;
			if ($('#VideoWallRemoveFromWall').css('display').indexOf('none')>=0) {
				//$('#VideoWallRemoveFromWall').css('display','block')
				$('#VideoWallRemoveFromWall').show();
			}
			else {
				$('#VideoWallRemoveFromWall').hide();
			}
			console.log(1);
		});
		$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxNavTopSetting').on('mouseover',function(){
			_VedioWallHideBox = 1;
		});
		$('#IPA1100VideoWallParameterContRxDrop .DeviceBoxNavTopSetting').on('mouseleave',function(){
			_VedioWallHideBox = 0;
		});
	break;
	}
}
// check resolution 是否存在
function CheckResolutionToChange(deviceId,parameterX,parameterY){	
	var videowallX = parseInt($('#VideoWallSizeX').val());
	var videowallY = parseInt($('#VideoWallSizeY').val());
	var _parameterX = parameterX;
	var _parameterY = parameterY;
	var _deviceId = deviceId;

	for (var j = 0; j < videowallY; j++) {		
		for (var i = 0; i < videowallX; i++) {
			if (PresetDataDetail[j][i]==_deviceId) {
				if (_parameterX!=i||_parameterY!=j) {
					PresetDataDetail[j][i] = '';
				}
			}
		}
	}
}
// 给已存在的设备上标志
function CheckDeviceInArr(){
	var videowallX = parseInt($('#VideoWallSizeX').val());
	var videowallY = parseInt($('#VideoWallSizeY').val());
	$('#IPA1100VideoWallParameterContWallUl li div').removeClass('videoWallDecoderBottomClick');
	for (var j = 0; j < videowallY; j++) {
		for (var i = 0; i < videowallX; i++) {
			if (PresetDataDetail[j][i]!=''&&typeof(PresetDataDetail[j][i])!='undefined') {
				console.log(j+':'+i);
				if (!$('#IPA1100VideoWallParameterContWallUl li:eq('+((j*videowallX)+i)+') div').hasClass('videoWallDecoderBottomClick')) {
					$('#IPA1100VideoWallParameterContWallUl li:eq('+((j*videowallX)+i)+') div').addClass('videoWallDecoderBottomClick');
				}
			}
		}
	}
}
// return Resolution
// function returnResolution(num,macaddress) {
// 	var _resolution;
// 	var _arr = _data.videoswitching_encode_arr.split(',');
// 	var _num;
// 	var _viewport = new Array();
// 	//checkParameterHasEncode = macaddress;
// 	for (var i = 0; i <_arr.length-1; i++) {		
// 		if (_arr[i]==macaddress) {
// 			_num=i;				
// 		}
// 	}
	
// 	_parameterWidth = VideoWallResolutionArr[VideoWallResolutionSelectNum][0];
// 	_parameterHeight = VideoWallResolutionArr[VideoWallResolutionSelectNum][1];
// 	_parameterFps = EncodeVideoWallDataArr[_num][8];
// 	_viewport[0] = 0;
// 	_viewport[1] = 0;
// 	_viewport[2] = _parameterWidth;
// 	_viewport[3] = _parameterHeight;
// 	var _keepWidthToChange = EncodeVideoWallDataArr[_num][6];
// 	var _keepHeightToChange = EncodeVideoWallDataArr[_num][7];
// 	var _h,_v,_i,_j;
// 	var _x,_y,_width,_height;
// 	_v = parseInt($('#VideoWallSizeX').val());
// 	_h = parseInt($('#VideoWallSizeY').val());
// 	//console.log(_checkInArr);
// 	var _top = parseInt($('#BezelTop').val());
// 	var _bottom = parseInt($('#BezelBottom').val());
// 	var _left = parseInt($('#BezelLeft').val());
// 	var _right = parseInt($('#BezelRight').val());

// 	var _keepWidth = parseInt(_parameterWidth/_h);
// 	var _keepHeight = parseInt(_parameterHeight/_v);
// 	//_checkInArr = _checkInArr.substr(0,_checkInArr.length-1).split(',');

// 	// 调整像素位置
// 	// _i = parseInt((parseInt(num)-1)/_v);
// 	// _j = (parseInt(num)-1)%_v;
// 	_i = parseInt((parseInt(num)-1)/_v);
// 	_j = (parseInt(num)-1)%_v;
// 	console.log('_i:'+_i+',_j:'+_j,_keepWidthToChange,_keepHeightToChange);
// 	if (_i==0) {//最上边
// 		if (_j==0) {//最左边	
// 			_x = 0;
// 			_y = 0;		
// 			if (_v>_h) {
// 				if (_v-_h>1) {
// 					_viewport[0] = _parameterWidth;
// 					_viewport[1] = _parameterHeight;
// 					_viewport[2] = 0;
// 					_viewport[3] = 0;
// 					_width = _keepWidthToChange;
// 					height = _keepHeightToChange;
// 				}
// 				else{
// 					_viewport[0] = _parameterWidth/2;
// 					_viewport[1] = 0;
// 					_viewport[2] = _parameterWidth/2;
// 					_viewport[3] = _parameterHeight;
// 					_width = _keepWidthToChange/(2*_h)-_right;
// 					height = _keepHeightToChange/_h-_bottom;
// 				}
// 			}
// 			else if(_v<_h){
// 				if (_h-_v>1) {
// 					_viewport[0] = _parameterWidth;
// 					_viewport[1] = _parameterHeight;
// 					_viewport[2] = 0;
// 					_viewport[3] = 0;
// 					_width = _keepWidthToChange;
// 					height = _keepHeightToChange;
// 				}
// 				else{
// 					_viewport[0] = 0;
// 					_viewport[1] = _parameterHeight/2;
// 					_viewport[2] = _parameterWidth;
// 					_viewport[3] = _parameterHeight/2;
// 					_width = _keepWidthToChange/_v-_right;
// 					height = _keepHeightToChange/(2*_v)-_bottom;
// 				}
// 			}
// 			else {							
// 				_width = _keepWidthToChange/_v - _right;
// 				height = _keepHeightToChange/_v - _bottom;
// 			}
// 		}
// 		else if((_j+1)<_v){
// 			_x = _keepWidth*_j + _left;
// 			_y = 0;
// 			if (_v>_h) {
// 				if (_v-_h>1) {
// 					if (parseInt(_v-2-_h)>1) {
// 						if (_j==1) {
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;
// 						}
// 						else if(_j==2){
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 						}
// 						else if(_j==3){
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;					
// 						}
// 						// _width = _parameterWidth/(2*_h)-_right;
											
// 					}
// 					else if(parseInt(_v-2-_h)==1){
// 						if (_j==1) {
// 							_x=0;
// 							_width = parseInt(_keepWidthToChange/(2*_h))-_right;
// 							_viewport[0] = _parameterWidth/2;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth/2;
// 							_viewport[3] = _parameterHeight;
// 						}
// 						else if(_j==2){
// 							_x = parseInt((_j-1)*(_parameterWidth/(2*_h)))+_left;
// 							if ((_v-_j-1)==1) {
// 								_width = parseInt(_keepWidthToChange/(2*_h))-_right;
// 								_viewport[0] = _parameterWidth/2;
// 								_viewport[1] = 0;
// 								_viewport[2] = _parameterWidth/2;
// 								_viewport[3] = _parameterHeight;
// 							}
// 							else {
// 								_width = parseInt(_keepWidthToChange/_h)-_left-_right;
// 							}						
// 						}
// 						else if(_j==3){
// 							_x = parseInt(_j*_parameterWidth/(2*_h))+_left;
// 							_width = parseInt(_keepWidthToChange/(2*_h))-_left;	
// 							_viewport[0] = _parameterWidth/2;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth/2;
// 							_viewport[3] = _parameterHeight;						
// 						}
// 						// _width = _parameterWidth/(2*_h)-_right;
// 						height = parseInt(_keepHeightToChange/_h)-_top;
// 					}
// 					else if(parseInt(_v-2-_h)<=0){
// 						if (_j==1) {
// 							_x=0;
// 							_width = _keepWidthToChange/_h-_right;							
// 						}
// 						else if(_j==2){
// 							_x = (_j-1)*(_parameterWidth/_h)+_left;
// 							if ((_v-_j-1)==1) {
// 								_width = _keepWidthToChange/_h-_left;
// 							}
// 							else {
// 								_width = _keepWidthToChange/_h-_left-_right;
// 							}						
// 						}
// 						else if(_j==3){
// 							_x = 2*_parameterWidth/_h+_left;
// 							_width = _keepWidthToChange/_h-_left;							
// 						}
// 						height = _keepHeightToChange/_h-_bottom;
// 					}
// 				}
// 				else{
// 					_x = _parameterWidth/(2*_h)+_right+(_j-1)*(_parameterWidth/_h);
// 					_width = _keepWidthToChange/_h-_left-_right;
// 					height = _keepHeightToChange/_h-_bottom;
// 				}
// 			}
// 			else if(_v<_h){
// 				if (_h-_v>1) {
// 					if (parseInt(_h-2-_v)>1) {
// 						if (_j==1) {
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;
// 						}
// 						else if(_j==2){
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 						}
// 						else if(_j==3){
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;					
// 						}						
// 					}
// 					else if(parseInt(_h-2-_v)==1){
// 						if (_j==1) {
// 							_x=0;
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;
// 						}
// 						else if(_j==2){
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;						
// 						}
// 						else if(_j==3){
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;					
// 						}
// 						// _width = _parameterWidth/(2*_h)-_right;
// 						// height = parseInt(_parameterHeight/_h)-_top;
// 					}
// 					else if(parseInt(_h-2-_v)<=0){						
// 						_x=0;
// 						_width = _keepWidthToChange;
// 						height = _keepHeightToChange;	
// 						_viewport[0] = _parameterWidth;
// 						_viewport[1] = _parameterHeight;
// 						_viewport[2] = 0;
// 						_viewport[3] = 0;
// 					}
// 				}
// 				else{
// 					_x = _parameterWidth/_v+_right+(_j-1)*(_parameterWidth/_v);
// 					_width = _keepWidthToChange/_v-_left-_right;
// 					height = _keepHeightToChange/(2*_v)-_bottom;
// 					_viewport[0] = 0;
// 					_viewport[1] = _parameterHeight/2;
// 					_viewport[2] = _parameterWidth;
// 					_viewport[3] = _parameterHeight/2;
// 				}
// 			}
// 			else {				
// 				_width = _keepWidthToChange/_v - _right - _left;
// 				height = _keepHeightToChange/_v - _bottom;
// 			}
// 		}
// 		else{//最右边
// 			_x = _keepWidth*_j + _left;
// 			_y = 0;
// 			if (_v>_h) {				
// 				if (_v-_h>1) {
// 					_x = 0;
// 					_viewport[0] = _parameterWidth;
// 					_viewport[1] = _parameterHeight;
// 					_viewport[2] = 0;
// 					_viewport[3] = 0;
// 					_width = _keepWidthToChange;
// 					height = _keepHeightToChange;
// 				}
// 				else{
// 					_x = _parameterWidth/(2*_h)+_right+(_j-1)*(_parameterWidth/_h);
// 					_viewport[0] = 0;
// 					_viewport[1] = 0;
// 					_viewport[2] = _parameterWidth/2;
// 					_viewport[3] = _parameterHeight;
// 					_width = _keepWidthToChange/(2*_h)-_left;
// 					height = _keepHeightToChange/_h-_bottom;
// 				}
// 			}
// 			else if(_v<_h){
// 				_x = _parameterWidth/_v+_right+(_j-1)*(_parameterWidth/_v);
// 				if (_h-_v>1) {
// 					_x=0;
// 					_width = _keepWidthToChange;
// 					height = _keepHeightToChange;	
// 					_viewport[0] = _parameterWidth;
// 					_viewport[1] = _parameterHeight;
// 					_viewport[2] = 0;
// 					_viewport[3] = 0;
// 				}
// 				else{
// 					_viewport[0] = 0;
// 					_viewport[1] = _parameterHeight/2;
// 					_viewport[2] = _parameterWidth;
// 					_viewport[3] = _parameterHeight/2;
// 					_width = _keepWidthToChange/_v-_right;
// 					height = _keepHeightToChange/(2*_v)-_bottom;
// 				}
// 			}
// 			else {				
// 				_width = _keepWidthToChange/_v - _left;
// 				height = _keepHeightToChange/_v - _bottom;
// 			}			
// 		}
// 	}
// 	else if((_i+1)<_h){//中间
// 		if (_j==0) {//最左边
// 			_x = 0;
// 			_y = _keepHeight*_i + _top;
// 			if (_v>_h) {
// 				if (_v-_h>1) {
// 					_x = 0;
// 					_y = 0;	
// 					_viewport[0] = _parameterWidth;
// 					_viewport[1] = _parameterHeight;
// 					_viewport[2] = 0;
// 					_viewport[3] = 0;
// 					_width = _keepWidthToChange;
// 					height = _keepHeightToChange;
// 				}
// 				else{
// 					_y = parseInt(_parameterHeight/_h) + _top;
// 					_viewport[0] = _parameterWidth/2;
// 					_viewport[1] = 0;
// 					_viewport[2] = _parameterWidth/2;
// 					_viewport[3] = _parameterHeight;
// 					_width = _keepWidthToChange/(2*_h)-_right;
// 					height = _keepHeightToChange/_h-_top-_bottom;
// 				}
// 			}
// 			else if(_v<_h){
// 				if (_h-_v>1) {
// 					_x = 0;					
// 					if (_h-_v==2) {
// 						if (_i==1) {
// 							_y = 0;
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 							_width = _keepWidthToChange/_v-_right;
// 							height = _keepHeightToChange/_v-_bottom;
// 						}
// 						else if(_i==2){
// 							_y = (_i-1)*(_parameterHeight/_v)+_top;
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 							_width = _keepWidthToChange/_v-_right;
// 							height = _keepHeightToChange/_v-_bottom-_top;
// 						}
// 						else if(_i==3){
// 							_y = (_i-1)*(_parameterHeight/_v)+_top;
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 							_width = _keepWidthToChange/_v-_right;
// 							height = _keepHeightToChange/_v-_bottom;
// 						}						
// 					}
// 					else if(_h-_v==3){
// 						if (_i==1) {
// 							_y = 0;
// 							_viewport[0] = 0;
// 							_viewport[1] = _parameterHeight/2;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight/2;
// 							_width = _keepWidthToChange/_v-_right;
// 							height = _keepHeightToChange/(2*_v)-_bottom;
// 						}
// 						else if (_i==2) {
// 							_y = parseInt(_parameterHeight/(2*_v))+_top;							
// 							_width = _keepWidthToChange/_v-_right;
// 							if (_v==1) {
// 								_viewport[0] = 0;
// 								_viewport[1] = _parameterHeight/2;
// 								_viewport[2] = _parameterWidth;
// 								_viewport[3] = _parameterHeight/2;
// 								height = _keepHeightToChange/(2*_v)-_top;
// 							}
// 							else {
// 								_viewport[0] = 0;
// 								_viewport[1] = 0;
// 								_viewport[2] = _parameterWidth;
// 								_viewport[3] = _parameterHeight;
// 								height = _keepHeightToChange/_v-_bottom-_top;
// 							}
							
// 						}
// 						else if (_i==3) {
// 							_y = parseInt(_parameterHeight/(2*_v))+_top+(_parameterHeight/_v);
// 							_viewport[0] = 0;
// 							_viewport[1] = _parameterHeight/2;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight/2;
// 							_width = _keepWidthToChange/_v-_right;
// 							height = _keepHeightToChange/(2*_v)-_top;
// 						}
// 					}
// 					else if(_h-_v==4){
// 						if (_i==1) {
// 							_y = 0;
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;
// 						}
// 						else if (_i==2) {
// 							_y = 0;
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;
// 						}
// 						else if (_i==3) {
// 							_y = 0;
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;
// 						}
// 					}
// 				}
// 				else{
// 					_y = parseInt(_parameterHeight/(2*_v))+_top+(_i-1)*(_parameterHeight/_v);
// 					_viewport[0] = 0;
// 					_viewport[1] = 0;
// 					_viewport[2] = _parameterWidth;
// 					_viewport[3] = _parameterHeight;
// 					_width = _keepWidthToChange/_v-_right;
// 					height = _keepHeightToChange/_v-_top-_bottom;
// 				}
// 			}
// 			else {
// 				_width = _keepWidthToChange/_v - _right;
// 				height = _keepHeightToChange/_v - _bottom - _top;
// 			}
// 		}
// 		else if((_j+1)<_v){				
// 			_x = _keepWidth*_j + _left;
// 			_y = _keepHeight*_i + _top;		
// 			if (_v>_h) {	
// 				_x = _parameterWidth/(2*_h)+parseInt(_parameterWidth/_h)*(_j-1) + _left;
// 				_y = parseInt(_parameterHeight/_h)*_i + _top;			
// 				if (_v-_h>1) {					
// 					if (parseInt(_v-2-_h)>1) {
// 						if (_j==1) {
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;
// 						}
// 						else if(_j==2){
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 						}
// 						else if(_j==3){
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;					
// 						}
// 						// _width = _parameterWidth/(2*_h)-_right;
											
// 					}
// 					else if(parseInt(_v-2-_h)==1){
// 						if (_j==1) {
// 							_x=0;
// 							_width = parseInt(_keepWidthToChange/(2*_h))-_right;
// 							_viewport[0] = _parameterWidth/2;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth/2;
// 							_viewport[3] = _parameterHeight;
// 						}
// 						else if(_j==2){
// 							_x = parseInt((_j-1)*(_parameterWidth/(2*_h)))+_left;
// 							if ((_v-_j-1)==1) {
// 								_width = parseInt(_keepWidthToChange/(2*_h))-_right;
// 								_viewport[0] = _parameterWidth/2;
// 								_viewport[1] = 0;
// 								_viewport[2] = _parameterWidth/2;
// 								_viewport[3] = _parameterHeight;
// 							}
// 							else {
// 								_width = parseInt(_keepWidthToChange/_h)-_left-_right;
// 							}						
// 						}
// 						else if(_j==3){
// 							_x = parseInt(_j*_parameterWidth/(2*_h))+_left;
// 							_width = parseInt(_keepWidthToChange/(2*_h))-_left;	
// 							_viewport[0] = _parameterWidth/2;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth/2;
// 							_viewport[3] = _parameterHeight;						
// 						}
// 						// _width = _parameterWidth/(2*_h)-_right;
// 						// height = parseInt(_parameterHeight/_h)-_top;
// 					}
// 					else if(parseInt(_v-2-_h)<=0){
// 						if (_j==1) {
// 							_x=0;
// 							_width = _keepWidthToChange/_h-_right;							
// 						}
// 						else if(_j==2){
// 							_x = (_j-1)*(_parameterWidth/_h)+_left;
// 							if ((_v-_j-1)==1) {
// 								_width = _keepWidthToChange/_h-_left;
// 							}
// 							else {
// 								_width = _keepWidthToChange/_h-_left-_right;
// 							}						
// 						}
// 						else if(_j==3){
// 							_x = 2*_parameterWidth/_h+_left;
// 							_width = _keepWidthToChange/_h-_left;							
// 						}
// 						// height = _parameterHeight/_h-_bottom-_top;
// 					}
// 				}
// 				else{
// 					_width = _keepWidthToChange/_h-_left-_right;
// 					// height = _parameterHeight/_h-_top-_bottom;
// 				}
// 				height = _keepHeightToChange/_h-_bottom-_top;
// 			}
// 			else if(_v<_h){
// 				if (_h-_v>1) {
// 					if (parseInt(_h-2-_v)>1) {
// 						if (_j==1) {
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;
// 						}
// 						else if(_j==2){
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 						}
// 						else if(_j==3){
// 							_x=0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;	
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;					
// 						}						
// 					}
// 					else if(parseInt(_h-2-_v)==1){
// 						if (_i==1) {
// 							_x=0;
// 							_width = parseInt(_keepWidthToChange/(2*_v))-_right;
// 							_viewport[0] = 0;
// 							_viewport[1] = _parameterHeight/2;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight/2;
// 						}
// 						else if(_i==2){
// 							_x = parseInt((_j-1)*(_parameterWidth/(2*_h)))+_left;
// 							if ((_v-_j-1)==1) {
// 								_width = parseInt(_keepWidthToChange/(2*_h))-_right;
// 								_viewport[0] = _parameterWidth/2;
// 								_viewport[1] = 0;
// 								_viewport[2] = _parameterWidth/2;
// 								_viewport[3] = _parameterHeight;
// 							}
// 							else {
// 								_width = parseInt(_keepWidthToChange/_h)-_left-_right;
// 							}						
// 						}
// 						else if(_i==3){
// 							_x = parseInt(_j*_parameterWidth/(2*_h))+_left;
// 							_width = parseInt(_keepWidthToChange/(2*_h))-_left;	
// 							_viewport[0] = _parameterWidth/2;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth/2;
// 							_viewport[3] = _parameterHeight;						
// 						}
// 						// _width = _parameterWidth/(2*_h)-_right;
// 						height = parseInt(_keepHeightToChange/_h)-_top;
// 					}
// 					else if(parseInt(_h-2-_v)<=0){
// 						if (_i==1) {
// 							_x = _parameterWidth/_v+_right+(_j-1)*(_parameterWidth/_v);
// 							_y = 0;
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 							_width = _keepWidthToChange/_v-_right-_left;
// 							height = _keepHeightToChange/_v-_bottom;
// 						}
// 						else if(_i==2){
// 							_x = _parameterWidth/_v+_right+(_j-1)*(_parameterWidth/_v);
// 							_y = (_i-1)*(_parameterHeight/_v)+_top;
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 							_width = _keepWidthToChange/_v-_right-_left;
// 							height = _keepHeightToChange/_v-_bottom-_top;
// 						}
// 						else if(_i==3){
// 							_x = _parameterWidth/_v+_right+(_j-1)*(_parameterWidth/_v);
// 							_y = (_i-1)*(_parameterHeight/_v)+_top;
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 							_width = _keepWidthToChange/_v-_right-_left;
// 							height = _keepHeightToChange/_v-_top;
// 						}						
// 					}
// 				}
// 				else{
// 					_x = _parameterWidth/_v+_right+(_j-1)*(_parameterWidth/_v);
// 					_y = parseInt(_parameterHeight/(2*_v))+_top+(_i-1)*(_parameterHeight/_v);
// 					_width = _keepWidthToChange/_v-_left-_right;
// 					height = _keepHeightToChange/_v-_bottom-_top;
// 					_viewport[0] = 0;
// 					_viewport[1] = 0;
// 					_viewport[2] = _parameterWidth;
// 					_viewport[3] = _parameterHeight;
// 				}
// 			}
// 			else {				
// 				_width = _keepWidthToChange - _right - _left;
// 				height = _keepHeightToChange - _bottom - _top;
// 			}
// 		}
// 		else{//最右边
// 			_x = _keepWidth*_j + _left;
// 			_y = _keepHeight*_i + _top;
// 			if (_v>_h) {
// 				if (_v-_h>1) {
// 					_x = 0;
// 					_y = 0;	
// 					_viewport[0] = _parameterWidth;
// 					_viewport[1] = _parameterHeight;
// 					_viewport[2] = 0;
// 					_viewport[3] = 0;
// 					_width = _keepWidthToChange;
// 					height = _keepHeightToChange;
// 				}
// 				else{
// 					_x = _parameterWidth/(2*_h)+parseInt(_parameterWidth/_h)*(_j-1) + _left;
// 					_y = parseInt(_parameterHeight/_h)*_i + _top;
// 					_viewport[0] = 0;
// 					_viewport[1] = 0;
// 					_viewport[2] = _parameterWidth/2;
// 					_viewport[3] = _parameterHeight;
// 					_width = _keepWidthToChange/(2*_h)-_right;
// 					height = _keepHeightToChange/_h-_top-_bottom;
// 				}
// 			}
// 			else if(_v<_h){
// 				_x = _parameterWidth/_v+_right+(_j-1)*(_parameterWidth/_v);				
// 				_y = parseInt(_parameterHeight/(2*_v))+_top+(_i-1)*(_parameterHeight/_v);
// 				if (_h-_v>1) {
// 					if (_h-_v==2) {
// 						if (_i==1) {
// 							_y = 0;
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 							_width = _keepWidthToChange/_v-_left;
// 							height = _keepHeightToChange/_v-_bottom;
// 						}
// 						else if(_i==2){
// 							_y = (_i-1)*(_parameterHeight/_v)+_top;
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 							_width = _keepWidthToChange/_v-_left;
// 							height = _keepHeightToChange/_v-_bottom-_top;
// 						}
// 						else if(_i==3){
// 							_y = (_i-1)*(_parameterHeight/_v)+_top;
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 							_width = _keepWidthToChange/_v-_left;
// 							height = _keepHeightToChange/_v-_bottom;
// 						}						
// 					}
// 					else if(_h-_v==3){
// 						if (_i==1) {
// 							_y = 0;
// 							_viewport[0] = 0;
// 							_viewport[1] = _parameterHeight/2;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight/2;
// 							_width = _keepWidthToChange/_v-_left;
// 							height = _keepHeightToChange/(2*_v)-_bottom;
// 						}
// 						else if (_i==2) {
// 							_y = parseInt(_parameterHeight/(2*_v))+_top;							
// 							_width = _keepWidthToChange/_v-_left;
// 							if (_v==1) {
// 								_viewport[0] = 0;
// 								_viewport[1] = _parameterHeight/2;
// 								_viewport[2] = _parameterWidth;
// 								_viewport[3] = _parameterHeight/2;
// 								height = _keepHeightToChange/(2*_v)-_top;
// 							}
// 							else {
// 								_viewport[0] = 0;
// 								_viewport[1] = 0;
// 								_viewport[2] = _parameterWidth;
// 								_viewport[3] = _parameterHeight;
// 								height = _keepHeightToChange/_v-_bottom-_top;
// 							}
							
// 						}
// 						else if (_i==3) {
// 							_y = parseInt(_parameterHeight/(2*_v))+_top+(_parameterHeight/_v);
// 							_viewport[0] = 0;
// 							_viewport[1] = _parameterHeight/2;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight/2;
// 							_width = _keepWidthToChange/_v-_left;
// 							height = _keepHeightToChange/(2*_v)-_top;
// 						}
// 					}
// 					else if(_h-_v==4){
// 						if (_i==1) {
// 							_y = 0;
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;
// 						}
// 						else if (_i==2) {
// 							_y = 0;
// 							_viewport[0] = 0;
// 							_viewport[1] = 0;
// 							_viewport[2] = _parameterWidth;
// 							_viewport[3] = _parameterHeight;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;
// 						}
// 						else if (_i==3) {
// 							_y = 0;
// 							_viewport[0] = _parameterWidth;
// 							_viewport[1] = _parameterHeight;
// 							_viewport[2] = 0;
// 							_viewport[3] = 0;
// 							_width = _keepWidthToChange;
// 							height = _keepHeightToChange;
// 						}
// 					}
// 				}
// 				else{
// 					_viewport[0] = 0;
// 					_viewport[1] = 0;
// 					_viewport[2] = _parameterWidth;
// 					_viewport[3] = _parameterHeight;
// 					_width = _keepWidthToChange/_v-_left;
// 					height = _keepHeightToChange/_v-_top-_bottom;
// 				}
// 			}
// 			else {				
// 				_width = _keepWidthToChange - _left;
// 				height = _keepHeightToChange - _bottom - _top;
// 			}			
// 		}
// 	}
// 	else{//最下边
// 		if (_j==0) {//最左边
// 			_x = 0;
// 			_y = _keepHeight*_i + _top;
// 			if (_v>_h) {				
// 				if (_v-_h>1) {
// 					_x = 0;
// 					_y = 0;	
// 					_viewport[0] = _parameterWidth;
// 					_viewport[1] = _parameterHeight;
// 					_viewport[2] = 0;
// 					_viewport[3] = 0;
// 					_width = _keepWidthToChange;
// 					height = _keepHeightToChange;
// 				}
// 				else{
// 					_y = _parameterHeight/_h+_bottom+(_h-2)*(_parameterHeight/_h);
// 					_viewport[0] = _parameterWidth/2;
// 					_viewport[1] = 0;
// 					_viewport[2] = _parameterWidth/2;
// 					_viewport[3] = _parameterHeight;
// 					_width = _keepWidthToChange/(2*_h)-_right;
// 					height = _keepHeightToChange/_h-_top;
// 				}
// 			}
// 			else if(_v<_h){
// 				if (_h-_v>1) {
// 					_x = 0;
// 					_y = 0;	
// 					_viewport[0] = _parameterWidth;
// 					_viewport[1] = _parameterHeight;
// 					_viewport[2] = 0;
// 					_viewport[3] = 0;
// 					_width = _keepWidthToChange;
// 					height = _keepHeightToChange;
// 				}
// 				else{
// 					_y = parseInt(_parameterHeight/(2*_v))+_top+(_i-1)*(_parameterHeight/_v);
// 					_viewport[0] = 0;
// 					_viewport[1] = _parameterHeight/2;
// 					_viewport[2] = _parameterWidth;
// 					_viewport[3] = _parameterHeight/2;
// 					_width = _keepWidthToChange/_v-_right;
// 					height = parseInt(_keepHeightToChange/(2*_v))-_bottom;
// 				}
// 			}
// 			else {				
// 				_width = _keepWidthToChange/_v - _right;
// 				height = _keepHeightToChange/_v - _top;
// 			}
				
// 		}
// 		else if((_j+1)<_v){
// 			_x = _keepWidth*_j + _left;
// 			_y = _keepHeight*_i + _top;
// 			if (_v>_h) {
// 				_x = _parameterWidth/(2*_h)+parseInt(_parameterWidth/_h)*(_j-1) + _left;
// 				_y = parseInt(_parameterHeight/_h)*_i + _top;
// 				if (_v-_h>1) {
// 					if (parseInt(_v-2-_h)>1) {
// 						_width = _keepWidthToChange;
// 						height = _keepHeightToChange;
// 					}
// 					else if(parseInt(_v-2-_h)==1){

// 						_width = _keepWidthToChange/(2*_h)-_right;
// 						height = _keepHeightToChange/_h;
// 					}
// 					else if(parseInt(_v-2-_h)<=0){
// 						if (_j==1) {
// 							_x=0;
// 							_width = _keepWidthToChange/_h-_right;							
// 						}
// 						else if(_j==2){
// 							_x = (_j-1)*(_parameterWidth/_h)+_left;
// 							if ((_v-_j-1)==1) {
// 								_width = _keepWidthToChange/_h-_left;
// 							}
// 							else {
// 								_width = _keepWidthToChange/_h-_left-_right;
// 							}						
// 						}
// 						else if(_j==3){
// 							_width = _keepWidthToChange/_h-_left;							
// 						}
// 						height = _keepHeightToChange/_h-_bottom;
// 					}					
// 				}
// 				else{
// 					_width = _keepWidthToChange/_h-_left-_right;
// 					height = _keepHeightToChange/_h-_top;
// 				}
// 			}
// 			else if(_v<_h){
// 				_x = parseInt(_parameterHeight/_v)*_j + _left;
// 				_y = _parameterWidth/(2*_v)+parseInt(_parameterWidth/_v)*(_i-1) + _top;
// 				if (_v-_h>1) {
// 					_x = 0;
// 					_y = 0;
// 					_viewport[0] = _parameterWidth;
// 					_viewport[1] = _parameterHeight;
// 					_viewport[2] = 0;
// 					_viewport[3] = 0;
// 					_width = _keepWidthToChange;
// 					height = _keepHeightToChange;				
// 				}
// 				else{
// 					_x = _parameterWidth/_v+_right+(_j-1)*(_parameterWidth/_v);
// 					_y = parseInt(_parameterHeight/(2*_v))+_top+(_i-1)*(_parameterHeight/_v);
// 					_width = _keepWidthToChange/_v-_left-_right;
// 					height = _keepHeightToChange/(2*_v)-_top;
// 					_viewport[0] = 0;
// 					_viewport[1] = 0;
// 					_viewport[2] = _parameterWidth;
// 					_viewport[3] = _parameterHeight/2;					
// 				}
// 			}
// 			else {				
// 				_width = _keepWidthToChange/_v - _right-_left;
// 				height = _keepHeightToChange/_v - _top-_bottom;
// 			}			
// 		}
// 		else{//最右边
// 			_x = _keepWidth*_j + _left;
// 			_y = _keepHeight*_i + _top;
// 			if (_v>_h) {
// 				if (_v-_h>1) {
// 					_x = 0;
// 					_y = 0;					
// 					_viewport[0] = _parameterWidth;
// 					_viewport[1] = _parameterHeight;
// 					_viewport[2] = 0;
// 					_viewport[3] = 0;
// 					_width = _keepWidthToChange;
// 					height = _keepHeightToChange;
// 				}
// 				else{
// 					_x = _parameterWidth/(2*_h)+parseInt(_parameterWidth/_h)*(_j-1) + _left;
// 					_y = parseInt(_parameterHeight/_h)*_i + _top;
// 					_viewport[0] = 0;
// 					_viewport[1] = 0;
// 					_viewport[2] = _parameterWidth/2;
// 					_viewport[3] = _parameterHeight;
// 					_width = _keepWidthToChange/(2*_h)-_right;
// 					height = _keepHeightToChange/_h-_top;
// 				}
// 			}
// 			else if(_v<_h){
// 				_x = _parameterWidth/_v+_right+(_j-1)*(_parameterWidth/_v);
// 				_y = parseInt(_parameterHeight/(2*_v))+_top+(_i-1)*(_parameterHeight/_v);
// 				if (_h-_v>1) {
// 					_x = 0;
// 					_y = 0;
// 					_viewport[0] = _parameterWidth;
// 					_viewport[1] = _parameterHeight;
// 					_viewport[2] = 0;
// 					_viewport[3] = 0;
// 					_width = _keepWidthToChange;
// 					height = _keepHeightToChange;
// 				}
// 				else{
// 					_viewport[0] = 0;
// 					_viewport[1] = 0;
// 					_viewport[2] = _parameterWidth;
// 					_viewport[3] = _parameterHeight/2;
// 					_width = _keepWidthToChange/_v-_left;
// 					height = _keepHeightToChange/(2*_v)-_top;
// 				}
// 			}
// 			else {				
// 				_width = _keepWidthToChange/_v - _left;
// 				height = _keepHeightToChange/_v - _top;
// 			}	
				
// 		}
// 	}
// 	// 像素的最终必须是2的倍数
// 	if ((_x%2)!=0) {
// 		_x += 1;
// 	}
// 	else if ((_y%2)!=0) {
// 		_y += 1;
// 	}
// 	else if ((_width%2)!=0) { 
// 		_width += 1;
// 	}
// 	else if ((height%2)!=0) {
// 		height -= 1;
// 	}
// 	return _x+','+_y+','+_width+','+height+','+_viewport[0]+','+_viewport[1]+','+_viewport[2]+','+_viewport[3];
// }
// return Resolution
function returnResolution(num,macaddress) {
	var _resolution;
	var _arr = _data.videoswitching_encode_arr.split(',');
	var _num;
	var _viewport = new Array();
	//checkParameterHasEncode = macaddress;
	for (var i = 0; i <_arr.length-1; i++) {		
		if (_arr[i]==macaddress) {
			_num=i;				
		}
	}
	
	_parameterWidth = parseInt(VideoWallResolutionArr[VideoWallResolutionSelectNum][0]);
	_parameterHeight = parseInt(VideoWallResolutionArr[VideoWallResolutionSelectNum][1]);
	var _parameterWidth1 = parseInt(EncodeVideoWallDataArr[_num][6]);
	var _parameterHeight1 = parseInt(EncodeVideoWallDataArr[_num][7]);
	_parameterFps = EncodeVideoWallDataArr[_num][8];
	_viewport[0] = 0;
	_viewport[1] = 0;
	_viewport[2] = _parameterWidth;
	_viewport[3] = _parameterHeight;

	var _h,_v,_i,_j;
	var _x,_y,_width,_height;
	_v = parseInt($('#VideoWallSizeX').val());
	_h = parseInt($('#VideoWallSizeY').val());
	//console.log(_checkInArr);
	var _top = parseInt($('#BezelTop').val());
	var _bottom = parseInt($('#BezelBottom').val());
	var _left = parseInt($('#BezelLeft').val());
	var _right = parseInt($('#BezelRight').val());

	var _keepWidth = parseInt(_parameterWidth1/_h);
	var _keepHeight = parseInt(_parameterHeight1/_v);
	//_checkInArr = _checkInArr.substr(0,_checkInArr.length-1).split(',');

	// 调整像素位置
	_i = parseInt((parseInt(num)-1)/_v);
	_j = (parseInt(num)-1)%_v;
	console.log('_i:'+_i+',_j:'+_j);
	var _topPix = (Math.round((_top)*(_parameterHeight1/_parameterHeight))%2!=0?(Math.round((_top)*(_parameterWidth1/_parameterWidth))+1):Math.round((_top)*(_parameterWidth1/_parameterWidth)));
	var _leftPix = (Math.round((_left)*(_parameterWidth1/_parameterWidth))%2!=0?(Math.round((_left)*(_parameterWidth1/_parameterWidth))+1):Math.round((_left)*(_parameterWidth1/_parameterWidth)));
	var _bottomPix = (Math.round((_bottom)*(_parameterHeight1/_parameterHeight))%2!=0?(Math.round((_bottom)*(_parameterWidth1/_parameterWidth))+1):Math.round((_bottom)*(_parameterWidth1/_parameterWidth)));
	var _rightPix = (Math.round((_right)*(_parameterWidth1/_parameterWidth))%2!=0?(Math.round((_right)*(_parameterWidth1/_parameterWidth))+1):Math.round((_right)*(_parameterWidth1/_parameterWidth)));

	var _leftright = parseInt((_left + _right)*(_parameterWidth1/_parameterWidth))%2!=0?parseInt((_left + _right)*(_parameterWidth1/_parameterWidth))+1:parseInt((_left + _right)*(_parameterWidth1/_parameterWidth));
	var _topbottom = parseInt((_top + _bottom)*(_parameterHeight1/_parameterHeight))%2!=0?parseInt((_top + _bottom)*(_parameterHeight1/_parameterHeight))+1:parseInt((_top + _bottom)*(_parameterHeight1/_parameterHeight));
	if (_i==0) {//最上边
		if (_j==0) {//最左边	
			_x = 0;
			_y = 0;		
			if (_v>_h) {
				if (_v-_h>1) {
					_viewport[0] = _parameterWidth-1;
					_viewport[1] = _parameterHeight-1;
					_viewport[2] = 1;
					_viewport[3] = 1;
					_width = _parameterWidth1;
					height = _parameterHeight1;
				}
				else{
					_viewport[0] = _parameterWidth/2;
					_viewport[1] = 0;
					_viewport[2] = _parameterWidth/2;
					_viewport[3] = _parameterHeight;
					_width = _parameterWidth1/(2*_h)-_rightPix;
					height = _parameterHeight1/_h-_bottomPix;
				}
			}
			else if(_v<_h){
				if (_h-_v>1) {
					_viewport[0] = _parameterWidth-2;
					_viewport[1] = _parameterHeight-2;
					_viewport[2] = 2;
					_viewport[3] = 2;
					_width = _parameterWidth1;
					height = _parameterHeight1;
				}
				else{
					_viewport[0] = 0;
					_viewport[1] = _parameterHeight/2;
					_viewport[2] = _parameterWidth;
					_viewport[3] = _parameterHeight/2;
					_width = _parameterWidth1/_v-_rightPix;
					height = _parameterHeight1/(2*_v)-_bottomPix;
				}
			}
			else {							
				_width = _keepWidth - _rightPix;
				height = _keepHeight - _bottomPix;
			}
		}
		else if((_j+1)<_v){
			_x = parseInt(_parameterWidth1/(2*_h)+parseInt(_parameterWidth1/_h)*(_j-2) + _leftPix);
			_y = 0;
			if (_v>_h) {
				if (_v-_h>1) {
					if (parseInt(_v-2-_h)>1) {
						if (_j==1) {
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = _parameterWidth-1;
							_viewport[1] = _parameterHeight-1;
							_viewport[2] = 1;
							_viewport[3] = 1;
						}
						else if(_j==2){
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
						}
						else if(_j==3){
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = _parameterWidth-1;
							_viewport[1] = _parameterHeight-1;
							_viewport[2] = 1;
							_viewport[3] = 1;					
						}
						// _width = _parameterWidth/(2*_h)-_right;
											
					}
					else if(parseInt(_v-2-_h)==1){
						if (_j==1) {
							_x=0;
							_width = parseInt(_parameterWidth1/(2*_h))-_rightPix;
							_viewport[0] = _parameterWidth/2;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth/2;
							_viewport[3] = _parameterHeight;
						}
						else if(_j==2){
							//_x = parseInt(_parameterWidth1/(2*_h)+parseInt(_parameterWidth1/_h)*(_j-2) + _left);
							if ((_v-_j-1)==1) {
								_width = parseInt(_parameterWidth1/(2*_h))-_rightPix;
								console.log(123);
								_viewport[0] = 0;
								_viewport[1] = 0;
								_viewport[2] = _parameterWidth/2;
								_viewport[3] = _parameterHeight;
							}
							else {console.log(456);
								_width = parseInt(_parameterWidth1/_h)-_leftright;
							}						
						}
						else if(_j==3){
							
							_width = parseInt(_parameterWidth1/(2*_h))-_leftPix;	
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth/2;
							_viewport[3] = _parameterHeight;						
						}
						// _width = _parameterWidth/(2*_h)-_right;
						height = parseInt(_parameterHeight1/_h)-_topPix;
					}
					else if(parseInt(_v-2-_h)<=0){
						_x =parseInt(_parameterWidth1/(2*_h)+parseInt(_parameterWidth1/_h)*(_j-1) + _leftPix);
						
						if (_j==1) {
							_x=0;
							_width = _parameterWidth1/_h-_rightPix;							
						}
						else if(_j==2){
							_x = parseInt(_parameterWidth1/_h)*(_j-1) + _leftPix;
							console.log(_x );
							if ((_v-_j-1)==1) {
								
								_width = _parameterWidth1/_h-_leftPix;
							}
							else {
								_width = _parameterWidth1/_h-_leftright;
							}
						}
						else if(_j==3){
							_x =parseInt(_parameterWidth1/_h)*(_j-1) + _leftPix;
							_width = _parameterWidth1/_h-_leftPix;							
						}
						height = _parameterHeight1/_h-_bottomPix;
					}
				}
				else{
					//_x = _parameterWidth/(2*_v)+(parseInt(_right*_h/_v)%2==0?parseInt(_right*_h/_v)+2:parseInt(_right*_h/_v)+1)+(_j-1)*(_parameterWidth/_v);
					_x = parseInt(_parameterWidth1/(2*_h)+_rightPix+(_j-1)*(_parameterWidth1/_v));
					_width = _parameterWidth1/_h-_leftright;
					height = _parameterHeight1/_h-_bottomPix;
				}
			}
			else if(_v<_h){
				if (_h-_v>1) {
					if (parseInt(_h-2-_v)>1) {
						if (_j==1) {
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = _parameterWidth-2;
							_viewport[1] = _parameterHeight-2;
							_viewport[2] = 2;
							_viewport[3] = 2;
						}
						else if(_j==2){
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
						}
						else if(_j==3){
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = _parameterWidth-2;
							_viewport[1] = _parameterHeight-2;
							_viewport[2] = 2;
							_viewport[3] = 2;					
						}						
					}
					else if(parseInt(_h-2-_v)==1){
						if (_j==1) {
							_x=0;
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = _parameterWidth-2;
							_viewport[1] = _parameterHeight-2;
							_viewport[2] = 2;
							_viewport[3] = 2;
						}
						else if(_j==2){
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = _parameterWidth-2;
							_viewport[1] = _parameterHeight-2;
							_viewport[2] = 2;
							_viewport[3] = 2;						
						}
						else if(_j==3){
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = _parameterWidth-2;
							_viewport[1] = _parameterHeight-2;
							_viewport[2] = 2;
							_viewport[3] = 2;					
						}
						// _width = _parameterWidth/(2*_h)-_right;
						// height = parseInt(_parameterHeight/_h)-_top;
					}
					else if(parseInt(_h-2-_v)<=0){						
						_x=0;
						_width = _parameterWidth1;
						height = _parameterHeight1;	
						_viewport[0] = _parameterWidth-2;
						_viewport[1] = _parameterHeight-2;
						_viewport[2] = 2;
						_viewport[3] = 2;
					}
				}
				else{
					_x = parseInt(_parameterWidth1/_v*_j+_rightPix+(_j-1)*(_parameterWidth1/_v));
					_width = _parameterWidth1/_v-_leftright;
					height = _parameterHeight1/(2*_v)-_bottomPix;
					_viewport[0] = 0;
					_viewport[1] = _parameterHeight/2;
					_viewport[2] = _parameterWidth;
					_viewport[3] = _parameterHeight/2;
				}
			}
			else {				
				_x = parseInt(_parameterWidth1/_h+parseInt(_parameterWidth1/_h)*(_j-1) + _leftPix);
				_width = _keepWidth - _leftright;
				height = _keepHeight - _bottomPix;
				
			}
		}
		else{//最右边
			_x = _keepWidth*_j + _leftPix;
			_y = 0;
			if (_v>_h) {				
				if (_v-_h>1) {
					_x = 0;
					_viewport[0] = _parameterWidth-1;
					_viewport[1] = _parameterHeight-1;
					_viewport[2] = 1;
					_viewport[3] = 1;
					_width = _parameterWidth1;
					height = _parameterHeight1;
				}
				else{
					//_x = _parameterWidth/(2*_v)+(parseInt(_left*_h/_v)%2==0?parseInt(_left*_h/_v)+2:parseInt(_left*_h/_v)+1)+(_j-1)*(_parameterWidth/_v);
					_x = parseInt(_parameterWidth1/(2*_h)+_leftPix+(_j-1)*(_parameterWidth1/_h));
					_viewport[0] = 0;
					_viewport[1] = 0;
					_viewport[2] = _parameterWidth/2;
					_viewport[3] = _parameterHeight;
					_width = _parameterWidth1/(2*_h)-_leftPix;
					height = _parameterHeight1/_h-_bottomPix;
				}
			}
			else if(_v<_h){
				_x = parseInt(_parameterWidth1/_v+_rightPix+(_j-1)*(_parameterWidth1/_v));
				if (_h-_v>1) {
					_x=0;
					_width = _parameterWidth1;
					height = _parameterHeight1;	
					_viewport[0] = _parameterWidth-2;
					_viewport[1] = _parameterHeight-2;
					_viewport[2] = 2;
					_viewport[3] = 2;
				}
				else{
					_viewport[0] = 0;
					_viewport[1] = _parameterHeight/2;
					_viewport[2] = _parameterWidth;
					_viewport[3] = _parameterHeight/2;
					_width = _parameterWidth1/_v-_rightPix;
					height = _parameterHeight1/(2*_v)-_bottomPix;
				}
			}
			else {				
				_width = _keepWidth - _leftPix;
				height = _keepHeight - _bottomPix;
			}			
		}
	}
	else if((_i+1)<_h){//中间
		if (_j==0) {//最左边
			_x = 0;
			_y = _keepHeight*_i + _topPix;
			if (_v>_h) {
				if (_v-_h>1) {
					_x = 0;
					_y = 0;	
					_viewport[0] = _parameterWidth-1;
					_viewport[1] = _parameterHeight-1;
					_viewport[2] = 1;
					_viewport[3] = 1;
					_width = _parameterWidth1;
					height = _parameterHeight1;
				}
				else{
					_y = parseInt(_parameterHeight1/_h) + _topPix;
					
					_viewport[0] = _parameterWidth/2;
					_viewport[1] = 0;
					_viewport[2] = _parameterWidth/2;
					_viewport[3] = _parameterHeight;
					_width = _parameterWidth1/(2*_h)-_rightPix;
					height = _parameterHeight1/_h-_topbottom;
				}
			}
			else if(_v<_h){
				if (_h-_v>1) {
					_x = 0;					
					if (_h-_v==2) {
						if (_i==1) {
							_y = 0;
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
							_width = _parameterWidth1/_v-_rightPix;
							height = _parameterHeight1/_v-_bottomPix;
						}
						else if(_i==2){
							_y = (_i-1)*(_parameterHeight1/_v)+_topPix;
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
							_width = _parameterWidth1/_v-_rightPix;
							height = _parameterHeight1/_v-_topbottom;
						}
						else if(_i==3){
							_y = (_i-1)*(_parameterHeight1/_v)+_topPix;
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
							_width = _parameterWidth1/_v-_rightPix;
							height = _parameterHeight1/_v-_bottomPix;
						}						
					}
					else if(_h-_v==3){
						if (_i==1) {
							_y = 0;
							_viewport[0] = 0;
							_viewport[1] = _parameterHeight/2;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight/2;
							_width = _parameterWidth1/_v-_rightPix;
							height = _parameterHeight1/(2*_v)-_bottomPix;
						}
						else if (_i==2) {
							_y = parseInt(_parameterHeight1/(2*_v))+_topPix;							
							_width = _parameterWidth1/_v-_rightPix;
							if (_v==1) {
								_viewport[0] = 0;
								_viewport[1] = 0;
								_viewport[2] = _parameterWidth;
								_viewport[3] = _parameterHeight/2;
								height = _parameterHeight1/(2*_v)-_topPix;
							}
							else {
								_viewport[0] = 0;
								_viewport[1] = 0;
								_viewport[2] = _parameterWidth;
								_viewport[3] = _parameterHeight;
								height = _parameterHeight1/_v-_topbottom;
							}
							
						}
						else if (_i==3) {
							_y = parseInt(_parameterHeight1/(2*_v))+_topPix+(_parameterHeight1/_v);
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight/2;
							_width = _parameterWidth1/_v-_rightPix;
							height = _parameterHeight1/(2*_v)-_topPix;
						}
					}
					else if(_h-_v==4){
						if (_i==1) {
							_y = 0;
							_viewport[0] = _parameterWidth-2;
							_viewport[1] = _parameterHeight-2;
							_viewport[2] = 2;
							_viewport[3] = 2;
							_width = _parameterWidth1;
							height = _parameterHeight1;
						}
						else if (_i==2) {
							_y = 0;
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
							_width = _parameterWidth1;
							height = _parameterHeight1;
						}
						else if (_i==3) {
							_y = 0;
							_viewport[0] = _parameterWidth-2;
							_viewport[1] = _parameterHeight-2;
							_viewport[2] = 2;
							_viewport[3] = 2;
							_width = _parameterWidth1;
							height = _parameterHeight1;
						}
					}
				}
				else{
					_y = parseInt(_parameterHeight1/(2*_v))+_topPix+(_i-1)*(_parameterHeight1/_v);
					_viewport[0] = 0;
					_viewport[1] = 0;
					_viewport[2] = _parameterWidth;
					_viewport[3] = _parameterHeight;
					_width = _parameterWidth1/_v-_rightPix;
					height = _parameterHeight1/_v-_topbottom;
				}
			}
			else {
				_width = _keepWidth - _rightPix;
				height = _keepHeight - _topbottom;
			}
		}
		else if((_j+1)<_v){				
			_x = _keepWidth*_j + _leftPix;
			_y = _keepHeight*_i + _topPix;		
			if (_v>_h) {	
				_x = parseInt(_parameterWidth1/(2*_h)+parseInt(_parameterWidth1/_h)*(_j-1) + _leftPix);
				_y = parseInt(_parameterHeight1/_h)*_i + _topPix;	
				console.log(_y );		
				if (_v-_h>1) {					
					if (parseInt(_v-2-_h)>1) {
						if (_j==1) {
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = _parameterWidth-1;
							_viewport[1] = _parameterHeight-1;
							_viewport[2] = 1;
							_viewport[3] = 1;
						}
						else if(_j==2){
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
						}
						else if(_j==3){
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = _parameterWidth-1;
							_viewport[1] = _parameterHeight-1;
							_viewport[2] = 1;
							_viewport[3] = 1;					
						}
						// _width = _parameterWidth/(2*_h)-_right;
											
					}
					else if(parseInt(_v-2-_h)==1){
						if (_j==1) {
							_x=0;
							_width = parseInt(_parameterWidth1/(2*_h))-_rightPix;
							_viewport[0] = _parameterWidth/2;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth/2;
							_viewport[3] = _parameterHeight;
						}
						else if(_j==2){
							_x = parseInt((_j-1)*(_parameterWidth1/(2*_h)))+_leftPix;
							if ((_v-_j-1)==1) {
								_width = parseInt(_parameterWidth1/(2*_h))-_rightPix;
								_viewport[0] = _parameterWidth/2;
								_viewport[1] = 0;
								_viewport[2] = _parameterWidth/2;
								_viewport[3] = _parameterHeight;
							}
							else {
								_width = parseInt(_parameterWidth1/_h)-_leftright;
							}						
						}
						else if(_j==3){
							_x = parseInt(_j*_parameterWidth1/(2*_h))+_leftPix;
							_width = parseInt(_parameterWidth1/(2*_h))-_leftPix;	
							_viewport[0] = _parameterWidth/2;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth/2;
							_viewport[3] = _parameterHeight;						
						}
						// _width = _parameterWidth/(2*_h)-_right;
						// height = parseInt(_parameterHeight/_h)-_top;
					}
					else if(parseInt(_v-2-_h)<=0){
						if (_j==1) {
							_x=0;
							_width = _parameterWidth1/_h-_rightPix;							
						}
						else if(_j==2){
							_x = parseInt((_j-1)*(_parameterWidth1/_h)+_leftPix);
							if ((_v-_j-1)==1) {
								_width = _parameterWidth1/_h-_leftPix;
							}
							else {
								_width = _parameterWidth1/_h-_leftright;
							}						
						}
						else if(_j==3){
							_x = parseInt(2*_parameterWidth1/_h+_leftPix);
							_width = _parameterWidth1/_h-_leftPix;							
						}
						// height = _parameterHeight/_h-_bottom-_top;
					}
				}
				else{
					_width = _parameterWidth1/_h-_leftright;
					// height = _parameterHeight/_h-_top-_bottom;
				}
				height = _parameterHeight1/_h-_topbottom;
			}
			else if(_v<_h){
				if (_h-_v>1) {
					if (parseInt(_h-2-_v)>1) {
						if (_j==1) {
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = _parameterWidth-1;
							_viewport[1] = _parameterHeight-1;
							_viewport[2] = 1;
							_viewport[3] = 1;
						}
						else if(_j==2){
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
						}
						else if(_j==3){
							_x=0;
							_width = _parameterWidth1;
							height = _parameterHeight1;	
							_viewport[0] = _parameterWidth-1;
							_viewport[1] = _parameterHeight-1;
							_viewport[2] = 1;
							_viewport[3] = 1;					
						}						
					}
					else if(parseInt(_h-2-_v)==1){
						if (_i==1) {
							_x=0;
							_width = parseInt(_parameterWidth1/(2*_v))-_rightPix;
							_viewport[0] = 0;
							_viewport[1] = _parameterHeight/2;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight/2;
						}
						else if(_i==2){
							_x = parseInt((_j-1)*(_parameterWidth1/(2*_h)))+_leftPix;
							if ((_v-_j-1)==1) {
								_width = parseInt(_parameterWidth1/(2*_h))-_rightPix;
								_viewport[0] = _parameterWidth/2;
								_viewport[1] = 0;
								_viewport[2] = _parameterWidth/2;
								_viewport[3] = _parameterHeight;
							}
							else {
								_width = parseInt(_parameterWidth1/_h)-_leftright;
							}						
						}
						else if(_i==3){
							_x = parseInt(_j*_parameterWidth1/(2*_h))+_leftPix;
							_width = parseInt(_parameterWidth1/(2*_h))-_leftPix;	
							_viewport[0] = _parameterWidth/2;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth/2;
							_viewport[3] = _parameterHeight;						
						}
						// _width = _parameterWidth/(2*_h)-_right;
						height = parseInt(_parameterHeight1/_h)-_topPix;
					}
					else if(parseInt(_h-2-_v)<=0){
						if (_i==1) {
							_x = parseInt(_parameterWidth1/_v+_rightPix+(_j-1)*(_parameterWidth1/_v));
							_y = 0;
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
							_width = _parameterWidth1/_v-_leftright;
							height = _parameterHeight1/_v-_bottomPix;
						}
						else if(_i==2){
							_x = parseInt(_parameterWidth1/_v+_rightPix+(_j-1)*(_parameterWidth1/_v));
							_y = parseInt((_i-1)*(_parameterHeight1/_v)+_topPix);
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
							_width = _parameterWidth1/_v-_leftright;
							height = _parameterHeight1/_v-_topbottom;
						}
						else if(_i==3){
							_x = parseInt(_parameterWidth1/_v+_rightPix+(_j-1)*(_parameterWidth1/_v));
							_y = parseInt((_i-1)*(_parameterHeight1/_v)+_topPix);
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
							_width = _parameterWidth1/_v-parseInt((_leftright)*(_parameterWidth1/_parameterWidth));
							height = _parameterHeight1/_v-parseInt((_topPix)*(_parameterHeight1/_parameterHeight));
						}						
					}
				}
				else{
					_x = parseInt(_parameterWidth1/_v+_rightPix+(_j-1)*(_parameterWidth1/_v));
					_y = parseInt(_parameterHeight1/(2*_v))+_topPix+(_i-1)*(_parameterHeight1/_v);
					_width = _parameterWidth1/_v-_leftright;
					height = _parameterHeight1/_v-_topbottom;
					_viewport[0] = 0;
					_viewport[1] = 0;
					_viewport[2] = _parameterWidth;
					_viewport[3] = _parameterHeight;
				}
			}
			else {				
				_width = _keepWidth - _leftright;
				height = _keepHeight - _topbottom;
			}
		}
		else{//最右边
			_x = _keepWidth*_j + _leftPix;
			_y = _keepHeight*_i + _topPix;
			if (_v>_h) {
				if (_v-_h>1) {
					_x = 0;
					_y = 0;	
					_viewport[0] = _parameterWidth-1;
					_viewport[1] = _parameterHeight-1;
					_viewport[2] = 1;
					_viewport[3] = 1;
					_width = _parameterWidth1;
					height = _parameterHeight1;
				}
				else{
					_x = parseInt(_parameterWidth1/(2*_h)+parseInt(_parameterWidth1/_h)*(_j-1) + _leftPix);
					_y = parseInt(_parameterHeight1/_h)*_i + _topPix;
					_viewport[0] = 0;
					_viewport[1] = 0;
					_viewport[2] = _parameterWidth/2;
					_viewport[3] = _parameterHeight;
					_width = _parameterWidth1/(2*_h)-_rightPix;
					height = _parameterHeight1/_h-_topbottom;
				}
			}
			else if(_v<_h){
				_x = parseInt(_parameterWidth1/_v+_rightPix+(_j-1)*(_parameterWidth1/_v));				
				_y = parseInt(_parameterHeight1/(2*_v))+_topPix+(_i-1)*(_parameterHeight1/_v);
				if (_h-_v>1) {
					if (_h-_v==2) {
						if (_i==1) {
							_y = 0;
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
							_width = _parameterWidth1/_v-_leftPix;
							height = _parameterHeight1/_v-_bottomPix;
						}
						else if(_i==2){
							_y = parseInt((_i-1)*(_parameterHeight1/_v)+_topPix);
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
							_width = _parameterWidth1/_v-_leftPix;
							height = _parameterHeight1/_v-_topbottom;
						}
						else if(_i==3){
							_y = parseInt((_i-1)*(_parameterHeight1/_v)+_topPix);
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
							_width = _parameterWidth1/_v-_leftPix;
							height = _parameterHeight1/_v-_bottomPix;
						}						
					}
					else if(_h-_v==3){
						if (_i==1) {
							_y = 0;
							_viewport[0] = 0;
							_viewport[1] = _parameterHeight/2;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight/2;
							_width = _parameterWidth1/_v-_leftPix;
							height = _parameterHeight1/(2*_v)-_bottomPix;
						}
						else if (_i==2) {
							_y = parseInt(_parameterHeight1/(2*_v))+_topPix;							
							_width = parseInt(_parameterWidth1/_v-_leftPix);
							if (_v==1) {
								_viewport[0] = 0;
								_viewport[1] = _parameterHeight/2;
								_viewport[2] = _parameterWidth;
								_viewport[3] = _parameterHeight/2;
								height = _parameterHeight1/(2*_v)-_topPix;
							}
							else {
								_viewport[0] = 0;
								_viewport[1] = 0;
								_viewport[2] = _parameterWidth;
								_viewport[3] = _parameterHeight;
								height = _parameterHeight1/_v-_topbottom;
							}
							
						}
						else if (_i==3) {
							_y = parseInt(_parameterHeight1/(2*_v))+_topPix+(_parameterHeight1/_v);
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight/2;
							_width = _parameterWidth1/_v-_leftPix;
							height = _parameterHeight1/(2*_v)-_topPix;
						}
					}
					else if(_h-_v==4){
						if (_i==1) {
							_y = 0;
							_viewport[0] = _parameterWidth-1;
							_viewport[1] = _parameterHeight-1;
							_viewport[2] = 1;
							_viewport[3] = 1;
							_width = _parameterWidth1;
							height = _parameterHeight1;
						}
						else if (_i==2) {
							_y = 0;
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth;
							_viewport[3] = _parameterHeight;
							_width = _parameterWidth1;
							height = _parameterHeight1;
						}
						else if (_i==3) {
							_y = 0;
							_viewport[0] = _parameterWidth-1;
							_viewport[1] = _parameterHeight-1;
							_viewport[2] = 1;
							_viewport[3] = 1;
							_width = _parameterWidth1;
							height = _parameterHeight1;
						}
					}
				}
				else{
					_viewport[0] = 0;
					_viewport[1] = 0;
					_viewport[2] = _parameterWidth;
					_viewport[3] = _parameterHeight;
					_width = _parameterWidth1/_v-_leftPix;
					height = _parameterHeight1/_v-_topbottom;
				}
			}
			else {				
				_width = _keepWidth - _leftPix;
				height = _keepHeight - _topbottom;
			}			
		}
	}
	else{//最下边
		if (_j==0) {//最左边
			_x = 0;
			_y = _keepHeight*_i + _topPix;
			if (_v>_h) {				
				if (_v-_h>1) {
					_x = 0;
					_y = 0;	
					_viewport[0] = _parameterWidth-1;
					_viewport[1] = _parameterHeight-1;
					_viewport[2] = 1;
					_viewport[3] = 1;
					_width = _parameterWidth1;
					height = _parameterHeight1;
				}
				else{
					_y = parseInt(_parameterHeight1/_h)*_i + _topPix;
					_viewport[0] = _parameterWidth/2;
					_viewport[1] = 0;
					_viewport[2] = _parameterWidth/2;
					_viewport[3] = _parameterHeight;
					_width = _parameterWidth1/(2*_h)-_rightPix;
					height = _parameterHeight1/_h-_topPix;
				}
			}
			else if(_v<_h){
				if (_h-_v>1) {
					_x = 0;
					_y = 0;	
					_viewport[0] = _parameterWidth-2;
					_viewport[1] = _parameterHeight-2;
					_viewport[2] = 2;
					_viewport[3] = 2;
					_width = _parameterWidth1;
					height = _parameterHeight1;
				}
				else{
					_y = parseInt(_parameterHeight1/(2*_v))+_topPix+(_i-1)*(_parameterHeight1/_v);
					_viewport[0] = 0;
					_viewport[1] = 0;
					_viewport[2] = _parameterWidth;
					_viewport[3] = _parameterHeight/2;
					_width = _parameterWidth1/_v-_rightPix;
					height = parseInt(_parameterHeight1/(2*_v))-_topPix;
				}
			}
			else {				
				_width = _keepWidth - _rightPix;
				height = _keepHeight - _topPix;
			}
				
		}
		else if((_j+1)<_v){
			_x = _keepWidth*_j + _leftPix;
			_y = _keepHeight*_i + _topPix;
			if (_v>_h) {
				_x = parseInt(_parameterWidth1/(2*_h)+parseInt(_parameterWidth1/_h)*(_j-1) + _leftPix);
				_y = parseInt(_parameterHeight1/_h)*_i+_topPix ;
				if (_v-_h>1) {
					if (parseInt(_v-2-_h)>1) {
						_width = _parameterWidth1;
						height = _parameterHeight1;
					}
					else if(parseInt(_v-2-_h)==1){
						
						if (_j==1) {
							_x=0;
							_width = _parameterWidth1/(2*_h)-_rightPix;									
							_viewport[0] = _parameterWidth/2;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth/2;
							_viewport[3] = _parameterHeight;
						}
						else if(_j==2){
							_x = parseInt(_parameterWidth1/(2*_h)+parseInt(_parameterWidth1/_h)*(_j-2) + _leftPix);
							if ((_v-_j-1)==1) {
								_width = _parameterWidth1/(2*_h)-_rightPix;
							}
							else {
								_viewport[0] = 0;
								_viewport[1] = 0;
								_viewport[2] = _parameterWidth;
								_viewport[3] = _parameterHeight;
								_width = _parameterWidth1/_h-_leftright;
							}						
						}
						else if(_j==3){
							_x = parseInt(_parameterWidth1/(2*_h)+parseInt(_parameterWidth1/_h)*(_j-2) + _leftPix);
							_viewport[0] = 0;
							_viewport[1] = 0;
							_viewport[2] = _parameterWidth/2;
							_viewport[3] = _parameterHeight;
							_width = _parameterWidth1/(2*_h)-_rightPix;							
						}
						//_width = _parameterWidth1/(2*_h)-parseInt((_right)*(_parameterWidth1/_parameterWidth));
						height = _parameterHeight1/_h;
					}
					else if(parseInt(_v-2-_h)<=0){
						if (_j==1) {
							_x=0;
							_width = _parameterWidth1/_h-_rightPix;
						}
						else if(_j==2){
							_x = parseInt((_j-1)*(_parameterWidth1/_h)+_leftPix);
							if ((_v-_j-1)==1) {
								_width = parseInt(_parameterWidth1/_h)-_leftPix;
							}
							else {
								_width = parseInt(_parameterWidth1/_h)-_leftright;
							}						
						}
						else if(_j==3){
							_x = parseInt((_j-1)*(_parameterWidth1/_h)+_leftPix);
							_width = parseInt(_parameterWidth1/_h)-_leftPix;									
						}
						height = parseInt(_parameterHeight1/_h)-_topPix;
					}					
				}
				else{
					_width = parseInt(_parameterWidth1/_h)-_leftright;
					height = parseInt(_parameterHeight1/_h)-_topPix;
				}
			}
			else if(_v<_h){
				_x = parseInt(_parameterHeight1/_v)*_j + _leftPix;
				_y = _parameterWidth1/(2*_v)+parseInt(_parameterWidth1/_v)*(_i-1) + _topPix;
				if (_h-_v>1) {
					_x = 0;
					_y = 0;
					_viewport[0] = _parameterWidth-2;
					_viewport[1] = _parameterHeight-2;
					_viewport[2] = 2;
					_viewport[3] = 2;
					_width = _parameterWidth1;
					height = _parameterHeight1;				
				}
				else{
					_x = _parameterWidth1/_v+_rightPix+(_j-1)*(_parameterWidth1/_v);
					_y = parseInt(_parameterHeight1/(2*_v))+_topPix+(_i-1)*(_parameterHeight1/_v);
					_width = _parameterWidth1/_v-_leftright;
					height = _parameterHeight1/(2*_v)-_topPix;
					_viewport[0] = 0;
					_viewport[1] = 0;
					_viewport[2] = _parameterWidth;
					_viewport[3] = _parameterHeight/2;					
				}
			}
			else {				
				_width = _keepWidth - _leftright;
				height = _keepHeight - _topPix;
			}			
		}
		else{//最右边
			_x = _keepWidth*_j + _leftPix;
			_y = _keepHeight*_i + _topPix;
			if (_v>_h) {
				if (_v-_h>1) {
					_x = 0;
					_y = 0;					
					_viewport[0] = _parameterWidth-1;
					_viewport[1] = _parameterHeight-1;
					_viewport[2] = 1;
					_viewport[3] = 1;
					_width = _parameterWidth1;
					height = _parameterHeight1;
				}
				else{
					_x = _parameterWidth1/(2*_h)+parseInt(_parameterWidth1/_h)*(_j-1) + _leftPix;
					_y = parseInt(_parameterHeight1/_h)*_i + _topPix;
					_viewport[0] = 0;
					_viewport[1] = 0;
					_viewport[2] = _parameterWidth/2;
					_viewport[3] = _parameterHeight;
					_width = _parameterWidth1/(2*_h)-_rightPix;
					height = _parameterHeight1/_h-_topPix;
				}
			}
			else if(_v<_h){
				_x = _parameterWidth1/_v+_rightPix+(_j-1)*(_parameterWidth1/_v);
				_y = parseInt(_parameterHeight1/(2*_v))+_topPix+(_i-1)*(_parameterHeight1/_v);
				if (_h-_v>1) {
					_x = 0;
					_y = 0;
					_viewport[0] = _parameterWidth-2;
					_viewport[1] = _parameterHeight-2;
					_viewport[2] = 2;
					_viewport[3] = 2;
					_width = _parameterWidth1;
					height = _parameterHeight1;
				}
				else{
					_viewport[0] = 0;
					_viewport[1] = 0;
					_viewport[2] = _parameterWidth;
					_viewport[3] = _parameterHeight/2;
					_width = _parameterWidth1/_v-_leftPix;
					height = _parameterHeight1/(2*_v)-_topPix;
				}
			}
			else {				
				_width = _keepWidth - _leftPix;
				height = _keepHeight - _topPix;
			}	
				
		}
	}
	// 像素的最终必须是2的倍数
	if ((_x%2)!=0) {
		_x += 1;
	}
	if ((_y%2)!=0) {
		_y += 1;
	}
	if (((_width=Math.round(_width))%2)!=0) { 
		_width += 1;
	}
	if (((height=Math.round(height))%2)!=0) {
		height -= 1;
	}
	// if (_left!=0||_right!=0) {
	// 	_width -= 2;
	// }
	// if (_top!=0||_bottom!=0) {
	// 	height -= 2;
	// }
	return parseInt(_x)+','+parseInt(_y)+','+parseInt(_width)+','+parseInt(height)+','+_viewport[0]+','+_viewport[1]+','+_viewport[2]+','+_viewport[3]+','+_parameterFps;
}
// 视频墙名字读取
function PresetNameReadFromFile(num,data){
	$.ajax({
        type: 'POST',
        url: 'common/readfile.php',
        data: 'PresetNameReadFromFile=1',
        datatype: 'json',
        async: true,
        success: function(rst) {
        	var _rst = rst.split('::');
        	_rst[num] = data;
        	var _rstTmp = _rst.toString().replace(/,/g,'::');
        	$('#VideoWallPresetList li:eq('+num+') div:eq(1)').html(data)
        	$.ajax({
		        type: 'POST',
		        url: 'common/readfile.php',
		        data: 'PresetNameWriteToFile='+_rstTmp,
		        datatype: 'json',
		        async: true,
		        success: function(rst) {
		        	
		        	
		        } 
		    });
        } 
    });
}
function PresetNameReadFromFileToLoad(){
	$.ajax({
        type: 'POST',
        url: 'common/readfile.php',
        data: 'PresetNameReadFromFile=1',
        datatype: 'json',
        async: true,
        success: function(rst) {
        	var _rst = rst.split('::');
        	$('#VideoWallPresetList li').each(function(e){
        		$('#VideoWallPresetList li:eq('+e+') div:eq(1)').html(_rst[e])
        	});
        	
        } 
    });
}