    var icon;
    var iconsm;
    var homeicon;
    var map;        
    var WhoChanged = 0;
    var WhatChanged = 0;
	var WhereChanged = 0;
    var maxAdCount = 20;
    var AdCounter = 0;
                    	
   function GUnload() {
        var bannertimer = setInterval("changeBanner()", bPause);
        clearInterval(bannertimer);
    }
    
    //This function adds the Google bits to the page
    
    function load()
    {
        if (noResults == 'true') {
         setTimeout("showcontent('noresultsfound', 0)",200);
        }
      init();
      if (GBrowserIsCompatible()) {
        var start = new GLatLng(mcLat, mcLong);
        map = new GMap2(document.getElementById("map"));
        map.setUIToDefault();
        map.setCenter(start, mZoom);
		map.enableScrollWheelZoom();

		// Create our "tiny" marker icon
		
		icon = new GIcon();
		icon.image = "/Includes/ASPX/GetDirectoryImage.aspx?ImageType=LargeTarget&MaxWidth=50&MaxHeight=50";
		icon.shadow = "/Includes/ASPX/GetDirectoryImage.aspx?ImageType=LargeTarget&MaxWidth=50&MaxHeight=50";
		icon.iconSize = new GSize(41, 42);
		icon.shadowSize = new GSize(41, 42);
		icon.iconAnchor = new GPoint(20, 21);
		icon.infoWindowAnchor = new GPoint(20, 21);
		
		iconsm = new GIcon();
		iconsm.image = "/Includes/ASPX/GetDirectoryImage.aspx?ImageType=SmallTarget&MaxWidth=50&MaxHeight=50";
		iconsm.shadow = "/Includes/ASPX/GetDirectoryImage.aspx?ImageType=SmallTarget&MaxWidth=50&MaxHeight=50";
		iconsm.iconSize = new GSize(26, 26);
		iconsm.shadowSize = new GSize(26, 26);
		iconsm.iconAnchor = new GPoint(13, 13);
		
		homeicon = new GIcon();
		homeicon.image = "flag.png";
		homeicon.shadow = "flag.png";
		homeicon.iconSize = new GSize(30,30);
		homeicon.shadowSize = new GSize (30,30);
		homeicon.iconAnchor = new GPoint(3,27);
		homeicon.infoWindowAnchor = new GPoint(15,15);
		
		// Add markers 
		setListingMarkers();
		
		geocoder = new GClientGeocoder();
		
		        carMarker = getCarMarker(start);
        map.addOverlay(carMarker);
        carMarker.hide();

        svClient = new GStreetviewClient();
        pano = new GStreetviewPanorama(document.getElementById("streetview"));

        GEvent.addListener(pano, "initialized", function(loc) {
          panoMetaData = loc;
          moveCar();
        });

        GEvent.addListener(pano, "error", function(errorCode) {
          showStatus("The requested panorama could not be displayed");
        });

        directions = new GDirections(map);
        GEvent.addListener(directions, "load", function() {
          jumpInMyCar();
        });

        GEvent.addListener(directions, "error", function() {
          showStatus("Could not generate a route for the current start and end addresses");
        });
                
	  }
	}        
      var TagsShown = 1;
      var ListingsShown = 1;
	  
      var lastlistingid;
      var geocoder;
      var address;
      
      lastlistingid = 0
     
      // Browser sniffer
      var ua,an,ie,mac,win,ns,ns6,ge,unx;
      ua  = navigator.userAgent;
      an  = navigator.appName;
      ie  = ua.indexOf('MSIE')>=0;
      mac = ua.indexOf('Mac')>=0;
      win = ua.indexOf('Windows')>=0;
      unx = ua.indexOf('Unix')>=0;
      ns  = an.indexOf('Netscape')>=0;
      ns6 = ua.indexOf('Netscape6')>=0;
      ge  = ua.indexOf('Gecko')>=0;

      function testInclude() {
       alert('yo');
      }

      // Javascript for displaying the banner ads for the business directory. AH
      function bannerAd(AdID, type, href, alt, imgID, half) {
	      this.AdID  = AdID;
	      this.type  = type;
	      this.href  = href;
	      this.alt   = alt;
	      this.imgID = imgID;
	      this.half  = half;
	      //this.strTag = strTag;
      }
      
      function swfClicked(theId) {
       var bannerId;
       for(bannerId = 0; bannerId < maxAdCount; bannerId++) {
        if (adList[bannerId].imgID == theId.substring(1)) {
         var load = window.open(adList[bannerId].href)
         break;
        }
       }
      }
      
      function fcnRouteCallback(theCoords) {
//       alert(theCoords);
       document.getElementById('from').value = theCoords;
       generateRoute();
      }
      
      function directionsMode(listingName, coOrds){
        document.getElementById('directions').style.display = 'block';
        document.getElementById('svPanel').style.display = 'block';
        document.getElementById('progressBorder').style.display = 'block';
        document.getElementById('ddinterface').style.display = 'block';
        document.getElementById('normalinterface').style.display = 'none';
        document.getElementById('ITo').innerHTML = listingName;
        document.getElementById('to').value = coOrds;
//        fcnResize();
      }
      

    function email(url)
      {window.open(url,"EMailWindow","width=530,height=450,top=0,left=0")}
	  // This function uses commands that are only compatible with MSIE 4+, NN6+. (innerHTML)
      // We need to test this page with different browsers and modify accordingly.
      
      function outputBanner(adCounter) {
          var newBannerHTML = "";
          var width;
          
          if (adList[adCounter].half) {
           width=232;
          } else {
           width=468;
          }
          
          switch(adList[adCounter].type) {
	        // Image BannerAds...
	        case "jpg" :
	        case "gif":
	        case "png":
	          if(adList[adCounter].href != "#") newBannerHTML += "<a status=\""+ adList[adCounter].alt +"\" href=" + adList[adCounter].href + ">"// target=_blank>"
	          newBannerHTML += "<img src=/includes/ImageStream/BannerAd.aspx?ID="+ adList[adCounter].imgID +" width=" + width + " style=margin-bottom:4px; height=60 border=0 alt=\""+ adList[adCounter].alt +"\">"
	          if(adList[adCounter].href != "#") newBannerHTML += "</a>"
	          break;
	        case "swf" :
              if (ie&&win) {
                newBannerHTML = "<object classid=\"clsid:D27CDB6E-AE6D-11CF-96B8-444553540000\" id=flashBannerAd width=" + width + " style=margin-bottom:4px; height=60>"
                newBannerHTML+= "<param name=movie value=/includes/ImageStream/BannerAd.aspx?ID="+ adList[adCounter].imgID +">"
                newBannerHTML+= "<param name=quality value=high>"
                newBannerHTML+= "<param name=wmode value=opaque>"
                newBannerHTML+= "<param name=loop value=true>"
                if(adList[adCounter].href != "#") newBannerHTML+= "<a href=/public/../public/BannerAdCounter.asp?BannerAdID="+ adList[adCounter].AdID +" target=_blank>"+ adList[adCounter].alt +"</a><br><br>Flash BannerAds are not supported by your browser"
                else newBannerHTML+= adList[adCounter].alt +"<br><br>Flash BannerAds are not supported by your browser"
                newBannerHTML+= "</object>"
              } else if (ns && !unx && !ns6 && !ge && navigator.mimeTypes && navigator.mimeTypes['application/x-shockwave-flash'] && navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin && navigator.plugins && navigator.plugins['Shockwave Flash']) {
                newBannerHTML = "<embed src=\"/includes/ImageStream/BannerAd.aspx?ID="+ adList[adCounter].imgID +"\" name=banner_click swLiveConnect=true width=" + width + " height=60 quality=high wmode=opaque loop=true type=\"application/x-shockwave-flash\"></embed>";
                if(adList[adCounter].href != "#") newBannerHTML+= "<noembed><a href=/public/../public/BannerAdCounter.asp?BannerAdID="+ adList[adCounter].AdID +" target=_blank>"+ adList[adCounter].alt +"</a><br><br>Flash BannerAds are not supported by your browser</noembed>"
                else newBannerHTML+= adList[adCounter].alt +"<br><br>Flash BannerAds are not supported by your browser"
              } else {
                if(adList[adCounter].href != "#") newBannerHTML+= "<a href=../public/BannerAdCounter.asp?BannerAdID="+ adList[adCounter].AdID +" target=_blank>"+ adList[adCounter].alt +"</a><br><br>Flash BannerAds are not supported by your browser"
                else newBannerHTML+= adList[adCounter].alt +"<br><br>Flash BannerAds are not supported by your browser"
              }
	            break;
	        default : newBannerHTML = "<b>Error:</b> BannerAD type ( <b>"+ adList[adCounter].type +"</b> ) is not recognised"
	      }
	      //document.getElementById('where').value = newBannerHTML;
	      return newBannerHTML;
      }
      
      function changeBanner() {
	      var newBannerHTML = "";
	      var width;
	      var secondId;
	      var gotOne = -1;
	      var adCounter = 0;
	      
	      if(adCounter == maxAdCount) adCounter = 0;
	      secondId = adCounter + 1;

          if (adList[adCounter].half) {
            newBannerHTML = outputBanner(adCounter);
            //loop through remainder of ads to find a second one
            for(secondId = adCounter + 1; secondId < maxAdCount; secondId++) {
             if (adList[secondId].half) {
              if (gotOne < 0) {
               //preferably not same ad
               if (!(adList[secondId].imgID == adList[adCounter].imgID)) {
                gotOne = secondId;
               }
              }
             }
            }
            if (gotOne < 0) {
             for(secondId = 0; secondId < maxAdCount; secondId++) {
              if (adList[secondId].half) {
               if (gotOne < 0) {
                //preferably not same ad
                if (!(adList[secondId].imgID == adList[adCounter].imgID)) {
                 gotOne = secondId;
                }
               }
              }
             }
            }
            if (gotOne < 0) {
             for(secondId = 0; secondId < maxAdCount; secondId++) {
              if (adList[secondId].half) {
               if (gotOne < 0) {
                gotOne = secondId;
               }
              }
             }
            }
            newBannerHTML = newBannerHTML + "<img src=\"spacer.gif\" width=4 height=2>" + outputBanner(gotOne);
          } else {
            newBannerHTML = outputBanner(adCounter);
          }

	      // Change the banner code..
	      document.getElementById("placeHolder").innerHTML = newBannerHTML;
	      // Increase the counter
	      adCounter++;
      }

      function init() {
        var bannertimer = setInterval("changeBanner()", bPause);
        if(maxAdCount > 0) {
	        changeBanner();
	        //setInterval("changeBanner()", <%'= Pause %>);
	      }
      }
       
 
    function fcnTest() {
     var centerlatlng = map.getCenter(); 
//     alert('lat: ' + centerlatlng.lat() + ', lng:' + centerlatlng.lng());
    }
      
    function beforeSubmit() 
    {
      var GeocoderResult;
      var TheResult;
      if (WhoChanged == 0) { document.getElementById('who').value = '' }
      if (WhereChanged == 0) { document.getElementById('where').value = '' }
      if (WhatChanged == 0) { document.getElementById('what').value = '' }
      if (document.getElementById('where').value == '') {
        geocoder.getLocations(map.getCenter(), runTheResult); 
        TheResult = false;
      } else {
        TheResult = true;
      }
      return TheResult;
      document.search.submit();
    }
    
    function hideMessageDiv()
    {
        document.getElementById('MessageDiv').style.display='none';
        document.getElementById("OverseaDivMessage").style.display='none';
    }
    
    function runTheResult(theresult) 
    {    
        if(undefined!=theresult.Placemark)
        {
            //The map is centre'd overland - OK to go
            place = theresult.Placemark[0];
            document.getElementById('where').value = place.address;
            document.getElementById('lat').value = place.Point.coordinates[1];
            document.getElementById('lng').value = place.Point.coordinates[0];
            document.search.submit();
        }
        else
        {
            //The map is centre'd oversea - (theresult.Placemark[0]) is undefined and gives an error.
            //Either give a message
            //document.getElementById("OverseaDivMessage").style.display='block';
            //Or move the map
            document.getElementById('where').value = "Preston";
            document.getElementById('lat').value = '53.7564846';
            document.getElementById('lng').value = '-2.7088698';
            document.search.submit();
        }
    }
    
    function getAddress(overlay, latlng) {
      if (latlng != null) {
        address = latlng;
        geocoder.getLocations(latlng, showAddress);
      }
    }
        	
	function opacitytwo(id, opacStart, opacEnd, millisec) {
	    //speed for each frame
    	var speed = Math.round(millisec / 100);
    	var timer = 0;
     
	    //determine the direction for the blending, if start and end are the same nothing happens
	    if(opacStart > opacEnd) {
	       document.getElementById('map').style.display = 'block';
           document.getElementById('overlaybg').style.display = 'none';
           document.getElementById('overlay').style.display = 'none';
           document.getElementById('overlaybottomline').style.display = 'none';
           document.getElementById('overlaybottomlinefilled').style.display = 'none';
//		    for(i = opacStart; i >= opacEnd; i--) {
//			    setTimeout("changeOpac(" + i + ",'overlaybg')",(timer * speed));
//			    setTimeout("changeOpac(" + (i + 10) + ",'overlay')",(timer * speed));
//			    if (i==0) {
//			     setTimeout("document.getElementById('overlaybg').style.display = 'none';",(timer * speed));
//			     setTimeout("document.getElementById('overlay').style.display = 'none';",(timer * speed));
//			    }
//			    timer++;
//    		}
	    } else if(opacStart < opacEnd) {
	       document.getElementById('map').style.display = 'none';
           document.getElementById('overlaybg').style.display = 'block';
           document.getElementById('overlay').style.display = 'block';
           document.getElementById('overlaybottomline').style.display = 'block';
           document.getElementById('overlaybottomlinefilled').style.display = 'block';
//		    for(i = opacStart; i <= opacEnd; i++)
//			    {
//			    setTimeout("changeOpac(" + i + ",'overlaybg')",(timer * speed));
//			    setTimeout("changeOpac(" + (i + 10) + ",'overlay')",(timer * speed));
//			    timer++;
//    		}
	    }
    }

	function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

	function showcontent(thepage, ListingID) {
	 document.getElementById('overlayframe').src = 'InfoFrame.aspx?page=' + thepage + '&ListingID=' + ListingID;
	 if (document.getElementById('overlaybg').style.display != 'block') {
	    document.getElementById('overlaybg').style.display = 'block';
	    document.getElementById('overlay').style.display = 'block';
        document.getElementById('overlaybottomline').style.display = 'block';
        document.getElementById('overlaybottomlinefilled').style.display = 'block';
	    opacitytwo('overlaybg', 0, 100, 500);
	    document.getElementById('shlistings').style.display = 'none';
	    document.getElementById('ListingsDIV').style.display = 'none';
	 }
	}
	
	function showMessageContent(divname, msgType) {
	 if (document.getElementById('overlaybg').style.display != 'block') {
	    document.getElementById('overlaybg').style.display = 'block';
	    document.getElementById('overlay').style.display = 'block';
        document.getElementById('overlaybottomline').style.display = 'block';
        document.getElementById('overlaybottomlinefilled').style.display = 'block';
	    opacitytwo('overlaybg', 0, 100, 500);
	    document.getElementById('shlistings').style.display = 'none';
	    document.getElementById('ListingsDIV').style.display = 'none';
	 }
	}
	
	function hidecontent(thepage) {
	 if (document.getElementById('overlaybg').style.display = 'block') {
	    opacitytwo('overlaybg', 100, 0, 500);
	    document.getElementById('shlistings').style.display = 'block';
	    document.getElementById('ListingsDIV').style.display = 'block';
        document.getElementById('overlaybottomline').style.display = 'none';
        document.getElementById('overlaybottomlinefilled').style.display = 'none';
	 }
	}
	
	function showbubble(ListingID, dblLat, dblLong, bitPremium, bitImages, Tag) {
	 if (!(sWhere == '')) {
	  if (lastlistingid != 0) {
	   document.getElementById('listing' + lastlistingid).style.backgroundColor = ''
	   document.getElementById('listing' + lastlistingid).style.backgroundImage = ''
	   document.getElementById('listing' + lastlistingid).style.backgroundRepeat = 'no-repeat'
	  }
	  
	  document.getElementById('listing' + ListingID).style.backgroundImage = ''
	  lastlistingid = ListingID
	 }
	  if (bitPremium != 0) {
	   document.getElementById('bubblediv').style.width = "400px";
	   if (bitImages > 0) {
	    document.getElementById('bubbleif').width = 400;
        document.getElementById('bubbleif').height = 260;
	   } else {
	    document.getElementById('bubbleif').width = 400;
        document.getElementById('bubbleif').height = 200;
	   }
	  } else {
	   document.getElementById('bubblediv').style.width = "250px";
	   document.getElementById('bubbleif').width = 250;
       document.getElementById('bubbleif').height = 120;
	  }
	  document.getElementById('bubbleif').src = 'bubble.aspx?ListingID=' + ListingID + '&Tag=' + Tag
      element = document.getElementById('bubblediv')
	  element = element.cloneNode(true)
	  element.style.display = 'block'
	  map.openInfoWindow(new GLatLng(dblLat, dblLong), element)	
	}
	
	function clickTag(strTag) {
	  document.getElementById('what').value = strTag;
	  if (document.getElementById('who').value.substring(0,3) == 'e.g'){document.getElementById('who').value = ''};
	  if (document.getElementById('where').value.substring(0,3) == 'e.g'){document.getElementById('where').value = ''};
	  if (!(document.getElementById('where').value == '')) {
	    document.getElementById("search").submit();
	  } else {
	    //alert(runTheResult);
        geocoder.getLocations(map.getCenter(), runTheResult);  
	  }
	}
	
	function changeColor(color, ID) 
	{
		document.getElementById(ID).style.backgroundColor = color;
	}
	
	function bannerTag(whatTag)
	{ 
	    whatTag = whatTag.replace('#space#', ' ');
	    document.getElementById('what').value = whatTag;	    
	    document.getElementById('who').value = '';
	    document.getElementById('where').value = '';
	    geocoder.getLocations(map.getCenter(), runTheResult);
	}
	
	function bannerAdList(){}
    
    var adList = new bannerAdList();