 #= require 'ng-map.min'
 
-angular.module 'forge', ['ngMap']
+forge = {}
 
-.controller 'ForgeCtrl', ($scope, $http) ->
+forge.ForgeController = ($scope, $http) ->
   $scope.buildings = []
   $scope.building  = null
   $scope.layers = []

    return

  return

.controller 'BuildingCtrl', ($scope) ->

  $http.get('/buildings.json').then (response) ->
    $scope.buildings = response.data?.buildings or []
  return
forge.ForgeController.$inject = ['$scope', '$http']


forge.LayersController = ($scope) ->
  $scope.selectLayer = ->
    console.log "Layer selected: ", $scope.layer.name
    $scope.$parent.layer = $scope.layer
    return
  return
forge.LayersController.$inject = ['$scope']

forge.MapController = ($scope, NgMap) ->
  kmlLayer = null
  $scope.showBuilding = (event, building) ->
    console.log building
    $scope.$parent.building = building
    return
  $scope.$watch 'buildings', (newValue, oldValue) ->
    return unless newValue
    if newValue.length is 1
