﻿var messageshown = false;
var messagecounter = 0;
var focusCurrent;
var hiddenExp;
var focusExp;

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)+"CollapseGlow_Off.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)+"ExpandGlow_On.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 hoverglow_ec_on(arrow_img, bgcolor)
{
	arrow_img.src = arrow_img.src.replace("_Off.png", "_On.png");
}
function hoverglow_ec_off(arrow_img, bgcolor)
{
	arrow_img.src = arrow_img.src.replace("_On.png", "_Off.png");
}

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, lnkmenu, bg_on, bg_off, fg_on, fg_off)
{
	//imgitem = lnkitem.getElementsByTagName("IMG")[0];
	if (lnkmenu.style.display == '')
	{
		lnkmenu.style.display = 'none';
	} else
	{
		lnkmenu.style.display = '';
	}
	if (lnkmenu.style.marginLeft == '0px')
	{
		wMenu = new Number(lnkmenu.style.width.replace('px', ''));
		lnkmenu.style.marginLeft = ((wMenu - lnkitem.width + 11) * -1)+'px';
	}
	if (lnkitem != null)
		lnkitem.src = lnkitem.src.replace("bg="+bg_off, "bg="+bg_on).replace("fg="+fg_off, "fg="+fg_on);
		
	//mpos = getAbsolutePos(lnkmenu);
	//hide_ddl(lnkmenu);
}

function hover_submenumain(lnkitem)
{
	if (lnkitem.className == "SubMenuMain_Off")
	{
		lnkitem.className = "SubMenuMain_On";
		//lnkitem.childNodes[1].style.display = '';
	} else
	{
		lnkitem.className = "SubMenuMain_Off";
		//lnkitem.childNodes[1].style.display = 'none';
	}
}

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;
}

function getAbsolutePos(el) {
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(el.tagName);
	if (is_div && el.scrollLeft)
		SL = el.scrollLeft;
	if (is_div && el.scrollTop)
		ST = el.scrollTop;
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if (el.offsetParent) {
		var tmp = this.getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

function hide_ddl(el) {
	//alert("yep");
	function getVisib(obj){
		var value = obj.style.visibility;
		if (!value) {
			if (document.defaultView && typeof (document.defaultView.getComputedStyle) == "function") { // Gecko, W3C
				if (!Calendar.is_khtml)
					value = document.defaultView.
						getComputedStyle(obj, "").getPropertyValue("visibility");
				else
					value = '';
			} else if (obj.currentStyle) { // IE
				value = obj.currentStyle.visibility;
			} else
				value = '';
		}
		return value;
	};
	
	var tags = new Array("applet", "iframe", "select");

	var p = getAbsolutePos(el);
	var EX1 = p.x;
	var EX2 = el.offsetWidth + EX1;
	var EY1 = p.y;
	var EY2 = el.offsetHeight + EY1;

	for (var k = tags.length; k > 0; ) {
		var ar = document.getElementsByTagName(tags[--k]);
		var cc = null;

		for (var i = ar.length; i > 0;) {
			cc = ar[--i];

			p = getAbsolutePos(cc);
			var CX1 = p.x;
			var CX2 = cc.offsetWidth + CX1;
			var CY1 = p.y;
			var CY2 = cc.offsetHeight + CY1;
			
			if (this.hidden || (CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) {
				if (!cc.__msh_save_visibility) {
					cc.__msh_save_visibility = getVisib(cc);
				}
				cc.style.visibility = cc.__msh_save_visibility;
			} else {
				if (!cc.__msh_save_visibility) {
					cc.__msh_save_visibility = getVisib(cc);
				}
				cc.style.visibility = "hidden";
			}
		}
	}
}

function module_hlon(what)
{
	what.style.backgroundColor = "#aaafff";
}
function module_hloff(what)
{
	what.style.backgroundColor = "";
}