// this site isn't supported on Mac IE
if ((navigator.appName.indexOf("Microsoft") != -1)&&(navigator.platform.indexOf("Mac") != -1)) {
	window.location = "../contemplate/assembler.php?page=error";
}


// decide whether we've been flattened or not

	function is_flattened() {
		return ((location.href.indexOf("flattened") != -1)&&(location.href.indexOf(".html") != -1));
	}


// return a path to a page, given a page name, in either a flattened or unflattened format
// change script_extension depending on what version of Contemplate we're using

	function format_page_name(page_name) {
		script_extension = "php";
		if (is_flattened()) {
			page_name_formatted = "../flattened/" + page_name + ".html";
		} else {
			page_name_formatted = "../contemplate/assembler." + script_extension + "?page=" + page_name;
		}
		return page_name_formatted;
	}
			

// gets the name value of a dynamic page, even if we're rewriting URLs

	function get_page_name() {
		if (location.href.indexOf("page=") != -1) {
			page_name = location.href.substring(location.href.indexOf('page=') + 5, location.href.length);
		} else {
			page_name = location.href.substring(location.href.lastIndexOf('/') + 1, location.href.indexOf('.htm'));
		}
		return page_name;
	}
	

// open a popup window, specifying source, width, and height, and optionally a name; if no name, choose a random one

	function popup(source,width,height,window_name,scrollbars) {
		if (navigator.platform.indexOf("Mac") != -1) {
			if (navigator.appVersion.indexOf("Safari") != -1) {
				height = height * 1.072;
				width = width * .975;
			} else {
				height = height * 1.045;
				width = width * .975;
			}
		} else {
			if (navigator.appVersion.indexOf("MSIE") == -1) {
				height = height * 1.045;
				width = width * .975;
			}
		}
		if (! window_name) { 
			now = new Date()
			window_name = now.getTime()
		} else {
			window_name = window_name.replace(/ /g, "_");
		}
		if (scrollbars == 0) {
			scrollbars = "no";
		} else {
			scrollbars = "yes";
		}
		popup_window = window.open(source,window_name,"width="+String(width)+",height="+String(height)+",location=no,menubar=no,directories=no,toolbar=no,scrollbars="+scrollbars+",resizable=yes,status=yes");
		popup_window.focus()
	}	


// the simplest possible rollover function

	function swap(name, state) {
		eval('document.images.' + name + '.src = ' + name + '_' + String(state) + '.src');
	}
	

// write a block of code that preloads a list of graphics
// - this version makes on and off states and is most often used for button rollovers

// names - a comma-delimited list of button names (e.g. "home,about,contact")
// path - the path to the graphics; defaults to "../graphics" if not set (e.g. "../graphics/menus/home")
// extension - the file extension of the graphics files; defaults to "gif" if not set (e.g. "jpg")

	function preload_buttons(names, path, extension) {
		names = names.split(",");
		path = (path) ? path : "../graphics" ;
		extension = (extension) ? extension : "gif" ;
		for (n=0; n < names.length; n++) {
			this_name = names[n];
			this_path = path + "/" + this_name;
			eval(this_name + "_0 = new Image()");
			eval(this_name + "_0.src = '" + this_path + "_0." + extension + "'");
			eval(this_name + "_1 = new Image()");
			eval(this_name + "_1.src = '" + this_path + "_1." + extension + "'");
		}
	}


// returns the index of an array element, something that ought to be built into JavaScript but isn't!
// returns -1 if not present

	function get_position(string, array) {
		for (n=0; n < array.length; n++) {
			if (array[n] == string) {
				return n;
				break;
			}
		}
		return -1;
	}