	// Note where menu initialization block is located in HTML document.
	// Don't try to position menu locating menu initialization block in
	// some table cell or other HTML element. Always put it before the closing BODY tag

	// each menu gets two parameters (see demo files)
	// 1. items structure
	// 2. geometry structure

var mymenu;
var center_default = "true";	// default center_menu value to use if no cookie is set
var float_default = "false";	// default float_menu value to use if no cookie is set
var float_timeout;
var float_interval = 150;	// default interval in milliseconds between menu float operations
var init_scroll_y_offset;	// saves initial offset for moving menu back to top if float is turned off without leaving page
var prev_scroll_y = 0;		// used for computing how far to move menu during float operation

// get the width of the browser window
function getWindowWidth() {
  var myWidth = 0	//, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    //myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    //myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    //myHeight = document.body.clientHeight;
  }
  return myWidth;
}

// custom function for moving the banner image to the top of the menu
function moveBanner() {
	// move a banner if there is one (banner should have id = "banner"	
	var banner = document.getElementById("banner");
	if (banner != "null") {
		// note: this can still crash and burn if html has class="banner" instead of id="banner"
		banner.style.top = mymenu.a_min_y - 30;	// banner should be 30px tall
		banner.style.left = mymenu.a_min_x;
	}
}

// start the menu
function startMenu() {
	if (document.all) {
		mymenu = new menu (MENU_ITEMS, MENU_POS_IE);
	} else {
		mymenu = new menu (MENU_ITEMS, MENU_POS_MOZ);
	}
	init_scroll_y_offset = mymenu.a_min_y;	// saved for in case float is turned off without leaving current page
	var ms = getMenuSettings();
	if (ms.center_menu == "true") {
		centerMenu();
		window.onresize=function(){centerMenu();};
	}
	if (ms.float_menu == "true") {
		floatMenu();
	}
}

// horizontally center the menu on the page
function centerMenu() {
	// move the menu
	var xAdjustment = (getWindowWidth() / 2) - (mymenu.a_menu_width / 2) - mymenu.a_min_x;
	mymenu.move(xAdjustment,0);
	moveBanner();
}

// set interval for how often scroll position is checked and menu is floated
function setFloatMenuInterval(interval) {
	float_interval = interval;
}

// float the menu to the top of the visible page when scrolling
function floatMenu() {
	var scrollY = getScrollY();
	if (scrollY != prev_scroll_y) {
		mymenu.move(0,scrollY - prev_scroll_y);
		moveBanner();
		prev_scroll_y = scrollY;
	}
	float_timeout = setTimeout("floatMenu()",float_interval);
}

// stop menu from floating and return it to it's original starting position
function unfloatMenu() {
	clearTimeout(float_timeout);
	mymenu.move(0,init_scroll_y_offset - mymenu.a_min_y);
	moveBanner();
}

// get horizontal scroll position
function getScrollX() {
	return (document.all) ? document.body.scrollLeft : window.pageXOffset;
}

// get vertical scroll position
function getScrollY() {
	return (document.all) ? document.body.scrollTop : window.pageYOffset; 
}

// get value for specified cookie
function getCookieValue(cookieName) {
	var cookieValue = "";
	var allcookies = document.cookie;
	var pos = allcookies.indexOf(cookieName+"=");
	if (pos >= 0) {
		var start = pos + cookieName.length + 1;
		var end = allcookies.indexOf(";", start);
		if (end < 0) {
			end = allcookies.length;
		}
		cookieValue = unescape(allcookies.substring(start,end));
	}
	return cookieValue;
}

// set cookie
function setCookie(cookieName, cookieValue, expiresGMTString) {
	var cookieString = cookieName + "=" + escape(cookieValue);
	if (expiresGMTString != "null" && expiresGMTString.length > 0) {
		cookieString = cookieString + "; expires=" + expiresGMTString;
	}
	document.cookie = cookieString;
}

// get menu settings as an object
function getMenuSettings() {
	var center_val = getCookieValue("centermenu");
	var float_val = getCookieValue("floatmenu");
	if (center_val == "") {
		center_val = center_default;
	} 
	if (float_val == "") {
		float_val = float_default;
	} 
	return new menu_settings(center_val,float_val);
}

// save menu settings in cookies using the specified menu settings object
function setMenuSettings(settings) {
	var nextyear = new Date();
	nextyear.setFullYear(nextyear.getFullYear() + 1);
	var nextyearStr = nextyear.toGMTString();
	setCookie("centermenu",settings.center_menu,nextyearStr);
	setCookie("floatmenu",settings.float_menu,nextyearStr);
}

// menu settings object for holding all possible menu settings
function menu_settings(mcenter,mfloat) {
	this.center_menu = mcenter;
	this.float_menu = mfloat;
}
	// make sure files containing definitions for these variables are linked to the document
	// if you got some javascript error like "MENU_POS is not defined", then you've made syntax
	// error in menu_tpl.js file or that file isn't linked properly.

	// also take a look at stylesheets loaded in header in order to set styles
