"use strict";
angular.module('monsart').directive('maImage', ['MediaHelper', function (MediaHelper) {
            return {
                templateUrl: '/directives/maImage.tpl',
                restrict: 'E',
                scope: {
                    val: "=ngModel"
                },
                link: function (scope, elem, attrs) {
                    scope.fromUrl = false;
                    var $elem = angular.element(elem);
                    var $fromUrl = angular.element($elem.find('input.upload_image'));
                    
                    var currentDirective = false;
                    window.original_send_to_editor = window.send_to_editor;

                    scope.openThickBox = function () {
                        MediaHelper.setCurrentDirective(scope);
                        currentDirective = true;
                        tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');

                    };
                    scope.useImage = function(){
                         scope.val  = $fromUrl.val();
                    };
                    scope.activateFromUrl = function(){
                        scope.fromUrl = $fromUrl.val() ? true : false;
                    };
                    scope.removeImage = function(){
                        scope.val = '';
                    };


                    


                }
            }
        }]);