angular.module("app").directive("appsZoom", function($rootScope, AppsZoomService) {
    return {
        restrict: 'E',
        replace: true,
        templateUrl: "../app/directives/appsZoom/views/appsZoom.html",
        scope: {

        },
        link: function ($scope, element, attrs) {
            $scope.zoomCurrentPercent=Math.round($rootScope.zoom.current*100);

            $rootScope.$watch(function() { 
                return $rootScope.zoom.current; 
            }, function(newVal, oldVal){ 
                if(newVal){
                    $scope.zoomCurrentPercent=Math.round($rootScope.zoom.current*100);
                }
            });

            $scope.zoomIn = function(){
                if($rootScope.zoom.current < $rootScope.zoom.max){
                    $rootScope.zoom.current += 0.1;
                    AppsZoomService.changeZoom($rootScope.zoom.current);
                }
            }

            $scope.zoomOut = function(){
                if($rootScope.zoom.current > $rootScope.zoom.min){
                    $rootScope.zoom.current -= 0.1;
                    AppsZoomService.changeZoom($rootScope.zoom.current);
                }
            }

        }
    };
});