// This code was originally authored by Jason Williams (jlwil@mit.edu)
//  and provided to Mario Valenti (valenti@mit.edu) for use.  


// This function creates a menu where each item is a list item in an unordered list
function ulmenu(menuItems) {
	document.write("<ul>\n");
	for (n = 0; n < menuItems.length; n++) {
  	document.write('<li><a href="' + menuItems[n][1] + '">' + menuItems[n][0] + '</a></li>\n');
	}
	document.write("</ul>\n");
}

// This function creates a menu where each item is in its own paragraph, such as the announcements
function pmenu(menuItems) {
	document.write("<p>\n");
	for (n = 0; n < menuItems.length; n++) {
  	document.write(menuItems[n][0] + ' <a href="' + menuItems[n][1] + '">more...</a>\n');
	}
	document.write("</p>\n");
}

// This function creates a horizonal menu such as the quick links menu
function horzmenu(menuItems) {
	for (n = 0; n < menuItems.length; n++) {
  	document.write('<a href="' + menuItems[n][1] + '">' + menuItems[n][0] + '</a>');
		if (n < menuItems.length - 1)
		  document.write(' | \n');
	}
	document.write("\n");
}

// This function creates the common navigation elements for each page
function commonnav(leftNavMenu,announceMenu,quickLinksMenu) {
  document.write('<div id="leftnav">\n');
  document.write('  <div id="sectionLinks">\n');
  ulmenu(leftNavMenu);
  document.write('</div>\n');
  document.write('<h3> </h3>\n');
  document.write('<h3> </h3>\n');  
  document.write('<center><a href="http://acl.mit.edu/"><img src="images/acl_blue.jpg" width="100" height="50" border="0"></a></center>\n');
  document.write('<h3> </h3>\n');  
  document.write('<center><a href="http://web.mit.edu/"><img src="images/mit-blackred-footer3.gif" border="0"></a></center>\n');  
  document.write('</div>\n');
	
//  document.write('  <div id="headlines"><h3>Recent Highlights</h3> \n');
//  pmenu(announceMenu);
  document.write('</div>\n');
  document.write('</div>\n');

/*
  document.write('<div id="globalNav"><strong>Quick links:</strong> ');
	horzmenu(quickLinksMenu);	
  document.write('</div>\n');
*/
  document.write('<div id="footer">\n');
  document.write('<table><tr>\n');
  document.write('<td><a href="http://web.mit.edu/"><img src="images/mit-blackred-footer3.gif" border="0"></a></td>\n');
  document.write('<td><a href="http://web.mit.edu/">Massachusetts Institute of Technology</a> | \n');
  document.write('<a href="http://acl.mit.edu/">Aerospace Controls Laboratory</a> | \n');
  document.write('<a href="http://vertol.mit.edu/">Autonomous UAV Aerobatics Project</a><br> \n');
  document.write('<a href="http://whereis.mit.edu/map-jpg?mapterms=33-336">77 Massachusetts Ave, Rm 33-336, Cambridge MA 02139</a><br>\n');
  document.write('<a href="contactus.html">Contact us</a></td>\n');
  document.write('</tr></table>\n');
  document.write('</div>\n');
}

// This function creates a gallery of thumbnail images
var galleryarray;
function drawgallery() {
	for (n = 0; n < galleryarray.length; n++) {
		if (galleryarray[n].length > 0) {
      document.write('<div class="galimg"><table><tr><td><a href="large.html?');
  		document.write(galleryarray[n][0]);
	  	document.write('">\n');
			document.write('<img src="');
			document.write(galleryarray[n][1]);
	  	document.write('"></a></td></tr></table>\n</div>\n');
		}
	}
}

// This function is called in the header of the file which displays a large image
function gallargehead() {
	// Interpret image name
	if (self.location.search)
	  imgname = self.location.search.substring(1);
  // Set image as background
	document.write('<style>\n');
	document.write('body { background-image: url(' + imgname + '); }\n');
	document.write('</style>');
	// Preload image
	imgpreload = new Image();
	imgpreload.src = imgname;
	// Find image in gallery list
	for (n = 0; n < galleryarray.length; n++)
		if (galleryarray[n][0] == imgname) break;
	// If image was found
	if (galleryarray[n][0] == imgname) {
		// Set link to previous image
		if (n > 0 && galleryarray[n-1].length > 0) {
			previmg = galleryarray[n-1][0];
			prevpreload = new Image();
			prevpreload.src = previmg;
			previmg = "large.html?" + previmg;
		}
		// Set link to previous image
		if (n+1 < galleryarray.length && galleryarray[n+1].length > 0) {
			nextimg = galleryarray[n+1][0];
			nextpreload = new Image();
			nextpreload.src = nextimg;
			nextimg = "large.html?" + nextimg;
		}
	}
}

// This function creates the controls for the large image display
function gallargecontrols() {
	// Link to previous image
	if (previmg.length > 0) document.write('<a href="javascript:location.replace(previmg)">');
  document.write('&lt;&lt; previous image');
	if (previmg.length > 0) document.write('</a>');
  // Link to save current image
	document.write(' | <a href="' + imgname + '"> save/print image </a> | ');
  // Link to next image
	if (nextimg.length > 0) document.write('<a href="javascript:location.replace(nextimg)">');
	document.write('next image &gt;&gt;</a>');
	if (nextimg.length > 0) document.write('</a>');
}
