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(){
		var map_height = $(window).height() - ($('#head').height() + $('#foot').height());
		$('#content').css('height', map_height);
		$('.slurl-info .info-body .info-container').css('height', map_height * .8);
	});
	
  $(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 * .8);
	});
	
	
	/* ===============================
	** SLurl-builder & about overlays
	** ===============================
	** Toggles the about slurl and buld-a-slurl info window overlays */

	$('#slurl-toolbar ul.slurl-info li span').toggle(
		function (){
			$(this).siblings('.info-body').show();
			$(this).parent('li').siblings('li').find('div.info-body').hide();
			$('#content #map-container').fadeTo("slow", 0.33);
     },
     function (){
			$(this).siblings('.info-body').hide();
			$(this).parent('li').siblings('li').find('div.info-body').hide();
			$('#content #map-container').fadeTo("slow", 1);
     }
	);
	
	/* close button for window overlays */
	$('#slurl-toolbar ul.slurl-info li div.info-body div.info-container span.close-button').click(function () { 
		$('#content #map-container').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;
	});
	
 }


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

function popUpExample() {
	$('a.popup').click(function(){
		var href = $(this).attr('href');
		var width = screen.width - 300;
		var height = screen.height - 200;
		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');

		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
		
		if(!$('#region').val() || !$('#x').val() || !$('#y').val() || !$('#y').val()){
			$('#build-location legend').after('<div class="slurl-error"><h4>We\'re having trouble creating your SLurl</h4><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></div>');
			document.getElementById('slurl-builder').scrollTop=0;
		} else{
			build_url();
		}
		
		
	})
}


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

function build_url()
{
	
	var slurl = "http://slurl.com/secondlife/" + 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: 'http://slurl.com/snip-url.php?url='+ escape(snip_slurl),
      type: 'GET',
      dataType: 'xml',
      timeout: 5000,
      error: function(){
        $('#ajax-loader').css({ display:"none" });
        $('#snurl p').append(error_msg);
      },
      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();

            // now create a var 'html' to store the markup we're using to output the feed to the browser window
            var html = "<h4 class=\"header\">Your shortened SLurl:</h4><p><input type=\"text\" id=\"snip-slurl\" size=\"80\" value=\""+ link +"\" /></p>";

            // hide the loading bar
            $('#ajax-loader').css({ display:"none" });

            // put that feed content on the screen!
            $('#snurl').append($(html));

						// 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() + 150;

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

      }
  });
}




/* ============================
** Bit.ly API setup
** ============================
** This contains the code we'd use for returning a bit.ly shortened URL using a JSON callback
** The bit.ly REST service API: http://code.google.com/p/bitly-api/wiki/ApiDocumentation  */

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

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

	var api_key = 'R_6aaeaac0fc514c13b2967cbbdd614893';
	var login = 'LindenLab';
	var bitlyVer = '2.0.1';

  $.ajax({
     	url: 'http://api.bit.ly/shorten?version='+ bitlyVer +'&longUrl='+ snip_slurl +'&login='+ login +'&apiKey='+ api_key +'&format=json',
      type: 'GET',
      dataType: 'jsonp',
      timeout: 5000,
      error: function(){
        $('#ajax-loader').css({ display:"none" });
        $('#snurl p').append(error_msg);
      },
      success: function(xml){
				var html = '';
				
				$.each(xml.results,function(i,item) {
					html += "<h4 class=\"header\">Your shortened SLurl:</h4><p><input type=\"text\" id=\"snip-slurl\" size=\"80\" value=\""+ item.shortUrl +"\" /></p>";
				});
								
        // hide the loading bar
        $('#ajax-loader').css({ display:"none" });

        // put that feed content on the screen!
        $('#snurl').append($(html));
				
				// 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() + 150;
				
				// fade out a color animation - requires color animation plugin
				$('#snurl').animate({ backgroundColor: '#fff' }, 2500);
				
      }
  });	
}

