//
//  File: amrs.js
//
//	This file contains most of the javascript used in the AMRS web site.
//
//  Author:  Marshall Wales
//  Date: 9/25/2009
//
//  Change Control:
//	Who		Date:	   Purpose
//	-----		-------	   -------
//	M. Wales	9/25/09	   Created
//	M. Wales	10/28/09   Added new code in makemenu function for new
//				   menu bar feature
//	M. Wales	11/02/09   Added code for windows that popup using window.open()
//	M. Wales	11/03/09   Added popupWin() window for popup window
//	M. Wales	11/11/09   Removed HO Switchman's Time Table menu option
//	M. Wales	11/12/09   Removed "rr park" from photo gallery
//	M. Wales	11/12/09   Added nscalepics.html to photo gallery
//	M. Wales	11/13/09   Added hoscalepics.html to photo gallery
//	M. Wales	11/19/09   Moved Calendar & Links from main menu bar and put them under Home
//	M. Wales	11/21/09   Added displayPhotos function
//	M. Wales	01/03/10   Added <span>&raquo;</span> to Links menu option; Change Scales to Scale on G Scale "Title"
//	M. Wales	02/01/10   Modified MakeMenu to support FreeStyle Menus by Angus Turnbull (www.twinhelix.com)
//				   Angus's solution supports dropdown menus on older browsers such as IE6 & Navigator 4.x
//	M. Wales	02/18/10   Added the function buildvideoGallery(videokeyArray,width,height) for displaying youtube videos
//	M. Wales	02/20/10   Added Members Only submenu to Home.
//	M. Wales	02/21/10   Added parameter passed to function "makeHeader"
//	M. Wales	04/02/10   Changed version of constitution from 3.3 to 3.4
//
//
//  Global data
//

var Home=0
var AboutUs=1
var Divisions=2
var NewsLetter=3
var History=4
var Library=5
var Links=6
var MailTo=7

//
//  Function: popupwin()
//
//	This function opens a pop up window
//
//  Inputs:
//	url - path(optional) and name of html file to be in the window
//	winName - name for the window...can be anything you want
//	w - width of window in pixels
//	h - height of window in pixels
//	type - "nonav" means no navigation features for the window.
//		anything else means navigation features for the window.
//

function popupWin(url,winName,w,h,type)
{
 	if(type == 'nonav')
	{
	    window.open(url, winName, 'width='+w+',height='+h+',scrollbars=yes,menubar=no,status=no,toolbar=no,resizable=yes');
	}
  	else
	{
	    this.popWindow = window.open(url, winName, 'width='+w+',height='+h+',scrollbars=yes,menubar=yes,status=no,toolbar=yes,resizable=yes');
	}
}

//
//  Function: makeHeader()
//
//	This function writes the AMRS header on all Web site pages
//
//	Inputs:  pathModifier - The path modifier to finding the images.  If "undefined" (i.e., not passed), pathModifier is set to "./"
//
//
function makeHeader(pathModifier)
{
	if (pathModifier==undefined)
	   pathModifier="./"

	var d = new Date()
	var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
	var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
	var today="<p class=date>"+weekday[d.getDay()] + " "+monthname[d.getMonth()] + " "+d.getDate() + ", "+d.getFullYear()+"<\/p>"
	document.write("<table width='100%' border='0' cellspacing='4' cellpadding='4'>")
	document.write("<tr>") 
	document.write("<td class='vtop_left'>"+today+"<br /><img src='"+pathModifier+"webimages/gifs/azflag.gif'  width='100' height='59'></td>")
	document.write("<td class='left'><img src='"+pathModifier+"webimages/animated gifs/crossing3.gif'  width='80' height='145'></td>")
	document.write("<td class='club_name'>Arizona<br />Model Railroading<br />Society</td>")
	document.write("<td class='right'><img src='"+pathModifier+"webimages/gifs/amrs_patch.gif' width='140' height='140'></td>")
	document.write("</tr>")
	document.write("</table>")

} // end makeHeader function

//
//  Function: makeHeader()
//
//	This function writes the AMRS menu on all Web site pages
//
//
//  Function: makeMenu(MenuOption)
//
//  This function makes the Option menu in the header.
//
//   Passed arguments:  MenuOption - contains a value specifying what menu option was selected
//

function makeMenu(MenuOption)
{
document.write("<ul class='menulist' id='listMenuRoot'>")
document.write("<li><a href='index.html' title='Home'>Home</a>")
document.write("<ul>")
document.write("<li><a href='join.html' title='Join'>Join</a></li>")
document.write("<li><a href='aboutus.html#hours_directions'>Hours &amp; Directions</a></li>")
document.write("<li><a href='calendar.html'>Calendar</a></li>")
document.write("<li><a href='links.html'>Links</a>")
document.write("<ul>")
document.write("<li><a href='links.html#rrassoc'>Railroad Assoc.</a></li>")
document.write("<li><a href='links.html#rrclubs'>Model RR Clubs</a></li>")
document.write("<li><a href='links.html#hobbyshops'>Hobby Shops</a></li>")
document.write("<li><a href='links.html#rrmanufactures'>Model RR Companies</a></li>")
document.write("<li><a href='links.html#mags'>Magazines</a></li>")
document.write("<li><a href='links.html#miscellaneous'>Miscellaneous</a></li>")
document.write("<li><a href='links.html#railsearch'>RR Search Engine</a></li>")
document.write("</ul></li>")
document.write("<li><a href='operationlifesaver.html'>Operation Life Saver</a></li>")
document.write("<li><a href='members/members-index.html'>Members Only</a></li>")
document.write("</ul></li>")

document.write("<li><a href='aboutus.html'>About Us</a>")
document.write("<ul>")
document.write("<li><a href='aboutus.html'>Introduction</a></li>")
document.write("<li><a href='join.html'>Join</a></li>")
document.write("<li><a href='aboutus.html#hours_directions'>Hours &amp; Directions</a></li>")
document.write("<li><a href='javascript:void(0)' onclick=\"popupWin('demographics.html','membership','423','320','nonav')\">Membership</a></li>")
document.write("<li><a href='#' title='Management'>Management</a>")
document.write("<ul>")
document.write("<li><a href='javascript:void(0)' onclick=\"popupWin('boardofdirectors.html','bod','423','260','nonav')\">Directors</a></li>")
document.write("<li><a href='javascript:void(0)' onclick=\"popupWin('officers.html','officers','425','440','nonav')\">Officers</a></li>")
document.write("<li><a href='javascript:void(0)' onclick=\"popupWin('superintendents.html','supers','430','280','nonav')\">Superintendents</a></li>")
document.write("</ul></li>")
document.write("<li><a href='AMRS documents/AMRS Constitution Rev 3.4.pdf' target='_blank' >Constitution</a></li>")
document.write("<li><a href='AMRS documents/AMRS BY-LAWS Rev 1.2.pdf' target='_blank'>By Laws</a></li>")
document.write("<li><a href='parkhistory.html'>RR Park History</a></li>")
document.write("</ul></li>")

document.write("<li><a href='divisions.html'>Divisions</a>")
document.write("<ul>")
document.write("<li><a href='divisions.html'>Introduction</a></li>")
document.write("<li><a href='g_scale.html'>G Scale</a></li>")
document.write("<li><a href='ho_scale.html'>HO Scale</a><li>")
document.write("<li><a href='n_scale.html'>N Scale</a></li>")
document.write("</ul></li>")

document.write("<li><a href='#'>AMRS News</a>")
document.write("<ul>")
document.write("<li><a href='#'>News Letters</a>")
document.write("<ul>")
document.write("<li><a href='newsletters/newsletter.pdf'>Current Issue</a></li>")
document.write("<li><a href='javascript:void(0)' onclick=\"popupWin('newsletters.html','newsletters','230','340','nonav')\">Back Issues</a></li>")
document.write("</ul></li>")
document.write("<li><a href='#'>News Bulletins</a>")
document.write("<ul>")
document.write("<li><a href='cob-prez-02-01-2010.html' target='_blank'>From Board Chairman & President</a></li>")
document.write("<li><a href='javascript:void(0)' onclick=\"popupWin('N-super-02-01-2010.html','nsuper','800','600','nonav')\">From N Scale Superintendent</a></li>")
document.write("</ul></li>")
document.write("</ul></li>")

document.write("<li><a href='videogallery.html'>Video Gallery</a></li>")

document.write("<li><a href='#'>Photo Gallery</a>")
document.write("<ul>")
document.write("<li><a href='buildingclubhousepics.html'>Club House</a></li>")
document.write("<li><a href='#' title='AMRS Layouts'>Layouts</a>")
document.write("<ul>")
document.write("<li><a href='gscalepics.html'>G Scale</a></li>")
document.write("<li><a href='hoscalepics.html'>HO Scale</a></li>")
document.write("<li><a href='nscalepics.html'>N Scale</a></li>")
document.write("</ul></li>")
document.write("<li><a href='tracksaheadpics.html'>Tracks Ahead</a></li>")
document.write("<li><a href='#'>Special Events</a>")
document.write("<ul>")
document.write("<li><a href='swapmeetpics.html'>Swap Meet</a></li>")
document.write("<li><a href='starlightpics.html'>Starlight Christmas</a></li>")
document.write("<li><a href='scoutpics.html'>Scouts</a></li>")
document.write("</ul></li>")
document.write("</ul></li>")

document.write("<li><a Href='mailto:azmodelrr@gmail.com' title='Send us email'>Contact Us</a></li>")
document.write("</ul>")

// The fsmenu-1.js script file is part of the FreeSytle Menu v1.0RC by Angus Turnbull
// This script and the fsmenu.js script invoked in the <head> of each html file are required to make dropdown menus work on older browers
// such as IE6 and ealier.
//

document.write("<script type='text/javascript' src='java scripts/fsmenu-1.js'></script>")

}  // end makeMenu function


//
//  Function: displayPhotos(photoArray)
//
//	This function creates a table of rows with varying number of photos per row
//	based on the screen resolution.
//
//
//   Passed arguments:  Directory where photos are located
//			An array by reference of photos to display
//

function displayGalleryPhotos(photoDir,photoArray) {

	var k=0;
	var photosPerRow = 6;  // for screen resolution gt. 1400
	if(screen.width > 1024 && screen.width < 1400)
	     photosPerRow = 5;
	if(screen.width > 800 && screen.width <= 1024)
	     photosPerRow = 4;
	if(screen.width <= 800)
	     photosPerRow = 3;

	numberPhotos=photoArray.length;

	document.write("<table id='GalleryPhotos'>");
	for (j=0; j<numberPhotos; )
	{
	   document.write("<tr>");
	   for (i=0; i<photosPerRow; i++)
	   {
		photo = "webimages/"+photoDir+"/"+photoArray[j];
		photoName=photoArray[j];
		photoTitle = "tn_"+photoArray[j];
		tn_photo = "webimages/"+photoDir+"/ThumbNails/tn_"+photoArray[j];
            document.write("<td><a href='"+photo+"'> <img src='"+tn_photo+"' title='"+photoName+"' alt='"+photoTitle+"' ></a></td>");
	      j++;
	   }
	   document.write("</tr>");
	   k=numberPhotos-j;
	   if(k<photosPerRow)
		photosPerRow=k;
		
	}
	document.write("</table>");

}  // end displayPhotos function

//
//  Function: galleryCaption(caption)
//
//	This function creates a caption for a table whose "ID" is GalleryPhotos.
//	The caption is passed to this function.  The rest of the caption is internal
//	to this function.
//
//

function galleryCaption(caption){
    var caption2 = '<p>The pictures below are thumbnail pictures. Click on them to get a larger image. If you see a magnifying glass with a "+" as the cursor, the picture can be expanded. Use the browser "back" feature to return to the thumbnails.</p>'
    var x=document.getElementById('GalleryPhotos').createCaption()
    x.innerHTML=caption+caption2
}

//
//  Function: buildvideoGallery(videoArray,width,height)
//
//	This function creates a table of rows with varying number of videos per row
//	based on the screen resolution.
//
//
//   Passed arguments:  An array by reference of youtube video keys
//

function buildvideoGallery(videokeyArray,width,height) {

	var k=0;
	var videosPerRow = 3;  // for screen resolution gt. 1400
	if(screen.width <= 800)
	     videosPerRow = 2;

	numbervideos=videokeyArray.length;

	document.write("<table id='Galleryvideos' align='center'>");
	for (j=0; j<numbervideos; )
	{
	   document.write("<tr>");
	   for (i=0; i<videosPerRow; i++)
	   {
	     videokey = videokeyArray[j];
             document.write("<td>");
	     document.write('<object width="'+width+'" height="'+height+'">')
	     document.write('<param name="movie" value="http://www.youtube-nocookie.com/v/'+videokeyArray[j]+'&hl=en_US&fs=1&rel=0&color1=0x006699&color2=0x54abd6&border=1"></param>')
	     document.write('<param name="allowFullScreen" value="true"></param>')
	     document.write('<param name="allowscriptaccess" value="always"></param>')
	     document.write('<param name="wmode" value="transparent"/>')
	     document.write('<embed src="http://www.youtube-nocookie.com/v/'+videokeyArray[j]+'&hl=en_US&fs=1&rel=0&color1=0x006699&color2=0x54abd6&border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="'+width+'" height="'+height+'"></embed>')
	     document.write('</object>')
             document.write("</td>");
	     j++;
	   }
	   document.write("</tr>");
	   k=numbervideos-j;
	   if(k<videosPerRow)
		videosPerRow=k;
		
	}
	document.write("</table>");

}  // end buildvideoGallery function
