// XeDAR website common javascript
// Copyright 2011 XeDAR, Inc.
//
// Author: David Piper, Marcom Engineering, Littleton, Colorado, 303-548-4269

// Move a z-layered DIV into position on a centered page

function moveDiv(id, idLeft, idTop)
{
	var myWidth = 0, myLeft = 0;

	// Calculate the width for the various browsers
	
	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth; // non IE
	} else 
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			myWidth = document.documentElement.clientWidth;  // IE Standards complient mode
		} else 
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
				myWidth = document.body.clientWidth; // Old IE versions
			}
			
	// Set the width of the outermost table
	
	var elem = document.getElementById("viewportTable");
	myWidth = elem.clientWidth;
	//elem.style.width = myWidth;

	var elem = document.getElementById(id);
	
	if (document.layers) {
		elem.visibility = 'show';
	} else
	{
		if (myWidth < 900) { 
			myLeft = idLeft ;
		} else 
		{
			myLeft = ((myWidth - 900) / 2) + idLeft;
		}
		elem.style.left = myLeft + "px";
		elem.style.top = idTop + "px";
		elem.style.visibility = 'visible';
	}
}

// function to duplilcate a drop-down menu to the left column of a content page

function duplicateMenu (menuId) {
	if (!document.getElementById("leftMenuDiv") && menuId != "") {
		
		// Create a copy of the submenu div
		
		var elem = document.getElementById(menuId).cloneNode(true);
		elem.id = "leftMenuDiv";
		
		// Get the current document url, and cut it to the local pathname
		
		var localPath = document.URL.toString();
		if (localPath.substr(0,7) == "http://") localPath = localPath.substr(7);
		if (localPath.substr(0,8) == "https://") localPath = localPath.substr(8);
		var i = localPath.indexOf('/');
		if (elem.children.item(0).pathname.toString().substr(0,1) != '/') {
			localPath = localPath.substr(localPath.indexOf('/')+1);
		} else {
			localPath = localPath.substr(localPath.indexOf('/'));
		}
		
		// remove any arguments
		
		if (localPath.indexOf("?") >= 0) localPath = localPath.substr(0, localPath.indexOf("?"));
		
		// Patch to correct the localpath if it is a press release
		
		if (localPath == "/home/pressrelease.shtml") localPath = "/home/pressreleases.shtml";
		if (localPath == "/home/casestudy.shtml") localPath = "/home/casestudies.shtml";
		
		// find the menu item in the div, and mark it as the current selection
		
		for (i=0; i<elem.children.length; i++) {
			
			// Is this child a link?
			
			if (elem.children.item(i).nodeName == 'A') {
				
				// If this link is the current page, mark it as the current selection

				if (localPath == elem.children.item(i).pathname) {
					elem.children.item(i).innerHTML = '<img src="/home/images/redArrow.gif" width="6" height="9" border=""><span style="color:#f8d7a5">&nbsp;' + elem.children.item(i).innerHTML.toString(); + '</span>'
				}
			}
		}

		
		// Append the new div to the document
		
		document.getElementById("leftMenuCol").appendChild(elem);
		elem.className = "leftMenu";
		elem.style.zIndex = 5;
		
		// Remove the mouseover timers
		
		elem.onmouseover = null;
		elem.onmouseout = null;
		
	}
}


// Process the drop-down menus, including timeouts to pause closure

var timeout	= 500;
var closeTimer	= 0;
var currentMenuItem	= 0;


function menuOpen(id)
{	

	menuCancelCloseTimer();

	// close old layer
	if(currentMenuItem) currentMenuItem.style.visibility = 'hidden';

	// get new layer and show it
	currentMenuItem = document.getElementById(id);
	currentMenuItem.style.visibility = 'visible';

}


function menuClose()
{
	if(currentMenuItem) currentMenuItem.style.visibility = 'hidden';
}


function menuCloseTimer()
{
	closeTimer = window.setTimeout(menuClose, timeout);
}

function menuCancelCloseTimer()
{
	if(closeTimer)
	{
		window.clearTimeout(closeTimer);
		closeTimer = null;
	}
}

document.onclick = menuClose;

// Function to replace an image with a larger image, lower-left justified to the original image, moving the associated caption and copy.

function replaceImage(divId, newImage, newWidth, newHeight)
{
	var thisDiv = document.getElementById(divId)
	var thisDivCaption = document.getElementById(divId+"Caption");
	var thisDivCopy = document.getElementById(divId+"Copy");
	var thisImg = document.getElementById(divId).firstChild;
	var oldWidth = thisImg.width;
	var oldHeight = thisImg.height;
	thisImg.src = newImage;
	if (thisDiv.style.top == "") {
		thisDiv.style.top = oldHeight - newHeight  + "px"
		thisDivCaption.style.top = oldHeight - newHeight  + "px"
		thisDivCopy.style.top = oldHeight - newHeight  + "px"
	} else {
		thisDiv.style.top = ""
		thisDivCaption.style.top = ""
		thisDivCopy.style.top = ""
	}
	thisDiv.style.height = newHeight + "px"
	thisDiv.style.width = newWidth + "px";
	thisDiv.height = newHeight;
	thisDiv.width = newWidth;
	thisImg.src = newImage;
	thisImg.width = newWidth;
	thisImg.height = newHeight;
}

// Google Analytics tracking code

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20595961-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

