
var album = angular.module("album", [ ]);

album.controller("AlbumController", ["$http", "$log", "$scope", function($http, $log, $scope) {
	var alb = this;
	this.roots = [ ];
	this.items = [ ];
	this.update = function() {
		$log.info("updating...");
		if (alb.roots.length == 0) {
			$http.get("/photo/album/_roots.json").success(function(data) {
				alb.roots = data;
				alb.update();
			});
		} else {
			$http.get("/photo/album/" + alb.roots[0] + ".json").success(function(data) {
				alb.items = data.contents;
				for (var i = 0; i < alb.items.length; i++) {
					if (alb.items[i].type == "movie") {
						alb.items[i].path += ".frame";
					}
				}
			});
		}
	}
    $scope.$watch('$viewContentLoaded', function(){
        alb.update();
    });
}]);
