OK....
at data parse
for each tiles
    tiles[i] = -1;
tiles[tilesAmount-1] = tilesAmount - 2;

in elementName == "tile"
--tiles[tilesAmount];
tiles[tilesAmount - 3 - tiles[tilesAmount-1]] = gid;

in layer parse end
if(tilesAmount >= 2 && tiles[TilesAmount - 2] == -1)  tiles[TilesAmount - 1] = -1