var iconBlue = new GIcon(); 
iconBlue.image = 'http://belfi.co.uk/images/blue.png';
iconBlue.iconSize = new GSize(24, 19);
iconBlue.iconAnchor = new GPoint(6, 20);
iconBlue.infoWindowAnchor = new GPoint(5, 1);

var iconRed = new GIcon(); 
iconRed.image = 'http://belfi.co.uk/images/red.png';
iconRed.iconSize = new GSize(24, 19);
iconRed.iconAnchor = new GPoint(6, 20);
iconRed.infoWindowAnchor = new GPoint(5, 1);

var iconPurple = new GIcon(); 
iconPurple.image = 'http://belfi.co.uk/images/purple.png';
iconPurple.iconSize = new GSize(24, 19);
iconPurple.iconAnchor = new GPoint(6, 20);
iconPurple.infoWindowAnchor = new GPoint(5, 1);

var iconGreen = new GIcon(); 
iconGreen.image = 'http://belfi.co.uk/images/green.png';
iconGreen.iconSize = new GSize(24, 19);
iconGreen.iconAnchor = new GPoint(6, 20);
iconGreen.infoWindowAnchor = new GPoint(5, 1);

var customIcons = [];
customIcons["free"] = iconBlue;
customIcons["pay"] = iconRed;
customIcons["other"] = iconPurple;
customIcons["bitbuzz"] = iconGreen;
var markerGroups = { "free": [], "pay": [], "other": [], "bitbuzz": []};

function load() {
if (GBrowserIsCompatible()) {
var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(55,220));
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl3D(), topLeft);
map.setCenter(new GLatLng(54.5972686, -5.9301088), 13);


GDownloadUrl("/script/phpsqlajax_genxml.php", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var postcode = markers[i].getAttribute("postcode");
var business_id = markers[i].getAttribute("business_id");
var type = markers[i].getAttribute("type");
var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var marker = createMarker(point, name, address, postcode, business_id, type);
map.addOverlay(marker);
}
});
}
}

function createMarker(point, name, address, postcode, business_id, type) {
var marker = new GMarker(point, customIcons[type]);
markerGroups[type].push(marker);
var html = "<h3>" + name + "</h3> <br/>" + address + "<br/>" + postcode + "<br/>" + '<iframe src="http://lookaly.com/widgets/rating/' + business_id + '" border="0" scrolling="no" height="15" width="75" style="background:transparent;overflow:hidden;border:0;"></iframe>'; 

GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
return marker;
}

  function toggleGroup(type) {
      for (var i = 0; i < markerGroups[type].length; i++) {
        var marker = markerGroups[type][i];
        if (marker.isHidden()) {
          marker.show();
        } else {
          marker.hide();
        }
      } 
    }

//]]>
 

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

