#include <stdio.h>
#include <string.h>

#define ACTIVE

int main(int argc, char **argv)
{
    FILE *infile, *outfile, *framefile, *thumbfile, *javaframefile, *javathumbfile, *javacornerfile, *description_file, *basehref_file;
    int pictureCount = 0, /* picture count outputs count for pics */
	alternate=1,  /* alternate is used to pack rows of 2 pics each in javathumbfile */
	categoryIdx=0; /* categoryIdx is used to have <a name="1"> for each category of a paris.html file, that paris-thumb.html can reference */

    int description_file_exists = 1,  /* normally, there would be a description */
	basehref_file_exists = 0,       /* by default there is no base href */
	defaulthref_file_exists = 1,    /* by default there is some default href */
	bunch_of_linebreaks=0; /* make it easy to add a bunch of linebreaks */
    
    char *infilename = (char *) malloc(80*sizeof(char)),
	*outfilename = (char *) malloc(80*sizeof(char)),
	*framefilename = (char *) malloc(80*sizeof(char)),
	*thumbfilename = (char *) malloc(80*sizeof(char)),
	*javaframefilename = (char *) malloc(80*sizeof(char)),
	*javathumbfilename = (char *) malloc(80*sizeof(char)),
	*javacornerfilename = (char *) malloc(80*sizeof(char)),
	*description_filename = (char *) malloc(80*sizeof(char)),
	*shades = (char *) malloc(80*sizeof(char)),
	*basehref_filename = (char *) malloc(80*sizeof(char)),
	*picture = (char *) malloc(140*sizeof(char)), /* picture filename ex: "brother" */
	*comment = (char *) malloc(400*sizeof(char)), /* comments on the particular picture */
	*line = (char *) malloc(400*sizeof(char)), /* an entire line fetched */
	*title = (char *) malloc(100*sizeof(char)),
	*next = (char *) malloc(100*sizeof(char)),
	*prev = (char *) malloc(100*sizeof(char)),
	*basehref = (char *) malloc(200*sizeof(char)), 
	*description = (char *) malloc(20000*sizeof(char)), 
	*absolutegallery = (char *) malloc(50*sizeof(char)), 
	*absolutehome = (char *) malloc(50*sizeof(char));
    
    sprintf(absolutegallery, "http://web.mit.edu/manoli/www/gallery");
    sprintf(absolutehome, "http://web.mit.edu/manoli/www/");
   
    if (argc != 3 && argc!=2) {
	printf("usage: make_thumbs <infile-list> <outfile.html>");
	printf("   makes a thumb html file for the docs listed in infile-list");
	printf("Also: make_thumbs <root>");
	printf("   same as: make_thumbs <root/root-list> <root/root.html>");
    }

    if (argc == 3) {
	infilename = argv[1];
	outfilename = argv[2];
    } else {
	strcpy(infilename, argv[1]);
	strcat(infilename, "/");
	strcat(infilename, argv[1]);
	strcat(infilename, "-list");

	strcpy(outfilename, argv[1]);
	strcat(outfilename, "/");
	strcat(outfilename, argv[1]);
	strcat(outfilename, ".html");
 
	strcpy(framefilename, argv[1]);
	strcat(framefilename, "/");
	strcat(framefilename, argv[1]);
	strcat(framefilename, "-frame.html");
 
	strcpy(thumbfilename, argv[1]);
	strcat(thumbfilename, "/");
	strcat(thumbfilename, argv[1]);
	strcat(thumbfilename, "-thumbs.html");
 
	strcpy(javaframefilename, argv[1]);
	strcat(javaframefilename, "/");
	strcat(javaframefilename, argv[1]);
	strcat(javaframefilename, "-javaframe.html");
 
	strcpy(javathumbfilename, argv[1]);
	strcat(javathumbfilename, "/");
	strcat(javathumbfilename, argv[1]);
	strcat(javathumbfilename, "-javathumbs.html");
 
	strcpy(javacornerfilename, argv[1]);
	strcat(javacornerfilename, "/");
	strcat(javacornerfilename, argv[1]);
	strcat(javacornerfilename, "-javacorner.html");
 
	strcpy(basehref_filename, argv[1]);
	strcat(basehref_filename, "/");
	strcat(basehref_filename, argv[1]);
	strcat(basehref_filename, "-href");

	strcpy(description_filename, argv[1]);
	strcat(description_filename, "/");
	strcat(description_filename, argv[1]);
	strcat(description_filename, "-description");
    }

    infile = fopen(infilename, "r");
    if (infile==NULL) {
	fprintf(stderr, "can't open file %s for reading\n", infilename);
	exit(0);
    }

    outfile = fopen(outfilename, "w");
    if (outfile==NULL) {
	fprintf(stderr, "can't open file %s for writing\n", outfilename);
	exit(0);
    }

    thumbfile = fopen(thumbfilename, "w");
    if (thumbfile==NULL) {
	fprintf(stderr, "can't open file %s for writing\n", thumbfilename);
	exit(0);
    }

    framefile = fopen(framefilename, "w");
    if (framefile==NULL) {
	fprintf(stderr, "can't open file %s for writing\n", framefilename);
	exit(0);
    }

    javathumbfile = fopen(javathumbfilename, "w");
    if (javathumbfile==NULL) {
	fprintf(stderr, "can't open file %s for writing\n", javathumbfilename);
	exit(0);
    }

    javacornerfile = fopen(javacornerfilename, "w");
    if (javacornerfile==NULL) {
	fprintf(stderr, "can't open file %s for writing\n", javacornerfilename);
	exit(0);
    }

    javaframefile = fopen(javaframefilename, "w");
    if (javaframefile==NULL) {
	fprintf(stderr, "can't open file %s for writing\n", javaframefilename);
	exit(0);
    }

    description_file = fopen(description_filename, "r");
    if (description_file==NULL) {
	fprintf(stderr, "No description for %s. Create a %s file\n", argv[1], description_filename);
	description_file_exists = 0;
    }

    basehref_file = fopen(basehref_filename, "r");
    if (basehref_file!=NULL) {
	fgets(basehref, 200, basehref_file);
	basehref[strlen(basehref)-1]='\0';
	fprintf(stderr, "Using base href %s in file %s.\n", basehref, basehref_filename);
	basehref_file_exists = 1;
    } else {
	strcpy(basehref_filename, "/afs/athena.mit.edu/user/m/a/manoli/www/gallery/gallery-href");
	basehref_file = fopen(basehref_filename, "r");
	if (basehref_file!=NULL) {
	    fgets(basehref, 200, basehref_file);
	    basehref[strlen(basehref)-1]='\0';
	    /* fprintf(stderr, "Using default base href %s in file %s.\n", basehref, basehref_filename); */
	    defaulthref_file_exists = 1;
	} else {
	    basehref[0]='\0';
	}
    }

    fgets(shades, 100, infile); /* shades contains "Shades of Blue - " */
    shades[strlen(shades)-1]='\0';
    fgets(line, 400, infile); /* line contains "Greece" */
    line[strlen(line)-1]='\0';
    fgets(title, 100, infile); /* title contains "greece" */
    title[strlen(title)-1]='\0';
    fgets(prev, 100, infile); /* prev contains "view" */
    prev[strlen(prev)-1]='\0';
    fgets(next, 100, infile); /* next contains "santorini" */
    next[strlen(next)-1]='\0';

    /* printf("Title is: Manoli's %s%s\n", shades, line); */

    /* create the frames top file */
    fprintf(framefile, "<html>\n<head>\n<title>\nManoli's %s%s\n</title>\n</head>\n", shades, line);

    fprintf(framefile, "<frameset cols=\"181,*\" noresize border=\"NO\" frameborder=0 framespaceing=0 framepadding=0>\n");

    /* create the java frames top file */
    fprintf(javaframefile, "<html>\n<head>\n<title>\nManoli's %s%s\n</title>\n</head>\n", shades, line);
    fprintf(javaframefile, "<frameset cols=\"181,*\" noresize border=\"NO\" frameborder=0 framespaceing=0 framepadding=0>\n");
    fprintf(javaframefile, "<frameset rows=\"108,*\" noresize border=\"NO\" frameborder=0 framespaceing=0 framepadding=0>\n");

    /* create the normal output with description and thumbs */
    fprintf(outfile, "<html>\n<head>\n<title>\nManoli's %s%s</title>\n", shades, line);
   
    /* create the thumbnails only file for the frames version */
    fprintf(thumbfile, "<html>\n<head>\n<title>\nManoli's %s%s - Thumbnails</title>\n", shades, line);

    /* create the java thumbnails file */
    fprintf(javathumbfile, "<html>\n<head>\n<title>\nManoli's %s%s - Java Thumbnails</title>\n", shades, line);

    /* create the java corner file Top corner when no picture is being displayed */
    fprintf(javacornerfile, "<html>\n<head>\n<title>\nManoli's %s%s - Java Corner File\n</title>\n</head>\n", shades, line);
    fprintf(javacornerfile, "<body bgcolor=\"#FFFFFF\" link=\"#000000\" vlink=\"#000000\" alink=\"#880000\">\n");
    /* new version: simply a picture that keeps changing */
    fprintf(javacornerfile, "<a target=\"main\" href=\"%s/%s/%s.html\">", absolutegallery, title, title); 
    fprintf(javacornerfile, "<img border=0 name=\"preview\" src=\"%s/thumb/%s.jpg\" width=160 height=108></a>\n", absolutehome, title);
    /*   fprintf(javacornerfile, "<b><font size=+2><a href=\"%s.html\" target=\"main\">%s</a></font></b><br>\n", title, line);
	 fprintf(javacornerfile, "<font size=2><a target=\"_top\" href=\"../%s/%s-javaframe.html\">Next</a> / \n", next, next);
	 fprintf(javacornerfile, "<a target=\"_top\" href=\"../%s/%s-javaframe.html\">Prev</a> / \n", prev, prev);
	 fprintf(javacornerfile, "<a target=\"javathumb\" href=\"%s/java-list.html\">Index</a> / \n", absolutegallery);
	 fprintf(javacornerfile, "<a target=\"_top\" href=\"%s/\">Home</a><br><br>\n", absolutehome);
	 fprintf(javacornerfile, "<a target=\"main\" href=\"%s/trips.html#%s\">Trips-List</a> / \n", absolutehome, title);
	 fprintf(javacornerfile, "<a target=\"_top\" href=\"%s/gallery.html\">Gallery</a> / \n", absolutehome);
	 fprintf(javacornerfile, "<a target=\"_top\" href=\"%s/\">Manoli</a>\n<br>", absolutehome);
	 fprintf(javacornerfile, "<a target=\"_top\" href=\"%s-frame.html\">No Java</a>", title);
	 fprintf(javacornerfile, " / <a target=\"_top\" href=\"%s.html\">No Frames</a></font>", title);
    */
    fprintf(javacornerfile, "</body>\n</html>");

    /*   fprintf(javacornerfile, "<body><b><a href=\"%s.html\" target=\"main\">%s</a></b><br>\n", title, line);
	 fprintf(javacornerfile, "<font size=2><a href=\"%s-frame.html\" target=\"_top\">Frames - no Java</a></font><br>\n", title);
	 fprintf(javacornerfile, "<font size=2><a href=\"%s.html\" target=\"_top\">No Frames</a></font><br>\n", title);
	 fprintf(javacornerfile, "<a href=\"%s/\" target=\"_top\">Manolis</a>\n", absolutehome);
	 fprintf(javacornerfile, "</body>\n</html>\n"); */
    fprintf(framefile, "<frame src=\"%s-thumbs.html\" name=\"thumb\" marginwidth=0 marginheight=0>\n", title);
    fprintf(framefile, "<frame src=\"%s.html\" name=\"main\">\n</frameset>\n</html>\n", title);

    fprintf(javaframefile, "<frame src=\"%s-javacorner.html\" name=\"corner\" marginwidth=0 marginheight=0 scrolling=no>\n", title);
    fprintf(javaframefile, "<frame src=\"%s-javathumbs.html\" name=\"javathumb\" marginwidth=0 marginheight=0>\n</frameset>", title);
    fprintf(javaframefile, "<frame src=\"%s.html\" name=\"main\">\n</frameset>\n</html>\n", title);

    /* grab the base href file */
    if (basehref_file_exists) {
	fprintf(outfile, "<base href=\"%s%s\">\n", basehref, title);
	fprintf(thumbfile, "<base href=\"%s%s\">\n", basehref, title);
	fprintf(javathumbfile, "<base href=\"%s%s\">\n", basehref, title);
    } else if (defaulthref_file_exists) {
	basehref[strlen(basehref)-3]='\0';     
	fprintf(outfile, "%s/%s/\">\n", basehref, title);
	fprintf(thumbfile, "%s/%s/\">\n", basehref, title);
	fprintf(javathumbfile, "%s/%s/\">\n", basehref, title);
	basehref[0]='\0';
    }

    fprintf(outfile, "<script type=\"text/javascript\">\n  var _gaq = _gaq || [];\n  _gaq.push(['_setAccount', 'UA-19575107-1']);\n  _gaq.push(['_trackPageview']);\n  (function() {\n    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n  })();\n</script>\n</head>\n<body bgcolor=\"#FFFFFF\">");
    fprintf(thumbfile, "<base target=\"main\">\n");
    fprintf(thumbfile, "</head>\n<body bgcolor=\"#FFFFFF\">");
    fprintf(javathumbfile, "<base target=\"main\">\n");
    fprintf(javathumbfile, "</head>\n<body bgcolor=\"#FFFFFF\">\n", title);
    fprintf(outfile, "<h1><a href=\"%s/\" target=\"_top\"><font color=\"#000000\">Manoli</font></a>'s %s%s</h1>\n",
	    absolutehome, shades, line);

    /* click on next and load next page. Moreover, based on the context, also loads (javathumbs and corner) or thumbs  */
    fprintf(outfile, "<font size=2><a href=\"%s/%s/%s.html\" ", absolutegallery, next, next);
    fprintf(outfile, "onClick=\"if (parent.list) parent.list.location.href='%s/all.html#%s'; ", absolutegallery, next);
    fprintf(outfile, "if (parent.newgallerythumb && parent.corner) { if (parent.corner.document.forms.daform.sitemenu.selectedIndex==parent.corner.document.forms.daform.sitemenu.length-1) { parent.corner.document.forms.daform.sitemenu.selectedIndex = 0; } else { parent.corner.document.forms.daform.sitemenu.selectedIndex++; } parent.corner.loadFrames(parent.corner.document.forms.daform.sitemenu.options[parent.corner.document.forms.daform.sitemenu.selectedIndex].value, parent.corner.document.forms.daform.viewtype.options[parent.corner.document.forms.daform.viewtype.selectedIndex].value);}");
    fprintf(outfile, "else if (parent.thumb) parent.thumb.location.href='%s/%s/%s-thumbs.html'; ", absolutegallery, next, next);
    fprintf(outfile, "else { if (parent.javathumb) parent.javathumb.location.href='%s/%s/%s-javathumbs.html';", absolutegallery, next, next);
    fprintf(outfile, "       if (parent.corner && parent.javathumb) parent.corner.location.href='%s/%s/%s-javacorner.html'; } \">Next</a> / \n", absolutegallery, next, next); 


    /* click on prev and load previous page. Moreover, based on the context, also loads (javathumbs and corner) or thumbs  */
    fprintf(outfile, "<a href=\"%s/%s/%s.html\" ", absolutegallery, prev, prev);
    fprintf(outfile, "onClick=\"if (parent.list) parent.list.location.href='%s/all.html#%s'; ", absolutegallery, prev);
    fprintf(outfile, "if (parent.newgallerythumb && parent.corner) { if (parent.corner.document.forms.daform.sitemenu.selectedIndex==0) { parent.corner.document.forms.daform.sitemenu.selectedIndex = parent.corner.document.forms.daform.sitemenu.length-1; } else { parent.corner.document.forms.daform.sitemenu.selectedIndex--; } parent.corner.loadFrames(parent.corner.document.forms.daform.sitemenu.options[parent.corner.document.forms.daform.sitemenu.selectedIndex].value, parent.corner.document.forms.daform.viewtype.options[parent.corner.document.forms.daform.viewtype.selectedIndex].value);}");
    fprintf(outfile, "if (parent.thumb) parent.thumb.location.href='%s/%s/%s-thumbs.html'; ", absolutegallery, prev, prev);
    fprintf(outfile, "else { if (parent.javathumb) parent.javathumb.location.href='%s/%s/%s-javathumbs.html';", absolutegallery, prev, prev);
    fprintf(outfile, "       if (parent.corner && parent.javathumb) parent.corner.location.href='%s/%s/%s-javacorner.html'; } \">Prev</a> / \n", absolutegallery, prev, prev); 

    /*   fprintf(outfile, "<a href=\"%s/%s/%s.html\" ", absolutegallery, prev, prev);
	 fprintf(outfile, "onClick=\"if (parent.list) parent.list.location.href='%s/all.html#%s'; ", absolutegallery, prev); 
	 fprintf(outfile, "if (parent.thumb) parent.location.replace('%s/%s/%s-frame.html');\">Prev</a> / \n", absolutegallery, prev, prev); 
    */

    fprintf(outfile, "<a target=\"_top\" href=\"%s/\">Home</a>", absolutehome);
    fprintf(outfile, " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(alternate views: ", absolutehome); 
    fprintf(outfile, "<a target=\"_top\" href=\"%s/%s/%s-frame.html\">SmallFrame</a>", absolutegallery, title, title);  
    fprintf(outfile, " / <a target=\"_top\" href=\"%s/%s/%s-javaframe.html\">MiniFrame</a>", absolutegallery, title, title);  
    fprintf(outfile, " / <a target=\"_top\" href=\"%s/%s/%s.html\">NoFrame</a>", absolutegallery, title, title);  
    fprintf(outfile, ")</font><br>", absolutehome); 

    fprintf(thumbfile, "<a href=\"%s/%s/%s.html\"><font size=+2><b>%s</b></font></a><br>\n", absolutegallery, title, title, line);
    fprintf(thumbfile, "<font size=2><a target=\"_top\" href=\"%s/%s/%s-frame.html\">Next</a> / \n", absolutegallery, next, next);
    fprintf(thumbfile, "<a target=\"_top\" href=\"%s/%s/%s-frame.html\">Prev</a> / \n", absolutegallery, prev, prev);
    fprintf(thumbfile, "<a target=\"_top\" href=\"%s/\">Home</a></font><br>\n", absolutehome);
    
    /* javathumbfile: no text for */
   
    /* printf("Append the following to: all.html"); */
    printf("\n\n<a name=\"%s\"><h2><a href=\"%s/%s/%s.html\" onClick='moveMenu(\"%s/all.html#%s\")'>%s</a></h2>\n",
	   title, absolutegallery, title, title, absolutegallery, title, line);

#ifdef INACTIVE   

    /*   fprintf(outfile, "<font color=\"#FF0000\" size=-1>Please note: the images below might not load today (Monday, May 17).  My page has been overloaded with 100+ hits an hour, and since all the pictures are now being downloaded off my home PC, my FTP server often refuses connections. Please check back tomorrow if you want faster access to all my wonderful pictures. :o) Thanks!\n</font></P>"); */

    /*fprintf(outfile, "<p><font color=\"#0000FF\" size=-1>My image gallery is partially shut down (since Feb 28, 2000).  I'm trying to hook up my FTP computer on the same ethernet jack with a second computer, and i need some hardware.  As soon as i get a hub, the gallery will be back up.  In the meantime, the thumbnails are still available, but no larger version of the pictures exists.  Come back soon (in say a week), for 130MB of 800x600 pictures. In the meantime, have a wonderful beginning of spring!</font></p>");*/

    fprintf(outfile, "<p><font color=\"#0000FF\" size=-1>My image gallery is temporarily down (as of Dec 23rd, 2001).  I'm unable to log onto the account where all the pictures reside.  In the meantime, the thumbnails are still available, but no larger version of the pictures exists.  Come back soon (maybe after the new year), for 130MB of 800x600 pictures.  In the meantime, have a wonderful holiday season</font></p>");

#endif

    if (description_file_exists) {
	/* now open the description file france-description and so on */
	fprintf(outfile, "<p>\n");
	while (fgets(description, 20000, description_file)) {
	    fprintf(outfile, "%s", description);
	}
	fprintf(outfile, "\n</p>");
    }

    alternate=0; /* alternate between 0 and 1 */
    fprintf(javathumbfile, "<nobr>");

    while (fgets(line, 400, infile)) {
	line[strlen(line)-1]='\0';
	if (strlen(line) != 0) {
	    if (line[0]!='#') {
		pictureCount++;

		/* separate the non-whitespace text = name from the rest = comment 
		   in other words: 
		   jury - the supernice jury
		   jury -> becomes the name of the file
		   the supernice jury -> becomes the comment of the file
		*/
		comment = strstr(line, " - ");
		if (comment != NULL) { 
		    comment[0] = '\0';
		    comment = comment + 3;
		    strcpy(picture, line);
		} else {
		    comment = (char *) malloc(400*sizeof(char));
		    strcpy(comment, line);
		}

		/* fprintf(stderr, "Line: \"%s\" and comment: \"%s\"\n", line, comment); */

		printf("<li><a href=\"%s%s/%s.jpg\">%s</a></li>\n", basehref, title, line, line);
#ifdef INACTIVE
		fprintf(outfile, "<img \nsrc=\"%s/%s/thumb/%s.jpg\" border=0 alt=\"%s\">", absolutegallery, title, line, comment);
#else
		fprintf(outfile, "<a href=\"%s.jpg\"><img border=0 src=\"%s/%s/thumb/%s.jpg\" height=120 alt=\"%s\"></a>\n", line, absolutegallery, title, line, comment);
#endif
		fprintf(thumbfile, "<a \nhref=\"%s.jpg\"><img src=\"%s/%s/thumb/%s.jpg\" border=0 alt=\"%s\"></a><br>",
			line, absolutegallery, title, line, comment);
		fprintf(javathumbfile, "<a \nonMouseOver=\"if (parent.corner.document.images) parent.corner.document.images.preview.src='%s/%s/thumb/%s.jpg';\"\n", absolutegallery, title, line);
		/* FIX IT: the line above has hardcoded the graphics account: unmovable */
		fprintf(javathumbfile, "onMouseOut=\"if (parent.corner.document.images) ");
		fprintf(javathumbfile, "parent.corner.document.images.preview.src='%s/thumb/%s.jpg';\"\n", absolutehome, title);
		fprintf(javathumbfile, "href=\"%s.jpg\"><img width=80 height=54 src=\"%s/%s/thumb/%s.jpg\" border=0 alt=\"%s\"></a>",
			line, absolutegallery, title, line, comment);
		if (alternate) fprintf(javathumbfile, "</nobr><br><nobr>");
		if (alternate) alternate=0; else alternate=1;
	    } else {
		/* handling a comment line */
		fprintf(stderr, "  Skip: %s\n", line);
	    }
	} else {
	    /* the line has zero length.  We're starting a new category. */
	    categoryIdx++; 
	    fgets(line, 400, infile);
	    line[strlen(line)-1]='\0';
	    printf("<a href=\"%s/%s/%s.html#%i\"><br><font color=\"#000000\"><b>%s</b></font></a>\n", absolutegallery, title, title, categoryIdx, line);
	    fprintf(outfile, "<a name=\"%i\"><h3>%s</h3></a>\n", categoryIdx, line);
	    fprintf(thumbfile, "<a href=\"%s/%s/%s.html#%i\"><font size=+1><b>%s</b></font></a><br>\n", absolutegallery, title, title, categoryIdx, line);
	    if (alternate) { fprintf(javathumbfile, "<br>", line); 
	    alternate=0; }
	    fprintf(javathumbfile, "<a href=\"%s/%s/%s.html#%i\"><font size=2><b>%s</b></font></a><br>", absolutegallery, title, title, categoryIdx, line); 
	}
    }
    fprintf(stderr, "%s has %i pictures\n", title, pictureCount);
    fprintf(outfile, "<hr><i>Manoli's Trips... ", title); 

    /* click on next and load next page. Moreover, based on the context, also loads (javathumbs and corner) or thumbs  */
    fprintf(outfile, "<a href=\"%s/%s/%s.html\" ", absolutegallery, next, next);
    fprintf(outfile, "onClick=\"if (parent.list) parent.list.location.href='%s/all.html#%s'; ", absolutegallery, next);
    fprintf(outfile, "if (parent.thumb) parent.thumb.location.href='%s/%s/%s-thumbs.html'; ", absolutegallery, next, next);
    fprintf(outfile, "else { if (parent.javathumb) parent.javathumb.location.href='%s/%s/%s-javathumbs.html';", absolutegallery, next, next);
    fprintf(outfile, "if (parent.corner) parent.corner.location.href='%s/%s/%s-javacorner.html'; } \">Next</a> / \n", absolutegallery, next, next); 

    /* click on prev and load previous page. Moreover, based on the context, also loads (javathumbs and corner) or thumbs  */
    fprintf(outfile, "<a href=\"%s/%s/%s.html\" ", absolutegallery, prev, prev);
    fprintf(outfile, "onClick=\"if (parent.list) parent.list.location.href='%s/all.html#%s'; ", absolutegallery, prev);
    fprintf(outfile, "if (parent.thumb) parent.thumb.location.href='%s/%s/%s-thumbs.html'; ", absolutegallery, prev, prev);
    fprintf(outfile, "else { if (parent.javathumb) parent.javathumb.location.href='%s/%s/%s-javathumbs.html';", absolutegallery, prev, prev);
    fprintf(outfile, "if (parent.corner) parent.corner.location.href='%s/%s/%s-javacorner.html'; } \">Prev</a> / \n", absolutegallery, prev, prev); 

    /*   fprintf(outfile, "<a href=\"%s/%s/%s.html\" ", absolutegallery, next, next);
	 fprintf(outfile, "onClick=\"if (parent.list) parent.list.location.href='%s/all.html#%s'; ", absolutegallery, next);
	 fprintf(outfile, "if (parent.thumb) parent.thumb.location.href='%s/%s/%s-thumbs.html';\">Next</a> - \n", absolutegallery, next, next); 

	 fprintf(outfile, "<a href=\"%s/%s/%s.html\" ", absolutegallery, prev, prev);
	 fprintf(outfile, "onClick=\"if (parent.list) parent.list.location.href='%s/all.html#%s'; ", absolutegallery, prev); 
	 fprintf(outfile, "if (parent.thumb) parent.location.replace('%s/%s/%s-frame.html');\">Prev</a> - \n", absolutegallery, prev, prev); 
    */
    fprintf(outfile, "<a href=\"%s/trips.html#%s\" ", absolutehome, title); 
    fprintf(outfile, "onClick=\"if (parent.list) parent.list.location.href='%s/all.html#%s';\">Trips List</a> - \n", absolutegallery, title); 
    fprintf(outfile, "<a target=\"_top\" href=\"%s/\">Manolis Kellis</a></i>", absolutehome); 
    fprintf(outfile, " (<img height=20 valign=center src=\"http://stuff.mit.edu/cgi/counter/manoli\"> hits, ", absolutehome); 
    fprintf(outfile, " <img height=20 valign=center src=\"http://stuff.mit.edu/cgi/perday/manoli\"> per day)", absolutehome); 

    fprintf(thumbfile, "<hr><a target=\"_top\" href=\"%s/%s/%s-frame.html\">Next</a> - \n", absolutegallery, next, next); 
    fprintf(thumbfile, "<a target=\"_top\" href=\"%s/%s/%s-frame.html\">Prev</a> - \n", absolutegallery, prev, prev); 
    fprintf(thumbfile, "<a target=\"_top\" href=\"%s/\">Home</a>", absolutehome); 
    if (alternate) fprintf(javathumbfile, "<br>");
    fprintf(javathumbfile, "<font size=2><a target=\"_top\" href=\"%s/%s/%s-javaframe.html\">Next</a> - \n", absolutegallery, next, next); 
    fprintf(javathumbfile, "<a target=\"_top\" href=\"%s/%s/%s-javaframe.html\">Prev</a> - \n", absolutegallery, prev, prev); 
    fprintf(javathumbfile, "<a target=\"_top\" href=\"%s/\">Home</a></font>", absolutehome); 
    fprintf(outfile, "</body>\n</html>\n");
    fprintf(thumbfile, "</body>\n</html>\n");
    fprintf(javathumbfile, "</body>\n</html>\n");

    /* in greece/greece.html add a bunch of line breaks and a zephyr warning when page is visited */
    for (bunch_of_linebreaks=0; bunch_of_linebreaks<80; bunch_of_linebreaks++) fprintf(outfile, "\n");
    fprintf(outfile, "<body background=\"http://www.mit.edu/zwrite?from=a+websurfer&to=manoli&body=Someone%%27s+visiting+http%%3A%%2F%%2Fweb.mit.edu%%2Fmanoli%%2Fwww%%2F%%40bold%%5Bgallery%%2F%s%%5D%%2F%s.html\">", title, title);
    for (bunch_of_linebreaks=0; bunch_of_linebreaks<80; bunch_of_linebreaks++) fprintf(outfile, "\n"); 

}
