﻿var messageshown = false;
var messagecounter = 0;
var focusCurrent;
var hiddenExp;
var focusExp;

function do_more(div_closed, div_open, size_closed, size_open)
{
	var curHeight = new Number(div_closed.style.height.replace("px", ""));
	if (curHeight < size_open)
	{
		alert_expand(div_closed, size_open, size_closed, "out");
		alert_expand(div_open, size_open, size_closed, "");
		alert_expand(div_closed.parentNode.parentNode, size_open+16, size_closed+16, "");
	} else
	{
		alert_expand(div_closed, size_open, size_closed, "in");
		alert_expand(div_open, size_open, size_closed, "");
		alert_expand(div_closed.parentNode.parentNode, size_open+16, size_closed+16, "");
	}
}

function alert_expand(alert_div, expanded_size, collapsed_size, do_fade)
{
	var alertHeight = new Number(alert_div.style.height.replace("px", ""));
	
	if (alertHeight < expanded_size)
	{
		//alert currently less than the expanded size; expand it
		handle_alert_expand(alert_div, expanded_size, do_fade);
	} else
	{
		//alert currently expanded; collapse it
		handle_alert_collapse(alert_div, collapsed_size, do_fade);
	}
}

function handle_alert_expand(alert_div, target_height, do_fade)
{
	var fth = new Number(target_height);
	var focusHeight = new Number(alert_div.style.height.replace("px", ""));
	
	var fto = do_fade == "out" ? 0 : 100;
	if (do_fade != "") var curOp = get_opacity(alert_div.parentNode);
	
	var move_by = Math.round((fth - focusHeight) / 4);
	if (do_fade != "") var fade_by = Math.round((fto - curOp) / 4);
	
	if (focusHeight < fth - move_by - 4)
	{
		alert_div.style.height = (focusHeight + move_by)+'px';
		if (do_fade != "" && fade_by != 0) set_opacity(alert_div.parentNode, curOp + fade_by);
		setTimeout(function() { handle_alert_expand(alert_div, target_height, do_fade) }, 1);
	} else
	{
		var last_nudge = fth - focusHeight;
		alert_div.style.height = target_height+'px';
		if (do_fade != "") set_opacity(alert_div.parentNode, fto);
	}
}

function handle_alert_collapse(alert_div, target_height, do_fade)
{
	var fth = new Number(target_height);
	var focusHeight = new Number(alert_div.style.height.replace("px", ""));
	
	var fto = do_fade == "out" ? 0 : 100;
	if (do_fade != "") var curOp = get_opacity(alert_div.parentNode);
	
	var move_by = Math.round((focusHeight - fth) / 5);
	if (do_fade != "") var fade_by = Math.round((fto - curOp) / 5);
	
	if (focusHeight > fth + move_by + 4)
	{
		alert_div.style.height = (focusHeight - move_by)+'px';
		if (do_fade != "" && fade_by != 0) set_opacity(alert_div.parentNode, curOp + fade_by);
		setTimeout(function() { handle_alert_collapse(alert_div, target_height, do_fade) }, 1);
	} else
	{
		var last_nudge = focusHeight - fth;
		alert_div.style.height = target_height+'px';
		if (do_fade != "") set_opacity(alert_div.parentNode, fto);
	}
}

function get_opacity(object)
{
	if (object.filters)
	{
		return object.filters.alpha.opacity;
	} else if (object.style.MozOpacity)
	{
		return object.style.MozOpacity * 100;
	} else if (object.style.opacity)
	{
		return object.style.opacity * 100;
	} else
	{
		return 100;
	}
}

function set_opacity(object, opValue)
{
	if (object.filters)
	{
		object.filters.alpha.opacity = opValue;
	} else if (object.style.MozOpacity)
	{
		object.style.MozOpacity = opValue / 100;
	} else if (object.style.opacity)
	{
		object.style.opacity = opValue / 100;
	}
}

function do_expand(arrow_img, focus_orig_size, focus_div, hidden_div)
{
	var hiddenHeight = new Number(document.getElementById(hidden_div).style.height.replace("px", ""));
	var focusHeight = new Number(document.getElementById(focus_div).style.height.replace("px", ""));
	hiddenAll = document.getElementById(hidden_div).childNodes;
	focusAll = document.getElementById(focus_div).childNodes;
	
	// Determine the current status of the focus div
	//	1 - Minimized
	//	2 - Normal
	//	3 - Maximized
	if (focusHeight == 40)
		focusCurrent = 1;
	else if (focusHeight == focus_orig_size)
		focusCurrent = 2;
	else
		focusCurrent = 3;

	hiddenExp = new Array();
	focusExp = new Array();
	
	he = 0;
	for (k = 0; k < hiddenAll.length; k++)
	{
		if (hiddenAll[k].id && hiddenAll[k].id.indexOf("divFeatureContent") > 0)
		{
			hiddenContent = hiddenAll[k].childNodes;
			for (k2 = 0; k2 < hiddenContent.length; k2++)
			{
				if (hiddenContent[k2].className == "content_expanded")
				{
					hiddenExp[he] = hiddenContent[k2];
					he = he + 1;
				}
			}
		}
	}
	
	fe = 0;
	for (k = 0; k < focusAll.length; k++)
	{
		if (focusAll[k].id && focusAll[k].id.indexOf("divFeatureContent") > 0)
		{
			focusContent = focusAll[k].childNodes;
			for (k2 = 0; k2 < focusContent.length; k2++)
			{
				if (focusContent[k2].className == "content_expanded")
				{
					focusExp[fe] = focusContent[k2];
					fe = fe + 1;
				}
			}
		}
	}
	
	var arrowBG = arrow_img.src.substring(arrow_img.src.indexOf("?")+1);
	if (arrow_img.src.indexOf('btnExpand') >= 0 || focusHeight == 40 || focusHeight == focus_orig_size)
	{
		//We're currently collapsed; expand the focus div and minimize the hidden one
		var expand_by = hiddenHeight - 40;
		//arrow_img.src = "images/btnCollapse.png?"+arrowBG;
		arrow_img.src = arrow_img.src.substring(0, arrow_img.src.indexOf("/btn")+4)+"Collapse.png?"+arrowBG;
		//alert(arrow_img.src.substring(0, arrow_img.src.indexOf("/btn")+4)+"Collapse.png?"+arrowBG);
		
		handle_expand(focus_div, hidden_div, focusHeight + expand_by);
	} else if (arrow_img.src.indexOf('btnCollapse') >= 0)
	{
		//We're currently expanded; collapse the focus div and restore the hidden one
		var collapse_by = focusHeight - focus_orig_size;
		//arrow_img.src = "images/btnExpand.png?"+arrowBG;
		arrow_img.src = arrow_img.src.substring(0, arrow_img.src.indexOf("/btn")+4)+"Expand.png?"+arrowBG;
		
		handle_collapse(focus_div, hidden_div, focus_orig_size);
	}
}

function handle_expand(focus_div, hidden_div, focus_target_height)
{
	var fth = new Number(focus_target_height);
	var hiddenHeight = new Number(document.getElementById(hidden_div).style.height.replace("px", ""));
	var focusHeight = new Number(document.getElementById(focus_div).style.height.replace("px", ""));
	
	var move_by = Math.round((fth - focusHeight) / 4);
	
	if (focusHeight < fth - move_by - 4)
	{
		for (x = 0; x < focusExp.length; x++)
		{
			if (focusCurrent == 1)
			{
				focusExp[x].style.height = "";
			} else
			{
				curHeight = new Number(focusExp[x].style.height.replace("px", ""));
				focusExp[x].style.height = (curHeight + move_by) + "px";
			}
		}
		if (focusCurrent == 1)
		{
			for (x = 0; x < hiddenExp.length; x++)
			{
				curHeight = new Number(hiddenExp[x].style.height.replace("px", ""));
				if (curHeight >= move_by) hiddenExp[x].style.height = (curHeight - move_by) + "px";
			}
		}
		
		document.getElementById(focus_div).style.height = (focusHeight + move_by)+'px';
		document.getElementById(hidden_div).style.height = (hiddenHeight - move_by)+'px';
		setTimeout(function() { handle_expand(focus_div, hidden_div, focus_target_height) }, 1);
	} else
	{
		var last_nudge = fth - focusHeight;
		document.getElementById(focus_div).style.height = focus_target_height+'px';
		document.getElementById(hidden_div).style.height = (hiddenHeight - last_nudge)+'px';
		
		for (x = 0; x < focusExp.length; x++)
		{
			if (focusCurrent > 1)
			{
				curHeight = new Number(focusExp[x].style.height.replace("px", ""));
				focusExp[x].style.height = (curHeight + last_nudge) + "px";
			}
		}
		for (x = 0; x < hiddenExp.length; x++)
		{
			hiddenExp[x].style.height = "0px";
		}
	}
}

function handle_collapse(focus_div, hidden_div, focus_target_height)
{
	var fth = new Number(focus_target_height);
	var hiddenHeight = new Number(document.getElementById(hidden_div).style.height.replace("px", ""));
	var focusHeight = new Number(document.getElementById(focus_div).style.height.replace("px", ""));

	var move_by = Math.round((focusHeight - fth) / 4);
	
	if (focusHeight > fth + move_by + 4)
	{
		for (x = 0; x < focusExp.length; x++)
		{
			curHeight = new Number(focusExp[x].style.height.replace("px", ""));
			if (curHeight == 0) curHeight = focusExp[x].offsetHeight;
			if (curHeight >= move_by) focusExp[x].style.height = (curHeight - move_by) + "px";
		}
		
		document.getElementById(focus_div).style.height = (focusHeight - move_by)+'px';
		document.getElementById(hidden_div).style.height = (hiddenHeight + move_by)+'px';
		setTimeout(function() { handle_collapse(focus_div, hidden_div, focus_target_height) }, 1);
	} else
	{
		var last_nudge = focusHeight - fth;
		document.getElementById(focus_div).style.height = focus_target_height+'px';
		document.getElementById(hidden_div).style.height = (hiddenHeight + last_nudge)+'px';
		
		for (x = 0; x < focusExp.length; x++)
		{
			focusExp[x].style.height = "0px";
		}
	}
}

function hover_ec(arrow_img, bgcolor)
{
	arrow_img.src = arrow_img.src.substring(0, arrow_img.src.indexOf("?"))+"?bg="+bgcolor;
}

function hoveron_menu(menu_img)
{
	menu_img.src = menu_img.src.replace("_Off.jpg", "_On.jpg");
}

function hoveroff_menu(menu_img)
{
	menu_img.src = menu_img.src.replace("_On.jpg", "_Off.jpg");
}

function hover_menumain(lnkitem, bg_on, bg_off, fg_on, fg_off)
{
	//imgitem = lnkitem.getElementsByTagName("IMG")[0];
	lnkitem.src = lnkitem.src.replace("bg="+bg_off, "bg="+bg_on).replace("fg="+fg_off, "fg="+fg_on);
}

function do_expand2(arrow_img, menu_div)
{
	var arrowBG = arrow_img.src.substring(arrow_img.src.indexOf("?")+1);
	menu_obj = document.getElementById(menu_div);
	if (arrow_img.src.indexOf("btnSlideOpen") > 0)
	{
		arrow_img.src = "images/btnSlideClosed.png?"+arrowBG;
		handle_slide(arrow_img, menu_obj, 246);
	} else
	{
		arrow_img.src = "images/btnSlideOpen.png?"+arrowBG;
		menu_obj.style.display = "";
		handle_slide(arrow_img, menu_obj, 146);
	}
}

function handle_slide(arrow_obj, menu_obj, target_position)
{
	current_position = new Number(menu_obj.style.marginLeft.replace("px", ""));
	current_width = new Number(menu_obj.style.width.replace("px", ""));
	arrow_position = new Number(arrow_obj.style.left.replace("px", ""));
	if (current_position > target_position)
	{
		move_by = Math.round((current_position - target_position) / 4);
		
		if (current_position > target_position + move_by + 4)
		{
			arrow_obj.style.left = arrow_position - move_by + "px";
			menu_obj.style.marginLeft = current_position - move_by + "px";
			menu_obj.style.width = current_width + move_by + "px";
			setTimeout(function() { handle_slide(arrow_obj, menu_obj, target_position) }, 1);
		} else
		{
			menu_obj.style.marginLeft = target_position + "px";
		}
	} else
	{
		move_by = Math.round((target_position - current_position) / 4);
		
		if (current_position < target_position - move_by - 4)
		{
			arrow_obj.style.left = arrow_position + move_by + "px";
			menu_obj.style.marginLeft = current_position + move_by + "px";
			menu_obj.style.width = current_width - move_by + "px";
			setTimeout(function() { handle_slide(arrow_obj, menu_obj, target_position) }, 1);
		} else
		{
			final_nudge = target_position - current_position;
			menu_obj.style.marginLeft = target_position + "px";
			menu_obj.style.width = "4px";
			menu_obj.style.display = "none";
		}
	}
}

function handle_slide_in(arrow_obj, menu_obj)
{
	
}

function fmi_hoveron(anchor)
{
	anchor.className = anchor.className+"HL";
}

function fmi_hoveroff(anchor)
{
	anchor.className = anchor.className.replace("HL", "");
}

function fmi_click(theurl)
{
	document.location.href = theurl;
}

function follow_link(theurl)
{
	window.location.href = theurl;
}
