//  07/02/05 Gallery 7 added


//Get gallery number from query string
function getNewGallery()
{
   if (document.location.search.length)
   {
        var galleryNum = parseInt(document.location.search.substring(1));
        return (isNaN(galleryNum))?0:galleryNum; // default to main gallery if passed value u/s
   }
   else return 0; // default to main gallery ref if no value passed
}
////////////////////////////////


// Get photo gallery number from page URL
function getGallery()
{
    var page = new String(window.document.location.pathname);
    var galleryNum = parseInt(page.substring(page.indexOf('gallery')+7, page.indexOf('gallery')+8));
    return (isNaN(galleryNum))?0:galleryNum; // default to main gallery if return value u/s
}
////////////////////////////////


// Check & load parent frameset for resepective photo gallery
// all gallery filenames must begin with 'galleryN' where N is the gallery number
// all gallery inner framesets must be named 'galleryN' where N is the gallery number
function checkFrames()
{

//    if (window.document.location.pathname == parent.window.location.pathname)// if page not in frameset
    if (parent.window.location.pathname.indexOf('photogallery') < 0)
    {
        window.location.replace('photogallery.htm?' +getGallery() );// not to UK2 redirect top frame
        return false;
    }
    else return true;
}
////////////////////////////////


//Set page title in header
function setTitle(num)
{
    var titles = new Array();
        titles[0] = "Class 40 Preservation Society - vintage main line photo gallery";
        titles[1] = "Class 40 Preservation Society - vintage railtour photo gallery";
        titles[2] = "Class 40 Preservation Society - D345/40145 mainline photos 2002";
        titles[3] = "Class 40 Preservation Society - D345/40145 mainline photos 2003";
        titles[4] = "Class 40 Preservation Society - preservation photos 1";
        titles[5] = "Class 40 Preservation Society - 40145 mainline photos 2004";
        titles[6] = "Class 40 Preservation Society - preservation photos 2";
        titles[7] = "Class 40 Preservation Society - 40145 mainline photos 2005";
    
    window.document.write('<TITLE>' +titles[num] +'</TITLE>')

}    
////////////////////////////////

// Set array of thumbnail images
function setPhotArray(num) {                                   
//array object ignoring 0th entry                              
  for (loop=num; loop>=1; loop--) {                            
      this[loop]=new Image();                                  
	  this[loop].src = photDir +photName[loop] +"tn.jpg";     
	  }
  return this;                                                 
}                                                              
////////////////////////////////


// Display photo in main frame
function show(num2){
 
 // insert line breaks in HTML caption, but not in image ALT
 var captionHTML = caption[num2].replace(/\s\s/g, "<br>");
 
 parent.main.document.open("text/html");
 parent.main.document.writeln('<HTML><HEAD><link rel="stylesheet" href="css/cfps.css" TYPE="TEXT/CSS"></HEAD><BODY CLASS="bodygallery">');
 parent.main.document.writeln('<TABLE ALIGN="LEFT" WIDTH="650" BORDER="0" CELLSPACING="0" CELLPADDING="0" BGCOLOR="#FFFFFF"><TR ALIGN="CENTER"><TD>');
 parent.main.document.writeln('<P CLASS="bodybold" ALIGN="CENTER"><BR><IMG SRC="' +photDir +photName[num2] + '.jpg" ALT="' +caption[num2].substring(caption[num2].indexOf('|')+1) +'" HEIGHT="360"><BR CLEAR="LEFT">');
 parent.main.document.writeln(captionHTML.substring(captionHTML.indexOf('|')+1) +'<BR>');
 parent.main.document.writeln('<SPAN CLASS="link"><A HREF="photogalleries.htm" TARGET="_parent" CLASS="link">&nbsp;<IMG SRC="images/bluestar2.gif" WIDTH="15" HEIGHT="15" ALIGN="ABSMIDDLE" BORDER="0">'); 
 parent.main.document.writeln(' Back to photo galleries page <IMG SRC="images/bluestar2.gif" WIDTH="15" HEIGHT="15" ALIGN="ABSMIDDLE" BORDER="0"></A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
 parent.main.document.writeln('<A HREF="index.html" TARGET="_parent" CLASS="link">&nbsp;<IMG SRC="images/bluestar2.gif" WIDTH="15" HEIGHT="15" ALIGN="ABSMIDDLE" BORDER="0">');
 parent.main.document.writeln(' Back to home page <IMG SRC="images/bluestar2.gif" WIDTH="15" HEIGHT="15" ALIGN="ABSMIDDLE" BORDER="0"></A>');
 parent.main.document.writeln('</SPAN></P>');
 parent.main.document.writeln('</TD></TR></TABLE></BODY></HTML>');
 parent.main.document.close(); 
 return;
 }
////////////////////////////////

// Display thumbnails
function showTn()
{
    document.writeln('<P ALIGN="CENTER" CLASS="footnote"><BR>Click the thumbnail<br>images to display<br>larger versions.<BR>');
    document.writeln('[ ' +(photName.length-1) +' photos ]</P>');
    for (i=photName.length-1; i>=1; i--)
    {
        document.writeln('<P ALIGN="CENTER" CLASS="footnote"><A CLASS="footnote" HREF="javascript:show(' +i +')\"');
        document.writeln('onMouseover="window.status=caption[' +i +'].substring(caption[' +i +"].indexOf('|')+1);" +' return true";');
        document.writeln('onMouseout=\"window.status=' +"''" +'; return true\">');
        document.writeln('<IMG SRC=\"' +phot[i].src +'"ALT=\"Click for main photo view - \n' +caption[i].substring(caption[i].indexOf('|')+1) +'\" BORDER=0></A><BR>' +caption[i].substring(0,caption[i].indexOf('|')) +'<HR WIDTH="50%"></P>');
    }
}

