	$.fn.rubricTree = function(settings){
		var config = {
			'nodes':[],
			'resourceId':'ru_rihmi-wdc_2320',
			'multiple': false,
			'count': 'false'
		};
		if (settings){$.extend(config, settings);}

		return this.each(function() {
			var nodesStr = '';
			for (var i in config.nodes)
				nodesStr = nodesStr+','+config.nodes[i];
			nodesStr = nodesStr.replace(',','');
			if (!config.multiple)
				$(this).jstree({
					"json_data" : {
						"ajax" : {
							"url" : "/dataview/rubric",
							"type": "POST",
							"data":{"resourceid":config.resourceId,"nodes":nodesStr, "count": config.count}
					}},
					"plugins" : [ "ui", "json_data"]
				});
			else
				$(this).jstree({
					"json_data" : {
						"ajax" : {
							"url" : "/dataview/rubric",
							"type": "POST",
							"data":{"resourceid":config.resourceId,"nodes":nodesStr, "count": config.count}
					}},
					"plugins" : [ "ui", "json_data","checkbox"]
				});
		});	
	};

	$.fn.rubricPicker = function(settings){
		var config = {
			'nodes':[],
			'resourceId':'ru_rihmi_wdc_2320',
			'count': 'false'
		};
		if (settings){$.extend(config, settings);}

		return this.each(function() {
			$(this).val('');
			$(this).css('display','none');
			var elementid = $(this).attr('id');
			if (elementid == undefined){
				elementid = 'dialog-rubric-input-field';
				$(this).attr('id',elementid);
			}
			$(this).after('<div class="chzn-container chzn-container-multi" style="width:'+$(this).width()+'px;"><ul class="chzn-choices" id="'+elementid+'-rubric-list"><li class="search-field"><input type="text" value="..."/></li></ul></div>');
			$(this).keydown(function(event){
				event.preventDefault();
			});
			$('#'+elementid+'-rubric-list li.search-choice a.search-choice-close').die().live('click',function(){
				var tempValue = $('#'+elementid).val();
				tempValue = tempValue.replace(','+$(this).parent('li.search-choice').attr('name'),'');
				$('#'+elementid).val(tempValue).change();
				$(this).parent('li.search-choice').remove();				
			});
			$('#'+elementid+'-rubric-list li.search-field input:text').click(function(event){
				$('#dialog-rubric-input').remove();
				$('body').append('<div id="dialog-rubric-input" title="Рубрикатор" style="padding:10px;">'+
				'<div id="dialog-rubric-input-tree" style="width:100%;"></div><br style="clean:both;"/>'+
				'</div>');
				$('#dialog-rubric-input').dialog({
					minHeight:140,
					minWidth:320,
					modal:false,
					draggable:false,
					resizable:false,
					position: { 
						my: 'left top',
						at: 'right top',
						of: $('#'+elementid+'-rubric-list')
					},
					open: function(){
						$('#dialog-rubric-input-tree').rubricTree({
							nodes: config.nodes,
							resourceId: config.resourceId,
							count: config.count
						});	
						$('#dialog-rubric-input-tree a').die().live('click',function(){
							var tempVal = $('#'+elementid).val();
							if (tempVal.indexOf('('+$(this).parent("li").attr("name")+')')==-1){
								$('#'+elementid+'-rubric-list li.search-field').before('<li class="search-choice" name="('+$(this).parent("li").attr("name")+')"><span>'+$(this).text()+'</span><a class="search-choice-close" href="javascript:void(0)"></a></li>');
								$('#'+elementid).val(tempVal+',('+$(this).parent("li").attr("name")+')').change();
							}
						});
					}
				});	
			});		
		});	
	};	
	
	function getDistinctColumn(resourceId, filter, distinct, count){
		var result = [];
		$.ajax({
			 "async":false,
			 "dataType": 'json', 
			 "type": 'POST', 
			 "url": '/dataview/getresourcetable', 
			 "data": { "resourceId":resourceId, "filter":filter, "distinct":distinct, "sSortCol":distinct, "iDisplayStart":0, "iDisplayLength":count}, 
			 "timeout": 30000,
			 "success": function(json){
				for (var i=0; i<json.aaData.length; i++)
					result.push(json.aaData[i][0])
			 },
			 "error": function(request, status, err) {
					if(status == "error") {
						alert("Нет соединения с сервисом данных");
					}								
					else if(status == "timeout") {
						alert("Время ожидания данных превысило 30 секунд. Отмена запроса.");
					}else alert(status);
			  }
		});			   
		return result;
	}

	function getResourceCodes(resourceId, codes){
		var result = '';
		if ((codes.indexOf('pp')>=0)||(codes.indexOf('mm')>=0)){
			$.ajax({
			  type: 'POST',
			  url: '/dataview/getResourceCodes',
			  data: {"resourceId":resourceId,"codes":codes},
			  async: false,
			  success: function(json){
					result = json.codes;
					try{
						if (result[result.length-1] == ',')
							result = result.substr(0,result.length-1);
					}catch(e){
						console.log(e.message);
					}
			  },
			  dataType: 'json'
			});
		} else {
			result = codes;
		}
		
		return result.split(',,').join(',');
	}
	
	function drawAnalytics(analyticsobject){
		
	}
	
	var messagesResourcesArray = ["RU_RIHMI-WDC_492","RU_RIHMI-WDC_491","RU_RIHMI-WDC_490","RU_RIHMI-WDC_489","RU_RIHMI-WDC_488","RU_RIHMI-WDC_487","RU_RIHMI-WDC_1758","RU_RIHMI-WDC_1757","RU_RIHMI-WDC_1756","RU_RIHMI-WDC_1754","RU_RIHMI-WDC_1753","RU_RIHMI-WDC_1752"];
	function drawTable(resourceId, table, namespace, filter, info){
		if (table.columns != undefined)
		if (table.columns.length > 0)
		if (!((table.columns.length == 1)&&(table.columns[0] == ''))){
			if (info){
				
				var checkImportant = false;
				for (var i=0; i<messagesResourcesArray.length; i++){
					if (resourceId.toLowerCase()==messagesResourcesArray[i].toLowerCase())
						checkImportant = true;
				}		
				$('#'+namespace).makeTableMetadataResource({
					'resourceId': resourceId,
					'columns': table.columns,
					'namespace': namespace,
					'filter': filter,
					'checkimportant': checkImportant
				});
			}	
			else
				$('#'+namespace).makeTableDataResource({
					'resourceId': resourceId,
					'columns': table.columns,
					'namespace': namespace,
					'filter': filter
				});
		}	
	}
	
	function getMapFilter(featureid, namespaceFilter){
		var resultstr = '';
		if (featureid == 'firstfeature'){
			try{
				var oMap = globalMapObject[namespaceFilter+'-map'];
				var feature = oMap.layers[1].features[0];
				var obj = feature.attributes;
				//$('#OpenLayers_Geometry_Point_'+(feature.id.replace('OpenLayers_Feature_Vector_','')-1)).attr('fill','#0000ff').attr('r','6');

				var mapfilterstr = '';
				for (attr in obj )
					if ((obj[attr] != '')&&(attr.indexOf('mod') == -1)&&(attr.indexOf('max') == -1)&&(attr.indexOf('min') == -1))
						mapfilterstr = mapfilterstr + "AND(" + attr + "='"+obj[attr]+"')";
				if (mapfilterstr != ''){
					resultstr = mapfilterstr.replace("AND","");
				}	
			}catch(e){;}	
		}else{
			var id = '';
			if (featureid.indexOf('Point')>0) 
				id = featureid.replace('OpenLayers_Geometry_Point_','');
			else if (featureid.indexOf('Polygon')>0)
				id = featureid.replace('OpenLayers_Geometry_Polygon_','');		
			id =  parseInt(id) + 1;
			id = 'OpenLayers_Feature_Vector_'+id;
			var oMap = globalMapObject[namespaceFilter+'-map'];
			var featuresArray = oMap.layers[1].features;
			for (index in featuresArray)
				if (id == featuresArray[index].id){
					var obj = featuresArray[index].attributes;
					var mapfilterstr = '';
					for (attr in obj )
						if ((obj[attr] != '')&&(attr.indexOf('mod') == -1)&&(attr.indexOf('max') == -1)&&(attr.indexOf('min') == -1))
							mapfilterstr = mapfilterstr + "AND(" + attr + "='"+obj[attr]+"')";
					if (mapfilterstr != ''){
						resultstr = mapfilterstr.replace("AND","");
					}	
					//$('#OpenLayers_Geometry_Point_'+(featuresArray[index].id.replace('OpenLayers_Feature_Vector_','')-1)).attr('fill','#0000ff').attr('r','6');	
				}
		}
		return resultstr;
	}
	function getMapFeature(featureid, namespaceFilter){
		var result = {};
		var id = '';
		if (featureid.indexOf('Point')>0) 
			id = featureid.replace('OpenLayers_Geometry_Point_','');
		else if (featureid.indexOf('Polygon')>0)
			id = featureid.replace('OpenLayers_Geometry_Polygon_','');		
		id =  parseInt(id) + 1;
		id = 'OpenLayers_Feature_Vector_'+id;
		var oMap = globalMapObject[namespaceFilter+'-map'];
		var featuresArray = oMap.layers[1].features;
		for (index in featuresArray)
			if (id == featuresArray[index].id){
				result = featuresArray[index].attributes;
			}
		return result;
	}
	
	function getFullFilter(filter,filtercolumns,filterobj,dateColumn,hasDateFilter,namespaceDateFrom,namespaceDateTo,axisY){
		var dochart = true;
		var tempfilter = [];
		var tempfilterNoMap = [];
		var tempfilternames = [];
		if (filter.length > 0){
			for (var i=0; i<filter.length; i++ ){
				tempfilter.push(filter[i]);
				tempfilterNoMap.push(filter[i]);
			}	
		}
		try{
			for (var i=0; i<filtercolumns.length; i++){
				if ((filterobj[filtercolumns[i]]!='')&&(filterobj[filtercolumns[i]]!='()')){
					tempfilter.push(filtercolumns[i]+"='"+filterobj[filtercolumns[i]].split("'").join("''")+"'");
					tempfilterNoMap.push(filtercolumns[i]+"='"+filterobj[filtercolumns[i]].split("'").join("''")+"'");
					tempfilternames.push(filterobj[filtercolumns[i]]);
				}	
				else
					dochart = false;
			}
		}catch(e){;}	
		
		try{
			if (hasDateFilter){
				if ($('#'+namespaceDateTo).val() == undefined)
					tempfilter.push(dateColumn+"='"+$('#'+namespaceDateFrom).val()+"'");
				else{
					if (dateColumn == 'm4400'){
						tempfilter.push("(("+dateColumn+" between '"+$('#'+namespaceDateFrom).val()+"' and '"+$('#'+namespaceDateTo).val()+"') or (CAST("+dateColumn+" as text) like '%"+$('#'+namespaceDateTo).val()+"%'))");
						tempfilterNoMap.push("(("+dateColumn+" between '"+$('#'+namespaceDateFrom).val()+"' and '"+$('#'+namespaceDateTo).val()+"') or (CAST("+dateColumn+" as text) like '%"+$('#'+namespaceDateTo).val()+"%'))");
					}	
					else{
						tempfilter.push(dateColumn+" between '"+$('#'+namespaceDateFrom).val()+"' and '"+$('#'+namespaceDateTo).val()+"'");
						tempfilterNoMap.push("(("+dateColumn+" between '"+$('#'+namespaceDateFrom).val()+"' and '"+$('#'+namespaceDateTo).val()+"') or (CAST("+dateColumn+" as text) like '%"+$('#'+namespaceDateTo).val()+"%'))");
					}	
				}	
				//alert(tempfilter[tempfilter.length-1]);
			}
		}catch(e){;}
		
		try{
			if (axisY != undefined)
			if (axisY != ''){
				var columns = axisY.split(',');
				for (var i in columns)
					tempfilterNoMap.push("("+columns[i]+" is not null)");
			}		
		}catch(e){console.log(e.message);}
		
		try{
			if ((filterobj['map'] != '')&&(filterobj['map'] != undefined)){
				tempfilter.push(filterobj['map']);
				var str = filterobj['map'].substring(filterobj['map'].indexOf("\'")+1,filterobj['map'].lastIndexOf("\'"));
				tempfilternames.push(str);
			}
		}catch(e){;}	
		//else if (filterobj['map'] == '')
		//	dochart = false;
		
		var result = {"dochart": dochart, "filter":tempfilter, "filterNoMap":tempfilterNoMap, "filternames":tempfilternames};
		return result;
	}
	
	function copyChartToDialog (namespace,number,width,height,resourceId,chart,sameY,tempFilterObj,inverted){
		var tempchartid = 'analytics-dialog-'+number;
		var title = '';
		for (var i=0; i<tempFilterObj.filternames.length; i++)
			title = title + tempFilterObj.filternames[i] +' ';
		$('body').append('<div id="'+tempchartid+'" title="'+'" style="text-align: center;">'+
		'<div id="'+tempchartid+'-display" style="width:100%;height:90%;"></div><br/>'+
        '</div>');
		$( '#analytics-dialog-'+number ).dialog({
			width:width,
			height:height
		});
		$('#'+tempchartid+'-display').chartResource({
											'renderTo':tempchartid+'-display',
											'resourceId':resourceId,
											'axisX': chart.axisX,
											'axisY': chart.axisY,
											'type': chart.type,
											'filter': tempFilterObj.filter,
											'sameY': sameY,
											'inverted': inverted
		});		
	}
	
	var elementsToExcludeArray = ['p0965_00','p0240_00','p0964_00','p0595_00','p0060_00','p0497_00','p0074_00','p0988_00','p0416_00','p0415_00','p0106_00','p0108_00','p0761_00','p0460_00','p0977_00','p0978_00','p0982_00','p0980_00','p0981_00','p0874','p0874_39'];
	function makeSelectForElements(resourceId, elementsArray){
		var selectHtml = '';
		try{
			var allSelectedArray = ['RU_SSRI-CENTR_81_2'];
			if ((elementsArray[0]=='pp')||((elementsArray.length > 1)&&(resourceId != ''))){
				$.ajax({
				  'url': "/dataview/getcodes",
				  'async': false,
				  'data': {"resourceId":resourceId},
				  'type': 'POST',
				  'success': function(json){
						var uniqueElementsArray = [];
						$.each(elementsArray, function(i, el){
							if($.inArray(el, uniqueElementsArray) === -1) uniqueElementsArray.push(el);
						});
						elementsArray = uniqueElementsArray;
						
						selectHtml = '<div style="width:100%;"><div class="portlet-msg-status" style="float:left;width:28%;text-align:right;">Выбор параметров:</div><select class="portlet-chzn-select" style="float:left; width:65%;" multiple="multiple">';
						if (elementsArray[0]=='pp'){
							var selected = false;
							if (json[0].code.indexOf('p') == 0){
								selectHtml += '<option value="'+json[0].code+'" selected >'+json[0].name+'</option>';
								selected = true;
							}	
							for (var i = 1; i<json.length; i++){
								if(json[i].code.indexOf('p') == 0)
								if (elementsToExcludeArray.indexOf(json[i].code.toLowerCase()) == -1){
									var name = json[i].name;
									/*if (name == '')
										name = json[i].nameshort;*/
									if (selected)
										selectHtml += '<option value="'+json[i].code+'">'+name+'</option>';
									else{
										selectHtml += '<option value="'+json[i].code+'" selected>'+name+'</option>';
										selected = true;
									}	
								}	
							}
						}else{
							var name = '';
							var firstSelected = '';
							for (var i = 0; i<elementsArray.length; i++)
								if (elementsToExcludeArray.indexOf(elementsArray[i].toLowerCase()) == -1){
									var selected = '';
									if (firstSelected == ''){
										firstSelected = i+1;
										selected = 'selected';
									}else if (firstSelected != ''){
										/*if (elementsArray[i].substring(0,5) == elementsArray[firstSelected].substring(0,5))
											selected = 'selected';*/
									}
									if (allSelectedArray.indexOf(resourceId) != -1)
										selected = 'selected';
									name = findCodeById(json,elementsArray[i])['name'];
									if (name == '')
										name = findCodeById(json,elementsArray[i])['nameshort'];
									selectHtml += '<option value="'+elementsArray[i]+'" '+selected+' >'+name+'</option>';
								}
						}
						selectHtml += '</select></div>';
				  },
				  'dataType': 'json'
				});
			}
		}catch(e){;}
		return selectHtml;		
	}
	
	$.fn.analyticsResource = function(settings){
		var config = {
			'resourceId': '',
			'filtercolumns':[],
			'filtercolumnsAllowChartFromMapOnly': true,
			'interf': 'full',
			'filtermap':{
				'resourceId':'',
				'column':'',
				'latmin':'18',
				'latmax':'82',
				'lonmin':'29',
				'lonmax':'165',
				'title':'',
				'wms':[],
				'isFilterable': false
			},
			'metadataResource':{
								'resourceId':'',
								'codeIn':'',
								'codeOut':''
			},
			'displaymap':{
				'resourceId': '',
				'latmin':'18',
				'latmax':'82',
				'lonmin':'29',
				'lonmax':'165',
				'criteriaParameter':'',
				'isFilterable': false,
				'distinct': ''
			},
			'rubricColumn':'',
			'table':{
				'columns':[]
			},
			'tableinfo': false,
			'chart':{
				 'axisX':'',
				 'axisY':'',
				 'type':'line',
				 'prebuilt': false,
				 'sameY': false,
				 'inverted': false
			},
			'chartgallery':{
				'distinct':'',
				'count':10,
				'axisX':'',
				'axisY':'',
				'type':'line',
				'sameY':false				
			},
			'parameterSelect':false,
			'chartSaving': false,
			'chartTypeSelect': true,
			'filter':[],
			'dateFrom':'',
			'dateTo':'',
			'dateColumn': '',
			'showSourceData': true
		};
		if (settings){$.extend(config, settings);} 
			
		return this.each(function() {
			var namespace = $(this).attr('id');
			var namespaceRubric = namespace +"-rubric";
			var namespaceFilter = namespace +"-filter";
			var namespaceDisplay = namespace +"-display";
			var namespaceTable = namespaceDisplay +"-table";
			var namespaceChart = namespaceDisplay +"-chart";
			var namespaceChartGallery = namespaceDisplay +"-chart-gallery";
			var namespaceMap = namespaceDisplay +"-map";
			var namespaceDateFrom = namespace +"-dateFrom";
			var namespaceDateTo = namespace +"-dateTo";
			
			var resourceId = config.resourceId;	
			var rubricColumn = config.rubricColumn;	
			var rubricSelected = '';
			var filtermap = config.filtermap;
			if (filtermap.column != undefined)
				filtermap.column = filtermap.column.toLowerCase();
			var mapClicked = false;
			var filter = config.filter;
			var filtercolumns = config.filtercolumns;
			var filterobj = {};
			for (var i=0; i<filtercolumns.length; i++ )
				filterobj[filtercolumns[i]] = '';
			if (filtermap.resourceId !='')
				filterobj['map'] = '';
			else
				filterobj['map'] = undefined;
			
			var table = config.table;
			if (table.columns != undefined)
				for (var i=0; i<table.columns.length; i++)
					table.columns[i] = table.columns[i].toLowerCase();
			var info = config.tableinfo;
			var chart = config.chart;
			var sameY = config.chart.sameY;
			var chartgallery = config.chartgallery;
			
			var dateText = '&nbsp;Дата с';
			var dateText2 = '&nbsp;по';
			var trend = false;
			
			var dateFrom = new Date(2000, 01, 01);
			try{
				if (config.dateFrom != ''){
					if (config.dateFrom.length > 10)
						config.dateFrom = config.dateFrom.substring(0,10);
					var dateSplit = config.dateFrom.split("-");
					if (dateSplit.length > 1)
						dateFrom = new Date(dateSplit[0],dateSplit[1]-1,dateSplit[2].replace('DD','01').replace('MM','01'));
					else
						dateFrom = new Date(config.dateFrom,1,1);
				}
			}catch(e){}
			
			var dateTo = new Date();
			try{
				if (config.dateTo != ''){
					if (config.dateTo.length > 10)
						config.dateTo = config.dateTo.substring(0,10);
					var dateSplit = config.dateTo.split("-");
					var month = dateSplit[1]-1;
					if (month == 0)
						month = 1;
					if (dateSplit.length > 1)
						dateTo = new Date(dateSplit[0],month,dateSplit[2]);
					else
						dateTo = new Date(config.dateTo,1,1);
					if (dateFrom == dateTo)
						dateFrom.setDate(dateFrom.getDate() - 1);
				}
			}catch(e){}
			
			var dateYearRange = dateFrom.getUTCFullYear()+":"+dateTo.getUTCFullYear();
			
			var dateColumn = config.dateColumn;
			var hasDateFilter = false;
			var dateFormat = 'yy-mm-dd';
			if 	(dateColumn != ''){
				hasDateFilter = true;
				if ((dateColumn == 'm4404')||(dateColumn == 'm4410')){
					dateFormat = 'yy';
					dateText = '&nbsp;Год с';
				}	
				else if (dateColumn == 'm4405'){
					dateFormat = 'mm';			
					dateFrom = new Date(2013,0,1);
					dateTo = new Date(2013,11,1);
					if (config.chart.axisX == 'm4404'){
						dateText = '&nbsp;Месяц';
						dateText2 = '';
						dateTo = dateFrom;
						trend = true;						
					}else 
						dateText = '&nbsp;Месяц с';
				}
				else if (dateColumn == 'm4406'){
					dateFormat = 'dd';
					dateFrom = new Date(2013,0,1);
					dateTo = new Date(2013,0,31);
					dateText = '&nbsp;День с';
				}
			}
			
			var hasChartTypeSelector = false;
			if (config.chartTypeSelect)
				hasChartTypeSelector = true;
			
			var hasChartSaving = false;
			if (config.chartSaving)
				hasChartSaving = true;
				
			var chartHeight = '300px';
			if (config.chart.inverted)
				chartHeight = '400px';
				
			var dialogNumber = 0;
			
			if ((namespace == undefined)||(resourceId == '')){
				;
			}
			else{
			/*<div class="portlet-form-button portlet-icon icon-help-flash" style="width:120px; float:left;">Видеоруководства
                            <ul class="portlet-popup-list" style="width:140px; margin-top:0px;">
                                <li><input id="main-video-help-1" type="button" class="portlet-form-button portlet-icon icon-help-flash" value="Получение данных"/></li>
                                <li><input id="main-video-help-2" type="button" class="portlet-form-button portlet-icon icon-help-flash" value="Работа с картой"/></li>
                            </ul>
                        </div>*/
				var internaltools = '<li><input value="Описание данных" type="button" class="portlet-form-button portlet-icon icon-download-text clickable-resource-metadata" name="'+resourceId+'"/></li>'+
				'<li><a id="'+namespace+'-sourcedata" target="_blank" href="/dataview/viewresource?resourceId='+resourceId+'&rawdata=true" style="text-decoration: none;"><input value="Смотреть исходные данные" type="button" class="portlet-form-button portlet-icon icon-data-access" /></a></li>';
				try{
					if (getHttpParam('external') == 'true')
						internaltools = '';
				}catch(e){console.log(e.message);}	
				$(this).css('background','#F4F3F3');
				$(this).append('<div id="'+namespace+'-buttons" style="width:100%; height: 40px; margin:0;">'+
				'<fieldset class="fieldset-analytics" style="width:100%; height:100%; padding:0px;">'+
				'<div class="portlet-form-button portlet-icon icon-tools" name="'+resourceId+'"" style="float:left; text-decoration: none; margin-left: 10px;" >Инструменты<ul class="portlet-popup-list" style="width:220px; margin-top:0px; z-index:1000;">'+
				internaltools+

				'<li><input id="'+namespace+'-export-xls" value="Загрузить данные в формате XLS" type="button" class="portlet-form-button portlet-icon icon-export-xls" /></li>'+
				'<li><input id="'+namespace+'-export-csv" value="Загрузить данные в формате CSV" type="button" class="portlet-form-button portlet-icon icon-export-csv" /></li>'+
				'</ul></div>'+
				/*'<input value="Описание" type="button" class="portlet-form-button portlet-icon icon-download-text clickable-resource-metadata" name="'+resourceId+'" style="float:left; text-decoration: none; margin-left: 10px;" />'+
				'<a id="'+namespace+'-sourcedata" target="_blank" href="/dataview/viewresource?resourceId='+resourceId+'&rawdata=true" style="float:left; text-decoration: none; margin-left: 5px;"><input value="Исходные данные" type="button" class="portlet-form-button portlet-icon icon-data-access" /></a>'+*/
				'<input value="Сбросить выбор" type="button" class="portlet-form-button portlet-icon icon-arrow-refresh clickable-refresh"  style="float:left; text-decoration: none; margin-left: 5px;" />'+
				'</fieldset></div>');

				
				if (!(config.showSourceData))
					$('#'+namespace+'-sourcedata').css('display','none');
				
				if (((filtercolumns.length == 0)||(filtercolumns[0]==''))&&(rubricColumn == '')&&(filtermap.resourceId == ''))
					$('#'+namespace+'-buttons .clickable-refresh').remove();					
					
				/*<br/><input id="'+namespace+'-reset" type="button" class="portlet-form-button portlet-icon icon-status-error" value="Сброс"/>*/
				if (((filtercolumns.length > 0)&&(filtercolumns[0]!='')&&(rubricColumn == ''))||(filtermap.resourceId != '')) {
						var minheight = 0;
						for (var i = 0; i<filtercolumns.length; i++)
							if (filtercolumns[i] != 'm4405')
								minheight += 410;
							else
								minheight += 100;
						if (filtermap.resourceId != '')	
							minheight += 400;
						if (minheight > 300){
							if (minheight > 400)
								chartHeight = '400px';
							else
								chartHeight = (minheight-15)+'px';
						}	
						$(this).append('<div id="'+namespaceFilter+'-wrapper" style="float: left; width: 30%; "><fieldset class="fieldset-analytics" id="'+namespaceFilter+'" style="width:100%; height:100%; border-bottom:0px;"></fieldset></div>');
						$(this).append('<div style="display: block; float: left; width: 70%; margin: 0px;"><fieldset class="fieldset-analytics" id="'+namespaceDisplay+'"style="width:100%; height:100%; border-bottom:0px;"></fieldset></div>');
						$(this).append('<hr class="cleaner"></div>');
						if ((chartgallery.distinct != '')&&(chartgallery.axisX != '')&&(chartgallery.axisY != ''))
							$('#'+namespaceDisplay).append('<fieldset class="fieldset-analytics" id="'+namespaceChartGallery+'" style="display: block; float: left; width: 100%; margin-top:5px;"></fieldset><hr class="cleaner">');
						if (((chart.axisX != '')&&(chart.axisY != ''))||(config.displaymap.resourceId != ''))
							$(this).append('<fieldset class="fieldset-analytics" id="'+namespaceDisplay+'-tablewrap" style="display: block; float: left; width: 100%; margin-top:0px;"></fieldset>');
				} /*else if ((filtercolumns.length <= 0)&&(rubricColumn != '')) {
						$(this).append('<div id="'+namespaceRubric+'-wrapper" style="float: left; width: 30%; "><fieldset id="'+namespaceRubric+'" style="width:100%; height:100%;"></fieldset></div>');
						$(this).append('<fieldset id="'+namespaceDisplay+'" style="display: block; float: right; width: 62%; margin-left: 40px; "></fieldset>');
				} else if ((filtercolumns.length > 0)&&(rubricColumn != '')) {
						$(this).append('<div id="'+namespace+'-rubricfilter-wrapper" style="float: left; width: 30%; "><fieldset id="'+namespaceRubric+'" style="width:100%; height:100%;"></fieldset><br/><fieldset id="'+namespaceFilter+'" style="width:100%; height:100%;"></fieldset></div>');
						$(this).append('<fieldset id="'+namespaceDisplay+'" style="display: block; float: right; width: 62%; margin-left: 40px; "></fieldset>');
				}*/ else {
					$(this).append('<div id="'+namespaceDisplay+'" style="float: right; width: 100%; margin-left: 5px; "></div>');
					if ((chartgallery.distinct != '')&&(chartgallery.axisX != '')&&(chartgallery.axisY != ''))
							$(this).append('<fieldset class="fieldset-analytics" id="'+namespaceChartGallery+'" style="display: block; float: left; width: 100%; margin-top:5px;"></fieldset>');
					if (((chart.axisX != '')&&(chart.axisY != ''))||(config.displaymap.resourceId != ''))
							$(this).append('<fieldset class="fieldset-analytics" id="'+namespaceDisplay+'-tablewrap" style="display: block; float: left; width: 100%; margin-top:5px;"></fieldset>');
				}
				if (config.displaymap.resourceId != ''){
					if (((filtercolumns.length == 0)||(filtercolumns[0]!=''))&&(rubricColumn == '')&&(filtermap.resourceId == ''))
						$('#'+namespaceDisplay).append('<div id="'+namespaceMap+'-wrapper" style="width:90%; margin:2px auto;"></div><br/>');
					else
						$('#'+namespaceDisplay).append('<div id="'+namespaceMap+'-wrapper" style="width:100%; margin:2px auto;"></div><br/>');					

					$('#'+namespaceMap+'-wrapper').append('<div id="'+namespaceMap+'" style="width:100%; margin:0px auto;"></div>');
					var mapheight = $('#'+namespaceMap).width()*0.4;
					if (config.displaymap.distinct)
						$('#'+namespaceMap).height(mapheight).makeMapDataFilterResource({
							'column': config.displaymap.distinct,
							'resourceId': config.displaymap.resourceId,
							'filter': filter,
							'latmin': config.displaymap.latmin,
							'latmax': config.displaymap.latmax,
							'lonmin': config.displaymap.lonmin,
							'lonmax': config.displaymap.lonmax,
							'criteriaParameter': config.displaymap.criteriaParameter
						});
					else
						$('#'+namespaceMap).height(mapheight).mapResource({
							'resourceId': config.displaymap.resourceId,
							'filter': filter,
							'latmin': config.displaymap.latmin,
							'latmax': config.displaymap.latmax,
							'lonmin': config.displaymap.lonmin,
							'lonmax': config.displaymap.lonmax,
							'criteriaParameter': config.displaymap.criteriaParameter
						});
					$('#'+namespaceMap+'-map-refresh').die().live('click',function(){
						config.displaymap.latmin = globalMapObject[namespaceMap].getExtent().bottom;
						config.displaymap.latmax = globalMapObject[namespaceMap].getExtent().top;
						config.displaymap.lonmin = globalMapObject[namespaceMap].getExtent().left;
						config.displaymap.lonmax = globalMapObject[namespaceMap].getExtent().right;
						var i = config.filter.length;
						while (i--) {
							if (config.filter[i] != undefined)
							if ((config.filter[i].indexOf('m4311') != -1) || (config.filter[i].indexOf('m4312') != -1))
								config.filter.splice(i,1);
						}
						config.filter.push('(m4311 between '+config.displaymap.latmin+' and '+config.displaymap.latmax+') and (m4312 between '+config.displaymap.lonmin+' and '+config.displaymap.lonmax+')');
						$('#'+namespace).html('').analyticsResource(config);
					});
				}
				
				$('#'+namespaceDisplay).append('<div id="'+namespaceChart+'-wrapper" style="width:98%; margin:2px auto;"></div><br/>');
				if (config.parameterSelect){
					var selectHtml = makeSelectForElements(config.resourceId, ['pp']);
					$('#'+namespaceChart+'-wrapper').css('width',$('#'+namespaceChart+'-wrapper').width()+'px').append(selectHtml);
					$('#'+namespaceChart+'-wrapper select.portlet-chzn-select').attr("data-placeholder","...").chosen({no_results_text: "Нет совпадений"});
					$('#'+namespaceChart+'-wrapper select.portlet-chzn-select').change(function(){
						var axisY = $(this).val().join(',');
						var tempFilterObj = getFullFilter(config.filter,filtercolumns,filterobj,dateColumn,hasDateFilter,namespaceDateFrom,namespaceDateTo, axisY);
						
						if (config.interf == 'short')
							table.columns = axisY; 
					
						drawTable(resourceId, table, namespaceTable, tempFilterObj.filterNoMap, info);						
							
						if (config.filtermap.isFilterable)
								$('#'+namespaceFilter+'-map').html('').makeMapDataFilterResource({
									'resourceId':filtermap.resourceId,
									'column': filtermap.column,
									'latmin': filtermap.latmin,
									'latmax': filtermap.latmax,
									'lonmin': filtermap.lonmin,
									'lonmax': filtermap.lonmax,
									'filter': tempFilterObj.filterNoMap,
									'metadataResource': config.metadataResource,
									'wms': filtermap.wms,
									'criteriaParameter': filtermap.criteriaParameter								
								});	
								
						if (config.displaymap.isFilterable)		
							if (config.displaymap.resourceId != ''){
								$('#'+namespaceMap+'-wrapper').html('').append('<div id="'+namespaceMap+'" style="width:100%; margin:0 auto;"></div>');
								mapheight = $('#'+namespaceMap).width()*0.4;
								$('#'+namespaceMap).height(mapheight).mapResource({
									'resourceId': config.displaymap.resourceId,
									'filter': tempFilterObj.filterNoMap,
									'latmin': config.displaymap.latmin,
									'latmax': config.displaymap.latmax,
									'lonmin': config.displaymap.lonmin,
									'lonmax': config.displaymap.lonmax,
									'criteriaParameter': config.displaymap.criteriaParameter
								});
							}
					});
				}
				if ((chart.axisX != '')&&(chart.axisY != '')){
					var message = 'Для получения графика выберите значение параметра слева.';
					if ((filtercolumns.length > 1))
						message = 'Для получения графика выберите значение параметров слева.';
					if (filtermap.resourceId != ''){
						message = 'Для получения графика выберите объект на карте.';
						if ((filtercolumns.length > 0)&&(filtercolumns[0]!=''))
							message = 'Для получения графика выберите объект на карте и значение параметра слева';							
					}	
					var selectHtml = makeSelectForElements(config.resourceId, chart.axisY.split(','));
					$('#'+namespaceChart+'-wrapper').css('width',$('#'+namespaceChart+'-wrapper').width()+'px').append(selectHtml+'<div id="'+namespaceChart+'" style="width:100%; height:40px; margin:0 auto;"><div class="portlet-msg-status" style="margin:20% auto; width: 90%; ">'+message+'</div></div>');
					$('#'+namespaceChart+'-wrapper select.portlet-chzn-select').attr("data-placeholder","...").chosen({no_results_text: "Нет совпадений"});
					$('#'+namespaceChart+'-wrapper select.portlet-chzn-select').change(function(){
						if ((chart.axisX != '')&&(chart.axisY != '')){
							if ($(this).val() != undefined){
								var axisY = $(this).val().join(',');
								var tempFilterObj = getFullFilter(config.filter,filtercolumns,filterobj,dateColumn,hasDateFilter,namespaceDateFrom,namespaceDateTo, axisY);	
								
								if (config.interf == 'short')
								if ($('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val() != undefined){
									var newColumns = [];
									newColumns.push(chart.axisX);
									
									var tempArr = $('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val(); 
									for(var i=0; i<tempArr.length; i++)
										newColumns.push(tempArr[i]);
										
									table.columns = newColumns;
									drawTable(resourceId, table, namespaceTable, tempFilterObj.filter, info);
								}
								
								
								if (!config.filtermap.isFilterable)
									$('#'+namespaceChart).html('').css('height',chartHeight).chartResource({
											'renderTo':namespaceChart,
											'resourceId':resourceId,
											'axisX': chart.axisX,
											'axisY': axisY,
											'type': chart.type,
											'filter': tempFilterObj.filter,
											'sameY': sameY,
											'inverted': config.chart.inverted
									});
								if (config.filtermap.isFilterable)
									$('#'+namespaceFilter+'-map').html('').makeMapDataFilterResource({
										'resourceId':filtermap.resourceId,
										'column': filtermap.column,
										'latmin': filtermap.latmin,
										'latmax': filtermap.latmax,
										'lonmin': filtermap.lonmin,
										'lonmax': filtermap.lonmax,
										'filter': tempFilterObj.filterNoMap,
										'metadataResource': config.metadataResource,
										'wms': filtermap.wms,
										'criteriaParameter': filtermap.criteriaParameter								
									});	
							}
						}	
					});
				}	
				if (((chart.axisX != '')&&(chart.axisY != ''))||(config.displaymap.resourceId != ''))
					$('#'+namespaceDisplay+'-tablewrap').append('<div id="'+namespaceTable+'" style="width:100%; margin:0 auto; "></div>');
				else
					$('#'+namespaceDisplay).append('<div id="'+namespaceTable+'" style="width:100%; margin:0 auto; "></div>');
				$(this).append('<hr class="cleaner"></div>');

				if (filtermap.resourceId == '')
					mapClicked = true;
				else{
					$('#'+namespaceFilter).append('<div id="'+namespaceFilter+'-map" style="width:95%; height:250px; margin:2px auto;"></div>');
					$('#'+namespaceFilter+'-map').makeMapDataFilterResource({
						'resourceId':filtermap.resourceId,
						'column':filtermap.column,
						'latmin': filtermap.latmin,
						'latmax': filtermap.latmax,
						'lonmin': filtermap.lonmin,
						'lonmax': filtermap.lonmax,
						'filter': filter,
						'metadataResource': config.metadataResource,
						'wms': filtermap.wms,
						'criteriaParameter': filtermap.criteriaParameter
					});
					$('#'+namespaceFilter+'-map-map-refresh').die().live('click',function(){
						config.filtermap.latmin = globalMapObject[namespaceFilter+'-map'].getExtent().bottom;
						config.filtermap.latmax = globalMapObject[namespaceFilter+'-map'].getExtent().top;
						config.filtermap.lonmin = globalMapObject[namespaceFilter+'-map'].getExtent().left;
						config.filtermap.lonmax = globalMapObject[namespaceFilter+'-map'].getExtent().right;
						var i = config.filter.length;
						while (i--) {
							if (config.filter[i] != undefined)
							if ((config.filter[i].indexOf('m4311') != -1) || (config.filter[i].indexOf('m4312') != -1))
								config.filter.splice(i,1);
						}
						config.filter.push('(m4311 between '+config.filtermap.latmin+' and '+config.filtermap.latmax+') and (m4312 between '+config.filtermap.lonmin+' and '+config.filtermap.lonmax+')');
						$('#'+namespace).html('').analyticsResource(config);
					});
					
					try{
						if ((filtercolumns.length == 0)||((filtercolumns.length == 1)&&((filtercolumns[0]=='m4308')||(filtercolumns[0]=='m4405')))){
							var firstFilter = '';
							setTimeout( function(){
									firstFilter = getMapFilter('firstfeature', namespaceFilter);
									if (firstFilter != ''){
										filterobj['map'] = firstFilter;
										if ((filtercolumns.length == 1)&&(filtercolumns[0]=='m4308')){
											firstFilter += "AND(m4308='0')";
											filterobj[filtercolumns[0]] = '0';
										}else if ((filtercolumns.length == 1)&&(filtercolumns[0]=='m4405')){
											firstFilter += "AND(m4405='1')";
											filterobj[filtercolumns[0]] = '1';
											$('#'+namespaceFilter+'-m4405 div.portlet-form-button').first().addClass('portlet-form-button-active');
										}	
										if ((chart.axisX != '')&&(chart.axisY != '')){
											var axisY = chart.axisY;
											if ($('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val() != undefined)
												axisY = $('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val().join(',');
											$('#'+namespaceChart).html('').css('height',chartHeight).chartResource({
													'renderTo':namespaceChart,
													'resourceId':resourceId,
													'axisX': chart.axisX,
													'axisY': axisY,
													'type': chart.type,
													'filter': [firstFilter],
													'sameY': sameY,
													'inverted': config.chart.inverted
											});
										}
										mapClicked = true;		
									}									
							} , 2000);
						}
					}catch(e){;}
						
					$('#'+namespaceFilter+'-map [id^="OpenLayers_Geometry_"]').die().live('click', function(){
						//$('#'+namespaceFilter+'-map [id^="OpenLayers_Geometry_"]').attr('fill','#3399ff').attr('r','4');
						var axisY = chart.axisY;
						if ($('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val() != undefined)
							axisY = $('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val().join(',');
						
						mapClicked = true;
						var featureid = $(this).attr('id');
						var mapfilterstr = getMapFilter(featureid, namespaceFilter);
						filterobj['map'] = mapfilterstr;
						if (mapfilterstr != ''){
									var tempfilter = [];
										tempfilter.push(mapfilterstr);
									if (filter.length > 0){
										for (var i=0; i<filter.length; i++ )
											tempfilter.push(filter[i]);
									}	
									/*for (var i=0; i<filtercolumns.length; i++){
										filterobj[filtercolumns[i]] = '';
										$('#'+namespaceFilter+'-'+filtercolumns[i]).html('').makeTableDataFilterResource({
											'resourceId': resourceId,
											'column': filtercolumns[i],
											'namespace':namespaceFilter+'-'+filtercolumns[i],
											'filter':tempfilter
										});
									}*/
									tempFilterObj = getFullFilter(tempfilter,filtercolumns,filterobj,dateColumn,hasDateFilter,namespaceDateFrom,namespaceDateTo,config.axisY);
									/*if (tempFilterObj.dochart)*/
									if (config.filtercolumnsAllowChartFromMapOnly){
										if ((chart.axisX != '')&&(chart.axisY != ''))
											$('#'+namespaceChart).html('').css('height',chartHeight).chartResource({
													'renderTo':namespaceChart,
													'resourceId':resourceId,
													'axisX': chart.axisX,
													'axisY': axisY,
													'type': chart.type,
													'filter': tempFilterObj.filter,
													'sameY': sameY,
													'inverted': config.chart.inverted
											});
									}
									else{	
										if (filterobj[filtercolumns[0]]!='')
											if ((chart.axisX != '')&&(chart.axisY != ''))
												$('#'+namespaceChart).html('').css('height',chartHeight).chartResource({
														'renderTo':namespaceChart,
														'resourceId':resourceId,
														'axisX': chart.axisX,
														'axisY': axisY,
														'type': chart.type,
														'filter': tempFilterObj.filter,
														'sameY': sameY,
														'inverted': config.chart.inverted
												});
									}		
									drawTable(resourceId, table, namespaceTable, tempFilterObj.filter, info);
						}
						try{
							
							if ((chartgallery.distinct != '')&&(chartgallery.axisX != '')&&(chartgallery.axisY != '')){
								var val = getMapFeature(featureid, namespaceFilter)[chartgallery.distinct];
								if ((val != undefined)&&(val != '')){
									var id = (new Date()).getTime();
									var alreadyExists = false;
									$('#'+namespaceChartGallery+' span[name="'+val+'"]').each(function(){
										alreadyExists = true;
									});
									if(alreadyExists){
										$('#'+namespaceChartGallery).displayTextMessage({
												  'text':'Данный объект уже выбран',
												  'type':'warning'
										});
									}else{
										var sOut ='<div style="float:left; width:350px;height:300px; margin:2px;"><p style="portlet-font">'+val+
										'<span class="portlet-form-button portlet-icon-notext icon-status-error" style="cursor:pointer; float:right; margin-top:1px;" title="Убрать элемент"></span>'+
										'<span class="portlet-form-button portlet-icon-notext icon-table" name="'+val+'" style="cursor:pointer; float:right; margin-top:1px;" title="Показать данные подробнее"></span>'+
										'</p>'+
										'<div id="'+namespaceChartGallery+'-'+id+'" name="'+val+'" style="width:100%;height:260px;"></div></div>';
										$('#'+namespaceChartGallery).prepend(sOut);
										$('#'+namespaceChartGallery+'-'+id).chartResource({
											'renderTo':namespaceChartGallery+'-'+id,
											'resourceId':resourceId,
											'axisX': chartgallery.axisX,
											'axisY': chartgallery.axisY,
											'type': chartgallery.type,
											'filter': ["("+chartgallery.distinct+"='"+val+"')"],
											'sameY': chartgallery.sameY,
											'interf': 'small'
										});		
									}
								}
							}
						}catch(e){
							console.log(e.message);
						}						
					});
				}				
				
				if (hasDateFilter){	
					$('#'+namespace+'-buttons fieldset').append('<div class="portlet-font portlet-icon icon-calendar" style="margin-right: 20%; margin-top:5px; width:390px; float: right;">'+dateText+' <input id="'+namespaceDateFrom+'" class="portlet-form-input-field portlet-onlydatepicker" style="width:110px;" type="text"/> '+dateText2+' <input  id="'+namespaceDateTo+'" class="portlet-form-input-field portlet-onlydatepicker"  style="width:110px;" type="text"/></div>');				
					if ((dateColumn == 'm4410')||(dateColumn == 'm4404')){
						var yearStart = parseInt(dateYearRange.substring(0,4));
						var yearEnd = parseInt(dateYearRange.substring(5,9));
						
						$('#'+namespaceDateFrom).replaceWith('<select id="'+namespaceDateFrom+'" class="portlet-form-input-field"></select>');
						$('#'+namespaceDateFrom).append('<option selected value="'+yearStart+'">'+yearStart+'</option>');
						var options = '';
						for (var i=yearStart+1; i<=yearEnd; i++)
							options += '<option value="'+i+'">'+i+'</option>';
						$('#'+namespaceDateFrom).append(options);
						
						$('#'+namespaceDateTo).replaceWith('<select id="'+namespaceDateTo+'" class="portlet-form-input-field"></select>');
						$('#'+namespaceDateTo).append('<option selected value="'+yearEnd+'">'+yearEnd+'</option>');
						var options = '';
						for (var i=yearStart; i<=yearEnd-1; i++)
							options += '<option value="'+i+'">'+i+'</option>';
						$('#'+namespaceDateTo).prepend(options);
					}else if (dateColumn == 'm4405'){
						var options = '';
						for (var i=1; i<=12; i++)
							options += '<option value="'+i+'">'+i+'</option>';
						$('#'+namespaceDateFrom).replaceWith('<select id="'+namespaceDateFrom+'" class="portlet-form-input-field">'+options+'</select>');
						$('#'+namespaceDateFrom+' option[value="1"]').attr('selected','selected');
						$('#'+namespaceDateTo).replaceWith('<select id="'+namespaceDateTo+'" class="portlet-form-input-field">'+options+'</select>');
						$('#'+namespaceDateTo+' option[value="12"]').attr('selected','selected');
					}else{
						$('#'+namespaceDateFrom).datepicker({
							dateFormat: dateFormat,
							changeMonth:true,
							changeYear:true,
							currentText: 'Сейчас',
							closeText: 'Закрыть',
							prevText: '&#x3c;Пред',
							nextText: 'След&#x3e;',
							monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь',
							'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
							monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн',
							'Июл','Авг','Сен','Окт','Ноя','Дек'],
							dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
							dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'],
							dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
							weekHeader: 'Не',
							firstDay: 1,
							isRTL: false,
							showMonthAfterYear: false,
							yearSuffix: '',
							yearRange: dateYearRange,
							defaultDate: dateFrom,
							onSelect: function() {
								$(this).data('datepicker').inline = true;
							},
							onClose: function() {
								$(this).data('datepicker').inline = false;
								var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
								var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
								var day = $("#ui-datepicker-div .ui-datepicker-current-day").text();
								if ((day == undefined)||(day == ''))
									day = '1';
								$(this).datepicker('setDate', new Date(year, month, day));
								$('#'+namespaceDateFrom).change();
							}
						});
						if (trend)
							$('#'+namespaceDateTo).remove();					
						else
							$('#'+namespaceDateTo).datepicker({
								dateFormat: dateFormat,
								changeMonth:true,
								changeYear:true,
								currentText: 'Сейчас',
								closeText: 'Закрыть',
								prevText: '&#x3c;Пред',
								nextText: 'След&#x3e;',
								monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь',
								'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
								monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн',
								'Июл','Авг','Сен','Окт','Ноя','Дек'],
								dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
								dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'],
								dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
								weekHeader: 'Не',
								firstDay: 1,
								isRTL: false,
								showMonthAfterYear: false,
								yearSuffix: '',
								yearRange: dateYearRange,
								defaultDate: dateTo,
								onSelect: function() {
									$(this).data('datepicker').inline = true;
								},
								onClose: function() {
									$(this).data('datepicker').inline = false;
									var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
									var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
									var day = $("#ui-datepicker-div .ui-datepicker-current-day").text();
									if ((day == undefined)||(day == ''))
										day = '1';
									$(this).datepicker('setDate', new Date(year, month, day));
									$('#'+namespaceDateTo).change();
								}
							});						
						$('#'+namespaceDateFrom).datetimepicker('setDate', dateFrom);
						$('#'+namespaceDateTo).datetimepicker('setDate', dateTo);
					}
					
					$('#'+namespaceDateFrom).change(function(){
						var axisY = config.axisY;
						if ($('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val() != undefined)
							axisY = $('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val().join(',');
							
						var tempFilterObj = getFullFilter(filter,filtercolumns,filterobj,dateColumn,hasDateFilter,namespaceDateFrom,namespaceDateTo,axisY);
						if (table.columns != undefined)
						if (table.columns.length > 0)
							drawTable(resourceId, table, namespaceTable, tempFilterObj.filter, info);
						if (!config.filtermap.isFilterable)	
						if ((tempFilterObj.dochart)||(mapClicked))
								if ((chart.axisX != '')&&(chart.axisY != ''))
									$('#'+namespaceChart).html('').css('height',chartHeight).chartResource({
												'renderTo':namespaceChart,
												'resourceId':resourceId,
												'axisX': chart.axisX,
												'axisY': axisY,
												'type': chart.type,
												'filter': tempFilterObj.filter,
												'sameY': sameY,
												'inverted': config.chart.inverted
									});	
						if (config.displaymap.resourceId != ''){
							$('#'+namespaceMap+'-wrapper').html('').append('<div id="'+namespaceMap+'" style="width:100%; margin:0 auto;"></div>');
							var mapheight = $('#'+namespaceMap).width()*0.4;
							$('#'+namespaceMap).height(mapheight).mapResource({
								'resourceId': config.displaymap.resourceId,
								'filter': tempFilterObj.filter,
								'latmin': config.displaymap.latmin,
								'latmax': config.displaymap.latmax,
								'lonmin': config.displaymap.lonmin,
								'lonmax': config.displaymap.lonmax,
								'criteriaParameter': config.displaymap.criteriaParameter
							});
							$('#'+namespaceMap+'-map-refresh').die().live('click',function(){
								config.displaymap.latmin = globalMapObject[namespaceMap].getExtent().bottom;
								config.displaymap.latmax = globalMapObject[namespaceMap].getExtent().top;
								config.displaymap.lonmin = globalMapObject[namespaceMap].getExtent().left;
								config.displaymap.lonmax = globalMapObject[namespaceMap].getExtent().right;
								var i = config.filter.length;
								while (i--) {
									if (config.filter[i] != undefined)
									if ((config.filter[i].indexOf('m4311') != -1) || (config.filter[i].indexOf('m4312') != -1))
										config.filter.splice(i,1);
								}
								config.filter.push('(m4311 between '+config.displaymap.latmin+' and '+config.displaymap.latmax+') and (m4312 between '+config.displaymap.lonmin+' and '+config.displaymap.lonmax+')');
								$('#'+namespace).html('').analyticsResource(config);
							});
						}
						if (filtermap.resourceId != ''){
							if (config.filtermap.isFilterable)
								$('#'+namespaceFilter+'-map').html('').makeMapDataFilterResource({
									'resourceId':filtermap.resourceId,
									'column': filtermap.column,
									'latmin': filtermap.latmin,
									'latmax': filtermap.latmax,
									'lonmin': filtermap.lonmin,
									'lonmax': filtermap.lonmax,
									'filter': tempFilterObj.filterNoMap,
									'metadataResource': config.metadataResource,
									'wms': filtermap.wms,
									'criteriaParameter': filtermap.criteriaParameter								
								});
						}		
					});
					$('#'+namespaceDateTo).change(function(){
						var axisY = config.axisY;
						if ($('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val() != undefined)
							axisY = $('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val().join(',');
							
						var tempFilterObj = getFullFilter(filter,filtercolumns,filterobj,dateColumn,hasDateFilter,namespaceDateFrom,namespaceDateTo,axisY);
						if (table.columns != undefined)
						if (table.columns.length > 0)
							drawTable(resourceId, table, namespaceTable, tempFilterObj.filter, info);
						if (!config.filtermap.isFilterable)		
						if ((tempFilterObj.dochart)||(mapClicked))
							if ((chart.axisX != '')&&(chart.axisY != ''))
								$('#'+namespaceChart).html('').css('height',chartHeight).chartResource({
											'renderTo':namespaceChart,
											'resourceId':resourceId,
											'axisX': chart.axisX,
											'axisY': axisY,
											'type': chart.type,
											'filter': tempFilterObj.filter,
											'sameY': sameY,
											'inverted': config.chart.inverted
								});
						if (config.displaymap.resourceId != ''){
							$('#'+namespaceMap+'-wrapper').html('').append('<div id="'+namespaceMap+'" style="width:100%; margin:0 auto;"></div>');
							var mapheight = $('#'+namespaceMap).width()*0.4;
							$('#'+namespaceMap).height(mapheight).mapResource({
								'resourceId': config.displaymap.resourceId,
								'filter': tempFilterObj.filter,
								'latmin': config.displaymap.latmin,
								'latmax': config.displaymap.latmax,
								'lonmin': config.displaymap.lonmin,
								'lonmax': config.displaymap.lonmax,
								'criteriaParameter': config.displaymap.criteriaParameter
							});
							$('#'+namespaceMap+'-map-refresh').die().live('click',function(){
								config.displaymap.latmin = globalMapObject[namespaceMap].getExtent().bottom;
								config.displaymap.latmax = globalMapObject[namespaceMap].getExtent().top;
								config.displaymap.lonmin = globalMapObject[namespaceMap].getExtent().left;
								config.displaymap.lonmax = globalMapObject[namespaceMap].getExtent().right;
								var i = config.filter.length;
								while (i--) {
									if (config.filter[i] != undefined)
									if ((config.filter[i].indexOf('m4311') != -1) || (config.filter[i].indexOf('m4312') != -1))
										config.filter.splice(i,1);
								}
								config.filter.push('(m4311 between '+config.displaymap.latmin+' and '+config.displaymap.latmax+') and (m4312 between '+config.displaymap.lonmin+' and '+config.displaymap.lonmax+')');
								$('#'+namespace).html('').analyticsResource(config);
							});
						}
						if (filtermap.resourceId != ''){
							if (config.filtermap.isFilterable)
								$('#'+namespaceFilter+'-map').html('').makeMapDataFilterResource({
									'resourceId':filtermap.resourceId,
									'column': filtermap.column,
									'latmin': filtermap.latmin,
									'latmax': filtermap.latmax,
									'lonmin': filtermap.lonmin,
									'lonmax': filtermap.lonmax,
									'filter': tempFilterObj.filterNoMap,
									'metadataResource': config.metadataResource,
									'wms': filtermap.wms,
									'criteriaParameter': filtermap.criteriaParameter								
								});
						}						
					});
				}
				
				
				if (rubricColumn != ''){
					$.ajax({
						 "dataType": "json", 
						 "type": "POST", 
						 "url": "/dataview/getresourcerubrics", 
						 "data": {"resourceid":resourceId,"rubriccolumn":rubricColumn}, 
						 "timeout": 5000,
						 "success": function(json){
							var nodes = [];
							var rubricArray = json.aaData; 
							for (var i in rubricArray)
								nodes.push(rubricArray[i][0]);								
								
							$("#"+namespaceRubric).rubricTree({'nodes':nodes});
							   
							$("#"+namespaceRubric+" a").die().live('click',function(){
								rubricSelected = $(this).parent("li").attr("name");
								var rubricfilter = rubricColumn+"='"+rubricSelected+"'";
								var tempfilter = [];
								tempfilter.push(rubricfilter);
								if (filter.length > 0)
										tempfilter.push(filter);
							
								for (var i=0; i<filtercolumns.length; i++){
									filterobj[filtercolumns[i]] = '';
									$('#'+namespaceFilter+'-'+filtercolumns[i]).html('').makeTableDataFilterResource({
										'resourceId': resourceId,
										'column': filtercolumns[i],
										'namespace':namespaceFilter+'-'+filtercolumns[i],
										'filter':tempfilter
									});
								}
								
								drawTable(resourceId, table, namespaceTable, tempfilter, info);
							});
						 },
						 "error": function(request, status, err) {
								if(status == "error") {
									alert("Нет соединения с сервисом данных");
								}								
								else if(status == "timeout") {
									alert("Время ожидания данных превысило 15 секунд. Отмена запроса.");
								}else alert(status);
							}
					});	
				}
				
				if (filtercolumns.length > 0){
					for (var i=0; i<filtercolumns.length; i++ ){
						$('#'+namespaceFilter).append('<div id="'+namespaceFilter+'-'+filtercolumns[i]+'" class="'+namespaceFilter+'-filtercolumn" attrnum="'+i+'" attrcode="'+filtercolumns[i]+'" style="width:98%; margin:0 auto; "></div><br/>');
						var displaycount = true;		
						if (filtermap.resourceId != '')
								displaycount = false;
						$('#'+namespaceFilter+'-'+filtercolumns[i]).makeTableDataFilterResource({
							'resourceId': resourceId,
							'column': filtercolumns[i],
							'namespace':namespaceFilter+'-'+filtercolumns[i],
							'filter':filter,
							'displaycount': displaycount
						});
					}
					$('.'+namespaceFilter+'-filtercolumn td:first-child,.'+namespaceFilter+'-filtercolumn .clickable-month-select').die().live('click',function(){
						if ($(this).attr('class') != undefined){
							if ($(this).attr('class').indexOf('clickable-month-reset') >= 0){
								filterobj['m4405']='';
								$('.'+namespaceFilter+'-filtercolumn .clickable-month-select').removeClass('portlet-form-button-active');
							}else if ($(this).attr('class').indexOf('clickable-month-select') >= 0){
								filterobj['m4405']=$(this).html();
								$('.'+namespaceFilter+'-filtercolumn .clickable-month-select').removeClass('portlet-form-button-active');
								$(this).addClass('portlet-form-button-active');
							}	
						}else{
							$(this).parent().parent().children('tr.portlet-table-selected').removeClass('portlet-table-selected');
							$(this).parent().addClass('portlet-table-selected')
							
							var param = $(this).parents('.'+namespaceFilter+'-filtercolumn').attr("attrcode");
							var paramnum = parseInt($(this).parents('.'+namespaceFilter+'-filtercolumn').attr("attrnum"));
							filterobj[param]=$(this).html();
						}	
						
						for (var i=paramnum+1; i<filtercolumns.length; i++){
							filterobj[filtercolumns[i]] = '';
							var tempfilter = [];
							if (filter.length > 0)
								tempfilter.push(filter);
							if (rubricSelected!= '')
								tempfilter.push(rubricColumn+"='"+rubricSelected+"'");
							for (var j=0; j<=paramnum; j++)
								if (filterobj[filtercolumns[j]]!='')
									tempfilter.push(filtercolumns[j]+"='"+filterobj[filtercolumns[j]]+"'");	
							var displaycount = true;		
							if (filtermap.resourceId != '')
								displaycount = false;
							$('#'+namespaceFilter+'-'+filtercolumns[i]).html('').makeTableDataFilterResource({
								'resourceId': resourceId,
								'column': filtercolumns[i],
								'namespace':namespaceFilter+'-'+filtercolumns[i],
								'filter':tempfilter,
								'displaycount': displaycount
							});
						}
						
						var axisY = chart.axisY;
						if ($('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val() != undefined)
							axisY = $('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val().join(',');
						
						var tempFilterObj = getFullFilter(filter,filtercolumns,filterobj,dateColumn,hasDateFilter,namespaceDateFrom,namespaceDateTo,config.axisY);
						if (filtermap.resourceId != ''){
							if (config.filtermap.isFilterable)
								$('#'+namespaceFilter+'-map').html('').makeMapDataFilterResource({
									'resourceId':filtermap.resourceId,
									'column': filtermap.column,
									'latmin': filtermap.latmin,
									'latmax': filtermap.latmax,
									'lonmin': filtermap.lonmin,
									'lonmax': filtermap.lonmax,
									'filter': tempFilterObj.filterNoMap,
									'metadataResource': config.metadataResource,
									'wms': filtermap.wms,
									'criteriaParameter': filtermap.criteriaParameter								
								});
							if (table.columns != undefined)
							if (table.columns.length > 0){
								if (mapClicked)
									drawTable(resourceId, table, namespaceTable, tempFilterObj.filter, info);
								else
									drawTable(resourceId, table, namespaceTable, tempFilterObj.filterNoMap, info);
							}	
							if (mapClicked){
								if ((chart.axisX != '')&&(axisY != ''))
										$('#'+namespaceChart).html('').css('height',chartHeight).chartResource({
													'renderTo':namespaceChart,
													'resourceId':resourceId,
													'axisX': chart.axisX,
													'axisY': axisY,
													'type': chart.type,
													'filter': tempFilterObj.filter,
													'sameY': sameY,
													'inverted': config.chart.inverted
										});	
							}		
						} else {
							if (table.columns != undefined)
							if (table.columns.length > 0)
								drawTable(resourceId, table, namespaceTable, tempFilterObj.filter, info);
							if (tempFilterObj.dochart)
								if ((chart.axisX != '')&&(axisY != ''))
									$('#'+namespaceChart).html('').css('height',chartHeight).chartResource({
												'renderTo':namespaceChart,
												'resourceId':resourceId,
												'axisX': chart.axisX,
												'axisY': axisY,
												'type': chart.type,
												'filter': tempFilterObj.filter,
												'sameY': sameY,
												'inverted': config.chart.inverted
									});
							if (config.displaymap.resourceId != ''){
								if (config.displaymap.distinct)
									highlightMapFeatures(globalMapObject[namespaceMap], tempFilterObj.filter);
									/*$('#'+namespaceMap).html('').makeMapDataFilterResource({
										'column':config.displaymap.distinct,
										'resourceId': config.displaymap.resourceId,
										'filter': tempFilterObj.filter,
										'latmin': config.displaymap.latmin,
										'latmax': config.displaymap.latmax,
										'lonmin': config.displaymap.lonmin,
										'lonmax': config.displaymap.lonmax,
										'criteriaParameter': config.displaymap.criteriaParameter
									});*/
								else
									highlightMapFeatures(globalMapObject[namespaceMap], tempFilterObj.filter);
									/*$('#'+namespaceMap).html('').mapResource({
										'resourceId': config.displaymap.resourceId,
										'filter': tempFilterObj.filter,
										'latmin': config.displaymap.latmin,
										'latmax': config.displaymap.latmax,
										'lonmin': config.displaymap.lonmin,
										'lonmax': config.displaymap.lonmax,
										'criteriaParameter': config.displaymap.criteriaParameter
									});*/
							}
						}
						try{
							if ((chartgallery.distinct != '')&&(chartgallery.axisX != '')&&(chartgallery.axisY != '')){
								var id = (new Date()).getTime();
								var val = $(this).html();
								var alreadyExists = false;
								$('#'+namespaceChartGallery+' span[name="'+val+'"]').each(function(){
									alreadyExists = true;
								});
								if(alreadyExists){
									$('#'+namespaceChartGallery).displayTextMessage({
											  'text':'Данный объект уже выбран',
											  'type':'warning'
									});
								}else{
									var sOut ='<div style="float:left; width:350px;height:300px; margin:2px;"><p style="portlet-font">'+val+
									'<span class="portlet-form-button portlet-icon-notext icon-status-error" style="cursor:pointer; float:right; margin-top:1px;" title="Убрать элемент"></span>'+
									'<span class="portlet-form-button portlet-icon-notext icon-table" name="'+val+'" style="cursor:pointer; float:right; margin-top:1px;" title="Показать данные подробнее"></span>'+
									'</p>'+
									'<div id="'+namespaceChartGallery+'-'+id+'" name="'+val+'" style="width:100%;height:260px;"></div></div>';
									$('#'+namespaceChartGallery).prepend(sOut);
									$('#'+namespaceChartGallery+'-'+id).chartResource({
										'renderTo':namespaceChartGallery+'-'+id,
										'resourceId':resourceId,
										'axisX': chartgallery.axisX,
										'axisY': chartgallery.axisY,
										'type': chartgallery.type,
										'filter': ["("+chartgallery.distinct+"='"+val+"')"],
										'sameY': chartgallery.sameY,
										'interf': 'small'
									});	
								}
							}
						}catch(e){
							console.log(e.message);
						}
					});	
				}
				
				var tempFilterObj = getFullFilter(filter,filtercolumns,filterobj,dateColumn,hasDateFilter,namespaceDateFrom,namespaceDateTo,config.axisY);				
				
				try{
					if (config.interf == 'short')
					if ($('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val() != undefined){
						var newColumns = [];
						newColumns.push(chart.axisX);
						
						var tempArr = $('#'+namespaceChart+'-wrapper select.portlet-chzn-select').val(); 
						for(var i=0; i<tempArr.length; i++)
							newColumns.push(tempArr[i]);
							
						table.columns = newColumns;
					}	
					
					if (table.columns != undefined)
					if (table.columns.length > 0)
					if (!((table.columns.length == 1)&&(table.columns[0] == '')))
						drawTable(resourceId, table, namespaceTable, tempFilterObj.filter, info);
				}catch(e){
					console.log(e.message);
				}
				
				try{
					if ((chartgallery.distinct != '')&&(chartgallery.axisX != '')&&(chartgallery.axisY != '')){
						var distinctArray = getDistinctColumn(resourceId,filter,chartgallery.distinct,chartgallery.count);
						for (var i=distinctArray.length-1; i>=0; i--)
						if (distinctArray[i] != ''){
							var sOut ='<div style="float:left; width:350px;height:300px; margin:2px;"><p style="portlet-font">'+distinctArray[i]+
							'<span class="portlet-form-button portlet-icon-notext icon-status-error" style="cursor:pointer; float:right; margin-top:1px;" title="Убрать элемент"></span>'+
							'<span class="portlet-form-button portlet-icon-notext icon-table" name="'+distinctArray[i]+'" style="cursor:pointer; float:right; margin-top:1px;" title="Показать данные подробнее"></span>'+
							'</p><hr class="cleaner">'+
							'<div id="'+namespaceChartGallery+'-'+i+'" name="'+distinctArray[i]+'" style="width:100%;height:260px;"></div><hr class="cleaner"></div>';
							$('#'+namespaceChartGallery).prepend(sOut);
						}	
						for (var i=0; i<distinctArray.length; i++){
							$('#'+namespaceChartGallery+'-'+i).chartResource({
									'renderTo':namespaceChartGallery+'-'+i,
									'resourceId':resourceId,
									'axisX': chartgallery.axisX,
									'axisY': chartgallery.axisY,
									'type': chartgallery.type,
									'filter': ["("+chartgallery.distinct+"='"+distinctArray[i]+"')"],
									'sameY': chartgallery.sameY,
									'interf': 'small'
							});							
						}
						$('#'+namespaceChartGallery+' span.icon-status-error').die().live('click',function(){
							$(this).parent().parent().remove();
						});
						$('#'+namespaceChartGallery+' span.icon-table').die().live('click',function(){
							$(this).analyticsResourcePopup({
											'resourceId': resourceId,
											'filter': ["("+chartgallery.distinct+"='"+$(this).attr('name')+"')"],
											'filtercolumns':[], 
											'table':{
													'columns':[chartgallery.axisX,chartgallery.axisY]
											},
											'tableinfo': false,
											'chart':{
													'axisX': chartgallery.axisX,
													'axisY': chartgallery.axisY,
													'type': 'spline',
													'prebuilt': true,
													'sameY': false
											},
											'chartSaving': true,
											'dateColumn': chartgallery.axisX
							});
						});
					}
				}catch(e){
					console.log(e.message);
				}
				
				try{
					if (chart.prebuilt){
						var axisY = chart.axisY;
						if ((config.interf == 'short')||(config.interf == 'medium'))
						if (axisY.indexOf(',') != -1){	
							try{
								for (var i=0; i<elementsToExcludeArray.length; i++)
									if (axisY.toLowerCase().indexOf(elementsToExcludeArray[i]) >=0 ){
										axisY.replace(elementsToExcludeArray[i],'');
										axisY.replace(',,',',');
									}	
							}catch(e){console.log(e.message);}	
							axisY = axisY.split(',')[0];
						}	
						if (axisY == 'p0074_00')
							axisY = 'p0075_00';
						var tmpflt = tempFilterObj.filter;
						if (resourceId.toUpperCase() == 'RU_SSRI-CENTR_82_1')
							tmpflt = ["m4017='Увеличение выпуска продукции судостроения РФ в денежном выражении'"];
						if (resourceId.toUpperCase() == 'RU_SSRI-CENTR_81_2')
							tmpflt = ["m4107='АО Адмиралтейские верфи'"];	
						
						if ((chart.axisX != '')&&(chart.axisY != ''))
							$('#'+namespaceChart).html('').css('height',chartHeight).chartResource({
									'renderTo':namespaceChart,
									'resourceId':resourceId,
									'axisX': chart.axisX,
									'axisY': axisY,
									'type': chart.type,
									'filter': tmpflt,
									'sameY': sameY,
									'inverted': config.chart.inverted
							});
					}
				}catch(e){
					console.log(e.message);
				}
				
				$('#'+namespace+'-buttons .clickable-refresh').die().live('click', function(){
					$('#'+namespace).html('').analyticsResource(config);
				});
				
				$('#'+namespace+'-export-csv').die().live('click',function(){
					exportResourceToCSV(config.resourceId,config.filter);
				});
				$('#'+namespace+'-export-xls').die().live('click',function(){
					exportResourceToXLS(config.resourceId,config.filter);
				});
				
				//alert($('#'+namespaceFilter+'-map [id^="OpenLayers_Geometry_"]').first().attr('id'));				
			}
		});  
	 };
	 
	 $.fn.analyticsResourcePopup = function(settings){
		var config = {
			'resourceId': '',
			'filtercolumns':[],
			'filtercolumnsAllowChartFromMapOnly': true,
			'interf': 'short',
			'filtermap':{
				'resourceId':'',
				'column':'',
				'latmin':'18',
				'latmax':'82',
				'lonmin':'29',
				'lonmax':'165',
				'title':'',
				'wms':[],
				'isFilterable': false
			},
			'metadataResource':{
								'resourceId':'',
								'codeIn':'',
								'codeOut':''
			},
			'displaymap':{
				'resourceId': '',
				'latmin':'18',
				'latmax':'82',
				'lonmin':'29',
				'lonmax':'165',
				'criteriaParameter':'',
				'isFilterable': false
			},
			'rubricColumn':'',
			'table':{
				'columns':[]
			},
			'tableinfo': false,
			'chart':{
				 'axisX':'',
				 'axisY':'',
				 'type':'line',
				 'prebuilt': false,
				 'sameY': false,
				 'inverted': false
			},
			'parameterSelect':false,
			'chartSaving': false,
			'chartTypeSelect': true,
			'filter':[],
			'dateFrom':'',
			'dateTo':'',
			'dateColumn': '',
			'showSourceData': true			
		};
		if (settings){$.extend(config, settings);} 
			
		return this.each(function() {
				var tempid = 'id'+new Date().getMilliseconds();
				var title = '';
				$('body').append('<div id="'+tempid+'" title="'+title+'" style="text-align: center;">'+
				'<div id="'+tempid+'-display" style="width:100%;height:90%;"><div class="portlet-font portlet-icon icon-loading-circle-small" style="width:100px; margin:0px auto;">Загрузка данных для представления...</div></div><br/>'+
				'</div>');
					$( '#'+tempid ).dialog({
						width:800,
						height:600,
						resizable: false,
						open: function(event, ui) {
								$.ajax({
									  type: 'POST',
									  url: '/dataview/getResourceCodes',
									  data: {"action": "minmaxdate", "resourceId": config.resourceId},
									  async: true,
									  dataType: 'json',                                          
									  success: function(json){
											try{
												config.dateFrom = json.minDate;
												config.dateTo = json.maxDate;
											}catch(e){
												console.log(e.message);
											}
											$('#'+tempid+'-display').html('').analyticsResource(config); 											
									  },
									  error: function(jqXHR, textStatus, errorThrown){
											$('#'+tempid+'-display').html('').analyticsResource(config); 
									  } 
								});
						}
					});				
		});
	 };