/*=======================================================================*
*	         Copyright 2002-10 by Virtual Gallerie, LLC.             *
*     This material is the confidential trade secret and proprietary     *
*     information of Virtual Gallerie, LLC. It may not be reproduced,    *
*     used, sold or transferred to any third party without the prior     *
*     written consent of Virtual Gallerie, LLC. All rights reserved.	 *
*=======================================================================*/
var b_smallPlayer = false;
var safetyLeft = 24;
var minWinW = 1024, minWinH = 730;
//1280 1024
var playerBorder_R = 800;
var playerBorder_B = 600;
var b_larger = false;//never used, eh?
var sizeType = 1280;
var maxSizeType = 1400;
//var sizeHeight = screen.height;

var gi_hardDim_W = 0, gi_hardDim_H = 0;

var gs_webPageBaseName = "VirtualGallery";
var gs_noFramesWebBaseName = "VirtualGallerie";
var gs_bldSetName = "default";

try {
	gs_bldSetName = bldSetName;
}
catch (e) {}

var buttRowH;

var gi_winSpace_W, gi_winSpace_H;

//1024x768
//1280x1024 //960?
//1400x1050
//1600x1200
//wideScreen?
//if (screen.width >= 1600) sizeType = 1600;
//else

/* //uncomment for 1280x768
gi_hardDim_W = 1280;
gi_hardDim_H = 768;
sizeType = 1024;
*/
var gb_useOpenerForSizetype = false;

try {
	gb_useOpenerForSizetype = gb_useMySizeTypeOpenee;
}
catch(er) {}

if (hasGoodOpener() && !isUndefined(opener.gi_winSpace_W) && gb_useOpenerForSizetype) {
	gi_winSpace_W = opener.gi_winSpace_W;
	gi_winSpace_H = opener.gi_winSpace_H;
	sizeType = opener.sizeType;
} else {
	var b_use_screen = true;
	var loc = window.location.toString();

	var i = loc.lastIndexOf(gs_webPageBaseName);
	var di, dl;
	var st = sizeType;

	if (gi_hardDim_W) {
		b_use_screen = false;
		st = sizeType;
	} else if (i > -1) {
		i += gs_webPageBaseName.length;
		if ((di = loc.indexOf(".", i)) == i) {
			st = maxSizeType; // same as 1600.. ie, page was <gs_webPageBaseName>.html
			b_use_screen = false;
		} else if (((dl = (di - i)) == 3) || (dl == 4) ) {
			if (((st = new Number(loc.substring(i, di))) >= 800) && (st <= maxSizeType)) {
				b_use_screen = false;
			}

		}
	}

	if (b_use_screen) {//can't use window initially b/c it won't be the correct size if just opened!
		gi_winSpace_W = screen.width; //todo: this is for testing, in reality, need to do the browser and on-web tests
		gi_winSpace_H = screen.height;
	} else {
		alert("not b_use_screen");
	}

	if (b_use_screen) {
		if (gi_winSpace_W >= 1400) sizeType = 1400;
		else if ((gi_winSpace_W >= 1280) && (screen.height >= 960)) sizeType = 1280;
		else if (gi_winSpace_W >= 1024) sizeType = 1024;
		else sizeType = 800;
	} else {
		sizeType = st;
	}
}

sizeType = new Number(sizeType);

function setSizeTypeFromWindowSize() {//todo: really need better aspect ratio dealing
	var dims = getMyDocDims(true);
	if (dims.w >= 1400) sizeType = 1400;
	else if ((dims.w >= 1280) && (dims.h >= 960)) sizeType = 1280;
	else if ((dims.w >= 1280) || (dims.h >= 1024))sizetype = 1024;
	else sizeType = 800;
}
var initialInfoFrameH = 530;
var initialUIFrameH = 180;
var initialContextFrameH = 110;
var initialContextFrameW = 800;
var minPlayerH = 100;
var minPlayerW = 100;
var gi_contextUnderhang = 0;
var gi_dfltThumbDim_W, gi_dfltThumbDim_H;

var gi_minDim_UI_H = 60; // arbitrary... should be aspect ratio to the map....

var divDim_Min_H_Con, divDim_Min_W_Con,
	divDim_Min_H_UI, divDim_Min_W_UI,
	divDim_Min_H_Info, divDim_Min_W_Info,
	minContextW; //todo: ditch this


var pct_PLAYER_W_WIDE = 0.6, pct_PLAYER_H_WIDE = 0.6;
var pct_PLAYER_W_43 = 0.65, pct_PLAYER_H_43 = 0.6;

var pct_PLAYER_W = pct_PLAYER_W_43, pct_PLAYER_H = pct_PLAYER_H_43;
var gi_prefFontSize = 0, gi_prefFontSerif = 0, gi_minFontSize = 8;

//todo: we want the wide aspect, so should just base the v pct on the aspect we want with the w...


var gb_wideAspect = false;
var gi_allowNoPctPrefs = false;
var gi_maxDim_B, gi_maxDim_R;

var gi_frameDim_W_Info,
	gi_frameDim_H_Info,
	gi_frameDim_W_UI,
	gi_frameDim_H_UI,
	gi_frameDim_W_Con,
	gi_frameDim_H_Con;

function setAspect(b_wide) {
	if (b_wide) {
		setPcts(b_wide, pct_PLAYER_W_WIDE, pct_PLAYER_H_WIDE);
	} else {
		setPcts(b_wide, pct_PLAYER_W_43, pct_PLAYER_H_43);
	}
}

function setPcts(b_wide, w, h) {
	gb_wideAspect = b_wide;
	pct_PLAYER_W = w;
	pct_PLAYER_H = h;

	playerBorder_R = Math.floor(pct_PLAYER_W * gi_winSpace_W);
	if (playerBorder_R % 2) playerBorder_R += 1;

	playerBorder_B = Math.floor(pct_PLAYER_H * gi_winSpace_H);
	if (playerBorder_B % 2) playerBorder_B += 1;

	gi_maxDim_B = gi_winSpace_H - playerBorder_B;
	gi_maxDim_R = gi_winSpace_W - playerBorder_R;

}

setAspect(gb_wideAspect);


minPlayerW = playerBorder_R;
minPlayerH = playerBorder_B;
divDim_Min_H_Info = playerBorder_B;

initialUIFrameH = gi_maxDim_B - gi_maxDim_R; //todo: find the min aspect ratio (which could change if, say it's really wide b/c of a wide info....
if (initialUIFrameH > gi_maxDim_B) initialUIFrameH = gi_maxDim_B;
else if (initialUIFrameH < gi_minDim_UI_H) initialUIFrameH = gi_minDim_UI_H;

initialInfoFrameH = gi_winSpace_H - (initialUIFrameH + 30);//30 for horiz scroll bar? should there even be one?

if (initialInfoFrameH < divDim_Min_H_Info) {
	initialInfoFrameH = divDim_Min_H_Info;
	initialUIFrameH = gi_winSpace_H - (initialInfoFrameH + 30);
}

initialContextFrameH = gi_maxDim_B;
initialContextFrameW = playerBorder_R;


//todo: when actually redrawing the window for a window resize, we can move up the UI as much as we need, until the info frame reaches
//its divDim_Min_H_Info, at which time need to stop moving the ui...


if (sizeType == 1280) {
	minWinW = 1280;
	minWinH = 1024;
	/*
	minPlayerW = playerBorder_R = 1000;
	minPlayerH = playerBorder_B = 750;
	initialInfoFrameH = 650;
	initialUIFrameH=200;
	initialContextFrameH = 210;
	initialContextFrameW = 964;
	*/
	gi_dfltThumbDim_W = gi_dfltThumbDim_H = 32;

} else if (sizeType == 1400) {
	minWinW = 1400;
	minWinH = 1050;
	/*
	minPlayerW = playerBorder_R = 1000;
	minPlayerH = playerBorder_B = 750;
	initialInfoFrameH = 650;
	initialUIFrameH=201;
	initialContextFrameH = 210;
	initialContextFrameW = playerBorder_R;
	*/
	gi_dfltThumbDim_W = gi_dfltThumbDim_H = 35;
} else if (sizeType == 800) {
	minWinW = 800;
	minWinH = 600;
	/*
	minPlayerW = playerBorder_R = 640;
	minPlayerH = playerBorder_B = 480;
	initialInfoFrameH = 416;
	initialUIFrameH = 140;
	initialContextFrameH = 76;
	initialContextFrameW = playerBorder_R;
	*/
	gi_dfltThumbDim_W = gi_dfltThumbDim_H = 16;
} else { //1024:
	minWinW = 1024;
	minWinH = 730;

	/*
	minPlayerH = initialInfoFrameH = 531;
	minPlayerW = playerBorder_R = 800;

	playerBorder_B = 600;
	initialContextFrameH = 110;
	initialContextFrameW = playerBorder_R;
	*/
	gi_dfltThumbDim_W = gi_dfltThumbDim_H = 27;
}



buttRowH = gi_dfltThumbDim_H;

gi_contextUnderhang = playerBorder_R - initialContextFrameW;

divDim_Min_H_Con = gi_dfltThumbDim_H;
divDim_Min_W_Con = initialContextFrameW;

divDim_Min_H_UI = initialUIFrameH;

/* html vals for 800 x 600
	<input type="hidden" name="h_frameDim_W_Info" value="212" cols="7" rows="1" wrap="virtual">
	<input type="hidden" name="h_frameDim_H_Info" value="600" cols="7" rows="1" wrap="virtual">
	<input type="hidden" name="h_frameDim_W_UI" value="212" cols="7" rows="1" wrap="virtual">
	<input type="hidden" name="h_frameDim_H_UI" value="180" cols="7" rows="1" wrap="virtual">
	<input type="hidden" name="h_frameDim_W_Con" value="800" cols="7" rows="1" wrap="virtual">
	<input type="hidden" name="h_frameDim_H_Con" value="110" cols="7" rows="1" wrap="virtual">

// info frame is 530 high, and ui frame, thus, starts at 530, and top of context is 801
*/



var minRightFramesW = (minWinW + safetyLeft) - playerBorder_R - 55;

if (minRightFramesW > gi_maxDim_R) minRightFramesW = gi_maxDim_R;

var initialRightFramesW = minRightFramesW;

var minUIFrameW = (sizeType != 1280) ? minRightFramesW : 296;
var initialUIFrameW = (sizeType != 1280) ? initialRightFramesW : 296;



var imageSizePrefix = "";

var contextFrameW = playerBorder_R;

var minContextWPct = 0.8; //as percentage of playerBorder_R
var minContextHPctOfWin = 0.3;//0.5; //todo: make different depending on the  window aspect ratio, really...
//todo: max w/ for info and then try to make player wider?

//todo: use pct!
function setNewSizeType(st) { //todo: unused? delete if so!
	sizeType = st;
	if (sizeType == 1280) {
		minWinW = 1280;
		minWinH = 1024;
		minPlayerW = playerBorder_R = 1000;
		minPlayerH = playerBorder_B = 750;
		initialInfoFrameH = 650;
		initialUIFrameH=200;
		initialContextFrameH = 210;
		initialContextFrameW = 964;
		gi_dfltThumbDim_W = gi_dfltThumbDim_H = 32;

	} else if (sizeType == 1400) {
		minWinW = 1400;
		minWinH = 1050;
		minPlayerW = playerBorder_R = 1000;
		minPlayerH = playerBorder_B = 750;
		initialInfoFrameH = 650;
		initialUIFrameH=201;
		initialContextFrameH = 210;
		initialContextFrameW = playerBorder_R;
		gi_dfltThumbDim_W = gi_dfltThumbDim_H = 35;
	} else if (sizeType == 800) {
		minWinW = 800;
		minWinH = 600;
		minPlayerW = playerBorder_R = 640;
		minPlayerH = playerBorder_B = 480;
		initialInfoFrameH = 416;
		initialUIFrameH = 140;
		initialContextFrameH = 76;
		initialContextFrameW = playerBorder_R;
		gi_dfltThumbDim_W = gi_dfltThumbDim_H = 16;
	} else if (sizeType == 795) {
		minWinW = 600;
		minWinH = 400;
		minPlayerW = playerBorder_R = 340;
		minPlayerH = playerBorder_B = 210;
		initialInfoFrameH = 300;
		initialUIFrameH = 100;
		initialContextFrameH = 76;
		initialContextFrameW = playerBorder_R;
		gi_dfltThumbDim_W = gi_dfltThumbDim_H = 16;

		//these are defined in vgThumbs.js
		thumbDim_W = gi_dfltThumbDim_W;
		thumbDim_H = gi_dfltThumbDim_H;

		//from contextFrame.js :|
		buttRowH = gi_dfltThumbDim_H;

		//from frameInfo.js
		menuFontSize_IE = 7.5;

		labelFontSize_IE = 7;

	} else { //1024:
		minPlayerH = initialInfoFrameH = 531;
		minPlayerW = playerBorder_R = 800;
		playerBorder_B = 600;
		minWinW = 1024;
		minWinH = 730;
		initialContextFrameH = 110;
		initialContextFrameW = playerBorder_R;
		gi_dfltThumbDim_W = gi_dfltThumbDim_H = 27;
	}


	thumbDim_W = gi_dfltThumbDim_W;
	thumbDim_H = gi_dfltThumbDim_H;

	buttRowH = gi_dfltThumbDim_H;

	gi_contextUnderhang = playerBorder_R - initialContextFrameW;

	divDim_Min_H_Con = gi_dfltThumbDim_H;
	divDim_Min_W_Con = initialContextFrameW;

	divDim_Min_H_UI = initialUIFrameH;

	/* html vals for 800 x 600
		<input type="hidden" name="h_frameDim_W_Info" value="212" cols="7" rows="1" wrap="virtual">
		<input type="hidden" name="h_frameDim_H_Info" value="600" cols="7" rows="1" wrap="virtual">
		<input type="hidden" name="h_frameDim_W_UI" value="212" cols="7" rows="1" wrap="virtual">
		<input type="hidden" name="h_frameDim_H_UI" value="180" cols="7" rows="1" wrap="virtual">
		<input type="hidden" name="h_frameDim_W_Con" value="800" cols="7" rows="1" wrap="virtual">
		<input type="hidden" name="h_frameDim_H_Con" value="110" cols="7" rows="1" wrap="virtual">

	// info frame is 530 high, and ui frame, thus, starts at 530, and top of context is 801
	*/



	minRightFramesW = (minWinW + safetyLeft) - playerBorder_R - 55;

	initialRightFramesW = minRightFramesW;

	minUIFrameW = (sizeType != 1280) ? minRightFramesW : 296;
	initialUIFrameW = (sizeType != 1280) ? initialRightFramesW : 296;


	imageSizePrefix = "";

	contextFrameW = playerBorder_R;

	//from contextFrame.js
	myWidth_CON = gi_frameDim_W_Con;
	myHeight_CON = gi_frameDim_H_Con;
	con_tableWidth = myWidth_CON - con_tableWidthInset;

	//from vg.js
	div_INFO = new Com.Jantje.DivObj("info", infoFrameName, initialRightFramesW, initialInfoFrameH, minRightFramesW, 100);
	div_UI = new Com.Jantje.DivObj("ui", uiFrameName, initialUIFrameW, initialUIFrameH, minUIFrameW, 100);
	div_CONTEXT = new Com.Jantje.DivObj("con", contextFrameName, initialContextFrameW, initialUIFrameH, divDim_Min_W_Con, divDim_Min_H_Con);
	div_UPL = new Com.Jantje.DivObj("upl", uplLayerName, initialContextFrameW, 0, divDim_Min_W_Con, 0);

}

var gn_playerAR = 1280 / 720;

// todo: make prefs where enter aspect ratio, and p/h the min con h (pct?)
var gn_playerPctW = 0.7;
var gn_playerPctW_WS = 0.6;

gn_playerPctW = 0.73;
gn_playerPctW_WS = 0.73;

var gb_maximizeToFitConOrInfoPct = false;
minContextHPctOfWin = 0.2, minInfoWPctOfWin = 0.2;

//gn_playerPctW = 0.8;
//gn_playerPctW_WS = 0.8;

//gn_playerPctW = 1.0;
//gn_playerPctW_WS = 1.0;

var go_originalDocDims = null;
var gb_everDAR = false;
dimsAreReady(false);

function getDocDimsIfDiffThanOriginal() {
	var dd = getMyDocDimsIf();

	if (!dd) return null;
	else if (!go_originalDocDims) return dd;
	else return ((dd.w != go_originalDocDims.w) || (dd.h != go_originalDocDims.h)) ? dd : null;
}

var gb_everDoneReallyDAR = false, gb_everDoneFontDfltsInit = false;

function getAutoFontSizeFromSizeType(st) {
	if (st == null) st = sizeType;
	var font_size = 13;
	if (st == 1280) {
		font_size = 12;

	} else if (st == 1400) {

	} else if (st == 800) {
		font_size = 9;
	} else { //1024:
		font_size = 11;
	}
	return font_size;
}
function dimsAreReady(b_really) {
	if (!gb_everDAR) {
		if (b_really) {
			gb_everDAR = true;
			dimsAreReady(b_really);
		}
	}
	function set_font_size_for_type(t, s, family) {
		var f = getStyleRuleByID_STD(t);
		if (f) {
			f.fontSize = s + "px";
			f.fontFamily = family;
		}
	}
			//debugger;
		//set_font_size_for_type("select", 20);
	function set_mins_from_size_type() {
		//sizeType = 800;
		//todo: fix for widescreen

		var font_size = 13;
		if (sizeType == 1280) {
			minWinW = 1280;
			minWinH = 1024;
			minPlayerW = playerBorder_R = 920;//1000;
			minPlayerH = playerBorder_B = 575;//600;
			initialInfoFrameH = 650;
			initialUIFrameH=200;
			initialContextFrameH = 210;
			initialContextFrameW = playerBorder_R - 300; //964;
			gi_dfltThumbDim_W = gi_dfltThumbDim_H = 35;
			minContextW = 800;
			font_size = 12;

		} else if (sizeType == 1400) {
			minWinW = 1400;
			minWinH = 1050;
			minPlayerW = playerBorder_R = 984;//1000;
			minPlayerH = playerBorder_B = 590;//600;
			initialInfoFrameH = 650;
			if (screen.width == 1600) {
				minPlayerH = playerBorder_B = 750;//700;
				minPlayerW = playerBorder_R = 1200;//1166;//1000;
				initialInfoFrameH = 700;
				minContextW = 900;
			} else {
				minContextW = 750;
			}
			initialUIFrameH=201;
			initialContextFrameH = 210;
			initialContextFrameW = playerBorder_R - 300;
			gi_dfltThumbDim_W = gi_dfltThumbDim_H = 35;

		} else if (sizeType == 800) {
			minWinW = 800;
			minWinH = 600;
			minPlayerW = playerBorder_R = 500;
			minPlayerH = playerBorder_B = 326;
			initialInfoFrameH = 416;
			initialUIFrameH = 140;
			initialContextFrameH = 76;
			initialContextFrameW = playerBorder_R - 50;
			minContextW = initialContextFrameW;
			gi_dfltThumbDim_W = gi_dfltThumbDim_H = 27;
			font_size = 9;
		} else { //1024:
			minPlayerH = initialInfoFrameH = 480;//531;
			minPlayerW = playerBorder_R = 734;//800;
			playerBorder_B = 430;//600;
			minWinW = 1024;
			minWinH = 730;
			initialContextFrameH = 110;
			initialContextFrameW = playerBorder_R - 200;//todo: use flarshdimz?
			gi_dfltThumbDim_W = gi_dfltThumbDim_H = 27;
			minContextW = initialContextFrameW;
			font_size = 11;
		}
		var o_dflt;
		if (!gb_everDoneFontDfltsInit && (o_dflt = getStyleRuleByID("dflt"))) {
			go_fontDflts = {size : getStyleNumAttrib(o_dflt, "fontSize"),
			s_serif : getStyleVal(".dflt_serif", "fontFamily"),
			s_sans : getStyleVal(".dflt_sans", "fontFamily")}

			go_fontDflts.b_serif = (o_dflt.fontFamily.indexOf("sans_serif") == -1);
			go_fontDflts.s_family = !go_fontDflts.b_serif
				? go_fontDflts.s_sans
				: go_fontDflts.s_serif;

			gb_everDoneFontDfltsInit = true;
			font_size = getAutoFontSizeFromSizeType();
		}
		if (gb_everDoneFontDfltsInit) {

			var font_size_SEL = font_size_TABLE = (gi_prefFontSize ? gi_prefFontSize : font_size),
				font_family;

			switch(gi_prefFontSerif) {
			default:
			case 0:
				font_family = go_fontDflts.s_family;
				break;
			case 1:
				font_family = go_fontDflts.s_sans;
				break;
			case 2:
				font_family = go_fontDflts.s_serif;
				break;
			}

			//font_size_TABLE = "1em";

			//debugger;
			set_font_size_for_type("select", font_size_SEL, font_family);
			set_font_size_for_type("table", font_size_TABLE, font_family);
			set_font_size_for_type("body", font_size_TABLE, font_family);
			//set_font_size_for_type("form", font_size_TABLE);
			//set_font_size_for_type("td", font_size_TABLE);
			//set_font_size_for_type("tr", font_size_TABLE);

			set_font_size_for_type(".fb", font_size_TABLE,font_family);
			set_font_size_for_type(".ff", font_size_TABLE,font_family);
			set_font_size_for_type(".fm", font_size_TABLE,font_family);
		}
	}

	if (b_really) {
		if (hasGoodOpener() && !opener.gb_doneInitialResize) return false;
		if (!go_originalDocDims) {
			if (!(go_originalDocDims = getMyDocDimsIf())) {
				return false;
			}
		}
		setSizeTypeFromWindowSize();
		set_mins_from_size_type();
		//debugger;
		gb_everDoneReallyDAR = true;
		var sar = go_originalDocDims.w / go_originalDocDims.h;
		var b_wide =  sar > 1.45;
		var wpct = b_wide ? gn_playerPctW_WS : gn_playerPctW;

		if (gb_maximizeToFitConOrInfoPct) {
			var pw = Math.floor(go_originalDocDims.w * (1.0 - minInfoWPctOfWin)),
				ph = Math.floor(go_originalDocDims.h * (1.0 - minContextHPctOfWin));

			var ph2 = Math.floor(pw / gn_playerAR);
			var pw2 = Math.floor(ph * gn_playerAR);

			if (ph2 >= ph) {
				pw = pw2;
				ph = pw / gn_playerAR;
			} else if (pw2 > pw) {
				ph = ph2;
				pw = ph * gn_playerAR;
			} else {
				debugger;
			}

			minPlayerH = playerBorder_B = ph;
			minPlayerW = playerBorder_R = pw;


		} else {
			minPlayerW = playerBorder_R = Math.floor(go_originalDocDims.w * wpct); //make even %
			minPlayerH = playerBorder_B = Math.floor(playerBorder_R / gn_playerAR);

			if (minPlayerH > (go_originalDocDims.h * (1.0 - minContextHPctOfWin))) { ///super wide
				minPlayerH = playerBorder_B = Math.floor(go_originalDocDims.h * (1.0 - minContextHPctOfWin));
				minPlayerW = playerBorder_R = Math.floor(playerBorder_B * gn_playerAR);
			}
		}
		minWinW = go_originalDocDims.w;
		minWinH = go_originalDocDims.h;

		initialInfoFrameH = minPlayerH;
	} else {
		set_mins_from_size_type();
	}
	thumbDim_W = gi_dfltThumbDim_W;
	thumbDim_H = gi_dfltThumbDim_H;
	buttRowH = gi_dfltThumbDim_H;

	initialContextFrameW = minContextW;


	gi_contextUnderhang = playerBorder_R - initialContextFrameW;

	if (gi_contextUnderhang < 0) {
		gi_contextUnderhang = 0;
		initialContextFrameW = playerBorder_R;
	}

	divDim_Min_H_Info = initialInfoFrameH;
	divDim_Min_H_Con = gi_dfltThumbDim_H;
	divDim_Min_W_Con = initialContextFrameW;

	divDim_Min_H_UI = initialUIFrameH;

	/* html vals for 800 x 600
		<input type="hidden" name="h_frameDim_W_Info" value="212" cols="7" rows="1" wrap="virtual">
		<input type="hidden" name="h_frameDim_H_Info" value="600" cols="7" rows="1" wrap="virtual">
		<input type="hidden" name="h_frameDim_W_UI" value="212" cols="7" rows="1" wrap="virtual">
		<input type="hidden" name="h_frameDim_H_UI" value="180" cols="7" rows="1" wrap="virtual">
		<input type="hidden" name="h_frameDim_W_Con" value="800" cols="7" rows="1" wrap="virtual">
		<input type="hidden" name="h_frameDim_H_Con" value="110" cols="7" rows="1" wrap="virtual">

	// info frame is 530 high, and ui frame, thus, starts at 530, and top of context is 801
	*/

	minRightFramesW = (minWinW + safetyLeft) - playerBorder_R - 55;

	initialRightFramesW = minRightFramesW;

	minUIFrameW = (sizeType != 1280) ? minRightFramesW : 296;
	initialUIFrameW = (sizeType != 1280) ? initialRightFramesW : 296;


//moved these here from vg.js.... todo: init any more of them?
//	gi_frameDim_W_Info=;
//	gi_frameDim_H_Info=;
	gi_frameDim_W_UI = initialUIFrameW;
	gi_frameDim_H_UI = initialUIFrameH;
//	gi_frameDim_W_Con=;
//	gi_frameDim_H_Con=;
	//imageSizePrefix = "";

	contextFrameW = playerBorder_R;

	return true;
}
/////bldg and floor stuff/////
//////////start of things to override in cmms////////////////////
var gs_museumName = null;
try {
	gs_museumName = gs_currentMuseumName;
}
catch(er) {}

var gs_workRecordElemNameMain = "painting";

var gs_lang = "E";
var gb_alwaysUseDemoMaps = false;
var gs_autoGalFldrName;//null; //set to project folder name if all bldgs use dflt project name "1.0"
var gb_autoSaveVal = false; //only if gs_autoGalFldrName?
/*
if autogalfldr not there, and edit mode, create as new project, using that as the name
*/
var gs_selectAStartString = "Please select a floor in ";
var gb_bldgsAreFloors = true;
var gs_origPartsInRootType = null;
var gb_useFauxQuery = true; //setting to true requires a launch from the launcher page, and doesn't use a query string
var gi_mapSizeOverride_W = 272, gi_mapSizeOverride_H = 114; //or 0x0?

var gi_dfltMapOrigDim_W = 272, gi_dfltMapOrigDim_H = 114;
var gs_mapOverlayFile = null;//"map_overlay_Chadron.png"

var gs_cmms_fmsModeType = "edit";
var gb_wtShowThumbsForView = true;
var gb_wtUseViewer = true;
var gb_tombstone_SHOW_BIG_THUMB = true;
var gb_tombstone_SHOW_ACCESSION_ID = true;
var gs_wtLoadLinksType = "l";// "m" is for multi, "l" is for vg demo links window, "s" is for non-vg, but single window each time
var gi_showUserOverride = 0; // 0 don't show, 1 show-but-don't-require-entry, 2 show-and-require (also, could embed...
var gb_dontClearOnViewRollOff = false;

var gs_bldgID = "Frost";

////////////////end of things to override in cmms... don't forget to end all cmms files with doneCMMS()!//////
var s_bldSetName = "default";

try {
	s_bldSetName = hasGoodOpener() ? opener.gs_bldSetName : gs_bldSetName;
}

catch(er) {
	s_bldSetName = "default";
}
var ga_bldgs = new Array();
var ga_floors = null;
var gi_numBldgs = 0;

var ga_bldgObjNames = new Array();

var gs_selectedFloorID = null,
	gs_selectedBldgID = null, // default to this
	gi_selectedFloorIndex = null,
	gs_currentBldgName = null,
	gs_currentFloorName = null,
	go_currentFloorMap = null,
	gi_currentFloorDMT = 0;

var go_galObjects = null; //to use, please include galObj.js in the gallery page
function initGalleryProjects() {
	go_galObjects = {tot : 0, a : new Array(), a_ids : new Array(), o_current : null,

		GetGal : function (id_or_obj) {
			return (typeof(id_or_obj) == "string") ? this.a[this.a_ids[id_or_obj]] : id_or_obj;
		},
		SetCurrent : function(id_or_obj) {
			this.o_current = this.GetGal(id_or_obj);
			if (!this.o_current) {
				alert("Invalid goid!");
				return null;
			}
			return this.o_current;
		},
		SetFloor : function(id, gal_id_or_obj0) {
			gal_id_or_obj0 = gal_id_or_obj0 ? gal_id_or_obj0 : this.o_current;
			gal_id_or_obj0.o_floor = gal_id_or_obj0.a_f[gal_id_or_obj0.a_fids[id]];
		}
	};
}
function addOneGalleryProj(id, proj_fldr_name0, proj_descriptive_name, floor) {
	if (!go_galObjects) initGalleryProjects();
	var args = addOneGalleryProj.arguments, na = args.length;
	if (na < 4) {
		alert("Not enough args for gal proj: (id: " + id + "), (fldr: " + proj_fldr_name0
			+ "), (descript: " + proj_descriptive_name + "), (floor: " + floor + ")!");
		return;
	}
	floor = floor.toString();
	var o = {id : id, fldr : (proj_fldr_name0 ? proj_fldr_name0 : id), name : proj_descriptive_name, a_f : [floor], bldg : gs_bldgID, num_floors : 1, b_multi_flr : false,
		o_floor : null, dflt_floor_id : floor.toString() //todo: customize this
		};

	if (na > 4) {
		for (var i = 4; i < na; i++) {
			apush(o.a_f, args[i].toString());
		}
		o.num_floors = o.a_f.length;
		o.b_multi_flr = true;
	}
	apush(go_galObjects.a, o);
	go_galObjects.a_ids[o.id] = go_galObjects.tot;
	go_galObjects.tot = go_galObjects.a.length;
	return o;
}

function associateGPs() {
	var o_gal, id;
	for (var i = 0; i < go_galObjects.tot; i++) {
		o_gal = go_galObjects.a[i];
		o_gal.o_bldg = ga_bldgs[o_gal.bldg];
		o_gal.a_fids = new Array();

		var a_new = new Array();

		for (var ii = 0; ii < o_gal.o_bldg.floors.length; ii++) {
			for (var iii = 0; iii < o_gal.num_floors; iii++) {
				if (o_gal.a_f[iii] == o_gal.o_bldg.floors[ii].id) {
					id = o_gal.a_f[iii];
					o_gal.a_fids[id] = a_new.length;
					apush(a_new, {id : id,
						o : o_gal.o_bldg.floors[ii],
						loc : null});
				}
			}
		}
		o_gal.a_f = a_new;
		go_galObjects.SetFloor(o_gal.dflt_floor_id, o_gal);
	}
}

function getMapObj(inset_n, inset_s, inset_w, inset_e, img_w, img_h) {//inset into world, (actual VG walls, NOT nav boundaries)
	var mo = new Object();
	mo.i_n = inset_n;
	mo.i_s = inset_s;
	mo.i_w = inset_w;
	mo.i_e = inset_e;
	mo.max_w = (img_w) ? img_w : gi_dfltMapOrigDim_W; //todo: should really be bldg-based!
	mo.max_h = (img_h) ? img_h : gi_dfltMapOrigDim_H;
	return mo;
}
function addFloor(bldg, id, name, o_map_or_dmt0) { //+ sid1, sname1, map2, sid2, sname2.... mapn, sidn, snamen
	var bldga = ga_bldgs[bldg];

	if (!bldga) {
		ga_bldgObjNames[gi_numBldgs] = bldg;
		gi_numBldgs++;
		ga_bldgs[bldg] = new Object();
		ga_bldgs[bldg].id = bldg;
		ga_bldgs[bldg].name = bldg;
		ga_bldgs[bldg].num_floors = 0;
		ga_bldgs[bldg].floors = new Array();
	}

	bldga = ga_bldgs[bldg];

	var o_fl;

	o_fl = ga_bldgs[bldg].floors[ga_bldgs[bldg].num_floors] = new Object();
	o_fl.id = id;
	o_fl.name = name;
	o_fl.bldg = bldg; // will make into a bldg array, really....
	o_fl.fldr = bldg + "_" + id;

	var a = addFloor.arguments;
	if (a.length <= 4) {
		if (typeof(o_map_or_dmt0) == "object") {
			o_fl.o_map = o_map_or_dmt0;
		} else {
			o_fl.dmt = o_map_or_dmt0;
		}
	} else if ((a.length - 3) % 3) {
		debugger;
	} else {
		o_fl.a_subs = new Array();
		o_fl.a_subs_i = new Array();
		var sid, o_new;
		for (var i = 3; i < a.length; i += 3) {
			sid = a[i + 1];
			o_fl.a_subs[sid] = o_new = {id : sid, o_map : a[i], name : a[i + 2], fldr : sid, mid : o_fl.id + "." + sid};
			apush(o_fl.a_subs_i, sid);

		}
	}

	ga_bldgs[bldg].num_floors++;

	/*
	var pl = ga_floors.length;
	ga_floors[pl] = new Object();
	ga_floors[pl].id = id;
	ga_floors[pl].name = name;
	ga_floors[pl].bldg = bldg; // will make into a bldg array, really....
	ga_floors[pl].fldr = bldg + "_" + id;
	ga_floors[pl].ns_fwd = ns_fwd;
	ga_floors[pl].ns_rot = ns_rot;
	ga_floors[pl].ns_tilt = ns_tilt;
	*/
}

function initBldgFromID(bid) {
	ga_floors = ga_bldgs[bid].floors;
	gs_selectedBldgID = bid;
	gs_currentBldgName = ga_bldgs[bid].name;
	galType = bid;
}

function getBldgFlr(bid, fid) {
	var a_flrs = ga_bldgs[bid].floors;
	var fi = getFloorIndexFromFloorID(fid, a_flrs);
	return a_flrs[fi];
}
function initFloorFromID(fid, sub_id) {
	var fi, o_s, o_fl, o_r;

	if ((fi = getFloorIndexFromFloorID(fid)) > -1) {
		gi_selectedFloorIndex = fi;
		o_fl = ga_floors[gi_selectedFloorIndex];
		o_r = {o_fl : o_fl};
		gs_selectedFloorID = o_fl.id;
		if (!sub_id || !o_fl.a_subs || !(o_s = o_fl.a_subs[sub_id])) {
			gs_currentFloorName = o_fl.name;
			go_currentFloorMap = o_fl.o_map;
			gi_currentFloorDMT = o_fl.dmt;
			gs_selectedSubID = null;
		} else {
			gs_currentFloorName = o_fl.name + ":" + o_s.name;
			go_currentFloorMap = o_s.o_map;
			gi_currentFloorDMT = o_s.dmt;
			gs_selectedSubID = sub_id;
			o_r.o_s = o_s;

		}
		return o_r;
	}
	return null;
}

function getFloorIndexFromFloorID(fid, a0) {
	if (!a0) a0 = ga_floors;
	for (var i = 0; i < a0.length; i++) {
		if (a0[i].id == fid) return i;
	}
	return -1;
}

function doneCMMS() {
	if (go_galObjects && go_galObjects.tot) {
		associateGPs();
	}
}
