
map.Layers = {};

map.Layers.items = [];

map.Layers.itemKeys = {
	  ID			: 0
	, NAME			: 1
	, COLOR			: 2
	, ICON			: 3
	, IS_VISIBLE	: 4
};

//---

map.Layers.init = function(){
	var layers = map.Params.getLayers();
	for(var i = 0; i < map.Layers.items.length; i++){
		for(var j = 0; j < layers.length; j++){
			if(map.Layers.items[i][map.Layers.itemKeys.ID] == layers[j]){
				map.Layers.items[i][map.Layers.itemKeys.IS_VISIBLE] = true;
			}
		}
	}
};

//---

map.Layers.getColorByIndex = function(index){
	return map.Layers.items[index][map.Layers.itemKeys.COLOR];
};

map.Layers.getIconByIndex = function(index){
	if(map.Layers.items[index][map.Layers.itemKeys.ICON])
		return map.Layers.items[index][map.Layers.itemKeys.ICON];
	else
		return map.Config.layersDefaultIcon;
};

map.Layers.getColorById = function(id){
	return map.Layers.getItemValue(id, map.Layers.itemKeys.ID, map.Layers.itemKeys.COLOR);
};

map.Layers.getIconById = function(id){
	return map.Layers.getItemValue(id, map.Layers.itemKeys.ID, map.Layers.itemKeys.ICON);
};

map.Layers.isVisibleById = function(id){
	return map.Layers.getItemValue(id, map.Layers.itemKeys.ID, map.Layers.itemKeys.IS_VISIBLE);
};

map.Layers.getItemValue = function(value, keyCondition, keyResult){
	for(var i = 0; i < map.Layers.items.length; i++){
		if(map.Layers.items[i][keyCondition] == value){
			if(keyResult == map.Layers.itemKeys.COLOR)
				return map.Layers.getColorByIndex(i);
			else if(keyResult == map.Layers.itemKeys.ICON)
				return map.Layers.getIconByIndex(i);
			else
				return map.Layers.items[i][keyResult];
		}
	}
};
