'use strict';
/** 
 * @controller VideoController
 * @property scope 
 * @property route
 * @property location
 * @property System
 * @property VideoService
 */
var VideoController = angular.module('videos.controllers.video', [
    'system'
])
    .controller('VideoController', [
        '$scope',
        '$route',
        '$location',
        'VideoService',
        function ($scope, $route, $location, VideoService) {
            
            $(".tooltip").tooltip();

            var id = $route.current.params["id"];

            /**
            *@method get
            *@description Load video object for id from params.
            */
            $scope.get = function() {
                VideoService.get(id)
                    .then(function (data) {
                        $scope.video = data;
                        
                        VideoService.query({ libraryId: data.LibraryID }).then(function(response) {
                            $scope.videos = response.Videos;
                        });
                       
                    });
            };

            /**
            *@action changeVideo
            *@description Open another video from current playlist.
            */
            $scope.changeVideo = function (videoId) {
                $location.url('/video/' + videoId);
            };
            
            /**
            *@action back
            *@description Back to video library.
            */
            $scope.back = function() {
                $location.url('/videos/' + $scope.video.LibraryID);
            };

            $scope.get();

        }
    ]);