// IE Background Image Cache Hack
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

// set default window name 
// popups can then refer links back to parent window
name = "endurant";

function initLinkRels() {
	if (!document.getElementsByTagName) return false;
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];		
		if (anchor.rel != "") {
			switch (anchor.rel) {
				case "popup":
					if (anchor.href.indexOf("popupWidth") != -1) {
						var popupWidth = anchor.href.match(/popupWidth=(\d+)/i)[1];
					} else {
						var popupWidth = 820;
					}
					if (anchor.href.indexOf("popupHeight") != -1) {
						var popupHeight = anchor.href.match(/popupHeight=(\d+)/i)[1];
					} else {
						var popupHeight = 650;
					}
					var attributes = "target=popwin,resizable=yes,scrollbars=yes,width=" + popupWidth + ",height=" + popupHeight;
					var link = anchor.href;
					anchor.onclick = setPopup(link, attributes);
					break;
				case "external":
					anchor.target = "_blank"; 
					break;
			}
		}
	}
}

function setPopup(link, attributes) {
	return function() {
		window.open(link, "popwin", attributes);	
		return false;
	};
}

// Adds hover support for older browsers
function addHover() {
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	if (!document.defaultView) {	
		nav = document.getElementById("navigation");
		if (!nav) return false;
		navListItems = nav.getElementsByTagName("li");
		for (i = 0; i < navListItems.length; i++) {
			var node = navListItems[i];
			if (node.nodeName == "LI") {
				node.onmouseover = function() {
					this.className += " hover";
				};
				node.onmouseout = function() {
					this.className = this.className.replace(" hover", "");
				};
			}
		}
	}
}

// Dynamically adds "selected" class to links pointing to the current page in the sidebar menu
function doSidebarClass() {
	if (!document.getElementById) {return false;}
	if (!document.getElementsByTagName) {return false;}
	if (!document.createElement) {return false;}
	var sideBar = document.getElementById("sidebarMenu");
	if (!sideBar) {return false;}
	var sideBarExpanders = sideBar.getElementsByTagName("li");
	for (var i = 0; i < sideBarExpanders.length; i++) {
		var node = sideBarExpanders[i];
		if (node.nodeName == "LI") {
			var testA = node.firstChild;
			if (testA.href == location.href) {
				var menuText = testA.firstChild.nodeValue;
				var newTextNode = document.createTextNode(menuText);
				node.appendChild(newTextNode);
				testA.parentNode.className = "selected";
				testA.parentNode.removeChild(testA);
			}
		}	
	}
}

// sIFR Replacement Inits
var endurantFontReplacement = {
    src: '/res/inc/endurant.swf'
    ,ratios: [10,1.32,16,1.27,25,1.23,29,1.21,31,1.22,48,1.2,72,1.19,77,1.18,78,1.19,1.18]
  };

  sIFR.useStyleCheck = true;
  sIFR.activate(endurantFontReplacement);

 
  sIFR.replace(endurantFontReplacement, {
    selector: '#mainContent>h1'
    ,css: {
      '.sIFR-root': { 'color': '#529D44', 'text-transform': 'uppercase' }
    }
    ,selectable: true
	,tuneHeight: -5
    ,onReplacement: function () { 
	}
  });
  
  sIFR.replace(endurantFontReplacement, {
    selector: '#mainContent>h2'
    ,css: {
      '.sIFR-root': { 'color': '#529D44' , 'display': 'inline' }
    }
    ,selectable: true
  });
  
  sIFR.replace(endurantFontReplacement, {
    selector: '#mainContent>h3'
    ,css: {
      '.sIFR-root': { 'color': '#529D44' , 'display': 'inline' }
    }
    ,selectable: true
  });
  
  // Activates the mootools accordion on sidebar menu based on HTML
  function makeTogglers() {
	if (!document.getElementById) {return false;}
	if (!document.getElementsByTagName) {return false;}
	if (!document.createElement) {return false;}
	var sideBar = document.getElementById("sidebarMenu");
	if (!sideBar) {return false;}
	var sideBarExpanders = sideBar.getElementsByTagName("li");
	for (var i = 0; i < sideBarExpanders.length; i++) {
		var node = sideBarExpanders[i];
		if (node.nodeName == "LI") {
			var testA = node.firstChild;
			if (testA.className == "plus") {
						var newimg=document.createElement('img');
						newimg.src = "/images/common/plus.sign.gif";
						newimg.className = "toggler";
						node.insertBefore(newimg,testA);
			}
		}	
	}
}