Index: trunk/cic-hcap/perllib/plugins/CICPlug.pm
===================================================================
--- trunk/cic-hcap/perllib/plugins/CICPlug.pm	(revision 11909)
+++ trunk/cic-hcap/perllib/plugins/CICPlug.pm	(revision 11912)
@@ -231,6 +231,6 @@
 
     # Create a document object for each institution
-    my %institution_state_to_names_mapping;
-    my %institution_name_to_id_mapping;
+    my %institution_id_to_name_mapping;
+    my %institution_state_to_ids_mapping;
     while (my $row_hashref = $institution_sql_handle->fetchrow_hashref) {
 	# Skip any institutions that didn't respond
@@ -353,14 +353,14 @@
 	# Build mappings for creating the static macrofiles
 	my $institution_name = $row_hashref->{"Institution_Name"};
-	$institution_name_to_id_mapping{$institution_name} = $institution_doc_obj->get_OID();
+	$institution_id_to_name_mapping{$institution_doc_obj->get_OID()} = $institution_name;
 	my $institution_state = $row_hashref->{"State"};
-	push(@{$institution_state_to_names_mapping{$institution_state}}, $institution_name);
+	push(@{$institution_state_to_ids_mapping{$institution_state}}, $institution_doc_obj->get_OID());
     }
 
     # Write the institutions.dm macrofile
-    &write_static_browser_macrofile("institutions", \%institution_name_to_id_mapping);
+    &write_static_browser_macrofile("institutions", \%institution_id_to_name_mapping);
 
     # Write the states.dm macrofile
-    &write_state_browser_macrofile("states", \%institution_state_to_names_mapping, \%institution_name_to_id_mapping);
+    &write_state_browser_macrofile("states", \%institution_state_to_ids_mapping, \%institution_id_to_name_mapping);
 }
 
@@ -427,9 +427,9 @@
 
     # Create a document object for each place
-    my %place_type_to_names_mapping;
-    my %place_style_to_names_mapping;
-    my %place_date_to_names_mapping;
-    my %place_function_to_names_mapping;
-    my %place_name_to_id_mapping;
+    my %place_type_to_ids_mapping;
+    my %place_style_to_ids_mapping;
+    my %place_date_to_ids_mapping;
+    my %place_function_to_ids_mapping;
+    my %place_id_to_name_mapping;
     my %place_id_to_institution_name_mapping;
     while (my $row_hashref = $place_sql_handle->fetchrow_hashref) {
@@ -491,5 +491,5 @@
 	while (my $place_styles_match_hashref = $place_styles_sql_handle->fetchrow_hashref()) {
 	    my $place_style = $place_styles_match_hashref->{"Architectural_Classification"};
-	    push(@{$place_style_to_names_mapping{$place_style}}, $place_name);
+	    push(@{$place_style_to_ids_mapping{$place_style}}, $place_doc_obj->get_OID());
 	    &new_metadata_entry($place_doc_obj, "Style", $place_style);
 	}
@@ -516,5 +516,5 @@
 	    elsif ($place_construction_date_value < 1995) { $place_time_period = "1945-1995"; }
 	    else { $place_time_period = "post-1995"; }
-	    push(@{$place_date_to_names_mapping{$place_time_period}}, $place_name);
+	    push(@{$place_date_to_ids_mapping{$place_time_period}}, $place_doc_obj->get_OID());
 	}
 	&new_metadata_entry($place_doc_obj, "Time_period", $place_time_period);
@@ -557,5 +557,5 @@
 	    $place_function =~ s/\s*$//;
 	    next if ($place_function eq "");
-	    push(@{$place_function_to_names_mapping{$place_function}}, $place_name);
+	    push(@{$place_function_to_ids_mapping{$place_function}}, $place_doc_obj->get_OID());
 	}
 	&new_metadata_entry($place_doc_obj, "Functions", $place_functions);
@@ -615,12 +615,12 @@
 
 	# Build mappings for creating the static macrofiles
-	$place_name_to_id_mapping{$place_name} = $place_doc_obj->get_OID();
-	push(@{$place_type_to_names_mapping{$place_type}}, $place_name);
-    }
-
-    &write_bilevel_static_browser_macrofile("types", \%place_type_to_names_mapping, \%place_name_to_id_mapping, \%place_id_to_institution_name_mapping);
-    &write_bilevel_static_browser_macrofile("styles", \%place_style_to_names_mapping, \%place_name_to_id_mapping, \%place_id_to_institution_name_mapping);
-    &write_bilevel_static_browser_macrofile("dates", \%place_date_to_names_mapping, \%place_name_to_id_mapping, \%place_id_to_institution_name_mapping);
-    &write_bilevel_static_browser_macrofile("functions", \%place_function_to_names_mapping, \%place_name_to_id_mapping, \%place_id_to_institution_name_mapping);
+	$place_id_to_name_mapping{$place_doc_obj->get_OID()} = $place_name;
+	push(@{$place_type_to_ids_mapping{$place_type}}, $place_doc_obj->get_OID());
+    }
+
+    &write_bilevel_static_browser_macrofile("types", \%place_type_to_ids_mapping, \%place_id_to_name_mapping, \%place_id_to_institution_name_mapping);
+    &write_bilevel_static_browser_macrofile("styles", \%place_style_to_ids_mapping, \%place_id_to_name_mapping, \%place_id_to_institution_name_mapping);
+    &write_bilevel_static_browser_macrofile("dates", \%place_date_to_ids_mapping, \%place_id_to_name_mapping, \%place_id_to_institution_name_mapping);
+    &write_bilevel_static_browser_macrofile("functions", \%place_function_to_ids_mapping, \%place_id_to_name_mapping, \%place_id_to_institution_name_mapping);
 }
 
@@ -897,10 +897,10 @@
 {
     my $static_browser_package_name = shift(@_);
-    my $name_to_id_mapping = shift(@_);
+    my $id_to_name_mapping = shift(@_);
 
     my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_name.dm";
     print STDERR "Writing $static_browser_macrofile_path...\n";
     open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
-    &write_static_browser_macros($static_browser_package_name, $name_to_id_mapping);
+    &write_static_browser_macros($static_browser_package_name, $id_to_name_mapping);
     close(BROWSER_MACROFILE);
 }
@@ -910,5 +910,5 @@
 {
     my $static_browser_package_name = shift(@_);
-    my $name_to_id_mapping = shift(@_);
+    my $id_to_name_mapping = shift(@_);
     my $id_to_extra_mapping = shift(@_);
 
@@ -916,13 +916,14 @@
     print BROWSER_MACROFILE "_cicstaticbrowser_ {\n";
 
-    my %letter_to_names_mapping;
-    foreach my $name (keys %$name_to_id_mapping) {
+    my %letter_to_ids_mapping;
+    foreach my $id (keys %$id_to_name_mapping) {
+	my $name = $id_to_name_mapping->{$id};
 	my ($letter) = ($name =~ /([A-Za-z0-9])/);
-	push(@{$letter_to_names_mapping{$letter}}, $name);
+	push(@{$letter_to_ids_mapping{$letter}}, $id);
     }
 
     print BROWSER_MACROFILE "<center><b>";
     foreach my $letter (split(//, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
-	if (defined($letter_to_names_mapping{$letter})) {
+	if (defined($letter_to_ids_mapping{$letter})) {
 	    print BROWSER_MACROFILE "<a href=\"#$letter\">$letter</a>&nbsp;";
 	}
@@ -934,7 +935,7 @@
 
     print BROWSER_MACROFILE "<table cellpadding=\"0\" cellspacing=\"0\" width=\"_pagewidth_\">\n";
-    foreach my $letter (sort(keys %letter_to_names_mapping)) {
-	my @letter_names = sort(@{$letter_to_names_mapping{$letter}});
-	&write_static_browser_macros_chunk($letter, \@letter_names, $name_to_id_mapping, $id_to_extra_mapping);
+    foreach my $letter (sort(keys %letter_to_ids_mapping)) {
+	my @letter_ids = @{$letter_to_ids_mapping{$letter}};
+	&write_static_browser_macros_chunk($letter, \@letter_ids, $id_to_name_mapping, $id_to_extra_mapping);
     }
     print BROWSER_MACROFILE "</table>\n";
@@ -947,17 +948,17 @@
 {
     my $chunk_title = shift(@_);
-    my $chunk_names_ref = shift(@_);
-    my $name_to_id_mapping = shift(@_);
+    my $chunk_ids_ref = shift(@_);
+    my $id_to_name_mapping = shift(@_);
     my $id_to_extra_mapping = shift(@_);
 
     print BROWSER_MACROFILE "<tr><td width=\"50%\"><br /><a name=\"$chunk_title\"/><span style=\"color: black;\"><b>$chunk_title</b></span></td><td width=\"50%\"></td></tr>\n";
 
-    my @chunk_names = @{$chunk_names_ref};
-    my $half_point = ((scalar(@chunk_names) % 2 == 0) ? scalar(@chunk_names) / 2 : (scalar(@chunk_names) + 1) / 2);
+    my @chunk_ids = @{$chunk_ids_ref};
+    my $half_point = ((scalar(@chunk_ids) % 2 == 0) ? scalar(@chunk_ids) / 2 : (scalar(@chunk_ids) + 1) / 2);
     for (my $i = 0; $i < $half_point; $i++) {
 	print BROWSER_MACROFILE "<tr>";
 
-	my $name = $chunk_names[$i];
-	my $id = $name_to_id_mapping->{$name};
+	my $id = $chunk_ids[$i];
+	my $name = $id_to_name_mapping->{$id};
 	my $extra = "";
 	if (defined($id_to_extra_mapping)) {
@@ -966,7 +967,7 @@
 	print BROWSER_MACROFILE "<td valign=\"top\"><a href=\"_gwcgi_?a=d&d=$id\">$name</a>$extra</td>";
 
-	$name = $chunk_names[$i+$half_point];
-	if (defined($name)) {
-	    $id = $name_to_id_mapping->{$name};
+	$id = $chunk_ids[$i+$half_point];
+	if (defined($id)) {
+	    $name = $id_to_name_mapping->{$id};
 	    $extra = "";
 	    if (defined($id_to_extra_mapping)) {
@@ -987,6 +988,6 @@
 {
     my $static_browser_package_root = shift(@_);
-    my $category_to_names_mapping = shift(@_);
-    my $name_to_id_mapping = shift(@_);
+    my $category_to_ids_mapping = shift(@_);
+    my $id_to_name_mapping = shift(@_);
     my $id_to_extra_mapping = shift(@_);
 
@@ -995,13 +996,13 @@
     open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
 
-    foreach my $category (keys(%{$category_to_names_mapping})) {
+    foreach my $category (keys(%{$category_to_ids_mapping})) {
 	my $static_browser_package_name = $static_browser_package_root . $category;
 	$static_browser_package_name =~ s/\W//g;
 
-	my %name_to_id_mapping_for_category = ();
-	foreach my $name (sort(@{$category_to_names_mapping->{$category}})) {
-	    $name_to_id_mapping_for_category{$name} = $name_to_id_mapping->{$name};
-	}
-	&write_static_browser_macros($static_browser_package_name, \%name_to_id_mapping_for_category, $id_to_extra_mapping);
+	my %id_to_name_mapping_for_category = ();
+	foreach my $id (@{$category_to_ids_mapping->{$category}}) {
+	    $id_to_name_mapping_for_category{$id} = $id_to_name_mapping->{$id};
+	}
+	&write_static_browser_macros($static_browser_package_name, \%id_to_name_mapping_for_category, $id_to_extra_mapping);
     }
 
@@ -1013,6 +1014,6 @@
 {
     my $static_browser_package_name = shift(@_);
-    my $state_to_names_mapping = shift(@_);
-    my $name_to_id_mapping = shift(@_);
+    my $state_to_ids_mapping = shift(@_);
+    my $id_to_name_mapping = shift(@_);
 
     my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_name.dm";
@@ -1023,7 +1024,7 @@
 
     print BROWSER_MACROFILE "<table cellpadding=\"0\" cellspacing=\"0\" width=\"_pagewidth_\">\n";
-    foreach my $state (sort(keys(%{$state_to_names_mapping}))) {
-	my @state_names = sort(@{$state_to_names_mapping->{$state}});
-	&write_static_browser_macros_chunk($state, \@state_names, $name_to_id_mapping, undef);
+    foreach my $state (sort(keys(%{$state_to_ids_mapping}))) {
+	my @state_ids = @{$state_to_ids_mapping->{$state}};
+	&write_static_browser_macros_chunk($state, \@state_ids, $id_to_name_mapping, undef);
     }
     print BROWSER_MACROFILE "</table>\n";
