﻿var searchMap;

function Maps_Startup()
{
    if($('map'))
    {
        if (GBrowserIsCompatible()) 
        {
            searchMap = new GMap2(document.getElementById("map"));
            searchMap.addControl(new GLargeMapControl());
            searchMap.addControl(new GMapTypeControl());
            searchMap.setMapType(G_NORMAL_MAP);

	        var oicon = new GIcon();
	        oicon.image='http://www.touros.co.uk/marker.gif';
	        oicon.iconSize= new GSize(15, 15);
	        oicon.iconAnchor = new GPoint(7, 7);
	        		       		        
	        if($('mapinfo_count'))
	        {
	            var p;
	            var bounds = new GLatLngBounds();
	            searchMap.setCenter(new GLatLng(0, 0), 10);                                             
	            for(var i=0; i<$F('mapinfo_count'); i++)
	            {
	                if($F('mapinfo_lat_'+i)!='')
	                {
	                    if($F('mapinfo_lon_'+i)!='')
	                    {
	                        p=new GLatLng($F('mapinfo_lat_'+i), $F('mapinfo_lon_'+i));		                		                        								
	                        searchMap.addOverlay(createMarker(p, oicon, $F('mapinfo_acc_' + i), $F('mapinfo_res_' + i),$F('mapinfo_ref_' + i),$F('mapinfo_thu_' + i)));	                		                		                
                            bounds.extend(p);                                                
                        }
                    }
	            }  
	            
	            searchMap.setZoom(searchMap.getBoundsZoomLevel(bounds));
                searchMap.setCenter(bounds.getCenter());
	        }
	        else
	        {
                searchMap.setCenter(new GLatLng($F('mapinfo_lat'), $F('mapinfo_lon')), parseInt($F('mapinfo_zoo')));                                                
	            setMarker=new GMarker(searchMap.getCenter(), oicon);									
	            searchMap.addOverlay(setMarker);	                
	        }
	        
        }
    }
}    
    function createMarker(point, oicon, name, resort, reference, thumbnail) 
    {    
        var marker = new GMarker(point, oicon);
        var aname = name;
        var aresort = resort;
        var aref = reference;
        var info = '<div style="height:160px"><p class="center">' + name + '<br/><img class="image" src="' + thumbnail + '" style="width:160px; height: 100px;"/><br/><a href="villa.aspx?reference=' + aref + '">More Info</a> - <a href="#" onclick="VillaBox_Step_1(\'' + aname + '\',\'' + aresort + '\');">Check Availability</a><br/><a href="#" onclick="General_AddFavourite(\'' + aref + '\')">Add To Favourites</a></p></div>';
        var apoint = point;
     
        
        marker.myRef=aref;
		marker.myName=aname;
		                        
		//GEvent.addListener(marker, "click", function() {document.location.href='villa.aspx?reference='+aref;});
		GEvent.addListener(marker, "click", function() {searchMap.openInfoWindowHtml(apoint,info,{pixelOffset: new GSize(8,-8)});});
		//GEvent.addListener(marker, "mouseout", function() {setTimeout("searchMap.closeInfoWindow()",5000);});
		                                                       
        return marker;
    }    
               
