	var $j = jQuery.noConflict();

	var gMapConfig = new Object();
	gMapConfig.visible = true;
	gMapConfig.open = false;
	gMapConfig.alwaysOpen = false;
	gMapConfig.openTitle = "Event and hotel finder";
	gMapConfig.closeTitle = "<a href=\"javascript:toggleMap()\">Click here</a> to discover just how close new and exciting events can be.<br/>Simply use our interactive map to find events of Interest and our nearby hotels.";

	gMapConfig.lat = 53.800651;
	gMapConfig.lng = -4.064941;
	gMapConfig.zoom = 5;
	gMapConfig.zoomEvent = 9;	

	gMapConfig.controls = Object();
	gMapConfig.controls.hotels = new Array(true, true, true); // 3 hotel brands, display all
	gMapConfig.controls.events = new Array(true, true, true, true); // 4 event types, display all
	gMapConfig.controls.gardens = new Array(false); // 4 event types, display all
	gMapConfig.data = Object();
	gMapConfig.data.hotels = new Array();

	/*
	// just as an example :
	var hotel = new Object();
	hotel.postalcode = "AL3 8HH"; 
	hotel.info = "just a test hotel"; 
	hotel.brandid = "1"; 
	hotel.id = "54"; 
	hotel.lat = "51.829"; 
	hotel.lng = "-0.444299";
	gMapConfig.data.hotels[0] = hotel;
	// end
	*/

	gMapConfig.data.events = new Array();

	/*
	// just as an example :
	var event = new Object();
	event.postalcode = "SK9 4LR"; 
	event.info = "just a test event"; 
	event.categoryid = "1"; 
	event.id = "1"; 
	event.lat = "53.343288"; 
	event.lng = "-2.276761";
	gMapConfig.data.events[0] = event;
	// end
	*/

	gMapConfig.data.gardens = new Array();
	
	gMapConfig.articleevent = new Array();	



	//$j(document).ready ( function() {$j("body").bind("onload", gMapInitialize());}); 

	var map;
	var mapPodcastControl;

    function gMapInitialize() {

		if ($j("#gMapLocalConfig"))
		{
			var cfg = $j("#gMapLocalConfig").attr("class");
			if (cfg != "")
			{
				try
				{
					gMapConfig.visible = (cfg.charAt(0) == "0" ? false :true );
					gMapConfig.controls.events[0] = (cfg.charAt(1) == "0" ? false :true );
					gMapConfig.controls.events[1] = (cfg.charAt(2) == "0" ? false :true );
					gMapConfig.controls.events[2] = (cfg.charAt(3) == "0" ? false :true );
					gMapConfig.controls.events[3] = (cfg.charAt(4) == "0" ? false :true );
					gMapConfig.controls.hotels[0] = (cfg.charAt(5) == "0" ? false :true );
					gMapConfig.controls.hotels[1] = (cfg.charAt(6) == "0" ? false :true );
					gMapConfig.controls.hotels[2] = (cfg.charAt(7) == "0" ? false :true );
				}
				catch (ex)
				{
				}
			}
		}

		try
		{
			gMapLocalConfig();
		}
		catch (e)
		{
		}


		if (!gMapConfig.visible)
		{
			$j("#map-cover").css("display", "none");
			return;
		}

		if (gMapConfig.open)
		{
			$j("#map-cover").animate( { height:"500px" }, 500, "swing" );
			$j("#map-header-close").hide();
			$j("#map-header-open").show();
		}

		if (gMapConfig.alwaysOpen)
		{
			$j("#map-header-open-right").hide();
			$j("#map-header-open-icon").hide();
		}

		$j("#map-header-open-left").html(gMapConfig.openTitle);
		$j("#map-header-close").html(gMapConfig.closeTitle);


		$j("#map-opt-lhs").bind("click", function(e){
			if ($j("#map-options").attr("rel") == "open")
			{
				$j("#map-options").animate( { left:"706px" }, { queue:false, duration:500 } );
				$j("#map-options-header-icon img").attr("src", "/images/gmap/btn_open.png");
				$j("#map-options").attr("rel", "close");
			}
			else
			{
				$j("#map-options").animate( { left:"506px" }, { queue:false, duration:500 } );
				$j("#map-options-header-icon img").attr("src", "/images/gmap/btn_close.png");
				$j("#map-options").attr("rel", "open");
			}
		});





		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById("map-area"));
			
			var center = new GLatLng(gMapConfig.lat, gMapConfig.lng);
			map.setCenter(center, gMapConfig.zoom);

			map.addControl(new GLargeMapControl());

			var mapTypeControl = new GMapTypeControl();
			var topRight = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(70,6));
			map.addControl(mapTypeControl, topRight);

			
			initMarkers();
			updateControlIcons();
			displayMarkers();


			mapPodcastControl = new PodcastPlayerControl();			
                        map.addControl(mapPodcastControl);

			var params = {AllowScriptAccess:"always"};
			var flashvars = {listener: "podcastPlayerListener", interval:500};
			swfobject.embedSWF("/assets/flash/player_mp3_js.swf", "podcastPlayerObject", "1", "1", "8.0.0", "", flashvars, params);

/*			
$j("#podcast-player #playerpause").bind("mouseover", function(e){
	$j(this).css("background", "url('/images/gmap/podcast/button_pause_over.gif')");
	$j(this).css("background-repeat", "no-repeat");
});
$j("#podcast-player #playerpause").bind("mouseout", function(e){
	$j(this).css("background", "url('/images/gmap/podcast/button_pause.gif')");
	$j(this).css("background-repeat", "no-repeat");
});
$j("#podcast-player #playerplay").bind("mouseover", function(e){
	$j(this).css("background", "url('/images/gmap/podcast/button_play_over.gif')");
	$j(this).css("background-repeat", "no-repeat");
});
$j("#podcast-player #playerplay").bind("mouseout", function(e){
	$j(this).css("background", "url('/images/gmap/podcast/button_play.gif')");
	$j(this).css("background-repeat", "no-repeat");
});
$j("#podcast-player #playerstop").bind("mouseover", function(e){
	$j(this).css("background", "url('/images/gmap/podcast/button_stop_over.gif')");
	$j(this).css("background-repeat", "no-repeat");
});
$j("#podcast-player #playerstop").bind("mouseout", function(e){
	$j(this).css("background", "url('/images/gmap/podcast/button_stop.gif')");
	$j(this).css("background-repeat", "no-repeat");
});
$j("#podcast-player #timeline").bind("mouseover", function(e){
	$j(this).css("background", "url('/images/gmap/podcast/timeline_bg_over.gif')");
	$j(this).css("background-repeat", "no-repeat");
});
$j("#podcast-player #timeline").bind("mouseout", function(e){
	$j(this).css("background", "url('/images/gmap/podcast/timeline_bg.gif')");
	$j(this).css("background-repeat", "no-repeat");
});
*/

$j("#podcast-player #timeline").bind("click", function(e){
	setPositionClick(e);
});




			if (gMapConfig.articleevent.length > 0)
			{
				var locFound = false;
				for (i=0; i<gMapConfig.data.events.length; i++)
				{
					var event = gMapConfig.data.events[i];
					if (event.id == gMapConfig.articleevent[0])
					{
						map.setCenter(new GLatLng(event.lat, event.lng), gMapConfig.zoomEvent);
						event.marker.openInfoWindowHtml(getBubbleContent(event, "event"));
					}
				}
			}				
		}
				

    }

	function updateControlIcons()
	{
		try
		{			
			$j("#hotelControl1 img").attr("src", gMapConfig.controls.hotels[0]==true ? "/images/gmap/thumbs/hotels/1.png" : "/images/gmap/thumbs/hotels/1_off.png");
			$j("#hotelControl2 img").attr("src", gMapConfig.controls.hotels[1]==true ? "/images/gmap/thumbs/hotels/2.png" : "/images/gmap/thumbs/hotels/2_off.png");
			$j("#hotelControl3 img").attr("src", gMapConfig.controls.hotels[2]==true ? "/images/gmap/thumbs/hotels/3.png" : "/images/gmap/thumbs/hotels/3_off.png");
		}
		catch (ex)
		{
		}

		try
		{			
			$j("#eventControl1 img").attr("src", gMapConfig.controls.events[0]==true ? "/images/gmap/thumbs/events/1.png" : "/images/gmap/thumbs/events/1_off.png");
			$j("#eventControl2 img").attr("src", gMapConfig.controls.events[1]==true ? "/images/gmap/thumbs/events/2.png" : "/images/gmap/thumbs/events/2_off.png");
			$j("#eventControl3 img").attr("src", gMapConfig.controls.events[2]==true ? "/images/gmap/thumbs/events/3.png" : "/images/gmap/thumbs/events/3_off.png");
			$j("#eventControl4 img").attr("src", gMapConfig.controls.events[3]==true ? "/images/gmap/thumbs/events/4.png" : "/images/gmap/thumbs/events/4_off.png");
		}
		catch (ex)
		{
		}
	}

	function displayMarkers()
	{
		for (i=0;i<gMapConfig.data.hotels.length;i++ )
		{
			var hotel = gMapConfig.data.hotels[i];
			if (hotel.marker)
			{
				if (gMapConfig.controls.hotels[hotel.brandid-1])
					hotel.marker.show();
				else
					hotel.marker.hide();
			}
		}
		for (i=0;i<gMapConfig.data.events.length;i++ )
		{
			var event = gMapConfig.data.events[i];
			if (event.marker)
			{
				if (gMapConfig.controls.events[event.categoryid-1])
					event.marker.show();
				else
					event.marker.hide();
			}
		}
		
		for (i=0;i<gMapConfig.data.gardens.length;i++ )
		{
			var garden = gMapConfig.data.gardens[i];
			if (garden.marker)
			{
				if (gMapConfig.controls.gardens[0])
					garden.marker.show();
				else
					garden.marker.hide();
			}
		}

	}


    // Create a base icon for all of our markers that specifies the
    // shadow, icon dimensions, etc.
    var baseIcon = new GIcon(G_DEFAULT_ICON);
    baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
    baseIcon.iconSize = new GSize(40, 20);
    baseIcon.shadowSize = new GSize(37, 34);
    baseIcon.iconAnchor = new GPoint(1, 1);
    baseIcon.infoWindowAnchor = new GPoint(9, 2);

	// Creates a marker whose info window displays the letter corresponding
    // to the given index.
    function createMarker(point, category, type, drag, content) {
      // Create a lettered icon for this point using our icon class
      var letteredIcon = new GIcon(baseIcon);
	  letteredIcon.image = "/images/gmap/thumbs/" + category + "/" + type + ".png";

	  if (category == "events")
	  {
		  letteredIcon.iconSize = new GSize(22, 41);
		  letteredIcon.shadow = "/images/gmap/icon_map_shadow.png";
		  letteredIcon.shadowSize = new GSize(34, 41);
		  letteredIcon.iconAnchor = new GPoint(11, 40);
		  letteredIcon.infoWindowAnchor = new GPoint(22, 2);
		  
	  }

	  if (category == "gardens")
	  {
		  letteredIcon.iconSize = new GSize(24, 24);
	  }


      // Set up our GMarkerOptions object
      markerOptions = { icon:letteredIcon, draggable:drag };
      var marker = new GMarker(point, markerOptions);

      GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(content);
      });
      return marker;
    }

	function initMarkers()
	{
		for (i=0; i<gMapConfig.data.hotels.length; i++)
		{
			var hotel = gMapConfig.data.hotels[i];
			if ((hotel.lat != "")  && (hotel.lng != ""))
			{							
				var point = new GLatLng(hotel.lat,hotel.lng);
				var mrk = createMarker(point, "hotels", hotel.brandid, false,  getBubbleContent(hotel, "hotel"));
				
				hotel.marker = mrk;
				map.addOverlay(hotel.marker);
				hotel.marker.hide();
			}
		}

		for (i=0; i<gMapConfig.data.events.length; i++)
		{
			var events = gMapConfig.data.events[i];
			if ((events.lat != "")  && (events.lng != ""))
			{							
				var point = new GLatLng(events.lat,events.lng);
				var mrk = createMarker(point, "events", events.categoryid, false, getBubbleContent(events, "event"));
				
				events.marker = mrk;
				map.addOverlay(events.marker);
				events.marker.hide();
			}
		}

		for (i=0; i<gMapConfig.data.gardens.length; i++)
		{
			var garden = gMapConfig.data.gardens[i];
			if ((garden.lat != "")  && (garden.lng != ""))
			{							
				var point = new GLatLng(garden.lat,garden.lng);
				var mrk = createMarker(point, "gardens", 0, false, getBubbleContent(garden, "garden"));
				
				garden.marker = mrk;
				map.addOverlay(garden.marker);
				garden.marker.hide();
			}
		}

	}

	function toggleMap()
	{
			if ($j("#map-cover").css("height") == "75px")
			{
				/*
				if (!map)
				{
					gMapInitialize();
				}
				*/

				$j("#map-cover").animate( { height:"500px" }, 500, "swing" );
				$j("#map-header-close").hide();
				$j("#map-header-open").show();
			}
			else
			{
				$j("#map-cover").animate( { height:"75px" }, 500, "swing", function() {$j("#map-header-close").show(); $j("#map-header-open").hide();} );				
			}
	}

	function toggleControlHotel(indx)
	{
		gMapConfig.controls.hotels[indx-1] = !gMapConfig.controls.hotels[indx-1];
		updateControlIcons();
		displayMarkers();
	}
	function toggleControlEvent(indx)
	{
		gMapConfig.controls.events[indx-1] = !gMapConfig.controls.events[indx-1];
		updateControlIcons();
		displayMarkers();
	}

	function toggleFilter()
	{
		if ($j("#map-options").attr("rel") == "open")
		{
			$j("#map-options").animate( { left:"706px" }, { queue:false, duration:500 } );
			$j("#map-options-header-icon img").attr("src", "/images/gmap/btn_open.png");
			$j("#map-options").attr("rel", "close");
		}
		else
		{
			$j("#map-options").animate( { left:"506px" }, { queue:false, duration:500 } );
			$j("#map-options-header-icon img").attr("src", "/images/gmap/btn_close.png");
			$j("#map-options").attr("rel", "open");
		}
	}


	function getBubbleContent(obj, type)
	{
		var res = "";
		if (type == "hotel")
		{
			res += "<div class=\"map-bubble\"><div class=\"map-bubble-icon\"><img class=\"thumb\" src=\"/images/gmap/thumbs/hotels/" + obj.brandid + ".png\"/></div>";
			res += "<div class=\"map-bubble-name\">" + obj.name + "</div><div class=\"map-bubble-clear\"/>";
			res += "<div class=\"map-bubble-address\">";
			if (obj.number != "") {res += (String(obj.number) + " ");}
			if (obj.address1 != "") {res += (obj.address1 + "<br/>");}
			if (obj.address2 != "") {res += (obj.address2 + "<br/>");}
			if (obj.address3 != "") {res += (obj.address3 + "<br/>");}
			if (obj.postalcode != "") {res += obj.postalcode;}

			res += "</div>";
			if (obj.links)
			{
				for (j=0;j<obj.links.length;j++)
				{
					res += "<div class=\"map-bubble-link\"><a href='" + obj.links[j].href + "' target='" + obj.links[j].target + "'>" + obj.links[j].text + "</a></div>";
				}
			}

                        if (obj.podcast_url != "") {
				res += "<div class=\"map-bubble-podcast\"><a href=\"javascript:runPodcast('"+ obj.podcast_url +"')\"><div class=\"podcast-icon\"></div><div class=\"podcast-copy\">listen to the podcast</div></a></div>";
			}

			res += "</div>";			
		}
		if (type == "event")
		{
			res += "<div class=\"map-bubble\"><div class=\"map-bubble-icon\"><img class=\"thumb\" src=\"/images/gmap/thumbs/events/" + obj.categoryid + ".png\"/></div>";
			res += "<div class=\"map-bubble-name\">" + obj.name + "</div><div class=\"map-bubble-clear\"/>";
			res += "<div class=\"map-bubble-address\">";
			if (obj.number != "") {res += (String(obj.number) + " ");}
			if (obj.address1 != "") {res += (obj.address1 + "<br/>");}
			if (obj.address2 != "") {res += (obj.address2 + "<br/>");}
			if (obj.address3 != "") {res += (obj.address3 + "<br/>");}
			if (obj.county != "") {res += (obj.county + "<br/>");}
			if (obj.postalcode != "") {res += obj.postalcode;}

			res += "</div>";
			if (obj.links)
			{
				for (j=0;j<obj.links.length;j++)
				{
					res += "<div class=\"map-bubble-link\"><a href='" + obj.links[j].href + "' target='" + obj.links[j].target + "'>" + obj.links[j].text + "</a></div>";
				}
			}
			res += "</div>";			


		}

		if (type == "garden")
		{
			res += "<div class=\"map-bubble\"><div class=\"map-bubble-icon\"><img class=\"thumb\" src=\"/images/gmap/thumbs/gardens/0.png\"/></div>";
			res += "<div class=\"map-bubble-name\">" + obj.name + "</div><div class=\"map-bubble-clear\"/>";
			res += "<div class=\"map-bubble-address\">";
			if (obj.address1 != "") {res += (obj.address1 + "<br/>");}
			if (obj.postalcode != "") {res += (obj.postalcode + "<br/>");}
			if (obj.url != "") {res += ("<a target=\"_blank\" href=\"http://" + obj.url + "\">" + obj.url + "</a>");}
			res += "</div></div>";			

		}

		return res;
	}

	function addMarkerLink(type, id, text, href, target, isdef)//'118','BookNow','http://www.brandwidth.co.uk','_blank','default')
	{
		var arr = null;
		if (type == "hotel") arr = gMapConfig.data.hotels;
		if (type == "event") arr = gMapConfig.data.events;
		if (type == "garden") arr = gMapConfig.data.gardens;

		if (arr == null) return;

		//alert(type);

		for (i=0; i<arr.length;i++ )
		{
			if (arr[i].id == id)
			{
				var link = new Object;
				link.href = href;
				link.text = text;
				link.target = target;

				if ((arr[i].links.length > 0) && (isdef == "default"))
				{
					arr[i].links[0] = link;
				}
				else
					arr[i].links[arr[i].links.length] = link;

			}
		}		

	}


	function runPodcast(asset)
	{
		var box = $j("#podcast-player");
		
		$j.ajax({
		   type: "GET",
		   url: "/podcasts/podcast.php?asset=" + asset
		 });
		
	
		box.show();
		startPodcast(asset);
	}


    function PodcastPlayerControl() {
    }
    PodcastPlayerControl.prototype = new GControl();
    
    // Creates a one DIV for each of the buttons and places them in a container
    // DIV which is returned as our control element. We add the control to
    // to the map container and return the element for the map class to
    // position properly.
    PodcastPlayerControl.prototype.initialize = function(map) {
      var container = document.createElement("div");
	container.id = "podcast-player";
	var button = document.createElement("div");
	button.id = "playerplay";
	button.className = "button play";
	var link = document.createElement("a");
	link.href="javascript:play()"
	button.appendChild(link);
	container.appendChild(button);

	button = document.createElement("div");
	button.id = "playerpause";
	button.className = "button pause";
	link = document.createElement("a");
	link.href="javascript:pause()"
	button.appendChild(link);
	container.appendChild(button);

	button = document.createElement("div");
	button.id = "playerstop";
	button.className = "button stop";
	link = document.createElement("a");
	link.href="javascript:stop()"
	button.appendChild(link);
	container.appendChild(button);

	button = document.createElement("div");
	button.id = "timeline";
	//button.addEventListener('click',function (e) {setPositionClick(e)},false);

	link = document.createElement("div");
	link.id = "progressbar";
	button.appendChild(link);
	link = document.createElement("div");
	link.id = "playerslider";
	button.appendChild(link);
	container.appendChild(button);


    
      map.getContainer().appendChild(container);
      return container;
    }
    
    // By default, the control will appear in the top left corner of the
    // map with 7 pixels of padding.
    PodcastPlayerControl.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 280));
    }
