function ShowImg2(img_no, e)
{

  PicIndex = img_no;

  document.getElementById('popup').style.top = ScreenTop(e, 50);

  ShowImg3((img_no == 1), (img_no == gPicMax));
  document.getElementById('popup').style.visibility = "visible";
  document.getElementById('opaque').style.visibility = "visible";
}
function ShowImg3(fIsFirst, fIsLast)
{
  var pic_path="";
  var media_html = "";
  var pic_caption = "";
  var sFirstVisibility = fIsFirst ? "/left_g.gif" : "/left.gif";
  var sLastVisibility  = fIsLast ? "/right_g.gif" : "/right.gif";
  var WinSize=new Array();

  if( PicFile[PicIndex].substr(PicFile[PicIndex].length-4,4) == ".flv") {
//	  pic_path = "http://blue.viaw3.com/" + gPicDir + "/images/" + PicFile[PicIndex];
	  pic_path = "/" + gPicDir + "/images/" + PicFile[PicIndex];
	  pic_caption = PicTitle[PicIndex];
      media_html = '<div id="flash_player"> </div>';
      document.getElementById('popup').getElementsByTagName('td')[1].innerHTML = media_html;
 
      var fo = new SWFObject(
        "/FlowPlayerDark.swf", "FlowPlayer", "400", "300", "9", "#00f", true
      );
      fo.addVariable("config", "{autoPlay: true, initialScale: 'scale', videoFile: '"+pic_path+"'}");
      fo.write("flash_player");
  } else {
	  pic_path = "/" + gPicDir + "/images/" + PicFile[PicIndex];
	  pic_caption = PicTitle[PicIndex];
      media_html = '<img name="large" OnMouseDown="next_pic()" onload="GotIt();" border="0" src="' + pic_path + '">';
  document.getElementById('popup').getElementsByTagName('td')[1].innerHTML = media_html;
  }
  document.getElementById('popup').getElementsByTagName('p')[0].innerHTML = pic_caption;
  document.getElementById('popup').getElementsByTagName('img')[0].src = gImgDir + sFirstVisibility;
  document.getElementById('popup').getElementsByTagName('img')[3].src = gImgDir + sLastVisibility;

  WinSize = GetWindowSize();
  document.getElementById('opaque').style.width = WinSize[0];
  document.getElementById('opaque').style.height= WinSize[1];
}
function GotIt() {
  if (navigator.appName.indexOf("Microsoft")!=-1) {
    document.getElementById('popup').style.left = (document.body.offsetWidth - document.getElementById('popup').getElementsByTagName('img')[4].width) / 2;
  }
}
function SaveImg()
{
  var pic_path="";
  pic_path = "save_as.php?d=" + gPicDir + "&p=" + PicFile[PicIndex];
  top.window.location.href = pic_path;
}

function HideImg()
{
  document.getElementById('popup').getElementsByTagName('td')[1].innerHTML = '<img name="large" OnMouseDown="next_pic()" onload="GotIt();" border="0" src="/' + gImgDir + '/wait.gif">';
  document.getElementById('popup').style.visibility = "hidden";
  document.getElementById('opaque').style.visibility = "hidden";
}

function ScreenTop(e, offset)
{
  var top = mouseY(e) - e.screenY + offset;
  if(top<0) {
    top = offset;
  }
  return top;
}


function prev_pic()
{
  if( PicIndex > 1) {
	  PicIndex--;
	  ShowImg3((PicIndex == 1), false);
  }
}
function next_pic()
{
  if( PicIndex < gPicMax) {
	  PicIndex++;
	  ShowImg3(false, (PicIndex == gPicMax));
  }
}
function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
	   return evt.clientY + (document.documentElement.scrollTop ?
	   document.documentElement.scrollTop :
	   document.body.scrollTop);
	else return null;
}

function ResizeScreen () {
  var WinSize = GetWindowSize();
  document.getElementById('opaque').style.width = WinSize[0];
  document.getElementById('opaque').style.height= WinSize[1];
}
function GetWindowSize() {	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	return [pageWidth,pageHeight,windowWidth,windowHeight];
}

function GetScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

