'use strict';

/* Controllers */

var potato = angular.module('potatoControllers', []);

potato.controller('potatoController', ['$scope', '$http',
    function($scope, $http) {
        $scope.openDetails = function(pictureIndex) {
            $scope.picture = $scope.pictureList[pictureIndex];
            $scope.tags = $scope.picture.tags.split(" ");
            $scope.showDetails = true;
        };

        $scope.backButtonClicked = function() {
            $scope.showDetails = false;
        };

        $scope.loadNewTag = function(tag) {
            $scope.isLoading = true;
            $http({
                method: 'JSONP',
                url: 'https://api.flickr.com/services/feeds/photos_public.gne?tags=' + tag + '&tagmode=all&format=json&jsoncallback=JSON_CALLBACK'
            }).success(function(data) {
                $scope.pictureList = data.items;
                $scope.showDetails = false;
                $scope.isLoading = false;
            });
        };
        /*alert(document.body.clientHeight +
            "\n" + document.body.clientWidth);*/
        $scope.loadNewTag("potato");
    }
]);