var w3c = (document.getElementById) ? 1:0;
var ns4 = (document.layers) ? 1:0;
var ie4 = (document.all) ? 1:0;
if(ns4)window.onResize=rI;function rI(){window.history.go(0);}

var whichPage = window.location.href;
var thisPage = "";
var rootLabel = "";
var rootURL = "";

if(whichPage.indexOf("about") != -1){
	thisPage = "Slice_02";
}else if(whichPage.indexOf("media") != -1){
	thisPage = "Slice_03";
}else if(whichPage.indexOf("contact") != -1){
	thisPage = "Slice_04";
}else if(whichPage.indexOf("portfolio") != -1){
	thisPage = "Slice_06";
}else if(whichPage.indexOf("location") != -1){
	thisPage = "Slice_07";
}else if(whichPage.indexOf("career") != -1){
	thisPage = "Slice_08";
}else{
	thisPage = "Slice_01";
	rootURL = '';
	rootLabel = "";
}

function strPath(){

	var baseTitle = document.title;
	var thisTitle = baseTitle.split(" :: ");

	var tempLoc = whichPage;
	tempLoc = tempLoc.replace(/(\w+):\/\/([\w.]+)\//, "");
	
	var strPath = '';
	
	var loc = tempLoc.split("/");
	
	// alert(loc.length);
	
	switch (loc.length){
		case 0,1:
			if(thisTitle[thisTitle.length - 1] != "ideo.com"){
				strPath = '<a href="/ideo.asp" class="pathHome">Home<\/a> : <span class="pathEnd">' + thisTitle[thisTitle.length - 1] + '<\/span>';
			}else{
				strPath = '<span class="pathEnd">Home<\/span>';	
			}
			break;
		case 2:
			if(loc[1] == ""){
				strPath = '<a href="/ideo.asp" class="pathHome">Home<\/a> : <span class="pathEnd">' + thisTitle[thisTitle.length - 1] + '<\/span>';
			}else{
				strPath = '<a href="/ideo.asp" class="pathHome">Home<\/a> : <a href="/' + loc[0] + '/" class="pathMiddle">' + thisTitle[thisTitle.length - 2] + '<\/a> : <span class="pathEnd">' + thisTitle[thisTitle.length - 1] + "<\/span>";
			}
			
			break;
		case 3:
			if(loc[0] == "about"){
				var qs = 0;
				switch(loc[1]){
					case "teams":
						qs = 1;
						break;
					case "methods":
						qs = 3;
						break;
					case "offerings":
						qs = 5;
						break;
				}
				
				if(qs != 0){
					strPath = '<a href="/ideo.asp" class="pathHome">Home<\/a> : <a href="/' + loc[0] + '/" class="pathMiddle">' + thisTitle[thisTitle.length - 3] + '<\/a> : <a href="/' + loc[0] + '/?x=' + qs + '&y=' + (qs + 1) + '" class="pathFar">' + thisTitle[thisTitle.length - 2] + '<\/a> : <span class="pathEnd">' + thisTitle[thisTitle.length - 1] + "<\/span>";
				}else{
					strPath = '<a href="/ideo.asp" class="pathHome">Home<\/a> : <a href="/' + loc[0] + '/" class="pathMiddle">' + thisTitle[thisTitle.length - 3] + '<\/a> : <a href="/' + loc[0] + "/" + loc[1] + '/" class="pathFar">' + thisTitle[thisTitle.length - 2] + '<\/a> : <span class="pathEnd">' + thisTitle[thisTitle.length - 1] + "<\/span>";
				}
			}else{
				strPath = '<a href="/ideo.asp" class="pathHome">Home<\/a> : <a href="/' + loc[0] + '/" class="pathMiddle">' + thisTitle[thisTitle.length - 2] + '<\/a> : <span class="pathEnd">' + thisTitle[thisTitle.length - 1] + "<\/span>";
			}
			break;
		case 4:
			strPath = '<a href="/ideo.asp" class="pathHome">Home<\/a> : <a href="/' + loc[0] + '/" class="pathMiddle">' + thisTitle[thisTitle.length - 4] + '<\/a> : <a href="/' + loc[0] + "/" + loc[1] + '/" class="pathFar">' + thisTitle[thisTitle.length - 3] + '<\/a> : <a href="/' + loc[0] + "/" + loc[1] + "/" + loc[2] + '/" class="pathFar">' + thisTitle[thisTitle.length - 2] + '<\/a> : <span class="pathEnd">' + thisTitle[thisTitle.length - 1] + "<\/span>";
			break;
	}
	
	return strPath;
}

function toolBox(){
	var selIndex = document.frmToolbox.toolSelect.selectedIndex;
	var selVal = document.frmToolbox.toolSelect.options[document.frmToolbox.toolSelect.selectedIndex].value;
	
	if(selIndex == 1){
		document.frmToolbox.action = "/email.asp";
		document.frmToolbox.submit();
	}
	
	if(selIndex == 2){
		document.frmToolbox.action = "/addCookie.asp";
		document.frmToolbox.submit();
	}
	
	if(selIndex == 3){
		document.frmToolbox.action = "/email.asp";
		document.frmToolbox.submit();
	}

}


function printWin(which){
	if(which.indexOf("&") != -1){
		var tempArray = which.split("&");
		var l = tempArray[0];
		var d = tempArray[1];
		var fileName = "print.asp?l=" + l + "&d=" + d;
	}else{
		var fileName = "print.asp?x=" + which;
	}
	
	x = window.open(fileName,"printWin","scrollbars=yes,menubar=yes,width=612,height=792");
	document.frmToolbox.toolSelect.selectedIndex = 0;
	x.focus();
}

function openWin(pg,n,w,h){
	if(w != "" && h != ""){
		d = window.open(pg,n,"scrollbars=yes,top=0,left=0,width="+w+"px,height="+h+"px");
	}else{
		d = window.open(pg,n,"scrollbars=yes,top=0,left=0,");
	}
}

function nSearch(){
	openWin("/news/nsearch.asp","newsSearch","300","400");
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			if(changeImages.arguments[i] == thisPage){
				document[changeImages.arguments[i]].src = "/images/nav/" + thisPage + "-over.gif";
			}else if (location.search.charAt(location.search.length - 1) == changeImages.arguments[i].charAt(changeImages.arguments[i].length - 1) && (changeImages.arguments[i].indexOf("Slice") == -1)){
				document[changeImages.arguments[i]].src = "/images/sub_arrow-over.gif";
			}else{
				document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
			}
		}
	}
}

var preloadFlag = false;

function preloadImages() {
	if (document.images) {
		Slice_02_over = newImage("/images/nav/Slice_02-over.gif");
		Slice_03_over = newImage("/images/nav/Slice_03-over.gif");
		Slice_04_over = newImage("/images/nav/Slice_04-over.gif");
		Slice_06_over = newImage("/images/nav/Slice_06-over.gif");
		Slice_07_over = newImage("/images/nav/Slice_07-over.gif");
		Slice_08_over = newImage("/images/nav/Slice_08-over.gif");
		preloadFlag = true;
	}
}

function setNav() {
	if(thisPage != "Slice_01"){
		var imgName = "/images/nav/" + thisPage + "-over.gif";
		changeImages(thisPage, imgName);
		
		temp = location.search;
		
		//if(temp != "" && thisPage != "Slice_06"){
		//	tempArr = temp.split("");
		//	var imgLink = "/images/sub_arrow-over.gif";
		//	changeImages("link_0" + tempArr[tempArr.length - 1], imgLink);
		//}
	}
}

function killScrollBars(){
	if(!ns4){
		document.body.scroll = "no";
	}
}

function SerendipityWin(){
			
	var which = "newSerendipityWin";
	var tempLink = "";
	for (var i=0; i<=(document.links.length-1); i++){
				
		tempLink = document.links[i].href;
				
		if(tempLink.indexOf("pID=") == -1 && tempLink.indexOf("pgNav") == -1 && tempLink.indexOf("addComment") == -1 && tempLink.indexOf("removePage") == -1 && tempLink.indexOf("movePage") == -1){
			document.links[i].target = which;
		}
	}
}

//=====================================================================
//	LTrim(string) : Returns a copy of a string without leading spaces.
//=====================================================================
function LTrim(str)
/*
	PURPOSE: Remove leading blanks from our string.
	IN: str - the string we want to LTrim
	
	RETVAL: An LTrimmed string
*/
{
	var whitespace = new String(" \t\n\r");

	var s = new String(str);

	if (whitespace.indexOf(s.charAt(0)) != -1) {
	// We have a string with leading blank(s)...

		var j=0, i = s.length;

		// Iterate from the far left of string until we
		// don't have any more whitespace...
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;


		// Get the substring from the first non-whitespace
		// character to the end of the string...
		s = s.substring(j, i);
	}

	return s;
}

//======================================================================
//	RTrim(string) : Returns a copy of a string without trailing spaces.
//======================================================================
function RTrim(str)
/*
	PURPOSE: Remove trailing blanks from our string.
	IN: str - the string we want to RTrim

	RETVAL: An RTrimmed string

*/
{
	// We don't want to trip JUST spaces, but also tabs,
	// line feeds, etc.  Add anything else you want to
	// "trim" here in Whitespace
	var whitespace = new String(" \t\n\r");

	var s = new String(str);

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
	// We have a string with trailing blank(s)...

		var i = s.length - 1;       // Get length of string

		// Iterate from the far right of string until we
		// don't have any more whitespace...
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;


		// Get the substring from the front of the string to
		// where the last non-whitespace character is...
		s = s.substring(0, i+1);
	}

	return s;
}


//=============================================================
//	Trim(string) : Returns a copy of a string without leading
//	or trailing spaces
//=============================================================
function Trim(str)
/*
	PURPOSE: Remove trailing and leading blanks from our string.
	IN: str - the string we want to Trim

	RETVAL: A Trimmed string
*/
{
	return RTrim(LTrim(str));
}

//=============================================================
//	cleanString(str,chr) : 
//  Returns a string without leading or trailing spaces and 
//  replaces the chr value with a "+" for passing in url
//=============================================================
function cleanString(str,chr){
	var tempArray = str.split(chr);
	var newStr = "";
	
	for(i = 0; i < tempArray.length; i++){
		if(i == tempArray.length - 1){
			newStr = newStr + Trim(tempArray[i]);
		}else{
			newStr = newStr + Trim(tempArray[i]) + "+";
		}
	}

	return newStr;
}
