// JavaScript PopupWindow System - © 2007 TMP

// This Script handles the creation of a popup window with embedded images
// You do NOT need to include the server address in the argument list when
// defining the image location, it has already been globally defined below.
// You do not need to apply an extension to the image name - simply define
// it below.  In order for the thumbnail images to work, you must name the
// thumbnail identically to the primary image, only adding the string data
// '_TN' to the end of the name (TN = ThumbNail).  This concludes the help.


// Server address, window title, preview image extension and width, mouse hover text, background image and color settings
var ServerHost=location.hostname,
    ServerName='http:\/\/'+ServerHost+'\/',
    ImageLocal='',
    ThumbLocal='',
    PopupTitle=ServerHost+' - Press F11 for fullscreen',
    MouseHover='Click for full size',
    PreviewExt='jpg',
    PreviewWid='160',
    BGImageSet='content_bk.png',
    BGColorSet='f0f0f0',
    AdjustSize=0;

// Writes the thumbnail to the window
function CreatePopup(ImageName, ImageInfo, XDim, YDim, Scrollbar)
{
  var POPSRC='';
  POPSRC+='<a href="#" title="'+MouseHover+'" onClick="PopupWindow(&quot;'+ServerName+ImageLocal+ImageName+'.'+PreviewExt+'&quot;,'+XDim+','+YDim+',&quot;'+ImageInfo+'&quot;,'+Scrollbar+'); return false;">';
  POPSRC+=  '<img src="'+ServerName+ThumbLocal+ImageName+'_TN'+'.'+PreviewExt+'" style="width: '+PreviewWid+'px" alt="'+MouseHover+'"\/>';
  POPSRC+='<\/a>';
  document.write(POPSRC);
}

// Creates a popup window with an embedded image
function PopupWindow(ImgSrc, Width, Height, Description, Scrollbars)
{
  // Adjsut window height based on scrollbar inclusion
  if (Scrollbars)
    AdjustSize=36;
  else
    AdjustSize=60;

  // Gets the window position
  function GetPosition()
  {
    // Set position of the popup window to the center of the screen
    Xpos=(Detect(window.screenLeft))? screenLeft+document.body.clientWidth /2-Width /2 : Detect(window.screenX)? screenX+innerWidth /2-Width /2 : 0;
    Ypos=(Detect(window.screenTop ))? screenTop +document.body.clientHeight/2-Height/2 : Detect(window.screenY)? screenY+innerHeight/2-Height/2 : 0;

    // Opera specific error checking
    if (window.opera)
    {
      Xpos-=screenLeft;
      Ypos-=screenTop;
    }
  }

  // Get the window position
  GetPosition();
  
  var WindowSettings='width='+Width+', height='+(Height+AdjustSize)+', status=0, location=0, toolbar=0, menubar=0, resizable=1, scrollbars='+Scrollbars+'left='+Xpos+', top='+Ypos;
  var   BodySettings=(BGColorSet.indexOf(".")!=-1)? 'background="'+BGColorSet+'"' : 'bgcolor="'+BGColorSet+'"';

  if (typeof NewPopupWindow=="undefined" || NewPopupWindow.closed)
  {
    NewPopupWindow=window.open(ImgSrc,"",WindowSettings);
    NewPopupWindow.moveTo(Xpos, Ypos);
  }
  else
  {
    NewPopupWindow.close();
    NewPopupWindow=window.open(ImgSrc,"",WindowSettings);
    NewPopupWindow.moveTo(Xpos, Ypos);
  }

  // Define the source code for the window
  var WindowSrc='';
  WindowSrc+='<html>';
  WindowSrc+='  <head>';
  WindowSrc+='    <style type="text\/css">';
  WindowSrc+='      <!--';
  WindowSrc+='        html';
  WindowSrc+='        {';
  WindowSrc+='          margin : 0em;';
  WindowSrc+='          border : 0px;';
  WindowSrc+='          padding: 0px;';
  WindowSrc+='        }';
  WindowSrc+='        body';
  WindowSrc+='        {';
  WindowSrc+='          top                  : 0px;';
  WindowSrc+='          margin               : 0px;';
  WindowSrc+='          position             : absolute;';
  WindowSrc+='          color                : #000000;';
  WindowSrc+='          background-color     : inherit;';
  WindowSrc+='          background           : url("'+ServerName+BGImageSet+'");';
  WindowSrc+='          background-attachment: scroll;';
  WindowSrc+='        }';
  WindowSrc+='        img';
  WindowSrc+='        {';
  WindowSrc+='          background   : transparent;';
  WindowSrc+='          border-top   : 2px solid #bcbcbc;';
  WindowSrc+='          border-bottom: 2px solid #5a5a5a;';
  WindowSrc+='          border-left  : 2px solid #9d9d9d;';
  WindowSrc+='          border-right : 2px solid #8b8b8b;';
  WindowSrc+='        }';
  WindowSrc+='        p';
  WindowSrc+='        {';
  WindowSrc+='          margin-top      : 3px;';
  WindowSrc+='          margin-left     : 6px;';
  WindowSrc+='          margin-right    : 6px;';
  WindowSrc+='          color           : #3e3e3e;';
  WindowSrc+='          background-color: inherit;';
  WindowSrc+='          font-family     : "lucidia console", monospace;';
  WindowSrc+='          font-size       : 16px;';
  WindowSrc+='          font-weight     : bold;';
  WindowSrc+='          cursor          : default;';
  WindowSrc+='        }';
  WindowSrc+='      \/\/-->';
  WindowSrc+='    <\/style>';
  WindowSrc+='  <\/head>';
  WindowSrc+='  <title>'+PopupTitle+'<\/title>';
  WindowSrc+='  <body '+BodySettings+'>';
  WindowSrc+='    <center>';
  WindowSrc+='      <img src="'+ImgSrc+'" width="100%" align="top" border="0" alt="">';
  WindowSrc+='    <\/center>';
  WindowSrc+='    <p>'+Description+'<\/p>';
  WindowSrc+='  </body>';
  WindowSrc+='</html>';

  // Create the window, and apply the source to it
  NewPopupWindow.document.open (         );
  NewPopupWindow.document.write(WindowSrc);
  NewPopupWindow.document.close(         );

  // Set the window as foreground
  NewPopupWindow.focus();
}

// Checks if an identical popup has already been opened - returns the active state
function Detect(Object)
{
  return (typeof Object!="undefined");
}

// END OF FILE
  
