// qdm.js
// Script support for the QDM Website

var x;
var y;
var xLimit;
var yLimit;
var xInc;
var yInc;
var ratio;
var popupText;
var t;
var tl;

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}


function getOffsetLeft (el) {
 var ol = el.offsetLeft;
 while ((el = el.offsetParent) != null)
 ol += el.offsetLeft;
 return ol;
}

function getOffsetTop (el) {
 var ot = el.offsetTop;
 while((el = el.offsetParent) != null)
 ot += el.offsetTop;
 return ot;
}

function show_pop(theImage, index) {
  coords = findPos(theImage);
  x=coords[0]; 
  y=coords[1]; 
  xInc = (xLimit - x)/25;
  yInc = (yLimit - y)/25;
  ratio = 0;

  switch(index) {

    case 1:
      popupText = "The <b>SPARC</b> program, developed by QDM software engineers, helps DOD planners " + 
	    "assess constantly changing worldwide airspace requirements and their impact on " +
                  "the growing number of equipage-based airspace limitations. SPARC helps planners " +
                  "make the decisions of what aircraft to upgrade and when, while considering " +
                  "the impact of non-compliance to both maximize effective use of resources and ensure " +
                  "global mobility. More info: <b>https://sparc.qdmetrics.com</b>";    
      break;
    case 2:
      popupText = "&lt;Information about image " + index + "&gt;";
      break;
    case 3:
      popupText = "&lt;Information about image " + index + "&gt;";
      break;
    case 4:
      popupText = "&lt;Information about image " + index + "&gt;";
      break;
    case 5:
      popupText = "&lt;Information about image " + index + "&gt;";
      break;
    case 6:
      popupText = "&lt;Information about image " + index + "&gt;";
      break;
  }

  thePopupLayer.style.visibility = "visible";
  open_pop()
}

function hide_pop(index) {
  popupText = "";
  thePopupLayer.innerHTML = popupText;
  thePopupLayer.style.background = "#FFFFDD";
  thePopupLayer.style.border = "1px solid #FF0000";
  thePopupLayer.style.visibility = "hidden";
}

function open_pop() {

    x = x + xInc;
    y = y + yInc;
    ratio += .036
  
    thePopupLayer.style.left = x + 'px';
    thePopupLayer.style.top = y + 'px';
    thePopupLayer.style.height = 150*ratio + 'px';
    thePopupLayer.style.width = 300*ratio + 'px';
  
    if (y <= yLimit) {
      clearTimeout(t);
      thePopupLayer.style.left = xLimit + "px";
      thePopupLayer.style.top = yLimit + "px";
      thePopupLayer.style.height = 150 + 'px';
      thePopupLayer.style.width = 275 + 'px';	
      thePopupLayer.style.background = "transparent url(/qdm/images/popup.gif) no-repeat";
      thePopupLayer.style.border = "0px solid #FF0000";
      thePopupLayer.innerHTML = popupText;
    }
    else {
      t=setTimeout("open_pop()", 1);
    }

}

function close_pop() {
  x = x - xInc;
  ratio = (x-130)/220;
  y = 157 + (64 * ratio);
  thePopupLayer.style.left = x;
  thePopupLayer.style.top = y;


  if (x <= 130) {
    clearTimeout(tl);
    popupText = "";
    thePopupLayer.innerHTML = popupText;
    thePopupLayer.style.background = "#FFFFDD";
    thePopupLayer.style.border = "1px solid #FF0000";
    thePopupLayer.style.visibility = "hidden";
  }
  else {
    tl=setTimeout("close_pop()", 10);
  }
}
