﻿// JScript File
function GalleryItem(src, resume, title) {
    this.Src = src;
    this.Resume = resume;
    this.Title = title;
}

function viewImage(sr) {
    
    var modal = openModal();
    
    $("gallery-image").style.display = "block";
   
    var x = getActualIndex(sr);
    var imgPreLoad = new Image();
    var img = $("model-image");
    var title = $("model-title")
    var resume = $("model-resume")   
    var top = $("modal-top");
    
    var n = $("modal-next");
    var p = $("modal-prev");
    
    bind(x);
    
    if(x==0)p.style.visibility = "hidden";
    
    n.onclick = function() {
        p.style.visibility = "visible";
        x++;
        bind(x);
    }
    
    p.onclick = function() {
        n.style.visibility = "visible";
        x--;
        bind(x);
    }   
    
    function bind(a) {
        if(a == (aGallery.length-1)) {
            n.style.visibility = "hidden";
        }else {
            n.style.visibility = "visible";
        }
        
        if(a == 0){
            p.style.visibility = "hidden";
        }else {
            p.style.visibility = "visible";
        }
        
        img.style.display = "none";
        imgPreLoad.onload = function() {    
            if(num(this.width) > 500) {
                img.onload = function() {
                    this.width = "500";
                    this.style.display = "block";
                    //if(!window.attachEvent) {
                      //  $("modal-body").style.height = (num(img.height) + 30) + "px";
                    //}
                }
            }else {
                img.onload = function() {
                    this.style.display = "block";
                }
            }
            img.src = this.src;
        }
        imgPreLoad.src = aGallery[x].Src;

        if(aGallery[a].Resume=="" && aGallery[a].Title=="") {
            //alert(img.width)
            //$("modal-box").style.width = (num(img.width) + 30) + "px";
            //$("modal-body").style.height = (num(img.height) + 30) + "px";
        }else {
            resume.innerHTML = aGallery[a].Resume;
            title.innerHTML =  aGallery[a].Title;                       
        }
                   
        
        //img.style.display = "none";
        

        /*if(window.attachEvent) {
            document.attachEvent("onload", function() {
                alert(1)
               // img.style.display = "block";
               // if(num(img.clientWidth) > 500) {
                    img.width = "70%";
                //}
            });
        }else {
            img.addEventListener("load", function() {
                img.style.display = "block";
                if(num(img.clientWidth) > 500) {
                    img.style.width = "70%";
                }
                $("modal-body").style.height = (num(img.height) + 30) + "px";
            }, true);
        }*/

        //resume.innerHTML = aGallery[a].Resume;
        //title.innerHTML =  aGallery[a].Title;    

        
        
    }
    
    function getActualIndex(src) {
        var x = 0;
                
        for(var i = 0; i < aGallery.length; i++) {
            if(aGallery[i].Src.indexOf(src) >=0)
                x = i;
        }
        
        
        return x;
    }    
}


