/* Browser check */
IS_DOM = (document.getElementById) ? true : false;
IS_IE = (document.all) ? true : false;
IS_IE50 = (navigator.userAgent.indexOf("IE 5.0") != -1);
IS_Mac = (navigator.appVersion.indexOf("Mac") != -1);



// Image Swapping
function changeImages() 
{
  if (document.getElementById) {
    for (var i = 0; i < changeImages.arguments.length; i += 2) { 
  		document.getElementById(changeImages.arguments[i]).src = eval(changeImages.arguments[i + 1] + ".src"); 
	}
  }
}

// Get an ID 
function getThis(sId)
{
	var oObject;
	oObject = false;
	
	if (IS_DOM) {
		if (document.getElementById(sId)) {
			oObject = document.getElementById(sId);
		}
	}
	
	return oObject;
}

// Returns single element or multiple elements in an array
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements[elements.length] = element;
	}
	return elements;
}

// accessible popup functions, this will work with or without javascript enabled
// reference like this "<a href="popup.htm" onclick="popUp(this.href,'console',400,200);return false;" target="newWin" title="This link will pop open a new window">This is my link</a>"
function popUp(strURL,strType,strHeight,strWidth,strWindow)
{
  var strOptions="";
  if (strType=="console") {
    strOptions="resizable,height=" + strHeight + ",width=" + strWidth;
  }
  if (strType=="fixed") {
    strOptions="status,height=" + strHeight + ",width=" + strWidth;
  }
  if (strType=="elastic") {
    strOptions="toolbar,menubar,scrollbars,resizable,location,height=" + strHeight + ",width=" + strWidth;
  }
  if (strType=="scroll") {
    strOptions="status,scrollbars,resizable,height=" + strHeight + ",width=" + strWidth;
  }
  window.open(strURL, strWindow, strOptions);
}

// This function creates a new HTML element which contains only child nodes which are other HTML elements
function cleanOutWhitespace(theElement)
{
	// Create an array which will hold the needed HTML elements
	var storeHTMLElement = new Array();
	var arrayCounter = 0;
	for (i = 0; i < theElement.childNodes.length; i++)
	{
		// Store HTML elements in the array
		if (theElement.childNodes[i].nodeType == 1) {
			storeHTMLElement[arrayCounter] = theElement.childNodes[i];
			arrayCounter = arrayCounter + 1;
		}
	}
	
	// Remove all child nodes
	// Set a variable to the length, because the length changes every time a node is removed
	var elementLength = theElement.childNodes.length;
	for (i = 0; i < elementLength; i++)
	{
		theElement.removeChild(theElement.childNodes[0]);
	}
	
	// Append HTML elements back onto the parent element
	for (i = 0; i < storeHTMLElement.length; i++)
	{
		theElement.appendChild(storeHTMLElement[i]);
	}
	
	return theElement;
}




// change image in header
bgImg = {
	// variables 
	url : window.location,
	urlRoot : '',
	bgEl : 'container',
	// functions
	init : function() {
		if (!document.getElementById) return;
		var bgObj = document.getElementById(bgImg.bgEl);
		var tempURL = new String(bgImg.url);
		tempURL = tempURL.toLowerCase();		
		
		// check what section of the website we are in
		if (tempURL.match('/company/')) {
			var baseURL = tempURL.indexOf("/company/",1)
			baseURL = tempURL.slice(0,baseURL+1);
			bgObj.style.backgroundImage = 'none';
			bgObj.style.backgroundImage = 'url(' + baseURL + 'img/interface/building1.jpg)';
		} else if (tempURL.match('/casestudy/')) {
			var baseURL = tempURL.indexOf("/casestudy/",1)
			baseURL = tempURL.slice(0,baseURL+1);
			bgObj.style.backgroundImage = 'none';
			bgObj.style.backgroundImage = 'url(' + baseURL + 'img/interface/building2.jpg)';
		} else if (tempURL.match('/services/')) {
			var baseURL = tempURL.indexOf("/services/",1)
			baseURL = tempURL.slice(0,baseURL+1);
			bgObj.style.backgroundImage = 'none';
			bgObj.style.backgroundImage = 'url(' + baseURL + 'img/interface/building3.jpg)';
		} else if (tempURL.match('/careers/')) {
			var baseURL = tempURL.indexOf("/careers/",1)
			baseURL = tempURL.slice(0,baseURL+1);
			bgObj.style.backgroundImage = 'none';
			bgObj.style.backgroundImage = 'url(' + baseURL + 'img/interface/building4.jpg)';
		} else if (tempURL.match('/contactus/')) {
			var baseURL = tempURL.indexOf("/contactus/",1)
			baseURL = tempURL.slice(0,baseURL+1);
			bgObj.style.backgroundImage = 'none';
			bgObj.style.backgroundImage = 'url(' + baseURL + 'img/interface/building5.jpg)';
		}
	}
}
// handle this through the css instead
//addEvent(window,'load',bgImg.init);


//Toggel Item for browsing
function Toggle1(item,linktext) {

   obj=document.getElementById(item);

   visible=(obj.style.display!="none")

   key=document.getElementById("icon_" + item);

   if (visible) {

     obj.style.display="none";

     key.innerHTML="&nbsp;&nbsp;" + linktext;

   } else {

      obj.style.display="block";

      key.innerHTML="<strong class=\"txt_red\">&nbsp;&nbsp;" + linktext + "</strong>";

   }

}

//Toggel Side Menu Item for browsing
function Toggle(item,linktext) {

   obj=document.getElementById(item);

   visible=(obj.style.display!="none")

   key=document.getElementById("icon_" + item);

   if (visible) {

     obj.style.display="none";

     key.innerHTML="<strong class=\"txt_red\">[ + ]</strong>&nbsp;&nbsp;" + linktext;

   } else {

      obj.style.display="block";

      key.innerHTML="<strong class=\"txt_red\">[ &ndash; ]&nbsp;&nbsp;" + linktext + "</strong>";

   }

}



