var sDfltUserName = "DefaultGallery";
var contentFldrName = "VirtualGallerie/Main"; //"ContentFolder";
var galleriesFldrName = "\\Galleries\\";
var pDfltUserDir = myDir + "\\" + contentFldrName + galleriesFldrName + "srcGalleryXML\\";
var usersDir = myDir + "\\" + contentFldrName + galleriesFldrName;
var contentDir = myDir + "\\" + contentFldrName + galleriesFldrName;

var b_smallPlayer = (screen.width < 1000);

var webPageName = gs_noFramesWebBaseName + ".html"

var pagePath = contentFldrName + DIR_SEP + "Web" + DIR_SEP + webPageName;

var winH = b_smallPlayer ? 560 : 730;
var winW = b_smallPlayer ? 800 : 1024;
var winX = -5, winY = -31; //will only really work in IE, in moz it'll be treated as 0,0

var win_prams = "scrollbars=no,resizable=yes,top=-24";
if (b_smallPlayer) win_prams = "scrollbars=yes,resizable=yes,top=-24";

var wio_GW = new Com.Jantje.WindowInfoObj(pagePath, "GW", "gallery", winH, winW, "no", win_prams);;
var wot = null;

var mac=(navigator.appVersion.indexOf("Mac")!=-1)?true:false;

var gb_doneInitialResize = false;
var gs_currentLaunchType = "";

function reallyDoneResize(b_really) {
	if (b_really) {
		gb_doneInitialResize = true;
	} else {
		setTimeout("reallyDoneResize(true);", 10);
	}
}
function doButtonClicked() {

	if (wio_GW.isWindowOpen()) {
		setWindowSizeAndLoc(true);
	} else {
		var er;
		if ((er = wio_GW.openOrReload()) == null) {
			if (wio_GW.isWindowOpen() && setWindowSizeAndLoc(true)) {
				reallyDoneResize(false);
				wio_GW.gotoTheWindow();
			} else {
				wot = setInterval('timerFill()',40);
			}
		} else {
			alert("There has been a problem opening up the main Curator page. Please contact your system administrator.");
			return false;
		}
	}

	return true;
}

function timerFill() {
	if (wio_GW.isWindowOpen() && setWindowSizeAndLoc(true)) {
		clearInterval(wot);
		wot = null;
		reallyDoneResize(false);
		wio_GW.gotoTheWindow();
	}
}

function setWindowSizeAndLoc(b_loc) {
	if (gi_hardDim_W && gi_hardDim_H) {
		try {
			wio_GW.setSize(gi_hardDim_W, gi_hardDim_H);
		}
		catch (er) {
			return false;
		}

		if (b_loc) {
			var y = (screen.height - (gi_hardDim_H + 31)) / 2.0;
			var x = 2 + (screen.width - (gi_hardDim_W)) / 2.0;
			try {
				wio_GW.setPosition(x, y);
			}
			catch (er) {
				return false
			}
		}
	} else {
		var lo = null;
		var er;
		if (b_loc) lo = { x : -5 , y : -31 };

		if (er = wio_GW.fillScreen(lo)) {
			return false;
		}

	}
	return true;
}

function quitGal() {
	if (wio_GW) wio_GW.closeWin();
}
/*
function pulseInstallCheck(br, os) {
//todo: add player check to launch/log-in page

	if (!Pulse.Player.isInstalled) {
		if (Pulse.Player.browserSupported) {
			if (os == "Windows") {
                if (IE4) {
					return true; //automated
				} else if (GECKO) { //todo: what about older ones?
					//loadPlayerLoadPage();
                    doOSText("getPlyr", br);
                    return false;
				}
				return false;
			} else if (os == "Mac") {

                doOSText("getPlyr", br);

                return false;
            }
		}
        doOSText(os, br);
		return false;
	}
	return true;
}
*/
var iev = getInternetExplorerVersion();

if (b_ie = (iev > 0)) {

	if (iev < 6.0) {
		setTimeout('alert("You are using a fairly old version of Internet Explorer. Your Virtual Gallerie may experience some difficulties.");', 2);
	}
}
/*
var gb_badWinFF = false, gb_shownBad = false;

function badFFCheck() { //return true if bad
	var os = BrowserDetect.OS, ffv;
	if ((os == "Windows") && (ffv = getFirefoxVersion())) { //ieq
		if (ffv[0] == 3) {
			gb_badWinFF =  (ffv[1] > 5);
		} else {
			gb_badWinFF = (ffv[1] >= 4);
		}
	}
	return gb_badWinFF;
}
function bCanOpen() {
	var bad_vers = "", b_bad_IE = false;
	//if (!pulseInstallCheck(BrowserDetect.browser, BrowserDetect.OS) || 1) {
	badFFCheck();

	if (gb_badWinFF) {
	} else if (Pulse.Player.isInstalled) return true;
	else if (Pulse.Player.browserSupported && IE4) {
		if (!gb_vista && (gi_maxAutoInstallIE >= getInternetExplorerVersion())) return true;
		else b_bad_IE = true;
	}

	var br = BrowserDetect.browser, os = BrowserDetect.OS;

	var s = "<center><strong>Pulse Player needed</strong></center><br>Virtual Gallerie products require the Pulse Player plugin in order to run. "

	if (gb_badWinFF) {
		s += "<br><br>Unfortunately, Virtual Gallerie is currently having problems with Windows versions of Firefox that are version 3.6 or higher."
			+ "<br><br>To use Virtual Gallerie on Windows, please use either Firefox version 3.5.x or below, or Internet Explorer. Or to use on Macs with Intel-based chips, you can use Safari or any version of Firefox.";
	} else if (!Pulse.Player.browserSupported) {
		s += "<br><br>Unfortunately, the Pulse Player is not supported ";

		if (os == "Windows") {
			s + "in " + br + " on Windows. It is currently supported in Windows in Firefox versions 3.5.x and below, and Internet Explorer. It is also supported in Firefox or Safari on Macs with Intel-based chips.";
		} else if (os == "Mac") {
			s + "in " + br + " on the Mac. It is currently supported in Firefox or Safari on Macs with Intel-based chips, or on Windows in Firefox versions 3.5.x and below or Internet Explorer."
		} else {
			s += "on the " + os + " operating system. It is currently supported in Internet Explorer or Firefox on Windows, or in Firefox or Safari on the Mac.";
		}

		s += "<br><br>Please try the Virtual Galleries on one of the abovementioned configurations.";
	} else {
		s += "It appears that you do not currently have it. Please click on the \"Get Pulse Player\" button below to ";

		if (gb_vista || b_bad_IE) {
			if (!b_bad_IE) {
				s += "download and start the installer. You will need to restart your browser after running the installer.  You will need to return to this page to start the demos.";
			} else {
				s += "download and start the installer. When you are done running the installer, please refresh this page and click on a demo button.";
			}
		} else if (br == "Firefox") {
			s += "start the installer. You will need to restart Firefox as part of the install, but Firefox should automatically prompt you to do so.(After clicking the button, Firefox may present you with a bar at the top of the screen preventing you from installing. If so, please click the 'Allow' (or 'Edit Options', depending on your version of Firefox) button on the right side of the bar to continue).";
 		} else if (br == "Safari") {
 			s += "download and start the installer. You will need to restart Safari after running the installer.  You will need to return to this page to start the demos. After dowloading, the file should automatically decompress and the installer should start. If it doesn't, you will need to open the downloaded \"PulsePlayer5Mac.mpkg.zip\" file, and then open and run the \"PulsePlayer5Mac.mpkg\" file.";
 		} else { //it's a non-firefox version of GECKO/Mozilla

 		}

 		s += '<br><br><center><input type="button" class="button-standard" id=getmacpl value="Get Pulse Player" href="#" onclick="getAutoPPlayer();return false;"></center>';

		s += "<br>You'll need administrator access on your machine to install the Pulse Player plugin.";
	}

	var lyr = objFromID("getPlyrDiv"), td = objFromID("getPlyrTD");





		lyr.style.visibility = "visible";
		td.innerHTML = s;
		return false;


}
*/
/*
	var qs = getNewQueryStart("iot", launch_type);

		qs += getNewQueryAppendItem("bid", bldg_id);
		qs += getNewQueryAppendItem("fid", floor_id);
		qs += getNewQueryAppendItem("mode", the_mode);

		if (gs_autoGalFldrName) qs += getNewQueryAppendItem("galFldrName", gs_autoGalFldrName);

		if (gs_location) {
			qs += getNewQueryAppendItem("nl", gs_location);
			qs += getNewQueryAppendItem("rt", relocationType);
		}

		if (launch_type == "new") {

		}

		if (gb_useFauxQuery) objFromID("fqs").value = qs;
		else wio_GW.setQueryString(qs, true);
	*/

function reloadPageWithLaunchType(lt) {
	var loc = window.location.toString();
	var qi;
	if ((qi = loc.indexOf("?")) > -1) loc = loc.substring(0, qi);
	loc += "?lt=" + lt;
	window.location.href = loc;
	return;
}

function launchPageLoaded() {
	var loc = window.location.toString();
	var qi = loc.indexOf("?");
	var b_do_check = true;
	if ((qi > -1) && ((qi = loc.indexOf("lt=", qi)) > -1)){
		switch(loc.charAt(qi + 3)) {
		case "w": LaunchGallerie(); b_do_check = false; break;
		case "c": LaunchCurator(); b_do_check = false; break;
		default:
			break;
		}
	}
	if (b_do_check) {
		badVersionsCheck();
	}
}
    function LaunchGallerie() {
    	if (gb_postInstallNeedsRefresh) {
    		reloadPageWithLaunchType("w");
    		return;
    	} else {
    		gs_currentLaunchType = "w";
    	}
    	if (bCanOpen(true)) {
		var fqs = "?mode=run&galName=" + contentDir + "DefaultGallery";

		document.theForm.nameFld.value = "DefaultGallery_VIEW";
		document.theForm.modeStr.value = "run";
		document.theForm.fqs.value = fqs;

		doButtonClicked();
    	}
    }
    function LaunchCurator() {
	if (gb_postInstallNeedsRefresh) {
		reloadPageWithLaunchType("c");
		return;
	} else {
		gs_currentLaunchType = "c";
	}
	if (bCanOpen(true)) {
		var fqs = "?mode=edit&galName=" + contentDir + "DefaultGallery";

		document.theForm.nameFld.value = "DefaultGallery";
		document.theForm.modeStr.value = "edit";
		document.theForm.fqs.value = fqs;

		doButtonClicked();
	}
    }
    function fldDown(the_event, fld) {

		if (the_event.keyCode == 13) {
			var fv = fld.value;

			if (fv != "") {
				goToUserPage(fv, document.theForm.modeStr.value);
			}
			return false;
		}
		return true;

	}

	function enterClicked() {
		if (document.theForm.nameFld.value) {
			goToUserPage(document.theForm.nameFld.value, document.theForm.modeStr.value);
		}
	}

	function goToUserPage(user_name, mode_str) {
		var user_dir = usersDir + user_name;
		//location = user_name;
		//window.open("Web/VirtualGallery.html");

		if (mode_str == "edit") {
			if (!folderExists(user_dir)) {
					if (folderExists(pDfltUserDir)) {
						if (copyFolder(user_dir, pDfltUserDir)) {

						} else {
							document.theForm.nameFld.value = sDfltUserName;
							alert("couldn't create new gallery for user, using default");
						}
					}

			}
		} // else we don't check, but won't work if not there (but don't want the activeX warning for viewing)

		doButtonClicked();
	}


/*
function getAutoPPlayer() {
	var b_explorer = (BrowserDetect.browser == "Explorer"); //has to be a "needs installer" version, or wouldn't be here!

	if (gb_vista || b_explorer) {

		addPostInstallClickInfo(b_explorer ? "Internet Explorer" : BrowserDetect.browser, b_explorer);
		window.location = gs_rootPathForPluginspage + "/english/5.2/win/PulsePlayer5.2Win.exe";
	} else if (BrowserDetect.browser != "Safari") { //todo: really check for things that suppport .xpi?
        	Pulse.Player.Install.startInstall();
    	} else {
    	    addPostInstallClickInfo("Safari");
    	    window.location = gs_rootPathForPluginspage + "/english/5.2/macx/PulsePlayer5Mac.mpkg.zip";

    	}
	return true;
}
function addPostInstallClickInfo(brz, b_no_restart) {
    var msg = !b_no_restart
    	? "When the installer has finished running, please restart " + brz + ", and return to this page. You may just want to copy the address from the address field before you quit, so you can paste it back in after restarting " + brz + ". Thanks!"
    	: "When the installer has finished running, please click on one of the 'Begin Demo' buttons to refresh the page and start the demo. If it still asks you to get the Player after installing and refreshing, you may need to restart " + brz + ". Thanks!";

    td = objFromID("getPlyrTD");
    td.innerHTML = msg;

    gb_postInstallNeedsRefresh = b_no_restart;
}

			function replSpan(id, v) {
				var sp = document.getElementById(id);
				sp.innerHTML = v;
			}

	    function drawMainText() {
			var bv = getOS();

            if (!pulseInstallCheck(BrowserDetect.browser, BrowserDetect.OS)) {
                return;
            }



			var b_ie = true;

			var iev = getInternetExplorerVersion();

			if (b_ie = (iev > 0)) {

				if (iev < 6.0) {
					alert("You are using a fairly old version of Internet Explorer. Your LACMA Virtual Gallerie may experience some difficulties.");
				}
			}



			if (!((bv == "Windows") || (bv == "MacOS"))) {
				doOSText(bv);
				return;
			} else {
				if (!b_ie) {
					replSpan("span_pub", "click the 'Options' button at the top right of the page. You should then select 'Allow Pop-ups for lacma.org'. You may then need to press " + getRefreshKeyDesc(bv) + " to reload the page.");
					replSpan("span_ip", "click the 'Click here to install the Pulse Player' link near the bottom left of the blue Pulse screen.");
				}
				var main_div = document.getElementById("mainDiv");
				main_div.style.visibility = "visible";


			}

	    }
	    function doOSText(bv, brv) {
            var b_can_do_auto_install = true;
	    	var main_div = document.getElementById("mainDiv");

	    	main_div.style.visibility = "hidden";
            if (bv == "getPlyr") {
                var get_plyr_div = document.getElementById("getPlyrDiv");
	    		get_plyr_div.style.visibility = "visible";
	    		get_plyr_div.style.position = "absolute";
                if (brv == "Firefox") {
                    if (b_can_do_auto_install) {
                        replSpan("ppAutoSpan",
                             "start the installer. (Firefox will most likely present you with a bar at the top of the screen preventing you from installing. If so, please Click the 'Allow' (or 'Edit Options', depending on your version of Firefox) button on the right side of the bar to continue). You will need to restart your browser as part of the install. You may then need to log back in to MyLACMA to see the gallery.");
                    } else {
                        replSpan("macInstallSpan", "In Firefox");
                    }
                }
	    	} else if (bv == "Mac") {
	    		var mac_div = document.getElementById("macDiv");
	    		mac_div.style.visibility = "visible";
	    		mac_div.style.position = "absolute";
	    	} else {
	    		var otheros_div = document.getElementById("otherosDiv");
				otheros_div.style.visibility = "visible";
				mac_div.style.position = "absolute";
	    	}

	    }


	    function getInternetExplorerVersion()
		// Returns the version of Internet Explorer or a -1
		// (indicating the use of another browser).
		{
		  var rv = -1; // Return value assumes failure.
		  if (navigator.appName == 'Microsoft Internet Explorer')
		  {
		    var ua = navigator.userAgent;
		    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		    if (re.exec(ua) != null)
		      rv = parseFloat( RegExp.$1 );
		  }
		  return rv;
		}
		function getRefreshKeyDesc(os) {
			return (os == "Windows") ? "F5" : "Apple Key + R";
		}
		function getOS() {
		//return "MacOS";
			var OSName="Unknown OS";
			if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
			if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
			if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
			if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

			return OSName;

		}


var gb_vista = BrowserDetect.dataOS.version && (BrowserDetect.dataOS.version[0] > 5); //well, really == 6, but for now make all as true
var gi_maxAutoInstallIE = 7;
var gb_postInstallNeedsRefresh = false;

*/
/*
var gb_forceInstaller = false;//true;
var gb_shownBad = false, gb_badPPC, gb_badEnviro, gb_safari64;

var gi_maxAutoInstallIE = 7;
var gb_postInstallNeedsRefresh = false;

function badVersionsCheck() { //return true if bad
	var os = BrowserDetect.OS, ffv;
	if (os == "Windows") {
		if (ffv = getFirefoxVersion()) { //ieq

		}
	} else if (os == "Mac") {
		if (!BrowserDetect.Mac.b_intel) {
			gb_badEnviro = gb_badPPC = true;
			bCanOpen();
			return true;
		} else if (gb_safari) {
			if (BrowserDetect.Mac.vers[1] >= 6) {
				gb_safari64 = true;
				var lyr = objFromID("getPlyrDiv"), td = objFromID("getPlyrTD");

				lyr.style.visibility = "visible";
				td.innerHTML = "Virtual Gallerie currently has an issue with running in Safari running in 64-bit mode on OS X versions 10.6 or later. If your version of Safari is running as a 64-bit application (the default), you will need to quit out and restart it as a 32-bit application. Or you can run on the Mac in Firefox or Chrome.";

				return false;
			}
		}
	}
	return false;
}
function bCanOpen(b_alert_if_unsupported) {
	var bad_vers = "";
	var b_updatePP = PP_doesWinFFNeedUpdate();

	if (gb_badEnviro && gb_shownBad) {
		if(b_alert_if_unsupported) showAlert(getLocalUIString_LI("unsupportedLaunch"));
		return false;
	}

	//if (!pulseInstallCheck(BrowserDetect.browser, BrowserDetect.OS) || 1) {

	if (!b_updatePP && (Pulse.Player.isInstalled || (Pulse.Player.browserSupported && IE4 && !gb_vista))) return true;

	gb_shownBad = true;

	var br = BrowserDetect.browser, os = BrowserDetect.OS;

	var s = "<center><strong>Pulse Player needed</strong></center><br>Virtual Gallerie products require the Pulse Player plugin in order to run. "

	if (gb_badPPC) {
		s += "<br><br>Unfortunately, Virtual Gallerie only works on Macs with Intel-based chips, or on Windows."
				+ "<br><br> To use Virtual Gallerie on Macs with Intel-based chips, you can use Safari, Chrome, or any version of Firefox. Or on Windows, please use either Firefox version 3.5.x or below, or Internet Explorer";
			if (b_alert_if_unsupported) showAlert(getLocalUIString_LI("unsupportedLaunch"));

	} else if (!Pulse.Player.browserSupported) {
		s += "<br><br>Unfortunately, the Pulse Player is not supported ";

		if (os == "Windows") {
			s + "in " + br + " on Windows. It is currently supported in Windows in Firefox versions 3.5.x and below, and Internet Explorer. It is also supported on Macs with Intel-based chips in Firefox, Chrome, and Safari.";
		} else if (os == "Mac") {
			s + "in " + br + " on the Mac. It is currently supported in Firefox, Chrome, and Safari, on Macs with Intel-based chips, or on Windows in Firefox versions 3.5.x and below or Internet Explorer."
		} else {
			s += "on the " + os + " operating system. It is currently supported on Windows in Internet Explorer or Firefox, and on the Mac in Firefox, Chrome, and Safari.";
		}

		s += "<br><br>Please try the Virtual Galleries on one of the abovementioned configurations.";
		if (b_alert_if_unsupported) showAlert(getLocalUIString_LI("unsupportedLaunch"));
	} else {
		if (b_updatePP) s += "It appears that your version is out of date.";
		else s += "It appears that you do not currently have it.";
		
		s += " Please click on the \"Get Pulse Player\" button below to ";

		if (br == "Firefox") {
			s += "start the installer. You will need to restart Firefox as part of the install, but Firefox should automatically prompt you to do so.(After clicking the button, Firefox may present you with a bar at the top of the screen preventing you from installing. If so, please click the 'Allow' (or 'Edit Options', depending on your version of Firefox) button on the right side of the bar to continue).";
		} else if (gb_vista) {
			if (br != "Explorer") {
				s += "download and start the installer. You will need to restart your browser after running the installer.  You will need to return to this page to start the demos.";
			} else {
				s += "download and start the installer. When you are done running the installer, please refresh this page and click on a demo button.";
			}
		} else if (br == "Safari") {
 			s += "download and start the installer. You will need to restart Safari after running the installer.  You will need to return to this page to start the demos. After dowloading, the file should automatically decompress and the installer should start. If it doesn't, you will need to open the downloaded \"PulsePlayer5Mac.mpkg.zip\" file, and then open and run the \"PulsePlayer5Mac.mpkg\" file.";
		} else if (br == "Chrome") {
			s += "download the installer.<br><br>After dowloading (a link should appear at the bottom left corner of this window when done), you will need to unzip the downloaded \"PulsePlayer5Mac.mpkg.zip\" file, and then open and run the \"PulsePlayer5Mac.mpkg\" file that it contains.  You will need to restart Chrome after running the installer, and return to this page to start the demos.";
 		} else { //it's a non-firefox version of GECKO/Mozilla

 		}

 		s += '<br><br><center><input type="button" class="button-standard" id=getmacpl value="Get Pulse Player" href="#" onclick="getAutoPPlayer();return false;"></center>';

		s += "<br>You'll need administrator access on your machine to install the Pulse Player plugin.";
	}

		//check to see if this platform is supported.... and if yes, then do the install, else....
		/// possibilities:
		//	1) windows
		//		a) IE: will automatically install when running the content
		//		b) FF: do it here, and will automatically reopen and return here
		//	2) mac
		//		a) Safari: download the installer, run it (or, if not automatic, unzip and run (hmmmm.... do some people not have unzip?
		//		b) FF: do it here, and will automatically reopen and return here.
		//
		//
	var lyr = objFromID("getPlyrDiv"), td = objFromID("getPlyrTD");


	lyr.style.visibility = "visible";
	td.innerHTML = s;
	return false;

}


function getAutoPPlayer() {
	if (gb_vista && (BrowserDetect.browser == "Explorer")) {
		var b_explorer = (BrowserDetect.browser == "Explorer");
		addPostInstallClickInfo(b_explorer ? "Internet Explorer" : BrowserDetect.browser, b_explorer);
		window.location = gs_rootPathForPluginspage + "/english/5.2/win/PulsePlayer5.2Win.exe";
	} else if (gb_safari || gb_chrome) {
		addPostInstallClickInfo(BrowserDetect.browser);
		window.location = gs_rootPathForPluginspage + "/english/5.2/macx/PulsePlayer5Mac.mpkg.zip";
	} else {
		Pulse.Player.Install.startInstall();
    }
	return true;
}

function addPostInstallClickInfo(brz, b_no_restart) {
    var msg = !b_no_restart
    	? "When the installer has finished running, please restart " + brz + ", and return to this page. You may just want to copy the address from the address field before you quit, so you can paste it back in after restarting " + brz + ". Thanks!"
    	: "When the installer has finished running, please refresh this page (F5) and click on one of the 'Begin Demo' buttons. If it still asks you to get the Player after installing and refreshing, you may need to restart " + brz + ". Thanks!";

    td = objFromID("getPlyrTD");
    td.innerHTML = msg;

    gb_postInstallNeedsRefresh = b_no_restart;
}



function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function getLocalUIString_LI(id) {
	switch(id) {
	case "unsupportedLaunch":
		return "We are sorry but you can not lunch Virtual Gallerie with your current Browser/OS configuration. Please see the note in the red-outlined box.";
		break;
	default:
		return id;
		break;
	}
}
*/