﻿// JScript File

var img_Win = null;
var img_Frame = null;
var img_popupHeight = null;
var img_popupWidth = null;
var img_CoverPop = null;

var img_URL = "";
var img_Title = "";
function img_showImage(title,url,width,height){

    img_URL=url;
    img_Title=title;
    
    img_createPop(width,height);

}

var img_Settings_Obj = null;

function img_Settings(){
    img_Settings_Obj = new img_oSettings();
    return img_Settings_Obj;
}



function img_oSettings(){
    var StopAtSmallestFitableSize = false;
    var inDirectory = "";
    var imgRootPath="../";
    this.init = function(){
        this.StopAtSmallestFitableSize=false;
        this.inDirectory="";
        this.imgRootPath="../";
    }
    
    this.init();
    
}

function img_createPop(w,h){
    img_destroyPop();  
    img_Win=document.createElement("div");
    
    
    img_popupWidth=w;
    img_popupHeight=h;
    
    window.onresize=img_myWindowResize;
    
    img_CoverPop = document.createElement("div");
    img_CoverPop.style.opacity=".75";
    img_CoverPop.style.filter="alpha(opacity=75)";
    img_CoverPop.style.position="absolute";
    img_CoverPop.style.top=img_WindowScrollTop()+"px";
    img_CoverPop.style.left=img_WindowScrollLeft()+"px";
    img_CoverPop.style.maxWidth="100%";
    img_CoverPop.style.maxHeight="100%";
    img_CoverPop.style.width=img_WindowWidth()+"px";
    img_CoverPop.style.height=img_WindowHeight()+"px";
    img_CoverPop.style.backgroundColor="#CCCCCC";
    img_CoverPop.style.zIndex=0;
    img_CoverPop.style.overflow="hidden";
    img_CoverPop.innerHTML = "<!- ->";
    
    img_Win = document.createElement("div");
    img_Win.style.position="absolute";
    img_Win.style.width=img_popupWidth+"px";
    img_Win.style.height=img_popupHeight+"px";
    img_Win.style.top=(img_WindowHeight()/2) - (img_popupHeight/2) +"px";
    img_Win.style.left=(img_WindowWidth()/2) - (img_popupWidth/2) +"px";
    img_Win.style.zIndex=0;
    img_Win.style.backgroundColor="#FFFFFF";
    img_Win.style.border="solid 1px #000000";
    
    var url="image_sizer/img_sizer.htm";
    
    if(img_Settings_Obj.inDirectory!=""){
        url = img_Settings_Obj.inDirectory + "/" + url;
    }
    var temp = "<iframe frameborder=\"0\" width=\""+img_popupWidth+"\" height=\""+img_popupHeight+"\" src=\""+url+"\" name=\"img_image_viewer\" id=\"img_image_viewer\"></iframe>";
    img_Win.innerHTML=temp;
        
   
    document.body.appendChild(img_CoverPop);
    document.body.appendChild(img_Win);
    //alert("test1");
    document.documentElement.style.overflow="hidden";
    //alert("test2");
    img_myWindowResize()
    //alert("test3");
    img_Frame = document.getElementById("img_image_viewer");
   
    
}

function img_destroyPop(){
    try{
        if(img_Frame){
            img_Win.removeChild(img_Frame);
        }
    }catch(e){}
    img_Frame=null;
    
    try{
        if(img_Win){
            document.body.removeChild(img_Win);
        }
    } catch(e){}
    img_Win=null;
    
    try{
        if(img_CoverPop){
            document.body.removeChild(img_CoverPop);
        }
    } catch(e){}
    img_CoverPop=null;
    
}


function img_showImageCallBack(doc){
    doc.setInfo(img_Title,img_URL,img_Settings_Obj);

}



function getWindowCoords(){
    var x = parseInt(img_Win.style.left.replace("px",""));
    var y = parseInt(img_Win.style.top.replace("px",""));
    return new Array(x,y);
    
}



function img_myWindowResize(){
    if(img_CoverPop != null){
        img_CoverPop.style.top=img_WindowScrollTop()+"px";
        img_CoverPop.style.left=img_WindowScrollLeft()+"px";
        img_CoverPop.style.width=img_WindowWidth()+"px";
        img_CoverPop.style.height=img_WindowHeight()+"px";
    }
    if(img_Win != null){
         img_Win.style.top=( ( ( img_WindowHeight() ) / 2 ) - ( img_popupHeight / 2 ) + img_WindowScrollTop() ) +"px";
         img_Win.style.left=( ( ( img_WindowWidth() ) / 2 ) - ( img_popupWidth / 2 ) + img_WindowScrollLeft() ) +"px";
    }
}

// to close the window from within the popup: parent.my_rem_popup();
function img_my_rem_popup(){
    window.setTimeout("img_my_rem_popup2()",100);
}

function img_my_rem_popup2(){

    img_destroyPop();
    window.onresize=null;
    document.documentElement.style.overflow="auto";
    
    
    
}


function img_getMe(){
    return img_Win;
}


function img_WindowWidth(){
  var myWidth = 0
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && document.documentElement.clientWidth ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && document.body.clientWidth ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function img_WindowHeight(){
  myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function img_WindowScrollTop(){
    var ScrollTop = 0;
   
    if(window.pageYOffset){
        ScrollTop = window.pageYOffset;
    }else if(document.body.parentElement){
        ScrollTop = document.body.parentElement.scrollTop;
    }else if(document.documentElement){
        ScrollTop = document.documentElement.scrollTop;
    }else{
        ScrollTop = 0;
    }
    
    return ScrollTop;
}

function img_WindowScrollLeft(){
    var ScrollLeft = 0;
    
    if (window.pageXOffset){
        ScrollLeft = window.pageXOffset;
    }else if(document.body.parentElement){
        ScrollLeft = document.body.parentElement.scrollLeft;
    }else if(ScrollLeft = document.documentElement){
        ScrollLeft = document.documentElement.scrollLeft;
    }else{
        ScrollLeft = 0;
    }
    
    return ScrollLeft;
}