﻿Type.registerNamespace("Efprog");

Efprog.ImageListViewerSettings = function(){
    Efprog.ImageListViewerSettings.initializeBase(this);
    this._contextID = "1";                                          //Ид контекста
    this._contextTypeID = "1";                                      //Ид типа контекста  
    this._imageViewerContainerId = null;                            //Ид контейнера                        
}

Efprog.ImageListViewerSettings.prototype = {         
    get_contextID: function(){
        return this._contextID;
    }, 
    set_contextID: function(value){
        this._contextID = value;
    },
    get_contextTypeID: function(){
        return this._contextTypeID;
    }, 
    set_contextTypeID: function(value){
        this._contextTypeID = value;
    }, 
    get_imageViewerContainerId: function(){
        return this._imageViewerContainerId;
    }, 
    set_imageViewerContainerId: function(value){
        this._imageViewerContainerId = value;
    }          
}

Efprog.ImageListViewerSettings._instance = null;
Efprog.ImageListViewerSettings.get_instance = function(){
        if(this._instance == null){
            this._instance = new Efprog.ImageListViewerSettings();
        }
        return this._instance;
}

Efprog.ImageListViewerSettings.registerClass("Efprog.ImageListViewerSettings");


Efprog.ImageLisViewerController = function(){
    Efprog.ImageLisViewerController.initializeBase(this);
    this._imageViewerContainer = window.parent.document.getElementById(Efprog.ImageListViewerSettings.get_instance().get_imageViewerContainerId()); 
    if(!this._imageViewerContainer) throw "Could not find image viewer container!"; 
    this._displayedImage = null;    
}

Efprog.ImageLisViewerController.prototype = {
    switchToImage: function(fileName){
        var e = Function._validateParams(arguments, [{name: "fileName", type: String}]);
        if (e) throw e;
        
        if(this._displayedImage != null){
            this._displayedImage.style.display = "none";
            this._displayedImage = null;
        }
        
        var imageNodes = this._imageViewerContainer.childNodes;
        var imageToShow = null;
        if(imageNodes != null && imageNodes.length > 0)
        {
            for(var i = 0; i < imageNodes.length; i++){
                if(!imageNodes[i].tagName || imageNodes[i].tagName.toLowerCase() != 'img') continue;
                if(imageNodes[i].alt != fileName) continue;
                imageToShow = imageNodes[i];
                break;
            }
        }
        if(imageToShow != null){
            this._displayedImage = imageToShow;
            this._displayedImage.style.display = "inline";
        }      
    },
    _getDoc: function(){
        return window.parent.document;
    },
    initialize: function(){
        var imageNodes = this._imageViewerContainer.childNodes;
        if(imageNodes != null && imageNodes.length > 0)
        {
            for(var i = 0; i < imageNodes.length; i++){
                if(!imageNodes[i].tagName || imageNodes[i].tagName.toLowerCase() != 'img')  continue;
                
                if(imageNodes[i].style.display != "none")
                    this._displayedImage = imageNodes[i];
            }
        }        
    }   
}


Efprog.ImageLisViewerController._instance = null;
Efprog.ImageLisViewerController.get_instance = function(){
        if(this._instance == null){
            this._instance = new Efprog.ImageLisViewerController();
        }
        return this._instance;
}

Efprog.ImageLisViewerController.registerClass("Efprog.ImageLisViewerController");
