var imgCounter = 1;
function getWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function getHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}
function popup(path,image,w,h) {
    image = image.replace(/\\/g,'');
    
    var width = Math.ceil(w * ( getHeight() / h ));
   
    win = window.open ("/detail.php?g="+path+"&i="+image+"&w="+width+"&h="+getHeight(), "image_detail","location=0,menubar=0,status=0,scrollbars=1,width="+(width+260)+",height="+getHeight());
    var posX = Math.ceil(screen.width/2 - (width+250)/2);
    var posY = Math.ceil(screen.height/2 - getHeight()/2);
    
    if (win) win.moveTo(posX,posY);
}

function initImage(id,min) {
  divId = (id=='mainPhoto')?'photoHolder':id.replace(/t/,"d");
  //alert(id+","+min+","+divId);
  image = document.getElementById(id);
  imageDiv = document.getElementById(divId);
  imageDiv.style.visibility = 'visible';
  setOpacity(image, 100);

  fadeOut(id,100,min);
  if ( !document.all ) {
    setOpacity(imageDiv, 0);
    fadeDelay = imgCounter * 400;
    if ( divId == 'photoHolder' ) { fadeDelay = 1200; }
    window.setTimeout("fadeIn('"+divId+"',0,100)", fadeDelay );
  }
}

function initGallery() {
    imgCounter = 0;
    var gallery = document.getElementById("gallery");
    if ( document.all ) {
        var images = document.all["gallery"].all.tags("IMG");
    } else {    
        var images = gallery.getElementsByTagName("img");
    }
    
    for (var i = 0; i <images.length; i++) {
        id = images[i].id;
        //alert(id);
        initImage(id, 20);
        imgCounter++;
    }
}

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}

function fadeIn(objId,opacity,max) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
	if (opacity == 'current') { opacity = document.getElementById(objId).style.opacity * 100; }
    if (opacity <= max) {
      setOpacity(obj, opacity);
      opacity += 5;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+","+max+")", 100);
    }
  }
}

function fadeOut(objId,opacity,min) {
  //alert(objId+","+opacity+","+min);
  if (document.getElementById) {
    obj = document.getElementById(objId);
	if (opacity == 'current') { opacity = document.getElementById(objId).style.opacity * 100; }
    if (opacity >= min) {
      setOpacity(obj, opacity);
      opacity -= 10;
      window.setTimeout("fadeOut('"+objId+"',"+opacity+","+min+")", 100);
    }
  }
}


