// JavaScript Document


window.onload = function(e) {
  //setColumns();
	
	if( window.location.pathname.indexOf( 'index' ) == -1 ){
	  lightNav();
	}
}

//window.onresize = function() { setColumns(); }

// Simple Rollovers
function imgOn(imgName) {
  var newImgName = imgName + "_on.gif";
	var ImageToChange = getElemRefs( imgName );
  ImageToChange.src = "../images/" + newImgName;
  return;
}

function imgOff(imgName) {
  var newImgName = imgName + "_off.gif";
	var ImageToChange = getElemRefs( imgName );
	//alert( "image to change class"+ ImageToChange.className );
	if ( ImageToChange.className == 'on' ) {
		return;
	} else {
    ImageToChange.src = "../images/" + newImgName;
		return;
	}
}

/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  Copyright 2001-3 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

// resize fix for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); setColumns(); }
}

var cur_lyr;	// holds id of currently visible layer
/*function swapLayers(id) {
  if (cur_lyr) hideLayer(cur_lyr);
  showLayer(id);
  cur_lyr = id;
}*/

function showLayer(id) {	
  var lyr = getElemRefs(id);
  if (cur_lyr) hideLayer(cur_lyr);
  if (lyr && lyr.css){   
    var services_img = getElemRefs( 'services_img' );
		var profile_img = getElemRefs( 'profile_img' );
		
		if( lyr.id.indexOf( "services" ) != -1 ) {
			
			if ( services_img.className == "off" ) {
				profile_img.className = "off";
				services_img.className = "on";
				imgOff('profile_img');
				imgOff('clients_img');
				imgOff('contact_img');
				imgOn('services_img');
			} 
		} 
	
		if( lyr.id.indexOf( "profile" ) != -1 ) {
			
			if ( profile_img.className == "off" ) {
				services_img.className = "off";
				profile_img.className = "on";		
				imgOff('services_img');
				imgOff('clients_img');
				imgOff('contact_img');
				imgOn('profile_img');
			} 
		}
		lyr.css.visibility = "visible";
  }
  cur_lyr = id;
}

function hideLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "hidden";
}


// get reference to nested layer for ns4
// from old dhtmllib.js by Mike Hall of www.brainjar.com
function getLyrRef(lyr,doc) {
	if (document.layers) {
		var theLyr;
		for (var i=0; i<doc.layers.length; i++) {
	  	theLyr = doc.layers[i];
			if (theLyr.name == lyr) return theLyr;
			else if (theLyr.document.layers.length > 0) 
	    	if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
					return theLyr;
	  }
		return null;
  }
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

// determines height of columns and sets left columns' heights

function setColumns() {
        
        if ( window.innerHeight ) {
          maxHeight = window.innerHeight;
        } else if ( document.body.clientHeight ) {
          maxHeight = document.body.clientHeight;
        }

	var bodyDiv = document.getElementById('body');
        if ( bodyDiv ) {
          if( bodyDiv.offsetHeight > maxHeight ) {
            maxHeight = bodyDiv.offsetHeight;
          }
        }

        var curveDiv = document.getElementById('curve');
        if ( curveDiv ) {
          if (curveDiv.offsetHeight > maxHeight ) {
            maxHeight = curveDiv.offsetHeight;
          }
        }

	var sidenavDiv = getElemRefs('leftcolumn');
	if (sidenavDiv) {
  	  if (sidenavDiv.offsetHeight > maxHeight ) { 
            maxHeight = sidenavDiv.offsetHeight; 
          }
	}

	// set the left columns to be as high as the longest bit
	// of the page except on the home page.

  if( window.location.pathname.indexOf('index.php') != -1)  {
    maxHeight = eval( curveDiv.offsetHeight - 1 );
	}
	sidenavDiv.style.height = maxHeight + 'px';
	curveDiv.style.height = maxHeight + 'px';
}

function lightNav() {
	var loc = window.location.pathname;
	var bits = loc.split('/');
	var pageName = bits[2];
	var menu = bits[1].replace( /\.php$/g, '');
  //alert( menu );
	if ( pageName ) {
	  var submenu = pageName.replace( /\.php$/g, '');
		//alert( "menu " + menu + "\nsubmenu " + submenu );
		if( menu == 'services' || menu == 'profile' ) {
			showLayer( menu + '_submenu' );
			var ImageToChange = getElemRefs( submenu );
			ImageToChange.className = 'on';
			imgOn( submenu );
		}
	}
	
	var menuImage = menu + '_img';
	var ImageToChange = getElemRefs( menuImage );
	ImageToChange.className = 'on';
	imgOn( menuImage );	
}
