//<![CDATA[

var map;
var gmarkerz = [];
var gmarkerz_i = 0;
var old_highlight_icon = "";

// PHP and Google Maps - http://code.google.com/support/bin/answer.py?answer=65622
// Other Code - http://www.choosebahrain.com/system/scripts/includes/googleMaps.js

function Gload ( optionz ) {
  var optionz = ( optionz == null ) ? [] : optionz;
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));

    if ( optionz.new_ui ) {
       map.navigation_control = new GLargeMapControl3D();
    } else {
       map.navigation_control = new GLargeMapControl();
    }
    map.addControl( map.navigation_control );

    // Add the Terrain Map Type and add Hybrid under Satellite
    map.addMapType( G_PHYSICAL_MAP );
    map.map_type = new GHierarchicalMapTypeControl();
    map.addControl( map.map_type );

    // maptype = G_SATELLITE_MAP / G_HYBRID_MAP / G_PHYSICAL_MAP [Terrain]
    // map.setMapType( G_HYBRID_MAP );

    // using (true) or (1) will make it in short form
    // map.addControl( new GMapTypeControl(true) ); // Regular
    // map.addControl( new GHierarchicalMapTypeControl(true) ); // Hierarchy
    // map.addControl( new GMenuMapTypeControl(true) ); // Drop down
    // http://econym.googlepages.com/example_maptypecontrols.htm

    map.addControl(new GScaleControl());

    //map.addControl(new GMapTypeControl());
    map.enableContinuousZoom();
    map.enableScrollWheelZoom();

     // Map view scale control
//     map.addControl(new GScaleControl());
     // Right-Bottom Corner Overview Map
//      overviewmap = new GOverviewMapControl();
//      map.addControl(overviewmap);
//      overviewmap.hide(true);

    Gload2();
  }
}

function Gload_mini ( optionz ) {
  var optionz = ( optionz == null ) ? [] : optionz;
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));

    map.navigation_control = new GSmallMapControl();
    map.addControl( map.navigation_control );
    map.map_type = new GMapTypeControl(1);
    map.addControl( map.map_type );
    map.removeMapType( G_SATELLITE_MAP );
    //map.addControl(new GMapTypeControl());
    //map.enableContinuousZoom();
    //map.enableScrollWheelZoom();

    Gload2();
  }
}

function Gload_micro ( optionz ) {
  var optionz = ( optionz == null ) ? [] : optionz;
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));

    if ( optionz.new_ui ) {
       map.navigation_control = new GSmallZoomControl3D();
    } else {
       map.navigation_control = new GSmallZoomControl();
    }
    map.addControl( map.navigation_control );
    //maptype = new GMapTypeControl(1)
    //map.addControl( maptype );
    //map.removeMapType( G_SATELLITE_MAP );
    //map.removeMapType( G_HYBRID_MAP );
    //map.addControl(new GMapTypeControl());
    //map.enableContinuousZoom();
    //map.enableScrollWheelZoom();

    Gload2();
  }
}

   function orderOfCreation(marker,b) {
     // http://econym.org.uk/gmap/zindex.htm
     return 1;
     // sends it to the back - http://esa.ilmari.googlepages.com/ZMarker2.htm
     // return GOverlay.getZIndex(marker.getPoint().lat())-n*10000;
   }

// taken from Google Maps API Tutorial [and modified]
// -- usage --
//  var marker = createMarker(43.65654,-79.90138,'<div style="width:240px">Some stuff to display in the First Info Window. With a <a href="http://www.econym.demon.co.uk">Link</a> to my home page</div>')
//  map.addOverlay( marker );
   function createMarker ( lat, lon, label, info_html, m_icon, optionz, marker_options ) {
     if ( lat == null ) {
        center_point = map.getCenter();
        lat = center_point.lat();
        lon = center_point.lng();
     }
     var info_html = ( info_html == null ) ? null : info_html;
     var m_icon = ( m_icon == null ) ? G_DEFAULT_ICON : m_icon;
     var optionz = ( optionz == null ) ? [] : optionz;
     // var marker_options = ( marker_options == null ) ? [] : marker_options;
     if ( marker_options ) {
        var marker = new GMarker( new GLatLng(lat,lon), marker_options );
     } else {
        if ( info_html ) {
           var marker = new GMarker( new GLatLng(lat,lon), {icon:m_icon, title:label, zIndexProcess:orderOfCreation} );
        } else {
           var marker = new GMarker( new GLatLng(lat,lon), {icon:m_icon, title:label, zIndexProcess:orderOfCreation, clickable:false } );
        }
     }

     if ( info_html ) {
        GEvent.addListener(marker, "click", function() {
          map.removeOverlay( marker );
          map.addOverlay( marker );
          marker.openInfoWindowHtml(info_html);
        });
     }

     if ( optionz['highlight_icon'] ) {
        GEvent.addListener(marker, "mouseover", function() {
          old_highlight_icon = marker.getIcon().image;
          marker.setImage( optionz['highlight_icon'].image );
        });

        GEvent.addListener(marker, "mouseout", function() {
          marker.setImage( old_highlight_icon );
        });
     }

     if ( label ) {
        // add a line to the side_bar html
        // document.getElementById("markers").innerHTML += '<a href="javascript:myclick(' + gmarkerz_i + ')">' + label + '</a><br>';
        // document.getElementById("select").options[i] = new Option( label, gmarkerz_i );

//        // save the info we need to use later for the side_bar
//        gmarkerz[gmarkerz_i] = marker;
//        gmarkerz_i++;
     }

     if ( optionz['add_marker'] ) {
        map.addOverlay( marker );
     }

     return marker;
   }

   function p(a){if(a.match(/\-/)){a= a.replace(/\-/,'');return parseInt(a,36)/(-10000);}else{return parseInt(a,36)/10000;}}

   // minimum requirements for GIcon to show a marker - .image, .iconAnchor
   // ---------------------------------
   // 'image': "micons/ylw-pushpin.png", 'iconanchor': "10x32", 'infoanchor': "16x0"
   // 'image': "micons/yellow-dot.png", 'iconanchor': "16x32", 'infoanchor': "16x0"
   // default google map icon - http://maps.google.com/intl/en_ALL/mapfiles/marker.png - 20x34
   // old - function create_icon ( attributes, use_base, icon_array, array_key, optionz ) {
   function create_icon ( attributes, optionz, icon_array, array_key ) {
      if ( attributes['image'] == null || attributes['image'] == "" ) {
         return null;
      }
      var optionz = ( optionz == null ) ? [] : optionz;
      var icon_array = ( icon_array == null ) ? [] : icon_array;
      var array_key = ( array_key == null ) ? null : array_key;

      if ( attributes['image'].match( /^m?icons\// ) ) {
         attributes['image'] = "http://maps.google.com/mapfiles/ms/" + attributes['image'];
      } else if ( attributes['image'].match( /^pal\d+\// ) ) {
         attributes['image'] = "http://maps.google.com/mapfiles/kml/" + attributes['image'];
      }
      if ( attributes['shadow'] ) {
         if ( attributes['shadow'].match( /^m?icons\// ) ) {
            attributes['shadow'] = "http://maps.google.com/mapfiles/ms/" + attributes['shadow'];
//         } else if ( attributes['shadow'].match( /^pal\d+\// ) ) {
//            attributes['shadow'] = "http://maps.google.com/mapfiles/kml/" + attributes['shadow'];
         }
      } else if ( attributes['image'].match( /http:\/\/maps\.google\.com\/mapfiles\/ms\/m?icons\/\w+\.png/ ) ) {
         attributes['shadow'] = attributes['image'].replace( ".png", ".shadow.png" );
//      } else if ( attributes['image'].match( /http:\/\/maps\.google\.com\/mapfiles\/kml\/pal\d+\/\w+\.png/ ) ) {
//         attributes['shadow'] = attributes['image'].replace( ".png", "s.png" );
      }

      if ( !attributes.iconsize ) {
         attributes.iconsize = "32x32";
         if ( attributes['image'].match( /mm_20_\w+\.png/ ) ) {
            attributes.iconsize = "12x20";
         }
      }
      if ( !attributes.iconanchor ) {
         if ( attributes.iconsize == "32x32" ) {
            if ( attributes['image'].match( /-pushpin\.png$/ ) ) {
               attributes.iconanchor = "10x32";
            } else if ( attributes['image'].match( /((blue|red|green|lightblue|yellow|purple|pink)|\w+-dot)\.png$/ ) ) {
               attributes.iconanchor = "16x32";
            } else if ( attributes['image'].match( /micons\/realestate\.png$/ ) ) {
               attributes.iconanchor = "5x31";
            } else if ( attributes['image'].match( /micons\/flag\.png$/ ) ) {
               attributes.iconanchor = "12x29";
            } else if ( attributes['image'].match( /micons\/POI\.png$/ ) ) {
               attributes.iconanchor = "25x25";
            } else if ( attributes['image'].match( /micons\/(tree|campground|campfire)\.png$/ ) ) {
               attributes.iconanchor = "16x28";
            } else {
               attributes.iconanchor = "16x16";
            }
         } else if ( attributes.iconsize == "12x20" ) {
            attributes.iconanchor = "6x20";
         } else {
            temp_array = attributes.iconsize.split("x");
            attributes.iconanchor = (temp_array[0]/2) + "x" + (temp_array[1]/2);
         }
      }

      if ( optionz['auto_set'] || attributes.auto_set ) {
         if ( attributes.shadow == undefined ) {
            if ( attributes['image'].match( /((blue|red|green|lightblue|yellow|purple|pink)|\w+-dot)\.png$/ ) ) {
               attributes['shadow'] = "http://maps.google.com/mapfiles/ms/micons/msmarker.shadow.png";
            } else if ( attributes['image'].match( /(\w+-pushpin)\.png$/ ) ) {
               attributes['shadow'] = "http://maps.google.com/mapfiles/ms/micons/pushpin_shadow.png";
            }
         }

//         if ( !attributes.iconsize ) {
//            attributes.iconsize = "32x32";
//            if ( attributes['image'].match( /mm_20_\w+\.png/ ) ) {
//               attributes.iconsize = "12x20";
//            }
//         }
         if ( !attributes.shadowsize && attributes['shadow'] ) {
            if ( attributes.iconsize == "32x32" ) {
               attributes.shadowsize = "59x32";
//               if ( attributes['image'].match( /\w+-pushpin\.png$/ ) && attributes['shadow'].match( /http:\/\/maps\.google\.com\/mapfiles\/ms\/micons\/msmarker\.shadow\.png/ ) ) {
//                  // msmarker.shadow.png doesnt work correction with the pushpins even if resized
//                  attributes.shadow = "";
//                  attributes.shadowsize = "0x0";
//               }
            } else if ( attributes.iconsize == "12x20" ) {
               attributes.shadowsize = "22x20";
            }
         }
//         if ( !attributes.iconanchor ) {
//            if ( attributes.iconsize == "32x32" ) {
//               if ( attributes['image'].match( /-pushpin\.png$/ ) ) {
//                  attributes.iconanchor = "10x32";
//               } else if ( attributes['image'].match( /((blue|red|green|lightblue|yellow|purple|pink)|\w+-dot)\.png$/ ) ) {
//                  attributes.iconanchor = "16x32";
//               } else {
//                  attributes.iconanchor = "16x16";
//               }
//            } else if ( attributes.iconsize == "12x20" ) {
//               attributes.iconanchor = "6x20";
//            }
//         }
         if ( !attributes.infoanchor ) {
            if ( attributes.iconsize == "32x32" ) {
               attributes.infoanchor = "16x0";
            } else if ( attributes.iconsize == "12x20" ) {
               attributes.infoanchor = "5x1";
            }
         }
      }

      // showObj_org( attributes );
      
      if ( !optionz.use_base ) {
         var newIcon = new GIcon( );
      } else {
         var newIcon = new GIcon( G_DEFAULT_ICON );
      }

      newIcon.image = attributes['image'];

      if ( attributes['shadow'] != undefined ) {
         newIcon.shadow = attributes['shadow'];
      }
      var temp_array = [];
      var resize = ( attributes.resize ) ? 100 / attributes.resize : 1;
      if ( attributes.iconsize ) {
         temp_array = attributes.iconsize.split("x");
         newIcon.iconSize = new GSize( parseInt(temp_array[0])/resize, parseInt(temp_array[1])/resize );
      }
      if ( attributes.shadowsize ) {
         temp_array = attributes.shadowsize.split("x");
         newIcon.shadowSize = new GSize( parseInt(temp_array[0])/resize, parseInt(temp_array[1])/resize );
      }
      if ( attributes.iconanchor ) {
         temp_array = attributes.iconanchor.split("x");
         newIcon.iconAnchor = new GPoint( parseInt(temp_array[0])/resize, parseInt(temp_array[1])/resize );
      }
      if ( attributes.infoanchor ) {
         temp_array = attributes.infoanchor.split("x");
         newIcon.infoWindowAnchor = new GPoint( parseInt(temp_array[0])/resize, parseInt(temp_array[1])/resize );
      }

      if ( attributes.imagemap ) {
         newIcon.imageMap = attributes.imagemap;
      } else if ( attributes['image'].match( /((blue|red|green|lightblue|yellow|purple|pink)|\w+-dot|\w+-pushpin)\.png$/ ) ) {
      }

//      newIcon.printImage = "http://maps.google.com/intl/en_ALL/mapfiles/markerie.gif";
//      newIcon.mozPrintImage = "http://maps.google.com/intl/en_ALL/mapfiles/markerff.gif";
//      newIcon.printShadow = "http://maps.google.com/intl/en_ALL/mapfiles/dithshadow.gif";
//      newIcon.transparent = "http://maps.google.com/intl/en_ALL/mapfiles/markerTransparent.png";
//      newIcon.imageMap = [ 7,0,7,3,8,4,8,11,4,12,0,16,0,18,1,19,6,23,3,29,4,31,6,29,8,24,15,24,17,20,16,17,15,14,17,9,19,7,21,5,16,1,10,0,7,0,7,0 ];
//      newIcon.maxHeight = 13;
//      newIcon.dragCrossImage = "http://maps.google.com/intl/en_ALL/mapfiles/drag_cross_67_16.png";
//      newIcon.dragCrossSize = new GSize( 16, 16 );
//      newIcon.dragCrossAnchor = new GPoint( 7, 9 );

      if ( icon_array && array_key ) {
         icon_array[array_key] = newIcon;
      } else {
         return newIcon;
      }
   }

// Marker switching
//  http://googlemapsapi.blogspot.com/2007/03/v275-gmarkersetimage-and-mole-whack.html
//  http://esa.ilmari.googlepages.com/hellocolorswitch.htm

// http://www.cycloloco.com/shadowmaker/shadowmaker.htm

// Icons
//  [12x20] http://gmapicons.googlepages.com/home
//  http://maps.google.com/help/maps/streetview/images/man_arrow-10.png
//  http://www.google.com/help/hc/images/maps_human.png
//  http://www.google.com/uds/solutions/localsearch/img/pin_red_A.png
//  G_DEFAULT_ICON, G_END_ICON, G_PAUSE_ICON, G_START_ICON

//  var baseIcon = new GIcon(); new GIcon(G_DEFAULT_ICON); new GIcon(G_DEFAULT_ICON, "numbers/tretton.png");
//  baseIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
//  baseIcon.iconSize=new GSize(32,32);
//  baseIcon.shadowSize=new GSize(32,32);
//  baseIcon.iconAnchor=new GPoint(16,16);
//  baseIcon.infoWindowAnchor=new GPoint(16,16);

//  http://code.google.com/apis/maps/documentation/overlays.html
//   tinyIcon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
//   tinyIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
//   tinyIcon.iconSize = new GSize(12, 20);
//   tinyIcon.shadowSize = new GSize(22, 20);
//   tinyIcon.iconAnchor = new GPoint(6, 20);
//   tinyIcon.infoWindowAnchor = new GPoint(5, 1);

// http://code.google.com/apis/maps/documentation/reference.html#GIcon
// http://groups.google.com/group/Google-Maps-API/msg/854c99c127c60448
// http://mapki.com/wiki/Available_Images
//   G_DEFAULT_ICON 
//   G_DEFAULT_ICON.image [String]
//   G_DEFAULT_ICON.shadow [String]
//   G_DEFAULT_ICON.iconSize [GSize]
//   G_DEFAULT_ICON.shadowSize [GSize]
//   G_DEFAULT_ICON.iconAnchor [GPoint]
//   G_DEFAULT_ICON.infoWindowAnchor [GPoint]
//   -- Most important settings above this line --
//   G_DEFAULT_ICON.printImage [String]
//   G_DEFAULT_ICON.mozPrintImage [String]
//   G_DEFAULT_ICON.printShadow [String]
//   G_DEFAULT_ICON.transparent [String]
//   G_DEFAULT_ICON.imageMap [Array]



// Google Local Search
// http://www.google.com/uds/solutions/localsearch/reference.html#_resultlist
// http://www.cnblogs.com/aspxphpjsprb/archive/2008/02/15/1069317.html

   // http://www.golfworldmap.com/js/gwm.js
function cMkr(id,p,u,n,c,i,r){
 var mkr = new GMarker(p,icon);
 mkrs[id]=new Array();
 mkrs[id][0]=mkr;
 mkrs[id][1]=n;
 if(c!=""){
   mkrs[id][2]='<span class="fm"><br>'+c+'</span>';
 } else {
   mkrs[id][2]='';
 }
 if(i!=""){
    mkrs[id][3]='<span class="fm"><br><br>'+i+'</span>';
  } else {
    mkrs[id][3]='';
 }
 if(r=="r"){
  mkrs[id][4]="<div id='mkr_d'>-> <a class=lnk href=javascript:mkrC('"+u+"','l')>click to zoom into this region</a></div>";
 }else{
  mkrs[id][4]="<div id='mkr_d'>-> <a class=lnk href=javascript:mkrC('"+u+"','l')>click to zoom to this course<br>for more information and photos</a></div>";
 }
 if(v_fScr){
  GEvent.addListener(mkr,"mouseover",function(){oI(id);});
  GEvent.addListener(mkr,"mouseout",function(){cI()});
  GEvent.addListener(mkr,"click",function(){mkrC(u,'l');});
 }else{
  GEvent.addListener(mkr,"click",function(){mkrC(u);});
 }
 return mkr;
}

//]]>