function mapExtensions()
{		
	
	/* =====================
	** Resize map area
	** =====================
	** Expands the map content area out to the entire page width/height
	** on reload or page resize */
	
	$(window).ready(function(){
		$('#content .map-search-opened > div > div:first').css({"left":"0", "height":"100%"});
		
	});
	
 /*	$(window).resize(function(){
		var map_height = $(window).height() - ($('#head').height() + $('#foot').height());
		
		$('#content').css('height', map_height);
		$('.slurl-info .info-body .info-container').css('height', map_height * .9);
		$('#map-search-results').css('height', map_height);
	}); */
	
	

	
	
	
	/* --------------------------------------------------------------------
	** SLIDING SIDE PANEL
	** dynamically control the slide in/slide out of the
	** search results pane
	** -------------------------------------------------------------------- */
	
	$('.bu_collapse').click(
		function () {
			$(this).removeClass('collapse');
			$('#content #search-container').removeClass('collapse');
			$('.bu_expand').addClass('reveal');
			
			/* $('#content .map-search-opened > div > div:not(:nth-child(5))').css({"left":"0px"}); */
			
			$('#content .map-search-opened div #smc').addClass('control-left');
			$('#content .map-search-opened div #logocontrol').addClass('control-left');
			
		}
	);
	$('.bu_expand').click(
		function () {
			$(this).addClass('collapse');
			$('#content #search-container').addClass('collapse');
			$('.bu_expand').removeClass('reveal');
			$('#content .map-search-opened div #smc').removeClass('control-left');
			$('#content .map-search-opened div #logocontrol').removeClass('control-left');
			
		/*	// order is very important on the next 2 lines
			$('#content .map-search-opened > div > div:not(:nth-child(5))').css({"left":"440px", "padding-right":"50px"});
			$('#content .map-search-opened > div > div:first').css({"left":"0", "height":"100%", "padding-right":"0px"}); */
			
		}
	);
}


/* ==============================================
** gaButtonTracker
** ==============================================
** Track when a user clicks a button (namely about/build slurls) */
function gaButtonTracker(buttonVal)
{
	if(buttonVal)
	{
		pageTracker._trackPageview('/tracker/maps/browse/' + buttonVal);
		pageTracker._trackEvent('maps', 'Browse', buttonVal);
	}
}

/* ==============================================
** gaSearchTracker
** ==============================================
** Track when a user does a search 
function gaSearchTracker()
{
	var searchVal = $("#slurl-search form input#q").val();
	if(searchVal)
	{
		searchVal = escape(searchVal.replace(' ','+'));
		pageTracker._trackPageview('/tracker/slurl/' + searchVal);
		pageTracker._trackEvent('slurl', 'Search', searchVal);
	}
}
*/

/* ==============================================
** gaTeleportTracker
** ==============================================
** Track when a teleports into secondlife from 
** map locations  */
function gaTeleportTracker(tp_link)
{
	pageTracker._trackPageview('/tracker/maps/teleport/' + tp_link);
	pageTracker._trackEvent('maps', 'Teleport', tp_link);
}


/* ==============================================
** directSLurl
** ==============================================
** get a directSlurl on click of a login link */
function directSlurl(_self, location_string)
{
    $.ajax({
        url: "/direct_slurl.php",
        type: "GET",
        data: { region_location_string: location_string },
        async: false,
        success: function(data)
        {
            if (data) $(_self).attr("href", data);
        }
    });
}



/* =========================================================================
** 	loadquery
** =========================================================================
** ajaxish loading of search and showcase results, 
** so we can load the map first */
function loadquery(doc,params)
{
	
		var error_response = "<div class=\"notice\" style=\"margin:60px 15px;\""
			+"<h3>We've encountered a problem</h3>"
			+"<p>We were unable to complete the search for the content you requested."
			+" Please continue exploring the map while we look into the cause. Thank you for your patience!</p>"
			+"</div>";
		
		$.ajax({
	     	url:  doc,
	      type: 'GET',
				data: params,
	      //dataType: 'xml',
	      timeout: 10000,
	      error: function(){
					$('#content #search-container #map-search-results .loader').remove();
					$('#content #search-container #map-search-results').append(error_response);
					mapquery();
	      },
	      success: function(data){
					$('#content #search-container #map-search-results .loader').remove();
					$('#content #search-container #map-search-results').append(data);
					mapquery();

					if(params && params.sidebarHeight && params.sidebarHeight > 0 )
					{
						$('.showcase-container').height(params.sidebarHeight);
					}
	      }
	  	});
		
}



/* =========================================================================
** 	sanitizeAddthis
** =========================================================================
** add this wants a urlencoded string for the url, which is tricky because
** we're retreiving data that has likely been encoded already, and then sending
** it back to a js function */
function sanitizeAddthis(addthis)
{
	// it has likely already been encoded, so decode it all
	var decodeAddthis = decodeURIComponent(addthis);
	// then encode everthing together
	var encodeAddthis = encodeURIComponent(decodeAddthis);
	// make sure to escape them single quotes, or it'll break
	var sanitized = escape(encodeAddthis);
	
	return sanitized;
}

function htmlEncode(value){ 
  return $('<div/>').text(value).html();
} 

function htmlDecode(value){ 
  return $('<div/>').html(value).text(); 
}







/* ----------------
** sideBarControl
** ----------------
** a GControl that simulates the size of the search results 
** sidebar so that infoWindows don't get stuck underneath it
*/
function sideBarControl() {} // initialize the function

sideBarControl.prototype = new GControl();

sideBarControl.prototype.initialize = function(map) {

  var container = document.createElement("div");

  var inset = document.createElement("div");
  container.appendChild(inset);
  inset.appendChild(document.createTextNode(" "));

  map.getContainer().appendChild(container);

  return container;
}

sideBarControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(550, 750));
}


/* ----------------
** userBarControl
** ----------------
** a GControl that simulates the size of the user bar 
** so that infoWindows don't get stuck underneath it
*/
function userBarControl() {} // initialize the function

userBarControl.prototype = new GControl();

userBarControl.prototype.initialize = function(map) {

  var container = document.createElement("div");

  var inset = document.createElement("div");
  container.appendChild(inset);
  inset.appendChild(document.createTextNode(" "));

  map.getContainer().appendChild(container);

  return container;
}

userBarControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(3000, 70));
}

