/*
AmTrust - Scripts
Sean Hecking
Brulant
Last modified: 10.30.07
*/

//getElementsByClassName()
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};

//Checks to see if a string is in the browser URL
function inUrl(pageName){
	if(window.location.href.indexOf(pageName)!=-1){
		return true
	}	
	else{
		return false
	}
}

//sets the inner nav
function Nav (color, align, width){
	this._color=color;
	this._align=align;
	this._width=width;
	this._navId=document.getElementById('topNav');
	this._navTd=this._navId.getElementsByTagName('td');
	this._navPersonal=document.getElementById('personal');
	this._navBusiness=document.getElementById('business');
	this._navAboutAmtrust=document.getElementById('aboutAmtrust');
	this.setNav=function(){
		
		
		//sets the left border to NONE
		this._navTd[1].style.borderLeft='none';
		//green tab
		if(color=='green'){
			this._navTd[0].setAttribute('width', this._width);
			this._navTd[1].setAttribute('width', 90);
			this._navTd[2].setAttribute('width', 90);
			this._navTd[3].setAttribute('width', 126);
			this._navTd[0].className='green';
			//this._navTd[1].className='green selected';
			//this._navTd[1].style.backgroundImage="url('/style library/images/amtrust/innerNavTopCornerRt.gif')";
			//this._navTd[1].style.backgroundPosition='top right';
			this._navPersonal.className='setNav';
			this._navPersonal.style.backgroundImage="url('/style library/images/amtrust/personal_on.gif')";
		}
		//light blue tab
		if(color=='lightBlue'){
			this._navTd[2].setAttribute('width', this._width);
			this._navTd[1].setAttribute('width', 90);
			this._navTd[3].setAttribute('width', 126);
			this._navTd[2].className='lightBlue';
			//this._navTd[2].style.backgroundImage="url('/style library/images/amtrust/innerNavTopCornerLf.gif')";
			//this._navTd[2].style.backgroundPosition='top left';
			this._navBusiness.className='setNav';
			this._navBusiness.style.backgroundImage="url('/style library/images/amtrust/business_on.gif')";
		}
		//blue tab
		if(color=='blue'){
			this._navTd[3].setAttribute('width', this._width);
			this._navTd[3].style.textAlign=this._align;
			this._navTd[3].className='blue';
			this._navTd[3].style.backgroundImage="url('/style library/images/amtrust/innerNavTopCornerLf.gif')";
			this._navTd[3].style.backgroundPosition='top left';
			this._navTd[3].style.backgroundRepeat='no-repeat';
			//this._navTd[3].style.borderLeft='1px solid #ffffff';
			this._navAboutAmtrust.className='setNav';
		}
		
	}
}

function setNavInnerColor(){

	if(document.getElementById('topNav')){

		//checks the personal section
		if(inUrl('/personal') || inUrl('/Personal') || inUrl('/PERSONAL')){
			//Sets the navigation (COLOR, ALIGN, WIDTH)
			var mynav1 = new Nav('green', 'center', 264);
			mynav1.setNav();
		}
		else if(inUrl('/Business') || inUrl('/business') || inUrl('/BUSINESS')){
			//Sets the navigation (COLOR, ALIGN, WIDTH)
			var mynav2 = new Nav('lightBlue', 'left', 351);
			mynav2.setNav();
		}
		else if(inUrl('/AboutAmTrust') || inUrl('/aboutAmTrust') || inUrl('/aboutamTrust') || inUrl('/aboutamtrust') || inUrl('/Aboutamtrust')|| inUrl('/ABOUTAMTRUST')){
			//Sets the navigation (COLOR, ALIGN, WIDTH)
			var mynav3 = new Nav('blue', 'right', 387);
			mynav3.setNav();
		}
		else if(inUrl('/Career-Center') || inUrl('/career-center') || inUrl('/CAREER-CENTER')){
			//Sets the navigation (COLOR, ALIGN, WIDTH)
			var mynav4 = new Nav('blue', 'right', 387);
			mynav4.setNav();
		}
		else{
			//Sets the navigation (COLOR, ALIGN, WIDTH)
			var mynav5 = new Nav('green', 'center', 264);
			mynav5.setNav();
		}
	}else{
		return false
	}
}

function loadUtlNav(){
	var oUtlDiv = document.getElementById('branchLocator');
	var oUtlUl = document.getElementsByClassName('branchLocator');
	var oUl = oUtlDiv.nextSibling.nextSibling;
	var oLi = oUtlDiv.parentNode;
	
	oUtlDiv.onclick = function(){
		if(oUl.style.display!='block'){
			oUl.style.display='block';
			oLi.className='on';
		}else{
			oUl.style.display='none';
			oLi.className='';
		}
	}
}
window.onload = function()
{
	_spBodyOnLoadWrapper();
	setNavInnerColor();
	loadUtlNav();
}