
window.addEvent("domready", init);

function init() {

	fi_config								= new Array();
	fi_global								= new Array();

	/*
	* configuration
	* any durations, delays, etc. are in milliseconds
	*/
	fi_config["overlay_fadeDuration"]		= 400;
	fi_config["overlay_fadeOpacity"]		= 0.75;
	fi_config["menu_rolloutDuration"]		= 400;
	fi_config["hero_rotateDelay"] = 7000;
	// [JMH] - Replace "../css/img/"; with "SiteCollectionsImages/FI/StyleImages/";
	fi_config["cssImagePath"] = "SiteCollectionsImages/FI/StyleImages/";

	/*fi_config["rootDir"]					= "/fic/";*/
	// [JMH] - Replace "/fic/extractable/"; with "/";
	fi_config["rootDir"]					= "/";

	fi_config["defaultValue_firstName"]		= "First Name";
	fi_config["defaultValue_lastName"]		= "Last Name";
	fi_config["defaultValue_title"]			= "Title";
	fi_config["defaultValue_company"]		= "Company";
	fi_config["defaultValue_industry"]		= "Industry";
	fi_config["defaultValue_email"]			= "Email Address";
	fi_config["defaultValue_password"]		= "Password";
	/*fi_config["defaultValue_search"]		= "I'm looking for...";*/

	/*
	* configuration - IE-specific
	*/
	if ($defined(window.ie)) {
	}

	/*
	* configuration - IE6-specific
	*/
	if ($defined(window.ie6)) {
	}

	/*
	* global variables - for internal script use only, do not modify
	*/
	fi_global["menu_inputActive"]			= false;
	fi_global["menu_activeMenu"]			= null;


	fi();
	fi_sIFR();
	fi_preloadImages();
}

function fi_sIFR() {
    if (typeof sIFR == "function") {
        // [JMH] - Replace "common/js/myriad-pro.swf"; with "/Flash Library/myriad-pro.swf";
        var fontFile = fi_config["rootDir"] + "Flash Library/common/js/myriad-pro.swf";

		sIFR.replaceElement(".testimonials .title", named({sFlashSrc: fontFile, sColor: "#777777", sWmode: "transparent"}));
		sIFR.replaceElement(".accordionClose h1", named({sFlashSrc: fontFile, sColor: "#FFFFFF", sWmode: "transparent"}));
		sIFR.replaceElement(".accordionOpen h1", named({sFlashSrc: fontFile, sColor: "#ef8200", sWmode: "transparent"}));
		sIFR.replaceElement(".moduleTitle", named({sFlashSrc: fontFile, sColor: "#777", sWmode: "transparent"}));
		sIFR.replaceElement("#contentColOne .sIFRContainer span", named({sFlashSrc: fontFile, sColor: "#000", sWmode: "transparent"}));
	};
}

function fi_preloadImages() {
}

function fi() {


	


	/*
	* overlays
	*/
	$$(".overlay").each(
		function(element, i) {
			element.fadeState = 0;
			//element.setStyle("opacity",0);

			element.toggle = function() {
				if ($defined(this.fx))
					this.fx.stop();

				var toggle	= 1 - this.fadeState;
				var opacity = toggle * fi_config["overlay_fadeOpacity"];

				var windowSize		= window.getSize();

				this.setStyles({
					width:	windowSize.scrollSize.x,
					height:	windowSize.scrollSize.y
				});

				this.fx = new Fx.Style(this, "opacity", {duration: fi_config["overlay_fadeDuration"]}).start(opacity);

				this.fadeState = toggle;
			};

			element.addEvent("click", function() {
				if (fi_global["menu_activeMenu"]) {
					fi_global["menu_activeMenu"].fireEvent("mouseleave");
				}
			});
		}
	);

	/*
	* main menu rollouts & overlay toggle
	*/
	$$("#menu li").each(
		function(element, i) {
			element.addEvent("mouseenter", function() {
				$("overlay_menu").toggle();
				$E("a", this).setStyle("backgroundPosition", "0 -33px");
				
			
				
				var box = $(this.id + "Box");
				box.setStyle("visibility", "visible");
				box.setStyle("left","auto");

				if ($defined(box.fx))
					box.fx.stop();

				box.fx = new Fx.Style(box, "height", {duration: fi_config["menu_rolloutDuration"]}).start(170);

			});
			element.addEvent("mouseleave", function() {
				$("overlay_menu").toggle();
				$E("a", this).setStyle("backgroundPosition", "");

				var box = $(this.id + "Box");

				if ($defined(box.fx))
					box.fx.stop();
				
				//box.setStyle("visibility","");

				box.fx = new Fx.Style(box, "height", {duration: fi_config["menu_rolloutDuration"]}).start(0).chain(
					function() {
						box.setStyle("visibility", "");
					}
				);
			});
		}
	);

	/*
	* toolbar menu rollouts & overlay toggle
	*/
	$$("#toolBar li.actuator").each(
		function(element, i) {

			var box = $(element.id + "Box");

			if ($defined(box)) {
				box.defaultHeight = box.getSize()["size"].y - 6;
				box.setStyle("height", 0);
			}

			box = null;

			element.addEvent("mouseenter", function() {

				if (fi_global["menu_inputActive"])
					return;

				fi_global["menu_activeMenu"] = this;

				var parent = this.getParent();
				var link = $E("a", this);

				$("overlay_toolbar").toggle();

				if ($defined(parent.fx))
					parent.fx.stop();

				var collection = $$("#toolBar li a.actuator");
				collection.remove(link);

				link.setStyles({
					"color": "black",
					"background-color": "#f2bb25"
				});

				parent.fx = new Fx.Elements(collection, {duration: fi_config["overlay_fadeDuration"]}).start({
					"0": { "color": "#FFFFFF" },
					"1": { "color": "#FFFFFF" },
					"2": { "color": "#FFFFFF" }
				});

				var box = $(this.id + "Box");

				box.setStyles({
					"top": link.getSize()["size"].y,
					"visibility": "visible"
				});

				if ($defined(box.fx))
					box.fx.stop();

				box.fx = new Fx.Style(box, "height", {duration: fi_config["menu_rolloutDuration"]}).start(box.defaultHeight);

			});
			element.addEvent("mouseleave", function() {

				if (fi_global["menu_inputActive"])
					return;

				fi_global["menu_activeMenu"] = null;

				var parent = this.getParent();
				var link = $E("a", this);

				$("overlay_toolbar").toggle();

				if ($defined(parent.fx))
					parent.fx.stop();

				var collection = $$("#toolBar li a.actuator");

				link.setStyles({
					"color": "#FFFFFF",
					"background-color": ""
				});

				parent.fx = new Fx.Elements(collection, {duration: fi_config["overlay_fadeDuration"]}).start({
					"0": { "color": "#98948f" },
					"1": { "color": "#98948f" },
					"2": { "color": "#98948f" },
					"3": { "color": "#98948f" }
				}).chain(
					function() {
						collection.each(
							function(element, i) {
								element.setStyle("color", "");
							}
						);
					}
				);

				var box = $(this.id + "Box");

				if ($defined(box.fx))
					box.fx.stop();

				box.fx = new Fx.Style(box, "height", {duration: fi_config["menu_rolloutDuration"]}).start(0).chain(
					function() {
						box.setStyle("visibility", "");
					}
				);
			});
			element.addEvent("click", function() {
				if (fi_global["menu_activeMenu"] != this) {
					fi_global["menu_activeMenu"].fireEvent("mouseleave");
					this.fireEvent("mouseenter");
				}
			});
		}
	);

	/*
	* "hero" rotating content
	*/
	$$("#hero").each(
		function(element, i) {
			element.rotate = function() {
				var container	= $E("div.rotate", this);
				var pool		= $E("div.pool", this);

				if (!$defined(container) || !$defined(pool))
					return;

				var div_old = $E("div", container);
				var div_new = $E("div", pool);

				if (!$defined(div_new))
					return;

				pool.adopt(div_old);
				container.adopt(div_new);

				element.rotate.delay(fi_config["hero_rotateDelay"]);

			};
			element.rotate.delay(fi_config["hero_rotateDelay"]);
		}
	);

	/*
	* inputs in menus, which disable menu collapse when focused
	*/
	$$(".menuBox *").each(
		function(element, i) {
			element.addEvent("focus", function() {
				fi_global["menu_inputActive"] = true;
			});
			element.addEvent("blur", function() {
				fi_global["menu_inputActive"] = false;
			});
		}
	);

	/*
	* text input boxes, which remove default value on click
	*/
	$$("input.defaultValue").each(
		function(element, i) {

			element.addEvent("focus", function() {
				if (!this.changed) this.value = "";
			});
			element.addEvent("keypress", function() {
				if (!this.changed) {
					this.value = "";
					this.changed = true;
				}
			});
			element.addEvent("blur", function() {
				if (!this.changed || this.getValue() == "") {
					var classes = this.className.split(" ");
					classes.each(
						function(c, i) {
							if (c.substr(0,13) == "defaultValue_") {
								if ($defined(fi_config[c])) {
									element.value = fi_config[c];
								}
							}
						}
					);
					this.changed = false;
				}
			});
		}
	);

	/*
	* expandable menus, ported from expandable_menu.js, which used the Prototype library
	*/
	$$("ul.dynamic li a.item").each(
		function(element, i) {
			element.addEvent("click", function(e) {
				new Event(e).stop();
				this.getParent().toggleClass("active");
			});
		}
	);
	
	/*
	* tabs
	*/
	$$(".js_tabSwitch").each(
		function(element, i) {
			element.addEvent("click", function() {

				element.className = element.className.replace("TSTabSel", "TSTab");
				element.className = element.className.replace("TSTab", "TSTabSel");

				$(element.id + "Contents").setStyle("display", "block");

				$$(".js_tabSwitch").each(
					function(item, n) {
						if (item != element) {
							item.className = item.className.replace("TSTabSel", "TSTab");
							$(item.id + "Contents").setStyle("display", "none");
						}
					}
				);
			});
		}
	);

	/*
	* column height normalizer, ported from column2.js, which used the Prototype library (Event.observe)
	*/
	function height_normalizer() {
		var divs = $ES("#middle_column, #right_column, #left_column");

		if (!$defined(divs))
			return false;

		var tallestHeight = 0;

		divs.each(
			function(element, i) {
				if (element.offsetHeight > tallestHeight)
					tallestHeight = element.offsetHeight;
			}
		);

		divs.each(
			function(element, i) {

				var box			= $E(".box", element);
				var box_top		= $E(".box_top", element);
				var box_mid		= $E(".box_mid", element);
				var box_end		= $E(".box_end", element);
				var newHeight	= 0;

				if ($defined(box) && $defined(box_top) && $defined(box_mid) && $defined(box_end)) {

					newHeight = tallestHeight - box_top.offsetHeight - box_end.offsetHeight - box.offsetTop;

					if (window.ie6)
						box_mid.style.height = newHeight + "px";
					else
						box_mid.style.minHeight = newHeight + "px";

					if (box_mid.offsetHeight > newHeight) {
						if (window.ie6)
							box_mid.style.height = (newHeight - (box_mid.offsetHeight - newHeight)) + 'px';
						else
							box_mid.style.minHeight = (newHeight - (box_mid.offsetHeight - newHeight)) + 'px';
					}
				}
			}
		);

	}
	height_normalizer();

}

function changeAccordion (parent,linkElement,hide) {
	var element = document.getElementById(parent);
	var link = document.getElementById(linkElement);
	
	if (hide) {
		link.className = 'plus';
	
		element.className = 'accordionClose';
	} else {
		if (element.className == 'accordionClose') {
			link.className = 'minus';
			element.className = 'accordionOpen';
		} else {
				link.className = 'plus';
			
		element.className = 'accordionClose'
		}
	}
}

function toggleDiv (id,parent,link) {
	var idArray = [];
	idArray[0] = 'One';
	idArray[1] = 'Two';
	idArray[2] = 'Three';
	idArray[3] = 'Four';
	
	for (i = 0; i < 4; i++) {
		if (id != "div" + idArray[i]) {
			changeAccordion("accordion" + idArray[i],"link" + idArray[i],true);
		}
	}
	animatedcollapse.toggle(id);
	changeAccordion(parent,link,false);


}

/************************************** Additional functions */

/*
Added by:    JMH
*/
function refer() {
    var referrerURL = "";

    if (!document.referrer) {
        referrerURL = top.document.location     
    }
    else {
        referrerURL = document.referrer;
    }
}

function removeWhiteSpace(objField) {
    return objField.value.replace(/^\s*|\s*$/g, '');    
}
