/* Global variables */
document.navigationItems = new Array();
document.nrOfNavigationItems = 0;

document.footerNavigationItems = new Array();
document.nrOfFooterNavigationItems = 0;


/* Constants */
var NAVIGATION_BACK = 1;
var NAVIGATION_CURRENT = 2;
var NAVIGATION_SECTION = 3;
var NAVIGATION_RELATED = 4;
var NAVIGATION_PAGEICON = 5;
var NAVIGATION_FOOTER_ITEM = 6;

/* 'Object' Constructors */


/**
	navigationPageIconItem
 	This is the constructor function for the navigation item: PageIcon
 */
function navigationPageIconItem( url ) {
	this.type = NAVIGATION_PAGEICON;
	this.url = url;

	this.getHTML = navigationPageIconItem_getHTML;
}

/**
	navigationBackItem
 	This is the constructor function for the navigation item: Back
 */
function navigationBackItem( name, url ) {
	this.type = NAVIGATION_BACK;
	this.url = url;
	this.name = name;

	this.getHTML = navigationBackItem_getHTML;
}

/**
	navigationCurrentItem
	This constructor function for the navigation item: Current
 */
function navigationCurrentItem( name, url ) {
	this.type = NAVIGATION_CURRENT;
	this.url = url;
	this.name = name;
	this.active = false;

	var currentPathName = getPathNameFromURL( document.location.href );
	if( currentPathName.valueOf() == url.valueOf() ) {
		this.active = true;
	}

	this.getHTML = navigationCurrentItem_getHTML;
}


/**
	navigationSectionItem
	This is the constructor function for the navigation item: Section
*/
function navigationSectionItem( name, url ) {
	this.type = NAVIGATION_SECTION;
	this.active = false;
	this.url = url;
	this.name = name;
	
	var currentPathName = getPathNameFromURL( document.location.href );
	if( currentPathName.valueOf() == url.valueOf() ) {
		this.active = true;	
	}
	
	this.getHTML = navigationSectionItem_getHTML;
}

/**
	navigationRelatedItem
	This is the constructor function for the navigation item: Related
 */
function navigationRelatedItem( name, url ) {
	this.type = NAVIGATION_RELATED;
	this.url = url;
	this.name = name;

	this.getHTML = navigationRelatedItem_getHTML;
}

/**
	navigationSeparatorItem
	This is the constructor function for the navigation item: - Separator
 */
function navigationSeparatorItem(  ) {
	this.getHTML = navigationSeparatorItem_getHTML;
}

/**
	footerNavigationItem
 	This is the constructor function for the footer navigation item 
 */
function footerNavigationItem( name, url ) {
	this.type = NAVIGATION_FOOTER_ITEM;
	this.url = url;
	this.name = name;

	this.getHTML = footerNavigationItem_getHTML;
}

/* Helper functions */

/**
	navigationBackItem_getHTML
	Returns the HTML for the navigationBackItem 'Object'
*/
function navigationPageIconItem_getHTML( ) {
	var text = "";
	text += "<IMG SRC=\""+this.url+"\" BORDER=\"0\" WIDTH=\"171\" HEIGHT=\"129\">";
	return text;
}

function navigationBackItem_getHTML( ) {
	var text = "";
	
	text += "<TR>";
		text += "<TD width=\"17\" align=\"right\" valign=\"top\">";
			text += "<DIV class=\"globnavcircleleft\">";
			text += "<A href=\""+this.url+"\" title=\""+this.name+"\">";
			text += "<IMG src=\"/bv/computers/navigation/left/arrows/pn_arrow_up.gif\" width=\"15\" height=\"9\" border=\"0\">";
			text += "</A>";
			text += "</DIV>";
		text += "</TD>";
		text += "<TD valign=\"bottom\">";
			text += "<DIV class=\"globnavtext\">";
			text += "<A href=\""+this.url+"\" class=\"globnavtext\" title=\""+this.name+"\">"+this.name+"</A>";
			text += "</DIV>";
		text += "</TD>";
		text += "<TD width=\"17\">&nbsp;</TD>";
	text += "</TR>";
	
	return text;
}

/**
	navigationCurrentItem_getHTML
	Returns the HTML for the navigationCurrentItem 'Object'
*/
function navigationCurrentItem_getHTML( ) {
	var text = "";

	if (this.active) {
		var style = "\"globnavactiveleft\"";
	}else{
		// when the current section is not open it has a special style
		var style = "\"globnavopen\"";
	}
	
	text += "<TR>";
		text += "<TD width=\"17\" align=\"right\" valign=\"top\">";
			text += "<DIV class=\"globnavcircleright\">";
			text += "<A href=\""+this.url+"\" title=\""+this.name+"\">";
			text += "<IMG src=\"/bv/computers/navigation/left/arrows/pn_arrow_right.gif\" width=\"15\" height=\"9\" border=\"0\">";
			text += "</A>";
			text += "</DIV>";
		text += "</TD>";
		text += "<TD valign=\"bottom\" align=\"left\">";
			text += "<DIV class="+style+">";
			text += "<A href=\""+this.url+"\" class="+style+" title=\""+this.name+"\">"+this.name+"</A>";
			text += "</DIV>";
		text += "</TD>";
		text += "<TD width=\"17\">&nbsp;</TD>";
	text += "</TR>";
	
	return text;
}

/**
	navigationSectionItem_getHTML
	Returns the HTML for the navigationSectionItem 'Object'
*/
function navigationSectionItem_getHTML( ) {
	var text = "";

	if (this.active) {
		var style = "\"globnavactiveright\"";
	}else{
		var style = "\"globnavtext\"";
	}
	
	text += "<TR>";
		text += "<TD width=\"17\">&nbsp;</TD>";
		text += "<TD valign=\"bottom\" align=\"right\">";
			text += "<DIV class="+style+">";
			text += "<A href=\""+this.url+"\" class="+style+" title=\""+this.name+"\">"+this.name+"</A>";
			text += "</DIV>";
		text += "</TD>";
		text += "<TD width=\"17\" align=\"right\" valign=\"bottom\">";
			text += "<DIV class=\"globnavcircleright\">";
			text += "<A href=\""+this.url+"\" title=\""+this.name+"\">";
			text += "<IMG src=\"/bv/computers/navigation/left/arrows/pn_arrow_right.gif\" width=\"15\" height=\"9\" border=\"0\">";
			text += "</A>";
			text += "</DIV>";
		text += "</TD>";
	text += "</TR>";
	
	return text;
}

/**
	navigationRelatedItem_getHTML
	Returns the HTML for the navigationRelatedItem 'Object'
*/
function navigationRelatedItem_getHTML( ) {
	var text = "";
	
	text += "<TR>";
		text += "<TD width=\"17\" align=\"right\" valign=\"top\">";
			text += "<DIV class=\"globnavcircleleft\">";
			text += "<A href=\""+this.url+"\" title=\""+this.name+"\">";
			text += "<IMG src=\"/bv/computers/navigation/left/arrows/pn_arrow_left.gif\" width=\"15\" height=\"9\" border=\"0\">";
			text += "</A>";
			text += "</DIV>";
		text += "</TD>";
		text += "<TD valign=\"bottom\">";
			text += "<DIV class=\"globnavtext\">";
			text += "<A href=\""+this.url+"\" class=\"globnavtext\" title=\""+this.name+"\">"+this.name+"</A>";
			text += "</DIV>";
		text += "</TD>";
		text += "<TD width=\"17\">&nbsp;</TD>";
	text += "</TR>";
	
	return text;
}

/**
	footerNavigationItem_getHTML
	Returns the HTML for the navigationSectionItem 'Object'
*/
function footerNavigationItem_getHTML( ) {
	var text = "";
	
	text += "<TR>";
		text += "<TD width=\"17\" align=\"right\" valign=\"top\">";
			text += "<DIV class=\"globnavcircleleft\">";
			text += "<A href=\""+this.url+"\" title=\""+this.name+"\">";
			text += "<IMG src=\"/bv/computers/navigation/left/arrows/pn_arrow_left.gif\" width=\"15\" height=\"9\" border=\"0\">";
			text += "</A>";
			text += "</DIV>";
		text += "</TD>";
		text += "<TD valign=\"bottom\">";
			text += "<DIV class=\"globnavtext\">";
			text += "<A href=\""+this.url+"\" class=\"globnavtext\" title=\""+this.name+"\">"+this.name+"</A>";
			text += "</DIV>";
		text += "</TD>";
		text += "<TD width=\"17\">&nbsp;</TD>";
	text += "</TR>";
	
	return text;
}

/**
	navigationSeparatorItem_getHTML
	Returns the HTML for the navigationSeparatorItem 'Object'
*/
function navigationSeparatorItem_getHTML( ) {
	var text = "";
	
	text += "<TR>";
		text += "<TD width=\"17\" height=\"1\" align=\"right\" valign=\"top\">";
			text += "<IMG src=\"/bv/computers/navigation/pixel.gif\" width=\"17\" height=\"1\" border=\"0\">";
		text += "</TD>";
		text += "<TD class=\"globlocalmenuseparator\" width=\"126\" height=\"1\" align=\"right\" valign=\"top\">";
			text += "<IMG src=\"/bv/computers/navigation/pixel.gif\" width=\"126\" height=\"1\" border=\"0\">";
		text += "</TD>";
		text += "<TD width=\"17\" height=\"1\" align=\"right\" valign=\"top\">";
			text += "<IMG src=\"/bv/computers/navigation/pixel.gif\" width=\"17\" height=\"1\" border=\"0\">";
		text += "</TD>";
	text += "</TR>";
	
	return text;
}

/* Functions */

/**
	addNavigationItem
	parameters:
 		type - navigation type (see NAVIGATION_XXXXXX constants)
		name - name of the navigation (will be shown in alt, title and <A> tags)
		url - url of the navigation (the real URL)

	Adds an navigation item to the global Array
	Called from the navigation "include" file.
*/
function addNavigationItem( type, name, url ) {

	// Are there any navigation items? Yes, check if we need a separator
	if( document.nrOfNavigationItems > 0 ) {
		/* Do we need a separator? If so, add one!
			A separator is added between after the Current Item and before an Related item
		*/
		if( ( document.navigationItems[document.nrOfNavigationItems-1].type == NAVIGATION_CURRENT && type == NAVIGATION_SECTION ) ||
			( document.navigationItems[document.nrOfNavigationItems-1].type == NAVIGATION_SECTION && type == NAVIGATION_RELATED ) ) {
			document.navigationItems[document.nrOfNavigationItems]=new navigationSeparatorItem(  );
			document.nrOfNavigationItems++;
		}
	}
	
	// First check what type navigation we have
	if ( type==NAVIGATION_BACK ) {
		document.navigationItems[document.nrOfNavigationItems]=new navigationBackItem( name, url );			
	} else if (type== NAVIGATION_CURRENT ) {
		document.navigationItems[document.nrOfNavigationItems]=new navigationCurrentItem( name, url );			
	} else if (type== NAVIGATION_SECTION ) {
		document.navigationItems[document.nrOfNavigationItems]=new navigationSectionItem( name, url );			
	} else if (type== NAVIGATION_RELATED ) {
		document.navigationItems[document.nrOfNavigationItems]=new navigationRelatedItem( name, url );			
	} else if (type== NAVIGATION_PAGEICON ) {
		document.navigationItems[document.nrOfNavigationItems]=new navigationPageIconItem( url );			
	} else { 
		alert( "Navigation error: Invalid navigation type!" );
	}

	/*switch( type ) { // This code doesn't work with Netscape!!!
		case NAVIGATION_BACK:
			document.navigationItems[document.nrOfNavigationItems]=new navigationBackItem( name, url );			
			break;
		case NAVIGATION_CURRENT:
			document.navigationItems[document.nrOfNavigationItems]=new navigationCurrentItem( name, url );			
			break;
		case NAVIGATION_SECTION:
			document.navigationItems[document.nrOfNavigationItems]=new navigationSectionItem( name, url );			
			break;
		case NAVIGATION_RELATED:
			document.navigationItems[document.nrOfNavigationItems]=new navigationRelatedItem( name, url );			
			break;
		case NAVIGATION_PAGEICON:
			document.navigationItems[document.nrOfNavigationItems]=new navigationPageIconItem( url );			
			break;
		default:
			alert( "Navigation error: Invalid navigation type!" );
	}*/
	
	document.nrOfNavigationItems++;
}

function addFooterNavigationItem( type, name, url ) {

  	// First check what type navigation we have
	if (type == NAVIGATION_BACK) {
		document.footerNavigationItems[document.nrOfFooterNavigationItems]=new navigationBackItem( name, url );
	}else if (type == NAVIGATION_FOOTER_ITEM) {
		document.footerNavigationItems[document.nrOfFooterNavigationItems]=new footerNavigationItem( name, url );
	}else{
		alert( "Navigation error: Invalid navigation type!" );
	}
	document.nrOfFooterNavigationItems++;
}

/**
	getNavigationHTML
	Returns the HTML of the complete navigation,
	Called from the main HTML file
*/
function getNavigationHTML( ) {
	var text = "";
	
	text += "<TABLE width=\"160\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
	for( var i = 0; i < document.nrOfNavigationItems; i++ ) {
		// each object in the 
		text += document.navigationItems[i].getHTML();
	}
	text += "</TABLE>";
	return text;
}

/**
	getFooterNavigationHTML
	Returns the HTML of the complete Footer navigation,
	Called from the main HTML file
*/
function getFooterNavigationHTML( ) {
	var text = "";
	
	text += "<TABLE width=\"160\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
	for( var i = 0; i < document.nrOfFooterNavigationItems; i++ ) {
		// each object in the 
		text += document.footerNavigationItems[i].getHTML();
	}
	text += "</TABLE>";
	return text;
}

/**
	getPathNameFromURL
	Checks the url, and returns the part after the server, so for
	'http://www.toshiba-europe.com/bv/computers/products/index.htm'
	it returns '/bv/computers/products/index.htm'
*/
function getPathNameFromURL( url ) {
	// Check if the URL starts with 'file:///' (length 8) or 'http://' (length 7)
	var tmpURL = new String( url );

	// Create new URL string, removing the 'file:///' or 'http://'
	if( tmpURL.indexOf( "http://" ) == 0) {
		tmpURL = tmpURL.substring( 7, tmpURL.length );
		// Now the pathname is the remainder of the string, after the next '/'
		var pathName = tmpURL.substring( tmpURL.indexOf('/'), tmpURL.length );
	} else if( tmpURL.indexOf( "file://" ) == 0 ) {
		// this part is probably not tested
		 tmpURL = tmpURL.substring( 9, tmpURL.length );
		var pathName = tmpURL.substring( tmpURL.indexOf('/'), tmpURL.length );
	} else {
		// assume it already starts with '/' or '../', so the pathname is the whole string
		var pathName = tmpURL;
	}
	return pathName;
}

