var ns4 = (document.layers)? true:false
docGet = (document.getElementById) ? true : false;
docLay = (document.layers) ? true : false;
docAll = (document.all) ? true : false;

var isNav = (navigator.appName.indexOf("Netscape") !=-1);
var isIE = (navigator.appName.indexOf("Microsoft") !=-1);


browserName = navigator.appName;
browserVersion = navigator.appVersion;



// This function finds the width of the browser.
function findWidth(){
	var browserWidth;
	browserWidth = isNav ? window.innerWidth : document.body.offsetWidth ;
	return browserWidth;
}

// This function changes the font color of the link onMouseOver.
function changeColor( obj, colr ) {
	if( ns4 ) obj.color = colr;
	else obj.style.color = colr;
}


var subID, startTPos, stopTPos, direction, slideInterval, hideSubTimer;
var prevSubID, prevStartTPos, prevStopTPos;
prevSubID = "";
prevStartTPos = "";
prevStopTPos = "";
slideInterval = null;
hideSubTimer = null;
function startInterval( psubID, pstartTPos, pstopTPos, pdirection ){
	if( psubID != prevSubID ) {
		clearInterval(slideInterval);
		
		hideSub( prevSubID, prevStartTPos );
		subID = psubID;

		startTPos = pstartTPos;
		stopTPos = pstopTPos;
		direction = pdirection;
		
		slideInterval = setInterval( "slideSub()", 50 );
		prevSubID = subID;
		prevStartTPos = startTPos;
		prevStopTPos = stopTPos; 
	}
}


function slideSub() {
	obj = MM_findObj( subID );
	currentPos = ( ns4 ) ? obj.top : parseInt( obj.style.top );

	if( direction == "up" ) {
		if( currentPos - 20 > stopTPos ) {
			setPos( subID ).top = currentPos - 20;
		} else {
			setPos( subID ).top = stopTPos;
			clearInterval(slideInterval);
		}
	} else {
		if( currentPos + 20 < stopTPos ) {
			setPos( subID ).top = currentPos + 20;
		} else {
			setPos( subID ).top = stopTPos;
			clearInterval(slideInterval);
		}
	}
}

function hideSub( objID, objPos ) {
	if( objID != "" ) {
		obj = MM_findObj( objID );
		// hide prev sub by moving prev sub back to orignall position
		if( ns4 ) obj.top = objPos;
		else obj.style.top = objPos;
		prevSubID = ""; 
	}
}

function mouseMove(e){
	mouseX = ( isNav ) ? e.pageX : event.clientX;
	mouseY = ( isNav ) ? e.pageY : event.clientY;

	if( subID == "contactSub" && page != "contact" ) {
		if( mouseX > contactX1 && mouseX < contactX2 && mouseY > contactY1 && mouseY < contactY2 ) {
		} else {
			//window.status = "turn off " + subID;
			clearInterval(slideInterval)
			hideSub( subID, startTPos );
			
			if( page == "about" ) startInterval( 'aboutSub', 410, 310, 'up' );
			if( page == "clients" ) startInterval( 'clientsSub', 18, 144, 'down' );
			if( page == "contact" ) startInterval( 'contactSub', 410, 335, 'up' );
			if( page == "portfolio" ) startInterval( 'portfolioSub', -6, 144, 'down' );
		} 
	}
	
	if( subID == "aboutSub" && page != "about" ) {
		if( mouseX > aboutX1 && mouseX < aboutX2 && mouseY > aboutY1 && mouseY < aboutY2 ) {
		} else {
			//window.status = "turn off " + subID;
			clearInterval(slideInterval)
			hideSub( subID, startTPos );
			
			if( page == "about" ) startInterval( 'aboutSub', 410, 310, 'up' );
			if( page == "clients" ) startInterval( 'clientsSub', 18, 144, 'down' );
			if( page == "contact" ) startInterval( 'contactSub', 410, 335, 'up' );
			if( page == "portfolio" ) startInterval( 'portfolioSub', -6, 144, 'down' );
		}
	}
	
	if( subID == "clientsSub" && page != "clients" ) {
		if( mouseX > clientsX1 && mouseX < clientsX2 && mouseY > clientsY1 && mouseY < clientsY2 ) {
		} else {
			//window.status = "turn off " + subID;
			clearInterval(slideInterval)
			hideSub( subID, startTPos );
			
			if( page == "about" ) startInterval( 'aboutSub', 410, 310, 'up' );
			if( page == "clients" ) startInterval( 'clientsSub', 18, 144, 'down' );
			if( page == "contact" ) startInterval( 'contactSub', 410, 335, 'up' );
			if( page == "portfolio" ) startInterval( 'portfolioSub', -6, 144, 'down' );
		}
	}
	
	if( subID == "portfolioSub" && page != "portfolio" ) {
		if( mouseX > portfolioX1 && mouseX < portfolioX2 && mouseY > portfolioY1 && mouseY < portfolioY2 ) {
		} else {
			//window.status = "turn off " + subID;
			clearInterval(slideInterval)
			hideSub( subID, startTPos );
			
			if( page == "about" ) startInterval( 'aboutSub', 410, 310, 'up' );
			if( page == "clients" ) startInterval( 'clientsSub', 18, 144, 'down' );
			if( page == "contact" ) startInterval( 'contactSub', 410, 335, 'up' );
			if( page == "portfolio" ) startInterval( 'portfolioSub', -6, 144, 'down' );
		}
	}
}

if( isNav ) document.captureEvents( Event.MOUSEMOVE );
 
document.onmousemove = mouseMove;


// This starts the interval calling the slideLine function
var lineInterval = "";
function startLineInterval( direction, goback ) {
	if( lock == "no" ) {
		//lock = "yes"; // set to no after interval is over in slideLine function
		clearInterval(lineInterval);
		if( direction == "right" ) {
			if( goback == "no" ) {
				lineInterval = setInterval( "slideLine( 'right', 'no' )", 50 );
			} else {
				lineInterval = setInterval( "slideLine( 'right', 'no' )", 50 );
			}
		} else {
			if( goback == "no" ) {
				lineInterval = setInterval( "slideLine( 'left', 'no' )", 50 );
			} else {
				//MM_findObj( "line" ).style.left = lineStopPos; // this is for if you want it to jump back to beginning
				lineInterval = setInterval( "slideLine( 'left', 'yes' )", 50 );
			}
		}
	}
}

lock = "no";

// This function slides the line left and right to similate a curtain
function slideLine( direction, goback ) {
	theLine = MM_findObj( "lineMove" );
	lineCurPos = ( docLay ) ? theLine.left : parseInt( theLine.style.left );
	if( theLine.style ) lineCurWidth = parseInt( theLine.style.width );
	
	if( direction == "right" ) {
		if( lineCurPos + 20 < lineStopPos ) {
			if( theLine.style ) {
				theLine.style.left = lineCurPos + 20;
				theLine.style.width = lineCurWidth - 20;
			} else theLine.left = lineCurPos + 20;
		} else {
			if( theLine.style ) theLine.style.left = lineStopPos;
			else theLine.left = lineStopPos;
			clearInterval( lineInterval );
			lock = "no"
			if( goback == "yes" ) {
				showHideSections( sectionName, vis );
				startLineInterval( "left", "no" );
			}
		}
	} else {
		if( lineCurPos - 20 > lineStartPos ) {
			if( theLine.style ) {
				theLine.style.left = lineCurPos - 20;
				theLine.style.width = lineCurWidth + 20;
			}
			else theLine.left = lineCurPos - 20;
		} else {
			if( theLine.style ) theLine.style.left = lineStartPos;
			else theLine.left = lineStartPos;
			clearInterval( lineInterval );
			lock = "no"
			if( goback == "yes" ) {
				if( preSection == "contentBra3" )showHideSections( preSection + "Sub",'hide' );
				if( preSection == "contentCol4" )showHideSections( preSection + "Sub",'hide' );
				if( preSection == "contentEve1" )showHideSections( preSection + "Sub",'hide' );
				if( preSection == "contentEve2" )showHideSections( preSection + "Sub",'hide' );
				if( preSection != "" ) {
					showHideSections( preSection+ "DivArray",'hide' );
				}
				showHideSections( curSection+ "DivArray",'show' );
				startLineInterval( "right", "no" );
			}
		}
	}
}

// This is used for subnavOver, subnavOut, subnavClick
curImgName = "";
curImgSrc = "";

// This is used for subavClick and slideLine
preSection = "";
curSection = "";
function subnavOver( imgName, imgSrc ) {
	if( curImgName != imgName ) {
		MM_findObj( imgName ).src = "images/" + imgSrc;
	}
}

function subnavOut( imgName, imgSrc ) {
	if( curImgName != imgName ) {
		MM_findObj( imgName ).src = "images/" + imgSrc;
	}
}



// This handles the right subnav clicks to swap out the images
function subnavClick( imgName, imgSrc, section ) {
	if( lock == "no" ) {
		if( curImgName != imgName ) {
			if( curImgName != "" ) {
				//alert(curImgName + " - " + curImgSrc);
				MM_findObj( curImgName ).src = "images/" + curImgSrc;	
				//document.getElementById( curImgName ).src = "images/" + curImgSrc;
			}
			curImgName = imgName;
			curImgSrc = imgSrc;
	
			preSection = curSection;
			curSection = section;
		}
	}
}  

// This swaps out the header for each subsection
function swapHeader( headerSrc ) {
	if( lock == "no" ) {
		//alert(headerSrc);
		MM_findObj( "headerImg" ).src = "images/" + headerSrc;
	}
}



// This is for setting the top and left values of objects
function setPos( theObj ) { ;
	if( docAll ) return document.all[ theObj ].style;
	else if( docGet ) return document.getElementById( theObj ).style;
	else if( docLay ) return document.layers[ theObj ];
	else return document.getElementById( theObj ).style;
}

// This will loop through an array of div names and turn the visibility on or off
// The array is defined the the page that contains the sub section.
// It is used when navigating through the subsections that have the left and right swipe
// It is called from the slideLine function.
function showHideSections( sectionName, vis ) {
	theArray = eval( sectionName );
	for( i = 0; i < theArray.length; i++ ) {
		MM_showHideLayers( theArray[i],'',vis )
	}
}


function showHideClients() {
	MM_showHideLayers( preSection,'','hide' );
	MM_showHideLayers( curSection,'','show' );
}



function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
//MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// These are images for the menus
MM_preloadImages('images/menu_mission_on.gif','images/menu_awards_on.gif','images/menu_process_on.gif','images/menu_team_on.gif','images/menu_about_on.gif','images/menu_map_on.gif','images/menu_email_on.gif','images/menu_rolodex_on.gif','images/menu_contactform_on.gif','images/menu_collateral_on.gif','images/menu_clients_on.gif','images/menu_portfolio_on.gif','images/menu_hightech_on.gif','images/menu_finance_on.gif','images/menu_law_on.gif','images/menu_nonprofit_on.gif','images/menu_professional_on.gif','images/menu_reports_on.gif','images/menu_branding_on.gif','images/menu_corporateid_on.gif','images/menu_events_on.gif','images/menu_web_on.gif','images/menu_contact_on.gif','images/arrow_left_on.gif','images/arrow_right_on.gif')