﻿function ProcessImn(){}
function ProcessImnMarkers(){}	

// struct to hold state from the interval function
var pluginLink = {
	possiblePlugins: [],
	hrefElements: [],
	actualPlugins: [],
	intervalID: null,
	busy: false
};

// Interval method to run the plugin search on a timer as opposed to all at once.
// Needed for IE7 workaround.
function intervalMethod() {
	if (!pluginLink.busy) {
		pluginLink.busy = true;
		try {  //try/catch to avoid edit mode errors.
			if (pluginLink.hrefElements.length > 0) {
				// Pop from the list of HREFs on the page and fold the extensions
				var href = pluginLink.hrefElements.pop();
				if (href != "")
				{
					var extension = href.substr(href.length - 3, 3);
					if ($.inArray(extension, pluginLink.possiblePlugins) != -1 &&
						$.inArray(extension, pluginLink.actualPlugins) == -1) {
						// Add the extension as an actual plugin
						pluginLink.actualPlugins.push(extension);
					}
				}
			}
			else {
				// No more HREFs left. Clear this timer, and display the plugins
				clearInterval(pluginLink.intervalID);
				if (pluginLink.actualPlugins.length > 0) {
					$.each(pluginLink.actualPlugins, function(index, value) {
						$("." + value).show();
					});
				}
				else {
					// No plugins at all
					$("#mha-footer-req").hide();
				}
			}
		} catch (err) { }
		pluginLink.busy = false;
	}
}

// Overrides the SharePoint menu hover in order to remove the SharePoint hover delay which
// was causing issues with menu hovers getting "stuck"
function overrideMenu_HoverStatic(item)
{        
	var node=Menu_HoverRoot(item);
	var data=Menu_GetData(item);
	if (!data) return;
	__disappearAfter=data.disappearAfter;
	Menu_Expand(node, data.horizontalOffset, data.verticalOffset);      
}


$(document).ready(function() {		

	$(".watermark").focus(function() {
		$(this).removeClass("watermark");
		$(this).val("");
		$(this).blur(function() {
			$(this).addClass("watermark");
		});
	});	
	
	$(function() {
		$(".watermark").val("Search");
		
		$("li[name='pluginLink']").each(function(index, element) {
			pluginLink.possiblePlugins.push(element.className);
		});

		// Build the list of HREFs to analyze for plugins in the interval method
		$("a").each(function(index, element) {
			pluginLink.hrefElements.push(element.href);
		});
		
		// Fire off the plugin timer to hit every millisecond
		pluginLink.intervalID = setInterval(intervalMethod, 1);
	});
});



/* foresee script - only reference script on prod */
var domainhostname = window.location.hostname.toLowerCase();
var produrls=["www.treasury.gov","treasury.gov","origins.treasury.gov","orgins.treasury.arcdns.gov"];
for (url in produrls)
{
 if (domainhostname == produrls[url])
 {
  document.write('<script src="', '/Style Library/foresee/foresee-trigger.js', '" type="text/JavaScript"></script>');
  break;
 }
}

