/* 
	Disney Research - Global Functions
	Author:  Deborah Foerst, UI Developer <debbie.foerst@tmp.com>
	Company: TMP Worldwide Advertising and Communications, LLC
*/

// Check Browser CSS Compatibility

// alert(document.compatMode);

// Supress BOM Script Errors	

function errorsuppressor(){
return true;
}

if(location.href.indexOf("localhost") == -1){

	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);

	}

}

// Global Pop-up (parse through DOM, if "newwindow" class exists, append event)

function newWinLinks() {

	for (var i=0; i < document.links.length; i++) {

		if (document.links[i].className == "new-window") {

			document.links[i].target = "_blank";

		}

	}

}

addLoadEvent(newWinLinks);

// Primary navigation script for dumb ol' IE6

primarynavhover = function() {

	if (!document.getElementById) return false;

	if (!document.getElementById("primarynav")) return false;

	var listElements = document.getElementById("primarynav").getElementsByTagName("li");

	for (var i=0; i < listElements.length; i++) {

		listElements[i].onmouseover = function() {

			this.className+=" iehover";

		}

		listElements[i].onmouseout = function() {

			this.className-= this.className.replace(new RegExp(" iehover\\b"));

		}

	}

}

// No longer used

// if (window.attachEvent) window.attachEvent("onload", primarynavhover); 

// Let's create some imaginary hotspots on home page and then 
// position them in the CSS (See pages.css)

if ($("#creative-collage").length) {

	$("#section").attr({style: "position: relative;"});
	$("#creative-collage").append('<a id="spot-06" class="hotspot" href="research-areas.html">Link</a>');
	$("#creative-collage").append('<a id="spot-05" class="hotspot" href="research-areas.html">Link</a>');
	$("#creative-collage").append('<a id="spot-04" class="hotspot" href="research-areas.html">Link</a>');
	$("#creative-collage").append('<a id="spot-03" class="hotspot" href="research-areas.html">Link</a>');
	$("#creative-collage").append('<a id="spot-02" class="hotspot" href="research-areas.html">Link</a>');
	$("#creative-collage").append('<a id="spot-01" class="hotspot" href="research-areas.html">Link</a>');

}

// Here we have some redundant text that needs to be placed on the page so let us clone it.

if ($("body.profile").length) {
	
	$(".people #article h1").clone().appendTo("#wrapper").attr("id", "h1-clone").end();
	$("#h1-clone strong").hide();
	$("#h1-clone").html($("#h1-clone").html().replace(/,/ig,""));

}


// Initiate jScrollPane

if ($("body.profile-index").length) {

	$("#content").jScrollPane();

}

//Let's override their !important rule by removing the style in all <a> elements.

$(".dolFooterLnk").removeAttr("style");

// Let's hijack some links to make creative happy...

$("#nav #pn-people > a").attr("href", "/people/management.html");

$("#nav #pn-opportunities > a").attr("href", "/jobs/senior-research-scientist.html");