// JavaScript Document

function ScrollUp() {

//alert ("Scroll!!!!!!!!!!!!!!!");

var fullHeight = getClientHeight();
var fullWidth = getClientWidth();


DIVM=document.getElementById("popupMask");
DIVP=document.getElementById("PictureDIV");
CDIV=document.getElementById("CloseDIV");
PIC=document.getElementById("PictureI");

DIVP.style.width=PIC.width;
DIVP.style.height=PIC.height;

DIVP.style.left = getBodyScrollLeft()+fullWidth/2-PIC.width/2+"px";
DIVP.style.top = getBodyScrollTop()+fullHeight/2-PIC.height/2+"px";
CDIV.style.left= PIC.width+getBodyScrollLeft()+fullWidth/2-PIC.width/2+"px";
CDIV.style.top=getBodyScrollTop()+fullHeight/2-PIC.height/2-19+"px";

DIVP.style.visibility="visible";

//alert(getBodyScrollTop());

DIVM.style.left = getBodyScrollLeft()+"px";
DIVM.style.top = getBodyScrollTop()+"px";
DIVM.style.width = fullWidth+"px";
DIVM.style.height = fullHeight+"px";
}

function setElementOpacity(sElemId, nOpacity)
{
  var opacityProp = getOpacityProperty();
  var elem = document.getElementById(sElemId);

//  if (!elem || !opacityProp) return;
  
  if (opacityProp=="filter")
  {
    var oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
    if (oAlpha) oAlpha.opacity = nOpacity;
    else elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";
  }
  else 
    elem.style[opacityProp] = nOpacity/100;
}

function getOpacityProperty()
{
  if (typeof document.body.style.opacity == 'string')
    return 'opacity';
  else if (typeof document.body.style.MozOpacity == 'string')
    return 'MozOpacity';
  else if (typeof document.body.style.KhtmlOpacity == 'string')
    return 'KhtmlOpacity';
  else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5)
    return 'filter';

  return false;
}

function setOpacity(value) {
   value += 10;
   setElementOpacity('PictureDIV', value);
   setElementOpacity('CloseDIV', value);
   if ((value) <= 70) setElementOpacity('popupMask', value);
   myTimeout = setTimeout("setOpacity("+value+")", 20);
   if ((value) >= 100) {
      clearTimeout(myTimeout);
   }
}

function removeOpacity(value) {
   value -= 10;
   setElementOpacity('PictureDIV', value);
   setElementOpacity('CloseDIV', value);
   if ((value) <= 70) setElementOpacity('popupMask', value);
   
   myTimeout1 = setTimeout("removeOpacity("+value+")", 20);
   
   if ((value) <= 0) {
      clearTimeout(myTimeout1);
	  DIVP.style.visibility="hidden";
      DIVM.style.visibility="hidden";
	  CDIV.style.visibility="hidden";
	  while (DIVP.childNodes.length!=0) { DIVP.removeChild(DIVP.lastChild); }
	  window.onscroll=function(){ };
	  window.onresize=function(){ };
	  //document.getElementById("PictureIMG").src="";
	}
}


function HideImage() {
removeOpacity(100);
}


function ShowImage(IN) {

var fullHeight = getClientHeight();
var fullWidth = getClientWidth();


DIVM=document.getElementById("popupMask");
DIVP=document.getElementById("PictureDIV");

PIC=document.getElementById("PictureI");
CDIV=document.getElementById("CloseDIV");


if (PIC==null) { 
var PIC = new Image();
PIC.id="PictureI";
DIVP.appendChild(PIC);
PIC.src = IN;
} else {
if(!PIC.complete){ setTimeout("ShowImage(\""+IN+"\")",1000); return 0; }
}
if(PIC.width==0) { setTimeout("ShowImage(\""+IN+"\")",1000); return 0; }
//alert(PIC.width);

DIVP.style.width=PIC.width;
DIVP.style.height=PIC.height;

DIVP.style.left = getBodyScrollLeft()+fullWidth/2-PIC.width/2+"px";
DIVP.style.top = getBodyScrollTop()+fullHeight/2-PIC.height/2+"px";
CDIV.style.left= PIC.width+getBodyScrollLeft()+fullWidth/2-PIC.width/2+"px";
CDIV.style.top=getBodyScrollTop()+fullHeight/2-PIC.height/2-19+"px";

if((PIC.width==0)) { alert("NOWIDTH");}

DIVP.style.visibility="visible";
CDIV.style.visibility="visible";

//alert(getBodyScrollTop());

DIVM.style.left = getBodyScrollLeft()+"px";
DIVM.style.top = getBodyScrollTop()+"px";
DIVM.style.width = fullWidth+"px";
DIVM.style.height = fullHeight+"px";
DIVM.style.visibility="visible";

setOpacity(0);
window.onscroll=function(){ScrollUp();}
window.onresize=function(){ScrollUp();}
}

function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function getBodyScrollTop()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft()
{
  return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function chkLoading(){
PIC=document.getElementById("PictureI");
if(PIC.complete){ return 0; }
else{setTimeout("chkLoading()",1000)}
}

