﻿// requires jQuery

// fast onload for map init
// faster map loading
// always after ufo!?
if (window.addEventListener)
	var eventName = 'addEventListener';
else if (window.attachEvent)
	var eventName = 'attachEvent';

if (eventName)
{
  var orig = window[eventName];
	window[eventName] = function(type, listener, useCapture)
	{
		if ((type == "load") || (type == "onload"))
		{
			$(document).ready(listener);
		}
		else if (eventName == "addEventListener")
		{
			orig(type, listener, useCapture);
		}
		else if (eventName == "attachEvent")
		{
			orig(type, listener);
		}
	};
}

// ArrowControl is a GControl.
// We define the function first
function ArrowControl()
{
  this.options = 
  {
    animate: true, setup: true,
    loadingImage: '/images/loading.gif',
    overlayBgImage: '/images/overlay-85.png',
    onOpen: function() { try { debugger;timer.stop(); } finally {} },
    onClose: function() { try { timer.start(); } finally {} }
  };
}

// To "subclass" the GControl, we set the prototype object to
// an instance of the GControl object
ArrowControl.prototype = new GControl(false, false);

// 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.
ArrowControl.prototype.initialize = function(map) {
  var rid = this.rid;
  var control = $('<img border="0" src="/images/left-top-arrow.png" />')
    .attr("title", this.title)
    .wrap('<a href="/Map.aspx" id="ex_map" />').parent()
    .click(function() {
      this.search = "?" +
        ["rid=" + rid, "lat=" + map.getCenter().lat(), "lng=" + map.getCenter().lng(), "zoom=" + map.getZoom()].join("&");
      debugger;
      $.fancybox(this.href, { type: 'iframe', width: $(window).width(), height: $(window).height() });
      return false;
    })
    .appendTo(map.getContainer())
    .get(0);

  return control;
};

// By default, the control will appear in the top left corner of the
// map with 5 pixels of padding.
ArrowControl.prototype.getDefaultPosition = function()
{
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(5, 5));
}

