function getWindowSize() {
  if (parseInt(navigator.appVersion)>3) {    if (navigator.appName=="Netscape") {      winW = window.innerWidth;      winH = window.innerHeight;    }    if (navigator.appName.indexOf("Microsoft")!=-1) {      winW = document.body.offsetWidth;      winH = document.body.offsetHeight;    }  }
}

var imageArray=new Array();

function galleryPreview(index) {
  tint = document.getElementById('screenOverlay');
  tint.style.display = 'block';

  theLightbox = document.getElementById('lightbox').style;
  theLightbox.left = (winW/2) - (imageArray[index][1]/2);
  theLightbox.top = (winH/2) - (imageArray[index][2]/2);
  theLightbox.width = imageArray[index][1];
  theLightbox.height = imageArray[index][2]+15;
  theLightbox.display = 'block';
  theImage = document.getElementById('previewPicture');
  if (imageArray[index][3] == "video") {
    theImage.innerHTML = '<object type="video/x-msvideo" data="'+imageArray[index][0]+'" width="320" height="260"> <param name="src" value="'+imageArray[index][0]+'" /> <param name="autostart" value="true" > <param name="controller" value="true" /> </object>';//    theImage.innerHTML = '<OBJECT ID="MediaPlayer1" width=320 height=260 classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading Microsoft® Windows® Media Player components..." type="application/x-oleobject"> <PARAM NAME="AutoStart" VALUE="True"> <PARAM NAME="FileName" VALUE="'+imageArray[index][0]+'"> <PARAM NAME="ShowControls" VALUE="True"> <PARAM NAME="ShowStatusBar" VALUE="True"> <EMBED type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" SRC="'+imageArray[index][0]+'" name="MediaPlayer1" width=320 height=260 autostart=1 showcontrols=1 showstatusbar=1> </EMBED> </OBJECT>';
//  theImage.innerHTML = '<object type="application/x-shockwave-flash" width="320" height="260" wmode="transparent" data="flvplayer.swf?file='+imageArray[index][0]+'">	<param name="movie" value="flvplayer.swf?file='+imageArray[index][0]+'" /> <param name="wmode" value="transparent" /> </object>';

//var FO = { movie:"flvplayer.swf",width:"320",height:"260",majorversion:"7",build:"0",bgcolor:"#FFFFFF",flashvars:"file="+imageArray[index][0] }; UFO.create(FO, "previewPicture");
  } else {
    theImage.innerHTML = '<img src="'+imageArray[index][0]+'">';
  }
  title = document.getElementById('previewTitle');
  title.innerHTML = imageArray[index][4];
  
  tempLeft = theLightbox.left.substring(0, theLightbox.left.length-2);
  tempTop = theLightbox.top.substring(0, theLightbox.top.length-2);
  tempHeight = theLightbox.height.substring(0, theLightbox.height.length-2);
  tempWidth = theLightbox.width.substring(0, theLightbox.width.length-2);

  prev = document.getElementById('prevPic');
  if (index > 0) {
    prev.style.left = parseInt(tempLeft) - 100;
    prev.style.top = parseInt(tempTop) + (parseInt(tempHeight)/2);
    thePrevPic = index - 1;
    if (imageArray[index-1][3] == "video") {
      thePreviewImage = 'images/videoPreview.jpg';
    } else {
      thePreviewImage = imageArray[index-1][0];
    }
    prev.innerHTML = '<a href="javascript:galleryPreview('+thePrevPic+');"><img id="prevPicture" src="'+thePreviewImage+'" onMouseOver="rollOver(\'prev\');" onMouseOut="rollOut(\'prev\');" border=0></a>';
  } else {
    prev.style.left = -1000;
  }
  
  next = document.getElementById('nextPic');
  if (index < imageArray.length-1) {
    next.style.left = parseInt(tempLeft) + parseInt(tempWidth) + 20;
    next.style.top = parseInt(tempTop) + (parseInt(tempHeight)/2);
    theNextPic = index + 1;
    if (imageArray[index+1][3] == "video") {
      thePreviewImage = 'images/videoPreview.jpg';
    } else {
      thePreviewImage = imageArray[index+1][0];
    }
    next.innerHTML = '<a href="javascript:galleryPreview('+ theNextPic+');"><img id="nextPicture" src="'+thePreviewImage+'" onMouseOver="rollOver(\'next\');" onMouseOut="rollOut(\'next\');" border=0></a>';
  } else {
    next.style.left = -1000;
  }
}

function galleryEdit(index) {
  tint = document.getElementById('screenOverlay');
  tint.style.display = 'block';

  theLightbox = document.getElementById('lightbox').style;
  theLightbox.left = (winW/2) - (imageArray[index][1]/2);
  theLightbox.top = (winH/2) - (imageArray[index][2]/2);
  theLightbox.width = imageArray[index][1];
  theLightbox.height = imageArray[index][2]+25;
  theLightbox.display = 'block';
  theImage = document.getElementById('previewPicture');
  if (imageArray[index][3] == "video") {
    theImage.innerHTML = '<object type="video/x-msvideo" data="'+imageArray[index][0]+'" width="320" height="260"> <param name="src" value="'+imageArray[index][0]+'" /> <param name="autostart" value="true" > <param name="controller" value="true" /> </object>';//    theImage.innerHTML = '<OBJECT ID="MediaPlayer1" width=320 height=260 classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading Microsoft® Windows® Media Player components..." type="application/x-oleobject"> <PARAM NAME="AutoStart" VALUE="True"> <PARAM NAME="FileName" VALUE="'+imageArray[index][0]+'"> <PARAM NAME="ShowControls" VALUE="True"> <PARAM NAME="ShowStatusBar" VALUE="True"> <EMBED type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" SRC="'+imageArray[index][0]+'" name="MediaPlayer1" width=320 height=260 autostart=1 showcontrols=1 showstatusbar=1> </EMBED> </OBJECT>';
//  theImage.innerHTML = '<object type="application/x-shockwave-flash" width="320" height="260" wmode="transparent" data="flvplayer.swf?file='+imageArray[index][0]+'">	<param name="movie" value="flvplayer.swf?file='+imageArray[index][0]+'" /> <param name="wmode" value="transparent" /> </object>';

//var FO = { movie:"flvplayer.swf",width:"320",height:"260",majorversion:"7",build:"0",bgcolor:"#FFFFFF",flashvars:"file="+imageArray[index][0] }; UFO.create(FO, "previewPicture");
  } else {
    theImage.innerHTML = '<img src="'+imageArray[index][0]+'">';
  }
  title = document.getElementById('previewTitle');
  title.innerHTML = '<form action="saveTitle.php" method="post"><input type="hidden" name="fileName" value="'+imageArray[index][5]+'"><input type="hidden" name="url" value="'+window.location.href+'"><input type="text" name="title" value="'+imageArray[index][4]+'" size=25><input type="submit" value="save">';

  tempLeft = theLightbox.left.substring(0, theLightbox.left.length-2);
  tempTop = theLightbox.top.substring(0, theLightbox.top.length-2);
  tempHeight = theLightbox.height.substring(0, theLightbox.height.length-2);
  tempWidth = theLightbox.width.substring(0, theLightbox.width.length-2);

  prev = document.getElementById('prevPic');
  if (index > 0) {
    prev.style.left = parseInt(tempLeft) - 100;
    prev.style.top = parseInt(tempTop) + (parseInt(tempHeight)/2);
    thePrevPic = index - 1;
    if (imageArray[index-1][3] == "video") {
      thePreviewImage = 'images/videoPreview.jpg';
    } else {
      thePreviewImage = imageArray[index-1][0];
    }
    prev.innerHTML = '<a href="javascript:galleryEdit('+thePrevPic+');"><img id="prevPicture" src="'+thePreviewImage+'" onMouseOver="rollOver(\'prev\');" onMouseOut="rollOut(\'prev\');" border=0></a>';
  } else {
    prev.style.left = -1000;
  }
  
  next = document.getElementById('nextPic');
  if (index < imageArray.length-1) {
    next.style.left = parseInt(tempLeft) + parseInt(tempWidth) + 20;
    next.style.top = parseInt(tempTop) + (parseInt(tempHeight)/2);
    theNextPic = index + 1;
    if (imageArray[index+1][3] == "video") {
      thePreviewImage = 'images/videoPreview.jpg';
    } else {
      thePreviewImage = imageArray[index+1][0];
    }
    next.innerHTML = '<a href="javascript:galleryEdit('+ theNextPic+');"><img id="nextPicture" src="'+thePreviewImage+'" onMouseOver="rollOver(\'next\');" onMouseOut="rollOut(\'next\');" border=0></a>';
  } else {
    next.style.left = -1000;
  }
}

function rollOver(which) {
  button = document.getElementById(which+'Pic');
  button.className = which+'PicActive';
//  button.opacity = 1;
}

function rollOut(which) {
  button = document.getElementById(which+'Pic');
  button.className = which+'Pic';
//  button.opacity = .4;
}

function closePreview() {
  tint = document.getElementById('screenOverlay');
  tint.style.display = 'none';

  preview = document.getElementById('lightbox');
  preview.style.display = 'none';

  prev = document.getElementById('prevPic').style;
  prev.left = -1000;

  next = document.getElementById('nextPic').style;
  next.left = -1000;
}

function closeEditPreview() {
  tint = document.getElementById('screenOverlay');
  tint.style.display = 'none';

  preview = document.getElementById('edit_lightbox');
  preview.style.display = 'none';
}
