/* "%Z%%Y%: %M%, version %I%, date %G% NL" */
// utilities for constructing navigation

// create the navigation associative array
var NAV = new Object();
var DEFAULT_DELIMETER = "&nbsp;&gt;&nbsp;";

// Constructor for a Navigation container
// @param name for this navigation
// @param delimeter between buttons 
//   ( optional, default = " > " )
function Navigation( navName, navDelimeter ) {
	this.name = navName;
	
	if ( navDelimeter ) {
	  this.delimeter = navDelimeter;
        } else {
          this.delimeter = DEFAULT_DELIMETER;
        }

	this.buttons = new Array();
}

// toString method for the Navigation object
Navigation.prototype.toString = function( ) {
	var nav = "";
        var delim = "";

	for ( var i = 0; i < this.buttons.length; i++ ) {
	  nav = nav + delim + this.buttons[ i ];
	  delim = this.delimeter;
	}

	return nav;
}

// Add a new navigation to this page
// @param name for this navigation
// @param delimeter between buttons
//   ( optional, default = " > " )
function addNavigation( navName, navDelimeter ) {
	NAV[ navName ] = new Navigation( navName, navDelimeter );
}

// Display the navigation to the browser
// @param name of the navigation
function displayNavigation( navName ) {
	document.write( NAV[ navName ] );
}

// Constructor for a Text Button
// @param text representation
// @param hypertext link ( optional )
function TextButton( butText, butLink ) {
	this.text = butText;
	this.link = butLink;
}

// toString method for the TextButton object
TextButton.prototype.toString = function( ) {
	var but = "";
	
	if ( this.link ) {
	  but = '<a href="' + this.link + '">' + this.text + '</a>';
	} else {
	  but = this.text;
	}

	return but;
}

// Constructor for an Image Button
// @param image src
// @param image width ( optional )
// @param image height ( optional )
// @param hypertext link ( optional )
function ImageButton( butSrc, butWidth, butHeight, butLink ) {
	this.src = butSrc;
	this.width = butWidth;
	this.height = butHeight;
	this.link = butLink;
	this.border = -1;
}

// toString method for the ImageButton object
ImageButton.prototype.toString = function( ) {
	var but = "";
	var img = "";

	img = '<img src="' + this.src + '" ';
	if ( this.width )
	  img = img + 'width="' + this.width + '" ';
	if ( this.height )
	  img = img + 'height="' + this.height + '" ';
	if ( this.border )
	  img = img + 'border="' + this.border + '" ';
	img = img + '/>';
	
	if ( this.link ) {
	  but = '<a href="' + this.link + '">' + img + '</a>';
	} else {
	  but = img;
	}
	
	return but;
}

// Add a button to this navigation
// @param name of the navigation
// @param button object
function addButton( navName, but ) {
	var buttons = NAV[ navName ].buttons;
	buttons[buttons.length] = but;
}

// Add a new text button to this navigation
// convenience method
// @param name of the navigation
// @param text representation
// @param hypertext link ( optional )
function addTextButton( navName, butText, butLink ) {
	addButton( navName, 
	new TextButton( butText, butLink ) );
}

// Add a new image button to this navigation
// convenience method
// @param name of the navigation
// @param image src
// @param image width ( optional )
// @param image height ( optional )
// @param hypertext link ( optional )
function addImageButton( navName, butSrc, butWidth, butHeight, butLink ) {
	addButton( navName,
	new ImageButton( butSrc, butWidth, butHeight, butLink ) );
}
