 angular.element(document).ready(function () {
    //angular.element(document).tooltip({ position: { my: 'left center', at: "right center" } });
    //angular.element('input').input();
    angular.bootstrap(document, ['cms.en']);
   
});


/**
 */
app = angular.module('cms.en', [
    'ngRoute',
    "ngTouch",
    'home',
    'app',
    'qusion',
    'system',
    'global',
    'localization',
    'navigation',
    'dashboard',
    'pages',
    'articles',
     'blogs',
    'images',
    'libraries',
    'documents',
    'videos',
    'classifications',
    'newsletters',
    'events',
    'contents',
    'karta',
    'weather',
    'jezik',
    'polls',
    'googlechart',
    'ngSocial',
    "mobile-angular-ui",
    'ui.bootstrap',
])

    .config([
        '$routeProvider',
        '$httpProvider',
        '$locationProvider',
        function ($routeProvider, $httpProvider, $locationProvider) {
            $routeProvider
                 .when('/', { redirectTo: '/dashboard' })
                 .when('/dashboard/', { templateUrl: template('en/main.html') })
                //pages
                .when('/pages', { templateUrl: template('pages/main.html') })
                .when('/page/:id', { templateUrl: template('pages/page.html') })
                .when('/404', { templateUrl: template('error/404.html') })
                // users
                .when('/users', { templateUrl: template('users/main.html') })
                .when('/users/:id', { templateUrl: template('users/main.html') })
                //articles
                .when('/articles', { templateUrl: template('articles/main.html')})
                .when('/articles/:id', { templateUrl: template('articles/article.html') })
                //images
                .when('/images', { templateUrl: template('images/main.html') })
                .when('/eimages', { templateUrl: template('images/emain.html') })
                .when('/images/:libraryId', { templateUrl: template('images/main.html') })
                .when('/imagesjson', { templateUrl: template('images/json.html') })
                //Videos
                .when('/videos', { templateUrl: template('videos/main.html') })
                .when('/videos/:libraryId', { templateUrl: template('videos/main.html') })
                .when('/video/:id', { templateUrl: template('videos/video.html') })
                 //blogs
                .when('/blogs', { templateUrl: template('blogs/main.html') })
                .when('/blogs/:BlogID', { templateUrl: template('blogs/blog.html') })
                //glibrarystype
                .when('/glibrarystype', { templateUrl: template('libraries/maintype.html') })
                .when('/glibrarystype/:GlibraryTypeID', { templateUrl: template('libraries/glibrarystype.html') })
                //classifications
                .when('/classifications', { templateUrl: template('classifications/main.html')})
                .when('/classifications/:alias', { templateUrl: template('classifications/classification.html')})
                .when('/classifications/:id/edit/', { templateUrl: template('classifications/edit.html') })
                .when('/label/:id', { templateUrl: template('classifications/label.html'), reloadOnSearch: false })
                 //newsletter
                .when('/newsletters', { templateUrl: template('newsletters/newsletters.html') })
                .when('/newsletters/create', { templateUrl: template('newsletters/newsletteradd.html') })
                //events
                .when('/events', { templateUrl: template('events/main.html') })
                .when('/events/:id', { templateUrl: template('events/event.html') })
                .when('/events/:id/edit', { templateUrl: template('events/edit.html') })
                 //poll
                .when('/vote/:id', { templateUrl: template('polls/vote.html') })
                //contents
                .when('/contents', { templateUrl: template('contents/main.html') })
                .when('/contents/:id/edit', { templateUrl: template('contents/edit.html') })
                //karta
                .when('/contact', { templateUrl: template('en/contact.html') })
                .when('/resume', { templateUrl: template('en/resume.html') })
                
                .otherwise({
                    redirectTo: '/404'
                });
           
          
           
         

            function template(url) {
                return '/areas/cms/scripts/templates/' + url;
            }

            // 
            // Common system http error handler
            //
            var interceptor = [
                '$rootScope',
                '$q',
                'Config',
                'System',
                function ($rootScope, $q, Config, System) {

                    function success(response) {
                        System.Broadcast.broadcast(Config.HTTP_STATUS_KEY, Config.HTTP_REQUEST_STATUS.NONE);
                        return response;
                    }

                    function error(response) {
                        System.Broadcast.broadcast(Config.HTTP_ERROR_KEY, response.status);
                        var reject = $q.reject(response);
                        System.Broadcast.broadcast(Config.HTTP_STATUS_KEY, Config.HTTP_REQUEST_STATUS.NONE);
                        return reject;
                    }

                    return function (promise) {
                        System.Broadcast.broadcast(Config.HTTP_STATUS_KEY, Config.HTTP_REQUEST_STATUS.LOADING);
                        return promise.then(success, error);
                    };
                }];

            $httpProvider.responseInterceptors.push(interceptor);
            // ovo je dodano
            $locationProvider.html5Mode(false);
            //$locationProvider.hashPrefix('!');

        }]);

app.service('analytics', [
  '$rootScope', '$window', '$location', function ($rootScope, $window, $location) {
      var send = function (evt, data) {
          ga('send', evt, data);
      }
  }
]);

app.directive("carouselExampleItem", function ($rootScope, $swipe) {
    return function (scope, element, attrs) {
        var startX = null;
        var startY = null;
        var endAction = "cancel";
        var carouselId = element.parent().parent().attr("id");

        var translateAndRotate = function (x, y, z, deg) {
            element[0].style["-webkit-transform"] = "translate3d(" + x + "px," + y + "px," + z + "px) rotate(" + deg + "deg)";
            element[0].style["-moz-transform"] = "translate3d(" + x + "px," + y + "px," + z + "px) rotate(" + deg + "deg)";
            element[0].style["-ms-transform"] = "translate3d(" + x + "px," + y + "px," + z + "px) rotate(" + deg + "deg)";
            element[0].style["-o-transform"] = "translate3d(" + x + "px," + y + "px," + z + "px) rotate(" + deg + "deg)";
            element[0].style["transform"] = "translate3d(" + x + "px," + y + "px," + z + "px) rotate(" + deg + "deg)";
        }

        $swipe.bind(element, {
            start: function (coords) {
                endAction = null;
                startX = coords.x;
                startY = coords.y;
            },

            cancel: function (e) {
                endAction = null;
                translateAndRotate(0, 0, 0, 0);
                e.stopPropagation();
            },

            end: function (coords, e) {
                if (endAction == "prev") {
                    $rootScope.carouselPrev(carouselId);
                } else if (endAction == "next") {
                    $rootScope.carouselNext(carouselId);
                }
                translateAndRotate(0, 0, 0, 0);
                e.stopPropagation();
            },

            move: function (coords) {
                if (startX != null) {
                    var deltaX = coords.x - startX;
                    var deltaXRatio = deltaX / element[0].clientWidth;
                    if (deltaXRatio > 0.3) {
                        endAction = "next";
                    } else if (deltaXRatio < -0.3) {
                        endAction = "prev";
                    } else {
                        endAction = null;
                    }
                    translateAndRotate(deltaXRatio * 200, 0, 0, deltaXRatio * 15);
                }
            }
        });
    }
});





