/* 
Title: Duff and Phelps - Global Functions
Author: Michael "Spell" Spellacy, Senior UI Developer
Email: michael.spellacy@tmp.com
Company: TMP Worldwide Advertising and Communications, LLC
*/

// Check Browser CSS Compatibility
	
// alert(document.compatMode);
	
// Supress BOM Script Errors	
	
function errorsuppressor(){
return true;

}

window.onerror = errorsuppressor;

// Multiple Onload Utility

function addLoadEvent(func) {

	var oldonload = window.onload;

	if (typeof window.onload != 'function') {
		
		window.onload = func;
	
	} else {
		
		window.onload = function() {
		oldonload();
		func();
		
		}
	}
}

// Insert-after Function

function insertAfter(newElement, targetElement) {

var parent = targetElement.parentNode;

if (parent.lastChild == targetElement) {

	parent.appendChild(newElement);
	
} else {

	parent.insertBefore(newElement, targetElement.nextSibling);
	
	}
}

// Load Flash Navigation

function prepNav() {

document.getElementById("wrapper").style.height = "100%";
document.getElementById("header").style.height = "100%";

}

addLoadEvent(prepNav);

function newsize(y) {
				
	//alert(y);					
	
	document.getElementById("mnav").style.height = y + "px";
	
	// D'oh! You can't access links in FireFox with Flash that is positioned over 
	// other elements so we have to dynamically set z-index
	// A hack, but it works
	
	if (y > 300) {
	
		document.getElementById("header").style.zIndex = 1;
	
	} else {
	
		document.getElementById("header").style.zIndex = 0;
	
	}

}

// Main Navigation (we use SWFObject 2)

function createNav() {

	var flashvars = {xmlPath: "data/navigation.xml", searchBox: 1, TabCount: 3, selectItem: "home", searchpage: "http://dp.duffandphelps.com/search/results.aspx?k="};	
	var params = {scale: "noscale", salign: "tl", quality: "high", wmode: "transparent", menu: "false"};
	//var attributes = {onfocus: "blur()"};
	var attributes = {};

	swfobject.embedSWF("flash/navigation.swf", "mnav", "100%", "100%", "8.0.0", "flash/app_expressinstall.swf", flashvars, params, attributes);

}

addLoadEvent(createNav);
									
function addOptionTitle() { 

// Add title attribute to all select boxes for usability
	
if (!document.getElementsByTagName("select")) return false;

var list = document.getElementsByTagName("select");
	
for(var i = 0; i < list.length; i++) {
	
	var option = list[i].getElementsByTagName("option")

		for(var j = 0; j < option.length; j++) {
			
			option[j].setAttribute("title", option[j].text);
		
		}
	}
}

addLoadEvent(addOptionTitle);

// Show country select navigation

function showCountry(obj,evt) {
	
	document.getElementById("country-select").getElementsByTagName("ul")[0].style.display = "block";
	
	// Eleminate event bubbling
	
	var e=(evt)?evt:window.event;

	if (window.event) {
		
		e.cancelBubble = true;

	} else {

		e.stopPropagation();
	}
	
}

// Hide country select navigation

function hideCountry () {
    
	document.getElementById("country-select").getElementsByTagName("ul")[0].style.display = "";
   
}

// Append show/hide country select navigation to appropriate elements

function changeCountry() {

	// Body
	
	var body = document.body;
	
	body.onclick = function() {
	
		hideCountry();
	
	}
	
	// First list element in country-select
	
	var countrylink = document.getElementById("country-select");
	var navigation = document.getElementById("mnav");
	
	var list = countrylink.getElementsByTagName("li")[0];

	list.onclick = function(event) {
	
		showCountry(this, event);
	
	}
	
	navigation.onclick = function() {
	
		hideCountry();
	
	}

}

addLoadEvent(changeCountry);

// Flash Image Replacement

addLoadEvent(setIFRFont);