﻿var popDialogueDiv = document.getElementById('popDialogueShadow'); //make global for close function
var popDialogueArrow = document.getElementById('dialogueArrow'); //make global for findPos function
var hrefLocation; //make global for findPos function
window.onresize = moveWindow; //move popup if resized

function moveWindow() { //check to see if moving is needed first
    if (popDialogueDiv != null && popDialogueDiv.style.display == 'block') {
        findPos(hrefLocation);
        }   
}
function PopDialogue(DialogueIframeUrl, href, DialogueTitle) //ShowPane (iframe link to show, referring link [cannot be areamap, has to be called from onClick] )
{

	popDialogueDiv = document.getElementById('popDialogueShadow'); //common popDialogue div
	popDialogueArrow = document.getElementById('dialogueArrow'); //arrow to show
	popDialogueTitle = document.getElementById('dialogueArrow'); //arrow to show

	popDialogueDiv.style.display = 'block'; //show popup win

	if(DialogueTitle==null){DialogueTitle=''};
	//document.getElementById('dialogueTitle').innerHTML= DialogueTitle;

	findPos(href); //position the popup... need to show it first to determine its height/width
	return false; // this removes the browser history
}

function findPos(href)// find place to draw popdialogue
{
	popDialogueArrow.style.display = 'block';	//show popup arrow
    hrefLocation = href;
	var curleft = curtop = 0;

	var linkWidth = href.offsetWidth;	

	if (href.offsetParent) { //get refering link's position top/left from page's top
		curleft = href.offsetLeft
		curtop = href.offsetTop
		while (href = href.offsetParent) {
			curleft += href.offsetLeft
			curtop += href.offsetTop
		}
		curleft -= 8;	//positioning fix
	}
	if (window.innerHeight){ //Mac Safari doesn't understand clientheight properly and winIE doesn't understand innerHeight
	}
	else {
		curtop = curtop+ 21; //fix IE positioning
	}
	var xoffSet = -495;	//drop popup 400px left
	var yoffSet = -50;	//drop popup 50px down
	var ArrowxoffSet = 488;	//drop arrow 410px right
	var ArrowyoffSet = 35;	//drop arrow 40px down
//*************************************************
	popDialogueDiv.style.left = curleft + xoffSet + 'px';
	popDialogueDiv.style.top = curtop + yoffSet + 'px'; // show link  below
	
	popDialogueArrow.className = 'arrowRight';
	popDialogueArrow.style.left = ArrowxoffSet + 'px'; //set arrow position
	popDialogueArrow.style.top = ArrowyoffSet + 'px'; //set arrow position

    toggleSelect('block',popDialogueDiv.style.left,popDialogueDiv.style.top,popDialogueDiv.offsetWidth,popDialogueDiv.offsetHeight);
}
function toggleSelect(displayIframe,x,y,w,h){// IE5&6 shows select items OVER popDialogue, fixed in IE7
	if (parseFloat(navigator.appVersion.split("MSIE")[1]) < 7) { //select box showing error in IE5&6
		var IEselectBoxFix = document.getElementById('IEselectBoxFix');
		IEselectBoxFix.style.left=x;
		IEselectBoxFix.style.top=y;
		IEselectBoxFix.style.display=displayIframe;
		IEselectBoxFix.width=w;
		IEselectBoxFix.height=h;
	}
} 
function PopDialogueClose() {
    toggleSelect('none',popDialogueDiv.style.left,popDialogueDiv.style.top,popDialogueDiv.offsetWidth,popDialogueDiv.offsetHeight);
	popDialogueDiv.style.display = 'none'; //hide popup win
	popDialogueArrow.style.display = 'none'; //hide popup win
}