var activeMenu = '';
var fastMenu = false;
var menuInfo = new Array;
var hasMenu = false; // If this page has a menu or not
var colTemplate = '';



function FW_Init(t)
{
	colTemplate = t;	// white or blue
	hasMenu = document.getElementById('fw_menu') != null;
	if (hasMenu) {
		// Called once the page is loaded to attach all the resizing information
		if (colTemplate == 'white') {
			FW_ResizeWhite();
			if (window.attachEvent) window.attachEvent('onresize', FW_ResizeWhite);
			else window.addEventListener('resize', FW_ResizeWhite, false);
		} 
		if (colTemplate == 'blue') {
			FW_ResizeBlue();
			if (window.attachEvent) window.attachEvent('onresize', FW_ResizeBlue);
			else window.addEventListener('resize', FW_ResizeBlue, false);
		} 
				
		
		// Layout the menus exactly where they should be
		AddMenuItem('welcome', 6);
		AddMenuItem('links', 4);
		AddMenuItem('theHeart', 3);
		AddMenuItem('fun', 5);
		AddMenuItem('prepare', 0);
		AddMenuItem('views', 3);
		AddMenuItem('family', 4);
		AddMenuItem('home', 0);

		var y = 0;
		for (var x = 0; x < menuInfo.length; x++) {
			document.getElementById('menuTxt_' + menuInfo[x].id).style.top = y + 'px';
			
			y += menuInfo[x].txtHeight;
			if (menuInfo[x].numItems != 0) {
				document.getElementById('subMenu_' + menuInfo[x].id).style.top = y + 'px';
				document.getElementById('blind_' + menuInfo[x].id).style.top = -menuInfo[x].height + 'px';
			}
			y += 11;
			var i = document.getElementById('menuImg_' + menuInfo[x].id);
			if (i != null) i.style.top = y + 'px';
			y += 13;
		}
	}
	// Set the footer position at the start.
	FW_PositionFooter();
	
	if (hasMenu) { 
		var mypath = location.pathname.toLowerCase();
		for (var x = 0; x < menuInfo.length; x++) { 
			if (mypath.indexOf('/' + menuInfo[x].id.toLowerCase()) == 0) {
				fastMenu = true;
				FW_SetMenu(menuInfo[x].id);
			}
		} 
	}
}

function FW_PositionFooter()
{
	if (document.getElementById('fw_footer') != null) {
		var pageHeight = Math.max(434, document.getElementById('fw_contentDiv').offsetHeight);
		document.getElementById('fw_footer').style.top = (pageHeight + 219) + 'px';
	}
}

function AddMenuItem(id, numItems)
{
	var loc = menuInfo.length;
	menuInfo[loc] = new Object;
	menuInfo[loc].id = id;
	menuInfo[loc].numItems = numItems;
	menuInfo[loc].height = (numItems * 23) + 5;
	menuInfo[loc].txtHeight = document.getElementById('menuTxt_' + id).offsetHeight;
}

function FW_ResizeWhite()
{
	var pageWidth = parseInt(document.getElementById('fw_contentDiv').style.width) + 383;
	
	var aw = document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;
	var sw = document.documentElement.scrollWidth?document.documentElement.scrollWidth:document.body.scrollWidth;
	
	//document.getElementById('fw_everything').style.left = Math.max(4, Math.round((aw - 867) / 2)) + 'px';
	document.getElementById('fw_everything').style.left = Math.max(4, Math.round((aw - pageWidth) / 2)) + 'px';
	document.getElementById('fw_horizon').style.width = Math.max(sw, pageWidth, aw, 887 + 5) + 'px'; 
}

function FW_ResizeBlue()
{
	var aw = document.documentElement.clientWidth?document.documentElement.clientWidth:document.body.clientWidth;
	document.getElementById('fw_sea').style.width = aw + 'px';
	
	aw = Math.max(aw, document.documentElement.scrollWidth?document.documentElement.scrollWidth:document.body.scollWidth);
	aw = Math.max(aw, document.getElementById('fw_everything').offsetWidth);
	document.getElementById('fw_sea').style.width = aw + 'px';
}

function GetMenuHeight(id)
{
	for (var x = 0; x < menuInfo.length; x++) 
		if (menuInfo[x].id == id) return menuInfo[x].height;
	return 0;
}

function FW_SetMenu(name)
{
	if (activeMenu == name) return FW_SetMenu(''); // return FW_MenuTop(); // Close
	
	if (name != '') {
		document.getElementById('menuTxt_' + name).className = 'activeMenuTitle';
		for (var x = 0; x < menuInfo.length; x++) {
			if (menuInfo[x].id != name) document.getElementById('menuTxt_' + menuInfo[x].id).className = 'fadedMenuTitle';
		}
	} else {
		for (var x = 0; x < menuInfo.length; x++) {
			document.getElementById('menuTxt_' + menuInfo[x].id).className = 'menuTitle';
		 }
	}
	
	activeMenu = name;
	animationCtrl.SetTransition(null, 'smooth', 'smooth', 'smooth', 'smooth', null);
	animationCtrl.std.numSteps = (fastMenu) ? 1 : 15;
	fastMenu = false;
	
	var y = 0;
	for (var x = 0; x < menuInfo.length; x++) {
		animationCtrl.SetWanted('menuTxt_' + menuInfo[x].id, null, y, null, null, null, null, null);
		y += menuInfo[x].txtHeight + 11;
		if (menuInfo[x].numItems != 0) {
			if (activeMenu == menuInfo[x].id) {
				animationCtrl.SetWanted('subMenu_' + menuInfo[x].id, null, y, null, menuInfo[x].height, null, null, null);
				animationCtrl.SetWanted('blind_' + menuInfo[x].id, null, 0, null, null, null, null, null);
				y += menuInfo[x].height;
			} else {
				animationCtrl.SetWanted('subMenu_' + menuInfo[x].id, null, y, null, 0, null, null, null);
				animationCtrl.SetWanted('blind_' + menuInfo[x].id, null, -menuInfo[x].height, null, null, null, null, null);
			}
			
		}
		animationCtrl.SetWanted('menuImg_' + menuInfo[x].id, null, y, null, null, null, null, null);
		y += 13;
	}
	animationCtrl.Start();
	return false;
}

function FW_RelPlaceObj(refID, objID, offsetX, offsetY)
{
	var p = new Object;
	p.x = p.y = 0;
	
	var ref = document.getElementById(refID);
	var obj = document.getElementById(objID);
	if (ref == null || obj == null) return;
  while (ref.id != 'fw_contentDiv') {
      p.x += ref.offsetLeft;
      p.y += ref.offsetTop;
      ref = ref.offsetParent;
  }
  if (offsetX != null) obj.style.left = (p.x + offsetX) + 'px';
	if (offsetY != null) obj.style.top = (p.y + offsetY) + 'px';
}


