/**
 * Popup (and Popout) Links Library
 * JavaScript for Aurora Software website http://www.aurorasoft.com.au/
 * (C) 2009 Aurora Software
 **/

function preparePopupLinks() {
  $('wrapper').getElementsBySelector('a.popup').each(function(a) {
    Event.observe(a, 'click', function(ev) { showPopup(ev.target.href); Event.stop(ev); return false; });
  });
  $('wrapper').getElementsBySelector('a.popout').each(function(a) {
    Event.observe(a, 'click', function(ev) { window.open(findLink(ev.target).href); Event.stop(ev); return false; });
  });
}
function findLink(start) {
	if (start.tagName.toUpperCase() != 'A') {
		return start.up('a');
	} else {
		return start;
	}
}
function showPopup(url) {
  new Ajax.Request(url,
    { method: "GET",
      onSuccess: function(transport) {
        $('popup-content').innerHTML=transport.responseText;
        $('overlay').addClassName('visible');
        $('popup').addClassName('visible');
      },
      onFailure: function(transport) {
      }
    }
  );
}
function hidePopup() {
  $('popup').removeClassName('visible');
  $('overlay').removeClassName('visible');
}

/**
 * KICK OFF THE SCRIPT
 **/
document.observe('dom:loaded', preparePopupLinks);


/**
 * Inline Popup Library
 * JavaScript for Aurora Software website http://www.aurorasoft.com.au/
 * (C) 2009 Aurora Software
 **/

function addInlinePopupTrigger(popup, target) {
	target=$(target);
	popup=$(popup);
  Event.observe(target, 'mouseover', function(ev) { showInlinePopup(popup, ev); });
  Event.observe(target, 'mouseout', function(ev) { hideInlinePopup(popup); });
  Event.observe(target, 'mousemove', function(ev) { moveInlinePopup(popup, ev); });
}

function showInlinePopup(id, ev) {
	moveInlinePopup(id, ev);
	$(id).setStyle({ display: 'block' });
}
function hideInlinePopup(id) {
	if ($(id).hasClassName('puffable')) {
		Effect.Puff(id, { duration: 0.3 });
	} else {
		Element.hide($(id));
	}
}
function moveInlinePopup(id, ev) {
	$(id).setStyle({ left: ev.clientX + 10 + "px", top: ev.clientY + 10 + "px" });
}
