
function FullScreenControl() {}

	FullScreenControl.prototype = new GControl();
	
	FullScreenControl.prototype.initialize = function(map) {
	  
	  var mapContainer = $('#' + map.getContainer().id);
	  mapContainer.append('<div id="full-screen-button-container"><a id="full-screen-button"></a></div>');
	  fullScreenModeDesired = (document.location.hash != '#full-screen');
	
	  fullScreenSwitch(map);
	  var buttonContainer = document.getElementById('full-screen-button-container');

	  fullScreenMap = map;
	  
	  GEvent.addDomListener(buttonContainer, 'click', function() {
	    fullScreenSwitch(map);
	  });
	  
	  return buttonContainer;
}

FullScreenControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(220, 7));
}

function fullScreenSwitch(map) {
  fullScreenModeDesired = !fullScreenModeDesired;
  var button = $('#full-screen-button');
  var mapContainer = $('#mapSet');
  var center = map.getCenter();
  var clickTimeout = 100;
  var mapControl;

  var hash = document.location.hash;
  if (hash == '' || hash == '#full-screen') {
    hash = '#';
  }

  if (fullScreenModeDesired) {
	
	var children = $('#fullScreenWrapper').children();
	
    $('body').append('<div id="full-screen-wrapper" style="display:none;"></div>');
    
	$('#full-screen-wrapper').append(children);
	
    mapContainer.after('<div id="full-screen-placeholder" style="display:none;"></div>');
	
    $('body').append('<div id="full-screen-content"></div>');
	
    mapContainer.appendTo('#full-screen-content');
    
	mapContainer.addClass('full-screen-map');

    $('body').addClass('full-screen');
    // IE6 
    $('body').height('100%');

    button.empty();
    button.append("Exit Full Screen");
	
	 setTimeout(function() {
      button.attr({
          'href':   '#',
          'title':  "Switch to normal view",
          'class':  'off'
        });
      }, clickTimeout);
	 
  }
  else {
    
	$('#full-screen-placeholder').after(mapContainer).remove();
	
    //$('#full-screen-wrapper').remove().children().appendTo('#fullScreenWrapper');
    //$('#full-screen-content').remove();
	
	//$('#full-screen-wrapper').children().appendTo('#fullScreenWrapper').remove();
    //$('#full-screen-content').remove();
	
	$('#full-screen-wrapper').children().appendTo('#fullScreenWrapper');
    $('#full-screen-content').remove();
	$('#full-screen-wrapper').remove();
	
	//registerListeners();

    mapContainer.removeClass('full-screen-map');
    $('body').removeClass('full-screen');

    button.empty();
    button.append("Full Screen");

    setTimeout(function() {
      button.attr({
          'href':   '#full-screen',
          'title':  "Show map in full screen",
          'class':  'off'
        });
      }, clickTimeout);
	  
  }

  map.checkResize();

  var infoWindow = map.getInfoWindow();
  if (infoWindow.isHidden()) {
    map.setCenter(center);
  }
  else {
    map.setCenter(infoWindow.getPoint());

   	if (fullScreenModeDesired) {
      map.panDirection(0, 0.5);
    }
    else {
      map.panDirection(0, 1);
    }
  }

  map.savePosition();
}


