﻿var map;
var marker;
var baseIcon = new GIcon();
var baseIcon2 = new GIcon();
var baseIconDestination = new GIcon();
var baseIconPlus = new GIcon();
var baseIconSelected = new GIcon();
var colors = [ '#00FF00', '#0000FF', '#FF0000', '#FF8000', '#400080' ];
var colorIndex = 0;

function WRBaseLoad() {      
            
      map = new GMap2(document.getElementById("map"));      
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());
      //var overview = new GOverviewMapControl(new GSize(150,100));
      //map.addControl(overview);
      
            
      baseIcon.shadow = "images/shadow50.png";
      baseIcon.iconSize = new GSize(20, 34);
      baseIcon.shadowSize = new GSize(37, 34);
      baseIcon.iconAnchor = new GPoint(9, 34);
      baseIcon.infoWindowAnchor = new GPoint(9, 2);
      baseIcon.infoShadowAnchor = new GPoint(18, 25);      
      
      baseIcon2.shadow = "";
      baseIcon2.iconSize = new GSize(8, 8);
      baseIcon2.shadowSize = new GSize(0, 0);
      baseIcon2.iconAnchor = new GPoint(4, 4);
      baseIcon2.infoWindowAnchor = new GPoint(4, 4);
      baseIcon2.infoShadowAnchor = new GPoint(4, 1);
      baseIcon2.image = "/images/iconLittle.png";
      baseIcon2.clickable = false;
      
//      baseIconDestination.iconSize = new GSize(24, 24);
//      baseIconDestination.iconAnchor = new GPoint(9, 23);
//      baseIconDestination.infoWindowAnchor =  new GPoint(21, 5);      
//      baseIconDestination.image = "/images/test/flag_green.png";
        
      baseIconDestination.shadow = "/images/map/RivetShadow.png";
      baseIconDestination.iconSize = new GSize(14, 27);
      baseIconDestination.shadowSize = new GSize(36, 28);
      baseIconDestination.iconAnchor = new GPoint(6, 24);
      baseIconDestination.infoWindowAnchor = new GPoint(9, 2);
      baseIconDestination.infoShadowAnchor = new GPoint(18, 25);
      baseIconDestination.image = "/images/map/RivetRed.png";  
      
      baseIconPlus.iconSize = new GSize(24, 24);
      baseIconPlus.iconAnchor = new GPoint(9, 23);
      baseIconPlus.infoWindowAnchor =  new GPoint(21, 5);      
      baseIconPlus.image = "/images/test/flag_green_plus.png"; 

//      baseIconSelected.iconSize = new GSize(24, 24);
//      baseIconSelected.iconAnchor = new GPoint(9, 23);
//      baseIconSelected.infoWindowAnchor =  new GPoint(21, 5);      
//      baseIconSelected.image = "/images/test/flag_selected.png"; 
      baseIconSelected.shadow = "/images/map/RivetShadow.png";
      baseIconSelected.iconSize = new GSize(14, 27);
      baseIconSelected.shadowSize = new GSize(36, 28);
      baseIconSelected.iconAnchor = new GPoint(6, 24);
      baseIconSelected.infoWindowAnchor = new GPoint(9, 2);
      baseIconSelected.infoShadowAnchor = new GPoint(18, 25);
      baseIconSelected.image = "/images/map/RivetBlack.png";  

}

function WRDisplayMarkerNormal(gPoint, text, marker)
{   
    if (marker == null)
    {
        //marker = new GxMarker(gPoint, baseIcon2, "<p>"+ text +"</p>");        
        marker = new GMarker(gPoint, {icon: baseIcon2, title: text});
        map.addOverlay(marker);
    }    
    
    return marker;
}

function WRDisplayMarkerDestination(gPoint, text, points, marker)
{    
    if (marker == null)
    {        
        //marker = new GxMarker(gPoint, baseIconDestination, "<p>"+ text +"</p>");                
        marker = new GMarker(gPoint, {icon: baseIconDestination, title: text});       
        
        //marker.text = text;         
        
//        GEvent.addListener(marker, 'mouseover', function() 
//        { 
//              var markerPoints = marker.getPoints();
//              
//              if (marker.getPolyline() == null && markerPoints != null)
//              {
//                for(var i=0;i<markerPoints.length;i++)
//                {
//                    poly = new GPolyline(markerPoints[i], '#000000', 4, 0.8);
//                    map.addOverlay(poly);
//                    marker.addPolyline(poly);
//                    
//                    poly2 = new GPolyline(markerPoints[i], '#00FF00', 2, 1);
//                    map.addOverlay(poly2);
//                    marker.addPolyline(poly2);
//                }
//              }

//        });
//        
//        GEvent.addListener(marker, 'mouseout', function() 
//        {   
//             var markerPoly = marker.getPolyline();
//                
//             if (markerPoly != null)
//             {       
//                for(var i=0;i<markerPoly.length;i++)
//                {  
//                    map.removeOverlay(markerPoly[i]);           
//                 }
//                 marker.resetPolyline();
//             }

//        });
//        
//        GEvent.addListener(marker, 'click', function() 
//        {
//              marker.openInfoWindowHtml(marker.getHtmlInfo());
//              //marker.showMapBlowup();

//        });
        
        map.addOverlay(marker);
    }
     
//    marker.addPoints(points); 
//    marker.addHtmlInfo(text);       
    
    return marker;
}
   
function WRDisplayMarkerAndBaloon(gPoint, text, html)
{
    //var marker = new GxMarker(gPoint, baseIconDestination, "<p>"+ text +"</p>");    
    var marker = new GMarker(gPoint, {icon: baseIconDestination, title: text});  
    GEvent.addListener(marker, 'click', function() {
          marker.openInfoWindowHtml(html);

    });
    
    map.addOverlay(marker);
}

function WRHide()
{
    var mDiv = document.getElementById("map");
    var mDivImg = document.getElementById("CollapseMap");
    if (mDiv.style.height == '200px')
    {
        mDiv.style.height = '400px';
        mDivImg.src = '/Images/map_footer_up.jpg';
    }
    else
    {
        mDiv.style.height = '200px';
        mDivImg.src = '/Images/map_footer_down.jpg';
    }
}

function WRSearchInArray( searchS, arraySA ) 
{
 var I = 0;
 var minI = 0;
 var maxI = arraySA.length - 1;
 //
 var s = "";
 //
 var foundB = false;
 //
 I = minI - 1;
 while ( ( I <= maxI ) && ( !( foundB ) ) ) 
 {
    I = I + 1;
    s = arraySA[ I ];
    foundB = ( searchS == s );
 }
 if ( foundB ) 
 {
    return( I );
 }
 else 
 {
    return( -1000 ); // some negative number indicating not found
 }
}
function WRSearchIDInArray( searchS, arraySA ) 
{
 var I = 0;
 var minI = 0;
 var maxI = arraySA.length - 1;
 //
 var s = "";
 //
 var foundB = false;
 //
 I = minI - 1;
 while ( ( I <= maxI ) && ( !( foundB ) ) ) 
 {
    I = I + 1;
    s = arraySA[ I ];
    foundB = ( searchS == s.id );
 }
 if ( foundB ) 
 {
    return( I );
 }
 else 
 {
    return( -1000 ); // some negative number indicating not found
 }
}

function WRNewWindow(path,size) 
{
  window.open(path,"",size);
} 

function WRNextColor() 
{
    if (colorIndex >= colors.length) 
    {
        colorIndex = 0;
    } 
    return colors[colorIndex++];
}