﻿var nvpProjectImages = new Object();
var galProjectImagesModal = new Object();

function ProjectImage(smallComp,smallSrc,largeComp,largeSrc,contId){
    this.smallCompId = smallComp;
    this.smallImageSrc = smallSrc;
    this.largeCompId = largeComp;
    this.largeImageSrc = largeSrc;
    this.containerDivId = contId;
    return this;
}

function NavigatorProjectImages(){
    this.compArr = new Array();
    for(i=0;i<arguments.length;i++){
        this.compArr[this.compArr.length] = arguments[i];
    }
    this.SelectSample(0);
    return this;
}

NavigatorProjectImages.prototype = {
    UnSelectSamples : function(){
        for(i=0;i<this.compArr.length;i++){
            var currItem = this.compArr[i];
            var currComp = this.GetComponent(currItem.smallCompId);            
            if(currComp != null){
                currComp.className = "unSelected";
            }
        }
    },
    LoadBigImage: function(){
        this.img = new Image();
        this.img.par = this;
        this.img.onload = function(){            
            this.par.onload = null;
            this.par.onerror = null;
            this.par.src = this.src;
            this.par.alt = "";
        }
        this.img.onerror = function(){
            loadEmptySrc(this.par);
            this.par.alt = "";
        }
        this.img.src = this.largesrc;
    },
    SelectSample : function(index,Modal){
       this.UnSelectSamples();
       var currItem = this.compArr[index];
       var currComp = this.GetComponent(currItem.smallCompId);
       var largeImgCom = this.GetComponent(currItem.largeCompId);
       var largeImg = currItem.largeImageSrc;
       var smallImg = currItem.smallImageSrc;       
       if(largeImgCom!=null){
            if(largeImgCom.img!=null){                
                largeImgCom.img.onload = null;
                largeImgCom.img.onerror = null;
                largeImgCom.img = null;
            }
            largeImgCom.largesrc = largeImg;
            largeImgCom.onload = this.LoadBigImage;
            largeImgCom.onerror = this.LoadBigImage;
            largeImgCom.alt = "Loading...";
            largeImgCom.src = currComp.src;
       }
       if(Modal!=null){
            Modal.Show();
       }
       if(currComp!=null){
            currComp.className = "Selected";
            var container = this.GetComponent(currItem.containerDivId);            
            if(container){
                var newScrollTop = findTopFrom(currComp,currItem.containerDivId);
                if(newScrollTop < container.scrollTop || newScrollTop > (container.scrollTop + container.offsetHeight - currComp.offsetHeight)){
                    container.scrollTop = newScrollTop;
                }
            }
            try{
                currComp.focus();
            }catch(e){
            }
       }
    },
    GetComponent : function(comp){
        return (typeof(comp)=="string") ? document.getElementById(comp) : comp;
    }
}
function findTopFrom(comp,fromCompId){
    if(comp!=null && fromCompId!=null){
        if(comp.offsetParent && comp.offsetParent.id!=fromCompId){
            return (comp.offsetTop + findTopFrom(comp.offsetParent,fromCompId));
        }
    }
    return 0;
}
function loadEmptySrc(imgcomp){
    if(imgcomp){
        imgcomp.onerror = null;
        imgcomp.onload = null;
        var pathext = (typeof(pathExt)=="string") ? pathExt : "";
        imgcomp.src = pathext + "images/pixel_trans.gif";
    }
}
