document.write('<script type="text/javascript" src="banner.js"></script>');

function preloadImages() 
{
  if (document.images) 
  {
    var imgFiles = preloadImages.arguments;
    if (document.preloadArray == null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) for (var j=0; j < imgFiles.length; j++)
    {
      preloadArray[i] = new Image;
      preloadArray[i++].src = imgFiles[j];
    }
  }
}
function swapImage(img,src)
{
	imgObj = eval('document.' + img);
	if (imgObj != null)
	{
		document.swappedImg = imgObj;
		document.swappedImgSrc = imgObj.src;
		imgObj.src = src;
	}
}
function swapImgRestore()
{
	if (document.swappedImg != null) document.swappedImg.src = document.swappedImgSrc;
}
// sniff the browser
var g_sBrowser = document.all ? "IE" : "NN";
var g_fBrowserVersion = 5;
var g_sOS = navigator.platform.indexOf('Mac') == -1 ? "Win" : "Mac";
if (g_sBrowser == "IE")
{
	nVersionIndex = navigator.userAgent.indexOf('MSIE ') + 5;
	g_fBrowserVersion = parseFloat(navigator.userAgent.substring(nVersionIndex,nVersionIndex+4));
}
else if (g_sBrowser == "NN")
{
	g_fBrowserVersion = parseFloat(navigator.appVersion.substring(0,4));
	if (g_fBrowserVersion == 5)
	{
		nVersionIndex = navigator.userAgent.indexOf('Netscape6/') + 10;
		g_fBrowserVersion = parseFloat(navigator.userAgent.substring(nVersionIndex,nVersionIndex+3));
	}
}
function buildFramePageName(nActivitySetID, nGrade, nTopic, nInitialPageID)
{
	var sPage = 'frames_asid_' + nActivitySetID + '_g_' + nGrade + '_t_' + nTopic + '.html';
	if (nInitialPageID == 2) sPage += "?open=activities&from=" + getPageName();
	else if (nInitialPageID == 3) sPage += "?open=instructions&from=" + getPageName();
	else sPage += '?from=' + getPageName()
	return sPage;
}
function buildPageName(sPage, nInitialPageID)
{
	if (nInitialPageID == 2) sPage += "?open=activities&from=" + getPageName();
	else if (nInitialPageID == 3) sPage += "?open=instructions&from=" + getPageName();
	else sPage += '?from=' + getPageName()
	return sPage;
}
function openVM(sUrl, nInitialPageID)
{
	openActivityPage(buildFramePageName(nActivitySetID, nGrade, nTopic, nInitialPageID));
}
function openActivityFromQuery(nActivitySetID, nGrade, nTopic, nInitialPageID)
{
	openActivityPage("../../../nav/" + buildFramePageName(nActivitySetID, nGrade, nTopic, nInitialPageID));
}
function openActivityPage(sPage)
{
	var nHeight = screen.availHeight - 60;
	var nWidth = screen.availWidth - 12;
	if (nWidth > 1500) nWidth = 1100;
	window.name = "nav";

	// IE
	if (document.all)
	{
		// WIN
		if (navigator.platform.indexOf('Mac') == -1)
		{
			// IE-Win
			return window.open(sPage,'activity','resizable=yes,top=0,left=0,width=' + nWidth + ',height=' + nHeight + ',toolbar=0,status=0,location=1,menubar=0');
		}
		// MAC
		else
		{
			var nVersionIndex = navigator.userAgent.indexOf('MSIE ') + 5;
			var sAppVersion = navigator.userAgent.substring(nVersionIndex,nVersionIndex+4);
			var fAppVersion = parseFloat(sAppVersion);

			// IE4-Mac
			if (fAppVersion < 5)
			{
				hwnd = window.open('','resizable=yes,top=42,left=6,width=' + (nWidth-8) + ',height=' + nHeight + ',toolbar=0,status=0,location=0,menubar=1');
				hwnd.document.location.href=sPage;
				return hwnd;
			}
			// IE5-MacOS
			else if (fAppVersion < 5.2)
			{
				nHeight -= 2;
				hwnd = window.open('','activity','resizable=yes,top=0,left=0,width=' + nWidth + ',height=' + nHeight + ',toolbar=0,status=0,location=0,menubar=1');
				hwnd.document.location.href=sPage;
				return hwnd
			}
			// IE5-MacOSX
			else
			{
				return window.open(sPage,'activity','resizable=yes,top=0,left=0,width=' + nWidth + ',height=' + nHeight + 8 + ',toolbar=0,status=0,location=0,menubar=1');
			}
		}
	}
	// NN
	else
	{
		// WIN
		if (g_sOS == "Win")
		{
			return window.open(sPage,'activity','resizable=yes,top=0,left=0,width=' + nWidth + ',height=' + nHeight + ',toolbar=1,status=0,location=1,menubar=0');
		}
		// MAC
		else
		{
			return window.open(sPage,'activity','resizable=yes,top=0,left=0,width=' + nWidth + ',height=' + (nHeight+30) + ',toolbar=0,status=0,location=0,menubar=1');
		}
	}
}

function getPageName()
{
    curURL = new String(window.location.href);
    indexLastSlash = curURL.lastIndexOf("/");
    if (indexLastSlash == -1)
    {
      indexLastSlash = curURL.lastIndexOf("\\");
    }
	sPage = curURL.substring(1+indexLastSlash);
	if (sPage.indexOf("query.htm") != -1) sPage = "applets/controller/query/" + sPage;
    return sPage;
}

function navLanguage()
{
  // Determine selected language
  box = document.forms[0].lang;
  language = box.options[box.selectedIndex].value;

  // If it needs to go to index, go there
  if (arguments[0] == "query")
  {
    newURL = "http://nlvm.usu.edu/" + language + "/nav/vlibrary.html";
  }
  else
  {
    // Determine page name
    pageName = getPageName();
    newURL = "../../" + language + "/nav/" + pageName;
  }
  // Redirect to the same page, but for the selected language
  window.open(newURL, "_top");
  return false;
}

// JSTarget function by Roger Johansson, www.456bereastreet.com
var JSTarget = {
	init: function() {
		if (document.getElementById && document.createElement && document.appendChild) {
			var strVal = 'vm';
			var arrLinks = document.getElementsByTagName('a');
			var oLink;
			var oRegExp = new RegExp("(^|\\s)" + strVal + "(\\s|$)");
			for (var i = 0; i < arrLinks.length; i++) {
				oLink = arrLinks[i];
				if (oRegExp.test(oLink.className)) {
					oLink.onclick = JSTarget.openWin;
				}
			}
		}
	},
	openWin: function(e) {
		var event = (!e) ? window.event : e;
		if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
		else {
		    var oWin = openActivityPage(buildPageName(this.getAttribute('href'), this.getAttribute("rel")));
			if (oWin) {
				if (oWin.focus) oWin.focus();
				return false;
			}
			oWin = null;
			return true;
		}
	},
	// addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
	addEvent: function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn]( window.event );}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};
JSTarget.addEvent(window, 'load', function(){JSTarget.init();});