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);
	}); */
	
	
	/* ===============================
	** SLurl-builder & about overlays
	** ===============================
	** Toggles the about slurl and buld-a-slurl info window overlays */

	$('.slurl-build').click(
		function (){
			$(this).siblings('.info-body').show();
			$(this).parent('li').siblings('li').find('div.info-body').hide(); 
			$('#content div').fadeTo("fast", 0.33);
			 gaButtonTracker($(this).attr('title'));
     }
	);
	
	/* close button for window overlays */
	$('span.close-button').click(function () { 
		$('#content div').fadeTo("slow", 1);
		$(this).parents('div.info-body').hide();
	});
	
	/* slurl builder button for window overlays */
	$('#slurl-toolbar ul.slurl-info li div.info-body div.info-container .build-link').click(function () { 
		$(this).parents('div.info-body').hide();
		$(this).parents('li').siblings().children('div.info-body').show();
		return false;
	});
	
	
	
	/* --------------------------------------------------------------------
	** 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"}); */
			
		}
	);
}


/* =====================
** Popup windows
** =====================
** Creates an unobtrusive popup window */

function popUpExample()
{
	$('a.popup').click(function(){
		var href = $(this).attr('href');
		var width = screen.width - 760;
		var height = screen.height - 550;
		var left = (screen.width - width)/2;
		var top = (screen.height - height)/2;

		window.open(href, 'popup', 'height='+ height +',width='+ width +',left='+ left +',top='+ top +',toolbar=no,scrollbars=yes');

		return false;		
	});
}


/* ============================
** Build a SLurl validation
** ============================
** Makes sure there are slurl coordinates input before we attempt to generate a SLurl OR a shortened SLurl */

function slurlBuildValidator()
{
	$('input#generate-slurl').click(function(){
		
		$('#build-location div.slurl-error').remove(); //remove the error message if there is one
		
		var intX = parseFloat($('#x').val());
		var intY = parseFloat($('#y').val());
		var intZ = parseFloat($('#z').val());
		
		
		if(!$('#region').val() 
			|| ( isNaN(intX) || intX<0 || intX>256 )
			|| ( isNaN(intY) || intY<0 || intY>256 )
			|| ( isNaN(intZ) )
			){
			
			var error_content = "";
			
			if(	!$('#region').val() )
			{
				error_content += "<p>A valid SLurl must contain a region name and x,y,z coordinates. Please make sure that each of these fields are properly filled in.</p>";
			}
			
			if( isNaN(intX) || isNaN(intY) || isNaN(intZ) || intX > 256 || intY > 256)
			{
				error_content += "<p>The x and y coordinates must each contain numbers between 0 and 256 to be valid. z index must be between -99 and 999. All coordinates (x,y,z) must be numeric.</p>";
			}
			
			if( intX<0 || intY<0)
			{
				error_content += "<p>The x and y coordinates must be positive numbers.</p>";
			}
			
			$('#build-location legend').after('<div class="slurl-error"><h4>We\'re having trouble creating your SLurl</h4>'+ error_content +'</div>');
			
			document.getElementById('slurl-builder').scrollTop=0;
		} else {
			build_url();
		}
		
		
	})
}


/* ============================
** Build a SLurl
** ============================
** Creates the SLurl */

function build_url()
{
	
	var slurl = $('#slurl_base').val() + escape($('#region').val()) + "/" + $('input#x').val() + "/" + $('input#y').val() + "/" + $('input#z').val() + "/";
	var slurlOptions = new Array;
	if ($('#windowImage').val()) slurlOptions.push("img=" + escape($('#windowImage').val()));
	if ($('#windowTitle').val()) slurlOptions.push("title=" + escape($('#windowTitle').val()));
	if ($('#windowMessage').val()) slurlOptions.push("msg=" + escape($('#windowMessage').val()));

	if ($('#u').val()) slurlOptions.push("u=" + escape($('#u').val()));

	if (slurlOptions.length > 0) {
    slurl += "?";
    
		for(f=0; f<slurlOptions.length; f++) {
      slurl += slurlOptions[f];
      if (f < slurlOptions.length - 1) slurl += "&";
    }
	
	}

	$('#slurl-builder form #return-slurl').css({'display' : 'block'});

	document.getElementById('slurl-builder').scrollTop = $('#slurl-builder').height() + $('#return-slurl').height();

	// return the slurl to the output field
	$('#output').val(slurl);
	
	// fade out a color animation - requires color animation plugin
	$('#return-slurl').animate({ backgroundColor: '#fff' }, 2500);
	
}




/* ============================
** SnipURL API setup
** ============================
** This contains the code we'd use for returning a SnipURL. 
** It requires a php proxy: snip-url.php (api key and login are included in this php file)
** API documentation for snip-url: http://snipurl.com/site/help?go=api */

function getSnurl() {
  //clear the content in the div for the next feed.
  $("#snurl p").empty();

  var error_msg = '<p>We\'re experiencing some problems with SnipUrl. Try copying the SLurl above and pasting it into the form on <a href="http://snipurl.com">SnipURL</a></p>';
	var snip_slurl = $('#output').val();

  $.ajax({
     	url: '/snip-url.php?url='+ escape(snip_slurl),
      type: 'GET',
      dataType: 'xml',
      timeout: 5000,
      error: function(){
        $('#ajax-loader').css({ display:"none" });
        $('#snurl').append('<p>'+error_msg+'</p>');
      },
      success: function(xml){
         $(xml).find('snip').each(function() {
						
            // name the current found item this for this particular loop run
            var $item = $(this);
            // grab the post's URL
            var link = $item.find('id').text();

						// put the value in the form field
						$('input#snip-slurl').val(link);

						// hide the shorten buttons
						$('#shorten-buttons').hide();
						
						// Show the shortened url div
						$('#snurl').css({'display':'block'});

						// scroll to it
						document.getElementById('slurl-builder').scrollTop = $('#slurl-builder').height() + $('#return-slurl').height() + $('#snurl').height();

						// fade out a color animation - requires color animation plugin
						$('#snurl').animate({ backgroundColor: '#fff' }, 2500);
												
         });

      }
  });
}


function clearSnurl()
{
	// Hide the shortened url div
	$('#snurl').css({'display':'none'});
	
	// Show the shorten buttons
	$('#shorten-buttons').show();
	
	// Reset the color for animation
	$('#snurl').css({ 'backgroundColor': '#FFF6BF' });
}


/* ==============================================
** 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(location_string)
{
	$.get("/direct_slurl.php", { region_location_string: location_string },
	  	function(data){
				window.location = data;
				return false;
	});
}



/* =========================================================================
** 	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: 5000,
	      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);
					}
	      }
	  	});
		
}




/* ==============================================
** repaginate
** ==============================================
** take pager from search results and resend as 
** ajax call 
function repaginate(url)
{
		var query = url.split('?');
		
		document.location.href= '/index.php?'+query[1];
		
}
*/



/* ==============================================
** JQUERY EXTENSIONS (fadeIn,fadeOut,fadeTo)
** ==============================================
** extend jquery to fix opacity issues in IE */

jQuery.fn.fadeIn = function(speed, callback) { 
    return this.animate({opacity: 'show'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeOut = function(speed, callback) { 
    return this.animate({opacity: 'hide'}, speed, function() { 
        if (jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
}; 
 
jQuery.fn.fadeTo = function(speed,to,callback) { 
    return this.animate({opacity: to}, speed, function() { 
        if (to == 1 && jQuery.browser.msie)  
            this.style.removeAttribute('filter');  
        if (jQuery.isFunction(callback)) 
            callback();  
    }); 
};













/* ----------------
** 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, 3000));
}

/* ----------------
** 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));
}
