// return an HTML table containing a white square chosen at random, with the requested product thumbnail centered over it

	function product_display(product_name, enlargeable) {
		squares_available = 4;
		square_number = (Math.round(Math.random() * (squares_available - 1)) + 1);
		output = '<div align="center" class="caption">';
		output += '<table width="161" cellpadding="0" cellspacing="0" border="0">';
		output += '<tr valign="middle">';
		output += '<td width="160" background="../graphics/templates/product_square_' + String(square_number) + '.gif" align="center">';
		if (enlargeable) { output += '<a href="JavaScript:popup(\'../graphics/products/' + product_name + '_big.gif\', 460, 440)">'; }
		output += '<img src="../graphics/products/' + product_name + '.gif" border="0" alt="' + product_name + '">';
		if (enlargeable) { output += '</a>'; }
		output += '</td>';
		output += '<td width="1">';
		output += '<img src="../graphics/spacer.gif" width="1" height="138" alt="">';
		output += '</td>';
		output += '</tr>';
		output += '</table>';
		if (enlargeable) { output += '(click to enlarge)'; }
		output += '</div>';
		return output;
	}


// redirect if we're not using a secure connection (in case the user forgot to specify https as the protocol)
// this can also be used to force a particular subdomain, in this case secure

	function require_SSL() {
		if (document.URL.indexOf("https://secure.") == -1) { 
			document.write("<p class=subheading>Redirecting to a secure port...</p>");
			location = "https://secure." + document.URL.substr(document.URL.indexOf("arlotone.com"), document.URL.length);
		}
	}


// redirect if we no longer need a secure connection

	function avoid_SSL() {
		if (document.URL.indexOf("https://") != -1) { 
			document.write("<p class=subheading>Redirecting to a standard port...</p>")
			// use the same subdomain we're on right now; just change the protocol
			location = "http://www." + document.URL.substr(document.URL.indexOf("arlotone.com"), document.URL.length);
		}
	}


// construct Flash object and embed tags
// FlashVars should be a string of name/value pairs separated by ampersands

	function get_flash_tags(filename, width, height, bgcolor, flashvars) {
		name = filename;
		if (name.indexOf("/")) { name = name.substring(name.lastIndexOf("/") + 1); }
		if (name.indexOf(".")) { name = name.substring(0, name.indexOf(".")); }
		
		output = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
		output += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"';
		output += ' WIDTH="' + String(width) + '" HEIGHT="' + String(height) + '" id="' + name + '" name="' + name + '" ALIGN="">';
		output += '<PARAM NAME=movie VALUE="' + filename + '"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=' + bgcolor + '> <EMBED src="' + filename + '" quality=high bgcolor=' + bgcolor + ' WIDTH="' + String(width) + '" HEIGHT="' + String(height) + '" NAME="' + name + '" ALIGN=""';
		output += ' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" swLiveConnect="true"';
		output += ' FlashVars="' + flashvars + '"></EMBED>';
		output += '<PARAM NAME="FlashVars" VALUE="' + flashvars + '">';
		output += '</OBJECT>';
		return output;
	}


// 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) {
		if (! window_name) { 
			now = new Date();
			window_name = now.getTime();
		} else {
			window_name = window_name.replace(/ /g, "_");
		}
		popup_window = window.open(source, window_name, "width=" + String(width) + ",height=" + String(height) + ",location=no,menubar=no,directories=no,toolbar=no,scrollbars=yes,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');
	}
	

// rollovers with sticky highlights
// - used in navigation frames where the buttons persist but other pages are changing

	var previous = null;
	var current = null;

	function sticky_swap(name, state, hold) {
		if (hold == 1) {
			// set previously lit button to normal
			previous = current;
			if (previous != null) {
				eval('document.images.' + previous + '.src = ' + previous + '_0.src');
			}
		}
		if ((name != null) && (name != current)) {
			// set new button state
			eval('document.images.' + name + '.src = ' + name + '_' + String(state) + '.src');
			if (hold == 1) { current = name; }
		}
	}
	

// rollovers with separate but linked button and label graphics
// - highlights both the button and label if you mouse over either one 
// - requires graphics to be named like "button_0.gif" and "button_label_0.gif"

	function label_swap(name, state) {
		eval('document.images.' + name + '.src = ' + name + '_' + String(state) + '.src');
		
		// change the label if one exists
		if (eval('document.images.' + name + '_label')) {
			eval('document.images.' + name + '_label.src = ' + name + '_label_' + String(state) + '.src');
		}
		
		// change the button if this is a label
		if (name.indexOf("_label") != -1) {
			name = name.substr(0, (name.length - 6));
			if (eval('document.images.' + name)) {
				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 + "'");
		}
	}
	

// write a block of code that preloads a list of graphics
// - this version just makes an on state and is most often used for tips associated with 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_tips(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 + " = new Image()");
			eval(this_name + ".src = '" + this_path + "." + extension + "'");
		}
	}
	

// write a block of code that preloads a list of graphics
// - this version uses the same source file for each instance and is most often used for markers associated with button rollovers

// names - a comma-delimited list of instance names (e.g. "home_marker,about_marker,contact_marker")
// marker_name - the base name of the marker graphic
// 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_markers(names, marker_name, 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 + "/" + marker_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 + "'");
		}
	}
	

// figure out whether a variable has been set or not without generating an undefined error if it hasn't

	function isset(variable) {
		eval("result = (typeof(" + variable + ") != 'undefined')");
		return result;
	}
	
