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));
	}
}
//if (g_sBrowser == "NN" && g_fBrowserVersion < 5 && g_sOS == "Win") document.classes.s1.all['fontSize']="11px";
function buildFramePageName(nActivitySetID, nGrade, nTopic, nInitialPageID)
{
	var sPage = 'frames_asid_' + nActivitySetID + '_g_' + nGrade + '_t_' + nTopic + '.html';
	if (nInitialPageID == 2) sPage += "?open=activities";
	else if (nInitialPageID == 3) sPage += "?open=instructions";
	return sPage;
}
function openActivity(nActivitySetID, nGrade, nTopic, nInitialPageID)
{
	openActivityPage(buildFramePageName(nActivitySetID, nGrade, nTopic, nInitialPageID),nInitialPageID);
}
function openActivityFromQuery(nActivitySetID, nGrade, nTopic, nInitialPageID)
{
	openActivityPage("../../../nav/" + buildFramePageName(nActivitySetID, nGrade, nTopic, nInitialPageID),nInitialPageID);
}
function openActivityPage(sPage, nInitialPageID)
{
	var nHeight = screen.availHeight - 60;
	var nWidth = screen.availWidth - 12;
	if (nWidth > 1500) nWidth = (nWidth / 2) - 5;

	// IE
	if (document.all)
	{
		// WIN
		if (navigator.platform.indexOf('Mac') == -1)
		{
			// IE-Win
			window.open(sPage,'activity','resizable=yes,top=0,left=0,width=' + nWidth + ',height=' + nHeight + ',toolbar=0,status=0,location=1,menubar=0').focus();
		}
		// 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;
				hwnd.focus();
			}
			// IE5-MacOS
			else if (fAppVersion < 5.2)
			{
				if (nInitialPageID != 1) nWidth -= 284;
				else nWidth -= 8;
				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;
			}
			// IE5-MacOSX
			else
			{
				if (nInitialPageID != 1) nWidth -= 266;
				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")
		{
			// NN4-Win
			if (g_fBrowserVersion < 6) window.open(sPage,'activity','resizable=yes,top=0,left=0,width=' + nWidth + ',height=' + nHeight + ',toolbar=0,status=0,location=1,menubar=0').focus();
			// NN6
			else window.open(sPage,'activity','resizable=yes,top=0,left=0,width=' + nWidth + ',height=' + nHeight + ',toolbar=1,status=0,location=1,menubar=0').focus();
		}
		// MAC
		else
		{
			// NN4-Mac
			window.open(sPage,'activity','resizable=yes,top=0,left=0,width=' + nWidth + ',height=' + (nHeight+30) + ',toolbar=0,status=0,location=0,menubar=1').focus();
		}
	}
}

function navLanguage(language) {
  // 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
    curURL = window.location.href;
    indexLastSlash = curURL.lastIndexOf("/");
    if (indexLastSlash == -1)
    {
      indexLastSlash = curURL.lastIndexOf("\\");
    }
    pageName = curURL.substring(1+indexLastSlash);
    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();});

