/*
www.capital-eng.com
Navigation_Class.js

written by 
Geoff Corriere
geoff@cpe1.com

created 18/April/2002
last modified 22/August/2002

*/

//######################################################################
// constructor
//######################################################################

function Navigation()
{
	this.active_section = "";		// tracks which section is currently active
	this.active_section_index = 0;		// tracks which element of the current section that is shown
	//alert( "leave Navigation constructor" );
}

//=======================================================

//######################################################################
// private function members
//######################################################################




//######################################################################
// public function members
//######################################################################

Navigation.prototype.rollOver = rollOver;
function rollOver( picture )
{
	if( this[ picture].normal != this.home_alt.unvisited )	// make sure image rolled over is not a clear.gif
	{
		this[ picture ].rollOver();
	}
}

//=======================================================

Navigation.prototype.loadPage = loadPage;
function loadPage( picture )
{
	
	if( this[ picture].normal != this.home_alt.unvisited )	// make sure image clicked over is not a clear.gif
	{
		this.active_section = picture;
		this.active_section_index = 0;
		this[ picture ].changeBodyLocation( 0 );	// 0 is the first element in the section_arr array. most nav_slice objects only have 1 element in that array.
		this[ picture ].makeImageStateActive();
		
		//	change currently active images to vistied
		for( var x=0; x < this.nav_slice_arr.length; x++ )	
		{
			if( picture != this.nav_slice_arr[x] )		// if the value of the of the image clicked (picture) does not match the value of array element 
			{
				this[ this.nav_slice_arr[x] ].makeImageStateVisited();		// 	make the image state visited
			}
		}
		
		//	turn the home_alt image on/off
		if( picture.search( this.nav_slice_arr[0] ) < 0 )		// if the image clicked is not a link to the home page ( assuming the value of the first element of the nav_slice array is for the home page )
		{
			this.home_alt.turnAltNavOn();
		}
		else
		{
			this.home_alt.turnAltNavOff();
		}
		
		// check if section has multiple page
		if( this[ picture ].section_arr.length > 1 )
		{
			// display arrows
			this.next.turnAltNavOn();
			this.prev.turnAltNavOn();
		}
		else
		{
			this.next.turnAltNavOff();
			this.prev.turnAltNavOff();
		}
	}	// end if
	
}	// end function

//=======================================================

Navigation.prototype.clickArrow = clickArrow;
function clickArrow( direction )
{
	
	if( this[ direction ].normal != this.home_alt.unvisited )	// make sure image clicked over is not a clear.gif
	{
		if( direction == 'next' )
		{
			if( (this.active_section_index + 1) <= ( this[ this.active_section ].section_arr.length - 1 ) )	// check to see if we are at the end of the array
			{
				//document.status_form.status_text.value = document.status_form.status_text.value + "\n" + this[ this.active_section ].section_arr[ ++this.active_section_index ];
				++this.active_section_index;
			}
			else	// if adding 1 to the active_section_index takes us out of the array
			{
				this.active_section_index = 0;
				//document.status_form.status_text.value = document.status_form.status_text.value + "\n" + this[ this.active_section ].section_arr[ this.active_section_index ];
			}
		}
		else
		{
			if( (this.active_section_index - 1) >= 0 )	// check to see if we are at the beginning of the array
			{
				//document.status_form.status_text.value = document.status_form.status_text.value + "\n" + this[ this.active_section ].section_arr[ --this.active_section_index ];
				--this.active_section_index
			}
			else	// wrap around to the end of the array
			{
				this.active_section_index = ( this[ this.active_section ].section_arr.length - 1 );
				//document.status_form.status_text.value = document.status_form.status_text.value + "\n" + this[ this.active_section ].section_arr[ this.active_section_index ];
			}
		}
		
		this[ this.active_section ].changeBodyLocation( this.active_section_index );
		
	} // end if
}	// end func

//=======================================================

Navigation.prototype.clickEmail = clickEmail;
function clickEmail( picture )
{
	//this[ picture ].makeImageStateActive();
	this[ picture ].changeBodyLocation( 0 );
	this[ picture ].normal = this[ picture ].visited;
	this[ picture ].rollOut();
}

//=======================================================

Navigation.prototype.preloadimages = preloadimages;
function preloadimages()
{
	var cached_img = new Array();		
	for( var x = 0; x < this.nav_slice_arr.length; x++ )	
	{
		cached_img[x] = new Array();		// each element of the cached_img array is an array of Image objects
		cached_img[x][0] = new Image();		// create the Image object
		cached_img[x][0].src = this[ this.nav_slice_arr[x] ].unvisited;		// this.nav_slice_arr[x] is a string containing the name of a nav_slice property in the Navigation object
		cached_img[x][1] = new Image();												//	using the syntax "this[ this.nav_slice_arr[x] ]" is equal to "this.property_name"
		cached_img[x][1].src = this[ this.nav_slice_arr[x] ].active;			//	the url of "this[ this.nav_slice_arr[x] ].active" gets assigned to the Image object
		cached_img[x][2] = new Image();												//	forcing the image to load off screen and be placed in the cache
		cached_img[x][2].src = this[ this.nav_slice_arr[x] ].visited;
		cached_img[x][3] = new Image();
		cached_img[x][3].src = this[ this.nav_slice_arr[x] ].hover;	
	}
}