        var notIE6 = (!/MSIE (5\.5|6\.)/.test(navigator.userAgent) || (event && !/(background|src)/.test(event.propertyName)));
        var googleZoomLevelCount = 17;
        var zoomLevelCount = 15;
        var zoomBarScaleHeight = 150;
        var sliderCursorOffset = -7;
        var zoomBarScaleOffset = 40;
        var zoomBarPixelPerZoomLevel = 10;
  
        GScaleControl.prototype.printable=function(){return true};
        function KoremControl() {
        }
        
        KoremControl.prototype = new GControl();
    
        KoremControl.prototype.initialize = function(map) {
          var container = document.createElement("div");

          var zoomIn = document.createElement("img");
          if (notIE6) {
            zoomIn.src = "images/Slider_ZoomIn.png";
          } else {
            zoomIn.src = "images/Slider_ZoomIn.gif";
          }
          zoomIn.style.position = 'absolute';
          zoomIn.style.cursor = "pointer";            
          zoomIn.style.top = "60px";
          zoomIn.style.left = "16px";
          zoomIn.title = mapControlTitleZoomIn;
          //zoomIn.style.behavior = "url(iepngfix.htc)";

          var zoomOut = document.createElement("img");
          if (notIE6) {
            zoomOut.src = "images/Slider_ZoomOut.png";
          } else {
            zoomOut.src = "images/Slider_ZoomOut.gif";
          }
          zoomOut.style.position = 'absolute';
          zoomOut.style.cursor = "pointer";                              
          zoomOut.style.top = "270px";
          zoomOut.style.left = "16px";
          zoomOut.title = mapControlTitleZoomOut;
          //zoomOut.style.behavior = "url(iepngfix.htc)";
         
          var zoomBar = document.createElement("div");
          if (notIE6) {
            zoomBar.style.backgroundImage = "url('images/" + color +  "/Slider_scale.png')";
          } else {
            zoomBar.style.backgroundImage = "url('images/" + color +  "/Slider_scale.gif')";
          }

          zoomBar.style.position = 'absolute';
          zoomBar.style.cursor = "pointer";            
          zoomBar.style.top = "65px";
          zoomBar.style.left = "16px";
          zoomBar.style.width = "30px";
          zoomBar.style.height = "234px";
          //zoomBar.style.behavior = "url(iepngfix.htc)";

          cursor = document.createElement("div");
          if (notIE6) {
            cursor.style.backgroundImage = "url('images/Slider_cursor.png')";
          } else {
            cursor.style.backgroundImage = "url('images/Slider_cursor.gif')";
          }

          cursor.style.position = 'absolute';
          cursor.style.cursor = "pointer";                              
          cursor.style.zIndex = 10;
          cursor.style.width = "30px";
          cursor.style.height = "14px";
          //cursor.style.behavior = "url(iepngfix.htc)";

          var compassContainer = document.createElement("div");
          compassContainer.style.position = 'absolute';
          compassContainer.style.top = "0px";
          
          var compass = document.createElement("img");
          if (notIE6) {
            compass.src = "images/" + color +  "/Compass.png";
          } else {
            compass.src = "images/" + color +  "/Compass.gif";
          }

          compass.style.border = "0px";
          compass.style.position = 'absolute';
          compass.style.cursor = "pointer";                 
          compass.style.width = "63px";
          compass.style.height = "62px";
          //compass.style.behavior = "url(iepngfix.htc)";

          compassContainer.appendChild(compass);

          var topDiv = document.createElement("div");
          topDiv.style.position = 'absolute';
          topDiv.style.top = "2px";
          topDiv.style.left = "22px";
          topDiv.style.cursor = "pointer";
          topDiv.onclick = function() { map.panDirection(0, 1); };
          topDiv.title = mapControlTitleTop;
          if (notIE6) {
            topDiv.innerHTML = "<img src='images/" + color +  "/Compass_Top.png' class='imgFix'>";
          } else {
            topDiv.innerHTML = "<img src='images/" + color +  "/Compass_Top.gif' class='imgFix'>";
          }

          var leftDiv = document.createElement("div");
          leftDiv.style.position = 'absolute';
          leftDiv.style.top = "21px";
          leftDiv.style.left = "3px";
          leftDiv.style.cursor = "pointer";
          leftDiv.onclick = function() { map.panDirection(1, 0); };
          leftDiv.title = mapControlTitleLeft;
          if (notIE6) {
            leftDiv.innerHTML = "<img src='images/" + color +  "/Compass_Left.png' class='imgFix'>";
          } else {
            leftDiv.innerHTML = "<img src='images/" + color +  "/Compass_Left.gif' class='imgFix'>";
          }

          var rightDiv = document.createElement("div");
          rightDiv.style.position = 'absolute';
          rightDiv.style.top = "21px";
          rightDiv.style.left = "41px";
          rightDiv.style.cursor = "pointer";
          rightDiv.onclick = function() { map.panDirection(-1, 0); };
          rightDiv.title = mapControlTitleRight;
          if (notIE6) {
            rightDiv.innerHTML = "<img src='images/" + color +  "/Compass_Right.png' class='imgFix'>";
          } else {
            rightDiv.innerHTML = "<img src='images/" + color +  "/Compass_Right.gif' class='imgFix'>";
          }


          var bottomDiv = document.createElement("div");
          bottomDiv.style.position = 'absolute';
          bottomDiv.style.top = "40px";
          bottomDiv.style.left = "22px";
          bottomDiv.style.cursor = "pointer";
          bottomDiv.onclick = function() { map.panDirection(0, -1); };
          bottomDiv.title = mapControlTitleBottom;
          if (notIE6) {
            bottomDiv.innerHTML = "<img src='images/" + color +  "/Compass_Bottom.png' class='imgFix'>";
          } else {
            bottomDiv.innerHTML = "<img src='images/" + color +  "/Compass_Bottom.gif' class='imgFix'>";
          }

          var initialDiv = document.createElement("div");
          initialDiv.style.position = 'absolute';
          initialDiv.style.top = "21px";
          initialDiv.style.left = "22px";
          initialDiv.style.cursor = "pointer";
          initialDiv.onclick = function() { map.returnToSavedPosition(); };
          initialDiv.title = mapControlTitleInitial;
          if (notIE6) {
            initialDiv.innerHTML = "<img src='images/" + color +  "/Compass_Initial.png' class='imgFix'>";
          } else {
            initialDiv.innerHTML = "<img src='images/" + color +  "/Compass_Initial.gif' class='imgFix'>";
          }

          compassContainer.appendChild(topDiv);
          compassContainer.appendChild(leftDiv);
          compassContainer.appendChild(rightDiv);
          compassContainer.appendChild(bottomDiv);
          compassContainer.appendChild(initialDiv);
          container.appendChild(compassContainer);

          container.appendChild(zoomBar);
          zoomBar.appendChild(cursor);
          container.appendChild(zoomIn);
          container.appendChild(zoomOut);
          
          GEvent.addDomListener(map, "zoomend", function(oldzoom, newzoom) {
              var zoomLevel = newzoom;
              var numberOfZoomLevel = (googleZoomLevelCount - zoomLevel);
              cursor.style.top = Math.round((numberOfZoomLevel * zoomBarPixelPerZoomLevel + zoomBarScaleOffset + sliderCursorOffset)) + "px";
          });
          
          GEvent.addDomListener(zoomIn, "click", function() {
            map.zoomIn();
          });
                   
          GEvent.addDomListener(zoomOut, "click", function() {
            map.zoomOut();
          });          

          var zoomBarDragging = false;
          GEvent.addDomListener(zoomBar, "mousedown", function(e) {
              zoomBarDragging = true;
              var position = Element.cumulativeOffset(zoomBar);
              var minZoomLevelPixel = sliderCursorOffset + zoomBarScaleOffset;
              var maxZoomLevelPixel = sliderCursorOffset + zoomBarScaleOffset + (zoomLevelCount * zoomBarPixelPerZoomLevel);
            
              var top = Event.pointerY(e) - position.top + sliderCursorOffset;
              if (top < minZoomLevelPixel) {
                top = minZoomLevelPixel;
              }
              if (top > maxZoomLevelPixel) {
                top = maxZoomLevelPixel;
              }              
              cursor.style.top = (top) + "px";
          });          

          
          GEvent.addDomListener(cursor, "mousedown", function(e) {
              zoomBarDragging = true;
          });

          function mouseUp(e) {
              zoomBarDragging = false;
              var position = Element.positionedOffset(cursor);
                
              zoomLevel = (position.top - sliderCursorOffset - zoomBarScaleOffset) / zoomBarPixelPerZoomLevel;
              zoomLevel = Math.round(zoomLevel);
              
              cursor.style.top = (zoomLevel * zoomBarPixelPerZoomLevel + sliderCursorOffset + zoomBarScaleOffset) + "px";
              map.setZoom(googleZoomLevelCount - zoomLevel);
          }

          GEvent.addDomListener(cursor, "mouseup", function(e) {
            mouseUp(e);
          });

          GEvent.addDomListener(zoomBar, "mouseup", function(e) {
            mouseUp(e);
          });

          GEvent.addDomListener(zoomBar, "mousemove", function(e) {
              if (zoomBarDragging) {
                  var position = Element.cumulativeOffset(zoomBar);
                  var minZoomLevelPixel = sliderCursorOffset + zoomBarScaleOffset;
                  var maxZoomLevelPixel = sliderCursorOffset + zoomBarScaleOffset + (zoomLevelCount * zoomBarPixelPerZoomLevel);

                  var top = Event.pointerY(e) - position.top + sliderCursorOffset;
                  if (top < minZoomLevelPixel) {
                    top = minZoomLevelPixel;
                  }
                  if (top > maxZoomLevelPixel) {
                    top = maxZoomLevelPixel;
                  }              
                  cursor.style.top = (top) + "px";
              }
          });
          
          map.getContainer().appendChild(container);
          return container;
        }

        // By default, the control will appear in the top left corner of the
        // map with 7 pixels of padding.
        KoremControl.prototype.getDefaultPosition = function() {
          return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
        }


        function KoremSmallControl() {
        }
        
        KoremSmallControl.prototype = new GControl();

        KoremSmallControl.prototype.initialize = function(map) {
          var container = document.createElement("div");

          var zoomIn = document.createElement("img");
          if (notIE6) {
            zoomIn.src = "images/small/Slider_ZoomIn.png";
          } else {
            zoomIn.src = "images/small/Slider_ZoomIn.gif";
          }
          zoomIn.style.position = 'absolute';
          zoomIn.style.cursor = "pointer";            
          zoomIn.style.top = "42px";
          zoomIn.style.left = "11px";
          zoomIn.title = mapControlTitleZoomIn;
          
          var zoomOut = document.createElement("img");
          if (notIE6) {
            zoomOut.src = "images/small/Slider_ZoomOut.png";
          } else {
            zoomOut.src = "images/small/Slider_ZoomOut.gif";
          }
          zoomOut.style.position = 'absolute';
          zoomOut.style.cursor = "pointer";                              
          zoomOut.style.top = "61px";
          zoomOut.style.left = "11px";
          zoomOut.title = mapControlTitleZoomOut;

          var compass = document.createElement("img");
          if (notIE6) {
            compass.src = "images/small/Compass.png";
          } else {
            compass.src = "images/small/Compass.gif";
          }
          compass.style.border = "0px";
          compass.style.position = 'absolute';
          compass.style.cursor = "pointer";                 
          compass.style.width = "44px";
          compass.style.height = "43px";

          var compassContainer = document.createElement("div");
          compassContainer.style.position = 'absolute';
          compassContainer.style.top = "0px";
          compassContainer.appendChild(compass);

          var topDiv = document.createElement("div");
          topDiv.style.position = 'absolute';
          topDiv.style.top = "2px";
          topDiv.style.left = "15px";
          topDiv.style.cursor = "pointer";
          topDiv.onclick = function() { map.panDirection(0, 1); };
          topDiv.title = mapControlTitleTop;
          if (notIE6) {
            topDiv.innerHTML = "<img src='images/small/Compass_Top.png'>";
          } else {
            topDiv.innerHTML = "<img src='images/small/Compass_Top.gif'>";
          }

          var leftDiv = document.createElement("div");
          leftDiv.style.position = 'absolute';
          leftDiv.style.top = "14px";
          leftDiv.style.left = "2px";
          leftDiv.style.cursor = "pointer";
          leftDiv.onclick = function() { map.panDirection(1, 0); };
          leftDiv.title = mapControlTitleLeft;
          if (notIE6) {
            leftDiv.innerHTML = "<img src='images/small/Compass_Left.png'>";
          } else {
            leftDiv.innerHTML = "<img src='images/small/Compass_Left.gif'>";
          }

          var rightDiv = document.createElement("div");
          rightDiv.style.position = 'absolute';
          rightDiv.style.top = "14px";
          rightDiv.style.left = "29px";
          rightDiv.style.cursor = "pointer";
          rightDiv.onclick = function() { map.panDirection(-1, 0); };
          rightDiv.title = mapControlTitleRight;
          if (notIE6) {
            rightDiv.innerHTML = "<img src='images/small/Compass_Right.png'>";
          } else {
            rightDiv.innerHTML = "<img src='images/small/Compass_Right.gif'>";
          }

          var bottomDiv = document.createElement("div");
          bottomDiv.style.position = 'absolute';
          bottomDiv.style.top = "28px";
          bottomDiv.style.left = "15px";
          bottomDiv.style.cursor = "pointer";
          bottomDiv.onclick = function() { map.panDirection(0, -1); };
          bottomDiv.title = mapControlTitleBottom;
          if (notIE6) {
            bottomDiv.innerHTML = "<img src='images/small/Compass_Bottom.png'>";
          } else {
            bottomDiv.innerHTML = "<img src='images/small/Compass_Bottom.gif'>";
          }


          var initialDiv = document.createElement("div");
          initialDiv.style.position = 'absolute';
          initialDiv.style.top = "15px";
          initialDiv.style.left = "15px";
          initialDiv.style.cursor = "pointer";
          initialDiv.onclick = function() { map.returnToSavedPosition(); };
          initialDiv.title = mapControlTitleInitial;
          if (notIE6) {
            initialDiv.innerHTML = "<img src='images/small/Compass_Initial.png'>";
          } else {
            initialDiv.innerHTML = "<img src='images/small/Compass_Initial.gif'>";
          }
          
          compassContainer.appendChild(topDiv);
          compassContainer.appendChild(leftDiv);
          compassContainer.appendChild(rightDiv);
          compassContainer.appendChild(bottomDiv);
          compassContainer.appendChild(initialDiv);
          container.appendChild(compassContainer);

          container.appendChild(zoomIn);
          container.appendChild(zoomOut);
          
          GEvent.addDomListener(zoomIn, "click", function() {
            map.zoomIn();
          });
                   
          GEvent.addDomListener(zoomOut, "click", function() {
            map.zoomOut();
          });          

          map.getContainer().appendChild(container);
          return container;
        }

        // By default, the control will appear in the top left corner of the
        // map with 7 pixels of padding.
        KoremSmallControl.prototype.getDefaultPosition = function() {
          return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(1, 1));
        }


        function KoremMapTypeControl(mapId) {
            this.mapId = mapId;
        }
        
        KoremMapTypeControl.prototype = new GControl();

        KoremMapTypeControl.prototype.initialize = function(map) {
          map.removeMapType(G_SATELLITE_MAP);
          map.addMapType(G_PHYSICAL_MAP);         
            
            var minMapScale = 2; 
            var maxMapScale = 17; 
            // get array of map types 
            var mapTypes = map.getMapTypes(); 
            // overwrite the getMinimumResolution() and getMaximumResolution() methods for each map type 
            for (var i=0; i<mapTypes.length; i++) { 
                mapTypes[i].getMinimumResolution = function() {return minMapScale;} 
                mapTypes[i].getMaximumResolution = function() {return maxMapScale;} 
            }
          var container = document.createElement("div");
          container.innerHTML = mapTypeControlHtml.gsub('!{mapId}', this.mapId);

          map.getContainer().appendChild(container);
          return container;
        }
        
 

        // By default, the control will appear in the top left corner of the
        // map with 7 pixels of padding.
        KoremMapTypeControl.prototype.getDefaultPosition = function() {
          return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 0));
        }


function resetMapTypeButtons(mapId) {
  document.getElementById(mapId + 'mapTypeNormalUnselected').style.display = "block";
  document.getElementById(mapId + 'mapTypeNormalSelected').style.display = "none";
  document.getElementById(mapId + 'mapTypeSatelliteUnselected').style.display = "block";
  document.getElementById(mapId + 'mapTypeSatelliteSelected').style.display = "none";
  document.getElementById(mapId + 'mapTypePhysicalUnselected').style.display = "block";
  document.getElementById(mapId + 'mapTypePhysicalSelected').style.display = "none";        
}
function showNormalMap(mapId) {
  var targetMap = map;
  if (mapId != '') {
    targetMap = segmentMaps[mapId];
  }
  resetMapTypeButtons(mapId);
  document.getElementById(mapId + 'mapTypeNormalUnselected').style.display = "none";
  document.getElementById(mapId + 'mapTypeNormalSelected').style.display = "block";          
  targetMap.setMapType(G_NORMAL_MAP);          
}
function showSatelliteMap(mapId) {
  var targetMap = map;
  if (mapId != '') {
    targetMap = segmentMaps[mapId];
  }
  resetMapTypeButtons(mapId);
  document.getElementById(mapId + 'mapTypeSatelliteUnselected').style.display = "none";
  document.getElementById(mapId + 'mapTypeSatelliteSelected').style.display = "block";          
  targetMap.setMapType(G_HYBRID_MAP);          
}
function showPhysicalMap(mapId) {
  var targetMap = map;
  if (mapId != '') {
    targetMap = segmentMaps[mapId];
  }
  resetMapTypeButtons(mapId);
  document.getElementById(mapId + 'mapTypePhysicalUnselected').style.display = "none";
  document.getElementById(mapId + 'mapTypePhysicalSelected').style.display = "block";              
  targetMap.setMapType(G_PHYSICAL_MAP);          
}          

function createPoint(lat, lon, infoWindow, markerLabelIndex, isPrint, shouldUseGoogleIcons) {
    
    if (markerLabelIndex != '') {
        if (!isPrint ) {
            if (notIE6) {
                var icon = new GIcon();
                icon.image = 'images/' + color + '/Pin_Mini_v2.png';
                icon.iconSize = new GSize(25, 34);
                icon.iconAnchor = new GPoint(8, 32);
                icon.infoWindowAnchor = new GPoint(20, 14);
                icon.shadow = 'images/2/shadow.png';
                icon.shadowSize = new GSize(43, 34);
                if (markerLabelIndex == 'A' || markerLabelIndex == 'B') {
                    opts = {
                    "icon": icon,
                    "clickable": false,
                    "labelText": markerLabelIndex,
                    "labelOffset": new GSize(-5, -30),
                    "labelClass": 'poiLabel'
                    };
                } else {
                    opts = {
                    "icon": icon,
                    "clickable": true,
                    "labelText": markerLabelIndex,
                    "labelOffset": new GSize(-5, -30),
                    "labelClass": 'poiLabel'
                    };
                }
                var marker = new LabeledMarker(new GLatLng(lat, lon), opts);
                return marker;                
            } else {
                var icon = new GIcon();
                icon.image = 'images/' + color + '/Pin_Mini_v2.gif';
                icon.iconSize = new GSize(25, 34);
                icon.iconAnchor = new GPoint(8, 32);
                icon.infoWindowAnchor = new GPoint(20, 14);

                if (markerLabelIndex == 'A' || markerLabelIndex == 'B') {
                    opts = {
                    "icon": icon,
                    "clickable": false,
                    "labelText": markerLabelIndex,
                    "labelOffset": new GSize(-5, -30),
                    "labelClass": 'poiLabel'
                    };
                } else {
                    opts = {
                    "icon": icon,
                    "clickable": true,
                    "labelText": markerLabelIndex,
                    "labelOffset": new GSize(-5, -30),
                    "labelClass": 'poiLabel'
                    };
                }
                var marker = new LabeledMarker(new GLatLng(lat, lon), opts);
                return marker;                
            }
        } else {
            var icon = new GIcon();

            var opts;
            if (markerLabelIndex == 'A') {
                if (shouldUseGoogleIcons) {
                    icon.image = 'images/' + color + '/googleA.gif';
                    icon.iconSize = new GSize(20, 34);
                    icon.iconAnchor = new GPoint(9, 34);
                    icon.infoWindowAnchor = new GPoint(20, 14);
                } else {
                    icon.image = 'images/' + color + '/A.gif';
                    icon.iconSize = new GSize(25, 31);
                    icon.iconAnchor = new GPoint(11, 29);
                    icon.infoWindowAnchor = new GPoint(20, 14);
                }
                opts = {
                "clickable": false,
                "icon": icon
                };
            } else if (markerLabelIndex == 'B') {
                if (shouldUseGoogleIcons) {
                    icon.image = 'images/' + color + '/googleB.gif';
                    icon.iconSize = new GSize(20, 34);
                    icon.iconAnchor = new GPoint(9, 34);
                    icon.infoWindowAnchor = new GPoint(20, 14);
                } else {
                    icon.image = 'images/' + color + '/B.gif';
                    icon.iconSize = new GSize(25, 31);
                    icon.iconAnchor = new GPoint(11, 29);
                    icon.infoWindowAnchor = new GPoint(20, 14);
                }
                opts = {
                "clickable": false,
                "icon": icon
                };
            } else {
                icon.image = 'images/' + color + '/' + markerLabelIndex + '.gif';
                icon.iconSize = new GSize(25, 31);
                icon.iconAnchor = new GPoint(11, 29);
                icon.infoWindowAnchor = new GPoint(20, 14);
                opts = {
                "clickable": false,
                "icon": icon
                };
            }
            
            var marker = new GMarker(new GLatLng(lat, lon), opts);
            return marker;
        }
    } else {
        if (!isPrint) {
            if (notIE6) {
                var icon = new GIcon();
                icon.image = 'images/Pin1.png';

                icon.iconSize = new GSize(34, 45);
                icon.iconAnchor = new GPoint(8, 42);
                icon.infoWindowAnchor = new GPoint(20, 14);
                icon.shadow = 'images/Pin1_shadow.png';
                icon.shadowSize = new GSize(57, 45);

                opts = {
                "icon": icon,
                "clickable": true
                };
                var marker = new LabeledMarker(new GLatLng(lat, lon), opts);
                return marker;                
            } else {
                var icon = new GIcon();
                icon.image = 'images/Pin1.gif';
                icon.iconSize = new GSize(34, 45);
                icon.iconAnchor = new GPoint(8, 42);
                icon.infoWindowAnchor = new GPoint(20, 14);

                opts = {
                "icon": icon,
                "clickable": true
                };
                var marker = new LabeledMarker(new GLatLng(lat, lon), opts);
                return marker;                
            }
        } else {
            var icon = new GIcon();
            icon.image = 'images/Pin1.gif';
            icon.iconSize = new GSize(34, 45);
            icon.iconAnchor = new GPoint(8, 42);
            icon.infoWindowAnchor = new GPoint(20, 14);
            opts = {
            "clickable": false,
            "icon": icon
            };
            var marker = new GMarker(new GLatLng(lat, lon), opts);
            return marker;
        }
    }
}


function applyMapType(targetMap, mapType) {
    if (mapType == 1) {
        targetMap.setMapType(G_NORMAL_MAP);
    } else if (mapType == 2) {
        targetMap.setMapType(G_HYBRID_MAP);
    } else if (mapType == 3) {
        targetMap.setMapType(G_PHYSICAL_MAP);
    } else {
    }
}

function getMapType(targetMap) {
    var mapType = targetMap.getCurrentMapType();
    if (mapType == G_NORMAL_MAP) {
        return 1;
    } else if (mapType == G_HYBRID_MAP) {
        return 2;
    } else if (mapType == G_PHYSICAL_MAP) {
        return 3;
    } else {
        return -1;
    }
}

