/*
 Disclosure:

 The follwing scripts were written by Joshaven Potter in Febuary 2003
 permission to use these functions is granted as long as this 
 introduction is left in tact.    
*/
/*
 Instructions:

 Save this text as DisplayPicInWin.js and keep it with the web page
 Place the following line in between the <HEAD></HEAD> tages:
 <SCRIPT SRC="DisplayPicInWin.js"></SCRIPT>
 Put the call to this script in between the <BODY></BODY> tags, see example below. 

 Example of use: 

 The image used is named Image.jpg 
 The title of the window will be "Picture of ..."

  <BODY>
  <SCRIPT TYPE="text/javascript">
  CreatePage(new Image("../pics/Image.jpg", "Picture of ..."))
  </SCRIPT>
  </BODY>
*/
/*
 Deffination of object attribute:
 path      Location of Image
 title     Title of the page that will be created
 width     Width of the page to be created
 height    Height of the page to be created
 xPos      How far to the right the window will appear (in pixels)
 yPos      how far down the window will appear from the top
           of the screen (in pixels)
 errorMsg  this is reserved for use by the script
*/

/////////////////////////////////////////////////////////////////////////////  

/*
 Function image(path, title, width, height, xPos, yPos, errorMsg)

 This function creates the object that will be used to store
 information for use with the following functions
 There are no required feeld's but without the path an error
 message will be displayed.
*/
function image(path, title, width, height, xPos, yPos, errorMsg){
  this.path = path;
  this.title = title;
  this.width = width;
  this.height = height;
  this.x = xPos;
  this.y = yPos;
  this.errorMsg = errorMsg;
}

/*
 Function CreatePage(objectData)
 This function calls all functions nessassory and passes the
 information needed for the function.
*/
function CreatePage(objectData){
  OpenNewWindow();
  SetDefaults(objectData);
  BeginHTML(objectData);
  SetHeightWidth(objectData);
  ErrorCheck(objectData);
  if(!objectData.errorMsg){
    ResizeWindow(objectData);
    EndHTML (objectData);
  }
}

/*
 Function CreatePage(objectData)
 This function openes a new Window called "newWindow".
*/
function OpenNewWindow(){
  if(window.newWindow)
    newWindow.close('fs');
  newWindow=window.open("about:blank","newWindow", "fullscreen=yes", width=100, height=100);
  newWindow.resizeTo(100,100);
}

/*
 Function SetDefaults(objectData)
 Sets any pramaters that are not defined by the caller of the function
 to the defaults established below
*/
function SetDefaults(objectData){
  if(!objectData.path)
    objectData.errorMsg = "No Image Defined.";
  if(!objectData.title)
    objectData.title = "Cambria Tool";
  if(!objectData.width)
    objectData.width = 0;
  if(!objectData.height)
    objectData.height = 0;
  if(!objectData.x)
    objectData.x = 10;
  if(!objectData.y)
    objectData.y = 10;
}

/*
 Function WriteHTML(objectData)
 This function writes the HTML code to the open window "newWindow"
 including placing the image on the page
*/
function BeginHTML(objectData){
  newWindow.document.writeln("<html>\n<head><title>" + objectData.title + "</title>");
  newWindow.document.writeln("</head>")
  newWindow.document.writeln("  <body bgcolor='#efefef'>");
  newWindow.document.writeln("  <Center><A HREF=\"#\" OnClick=\"window.close('fs')\"><IMG BORDER=\"0\" SRC=\"" + objectData.path + "\" NAME=\"picture\"></A></center>")
  newWindow.document.writeln("  <CENTER><A HREF=\"#\" OnClick=\"window.close('fs')\">Close Window</A></CENTER>")
}

/*
 Function ResizeWindow(objectData)
 This function will re-size the window "newWindow" to designated
 size if there is one.  If width and or the  height is not defined
 the script detects the size of the image in "newWindow" and sets
 the window size to an approate size
*/
function ResizeWindow(objectData){
  newWindow.resizeTo(objectData.width, objectData.height);
  newWindow.moveTo(objectData.x,objectData.y);
}

/*
 Function SetHeightWidth(objectData)
 This function set the proper height and width for the new window
 if it is not defined by the function call 
*/
function SetHeightWidth(objectData){
  while (objectData.width < 1){
    if(newWindow.document.images.picture.width>30){
      if(objectData.height < 1)
        objectData.height = newWindow.document.images.picture.height;
      if(objectData.width < 1)
        objectData.width = newWindow.document.images.picture.width;
    }
  }
  if(objectData.width < 150){
    newWindow.document.writeln(objectData.width+" x "+objectData.height);
    objectData.height = 100;
    objectData.width = 150;
  }
  objectData.height+=52
  objectData.width+=38
}

/*
 Function ErrorCheck(objectData)
 Sets any pramaters that are not defined by the caller of the function
 to the defaults below
*/
function ErrorCheck(objectData){
  if(objectData.height+50 >screen.height||objectData.width+50>screen.width ){
    newWindow.document.writeln("<img src = '"+objectData.path+"' onLoad = 'window.close()'></image>");
    alert("Sorry!\nYour screen resolution is set too low to view this picture.\nPlease choose a smaller picture.")
  }
}


/*
 Function EndHTML(objectData)
 This function finishes the BODY and HTML tags
*/
function EndHTML(objectData){
  newWindow.document.writeln("  </BODY>\n</HTML>");
}
