use("thing.mouse.local");

var tempfolders = location.pathname.toLowerCase().replace("index.htm", "").split("/");
var folders = new Array();
for( var i=1; i<tempfolders.length; i++ ){
	if( tempfolders[i] != '' ){
		folders[ folders.length ] = tempfolders[i];
	}
}
tempfolders = null;

/********************************************************************************

	Nav construction

********************************************************************************/
function Nav( name, title, parent, isBig, isUtilNav, url ){
	this.name = name;
	this.title = title;
	this.parent = parent;
	this.path = this.url;
	this.kids = new Array();
	this.tier = (this.parent) ? this.parent.tier + 1 : 0;
	this.isBig = isBig;
	this.isUtilNav = isUtilNav;
	this.url = url;
	this.path = this.url;
	this.isCurrent = (this.parent) ? this.parent.isCurrent && folders[this.tier] == this.name : true;

	if( this.parent ){
		if( this.parent.isCurrent ){
			if( folders[this.tier] == this.name ) this.isCurrent = true;
			else if( folders[this.tier] == null && this.name == '' ) this.isCurrent=true;
			else this.isCurrent = false;
		}
		else{
			this.isCurrent = false;
		}
	}
	else{
		this.isCurrent = true; // root
	}
	if( this.isCurrent ){
		Nav.currentNav = this;
		if( this.parent && ! Nav.currentT1 ){
			Nav.currentT1 = this;
		}
	}
}
Nav.currentNav = null;
Nav.currentT1 = null;
Nav.prototype.add = function( name, title, isBig, isUtilNav, url){

	return this.kids[ this.kids.length ] = new Nav( name, title, this, isBig, isUtilNav, url);
}

/********************************************************************************

	html writing

********************************************************************************/
Nav.globalNav = function(){
	var htmlDropdowns = '';

	for( var i=0; i<Nav.root.kids.length; i++ ){
		htmlDropdowns += Nav.root.kids[i].dropdown();
	}

	return htmlDropdowns;
}
Nav.prototype.dropdown = function(){
	if( ! this.isBig ) return '';
	var html = '<div id="navDrop' + this.name + 'Div" class="navDrop">\n';

	for( var i=0; i<this.kids.length; i++ ){
		html += this.kids[i].dropdownRow(i);
	}
	html += '</div>\n\n';
	return html;
}
Nav.prototype.dropdownRow = function(index){
	var cssClass = (index == 0) ? 'navDropRow0' : 'navDropRow';
	if( is.ns4 ){
		return '<div class="' + cssClass + '"><a href="' + this.path + '">' + this.title.replace(/\s/gi, '&nbsp;') + '</a></div>\n';
	}
	else{
		return '<div href="' + this.path + '" onclick="location.href=\'' + this.path + '\'" onmouseover="navDropOver(this)" onmouseout="navDropOut(this)" class="' + cssClass + '">' + this.title.replace(/\s/gi, '&nbsp;') + '</div>\n';
	}
}

function leftnavHTML(){
	var html = '';
	if( Nav.currentT1 ){
		html += '<table width="178" border="0" cellpadding="0" cellspacing="0">'
		+ Nav.currentT1.leftnav()
		+ '</table><img src="/maxtor/en_us/images/pixel.gif" width="1" height="40" border="0" alt=""><br>';
	}
	return html;
}

function utilnavHTML(){
	var html = '';
	html += '<table width="178" border="0" cellpadding="0" cellspacing="0">'
	+ Nav.currentNav.utilnav()
	+ '</table>';
	return html;
}

Nav.prototype.getLeftnavCssClass = function(){
	return ( this.isCurrent )
		? 'leftnavT' + this.tier + 'on'
		: 'leftnavT' + this.tier + 'off';
}
Nav.prototype.getLeftnavLineCssClass = function(i){
	return( (i==0 && this.tier == 3) 										// first of the tier 3's
		||	(this.tier == 2 && i>0  && this.parent.kids[i-1].isCurrent) ) 	// first of the tier 2's after the current
		? this.parent.getLeftnavCssClass() + 'Line'
		: this.getLeftnavCssClass() + 'Line';
}

Nav.prototype.leftnav = function(){
	var html = '';

	if( this.tier > 1 ){
		html += '<tr><td class="' + this.getLeftnavCssClass() + '" onclick="location.href=\'' + this.path + '\'">&nbsp;<a href="' + this.path + '">' + this.title + '</a></td></tr>';
	}

	if( this.isCurrent && this.tier < 3 ){
		for( var i=0; i<this.kids.length; i++ ){
			if( this.tier + i > 1 || this.isCurrent ){
				html += '<tr><td class="' + this.kids[i].getLeftnavLineCssClass(i) + '"><img src="/maxtor/en_us/images/dottedLine_178.gif" width="178" height="1" alt="-" border="0"></td></tr>';
			}
			html += this.kids[i].leftnav();

			//if last & current, draw the line
			if( this.kids[i].isCurrent && (this.kids.length -1 == i) ) html += '<tr><td class="leftnavT2onLine"><img src="/maxtor/en_us/images/dottedLine_178.gif" width="178" height="1" alt="-" border="0"></td></tr>';
		}
	}
	return html;
}

Nav.prototype.utilnav = function(){
	var tdClass = '';
	var html = '';
	var gotOne = false;

	for( var i=0; i<Nav.root.kids.length; i++ ){

		if( Nav.root.kids[i].isUtilNav ){

			//if you're the first util nav, write a white line
			if( Nav.root.kids[i].isCurrent && !gotOne  ) html += '<tr><td class="leftnavT2onLine"><img src="/maxtor/en_us/images/dottedLine_178.gif" width="178" height="1" alt="-" border="0"></td></tr>';

			tdClass = ( Nav.root.kids[i].isCurrent ) ? 'leftnavT2on' :	'leftnavT2off';

			//links
			html += '<tr><td class="' + tdClass + '" onclick="location.href=\'' + Nav.root.kids[i].path + '\'">&nbsp;<a href="' + Nav.root.kids[i].path + '">' + Nav.root.kids[i].title + ' </a></td></tr>';

			//draw a line if your aren't last or your are current
			if( i < Nav.root.kids.length-1 || Nav.root.kids[i].isCurrent ){
				// line is solid if you are current or next is current
				if( i < Nav.root.kids.length-1 && Nav.root.kids[i+1].isCurrent ) tdClass = 'leftnavT2on'
				html += '<tr><td class="' + tdClass + 'Line"><img src="/maxtor/en_us/images/dottedLine_178.gif" width="178" height="1" alt="-" border="0"></td></tr>';

			}
		gotOne = true;
		}
	}
	return html;
}


/********************************************************************************

	initialization

********************************************************************************/
Nav.init = function(){
	for( var i=0; i<Nav.root.kids.length; i++ ){
		Nav.root.kids[i].initT1();
	}
}
Nav.prototype.initT1 = function(){

	this.thing = Thing.all['nav' + this.name];
	if( ! this.thing ) return;

	this.thing.nav = this;

	if( this.isBig ){
		this.thing.captureMouseClick( thing_navMouseClick );
		this.thing.captureMouseMove( thing_navMouseMove );
		this.thing.captureMouseOut( thing_navMouseOut );
		this.dropThing = Thing.all['navDrop' + this.name];
		this.dropThing.moveTo( this.thing.position.add(0, 26) );
		this.dropThing.nav = this;
		this.dropThing.captureMouseMove(thing_navMouseMove);
		this.dropThing.captureMouseOut(thing_navMouseOut);
	}
	else{
		this.thing.captureMouseClick( thing_navSmallClick );
		this.thing.captureMouseMove( thing_navSmallMove );
		this.thing.captureMouseOut( thing_navSmallOut );
	}
	if( this.isCurrent ){
		this.thing.setBackground("#000000");
		if( !this.isBig ) this.thing.div.className = 'navT1smallon';
	}
}
init("Nav.init()");

/********************************************************************************

	mouse activity

********************************************************************************/
Nav.currDrop = null;
Nav.prototype.setCurr = function(){
	clearTimeout( this.hideTimeout );
	clearTimeout( this.showTimeout );
	if( Nav.currDrop && Nav.currDrop != this ){
		Nav.currDrop.thing.hideNav();
	}
	Nav.currDrop = this;
	this.showTimeout = setTimeout( this.dropThing.name + '.show()' , 100 );
	if( is.ns4 ) this.hideTimeout = setTimeout( this.dropThing.name + '.hide()', 1250 );
}
Thing.prototype.showNav = function(){
	this.setBackground("black");
	this.nav.dropThing.name.show();
}
Thing.prototype.hideNav = function(){
	if( ! this.nav.isCurrent ){
		//this.setBackground( "#002c84");
	}
	this.nav.dropThing.hide();
}

function thing_navMouseClick(p){
	location.href = this.nav.path;
	return false;
}
function thing_navMouseMove(p){
	this.nav.setCurr();
	if( this.name == "nav" + this.nav.name ){
		setStatusHref( this.nav.path );
	}
	return false;
}
function thing_navMouseOut(p){
	clearTimeout( this.nav.hideTimeout );
	clearTimeout( this.nav.showTimeout );
	this.nav.hideTimeout = setTimeout( this.nav.thing.name + '.hideNav()', 100 );
	return true;
}
function navMouseover(name){
	if( Thing.all[name] ){
		Thing.all[name].mouseMove();
	}
}




function thing_navSmallClick(p){
	location.href = this.nav.path;
}
function thing_navSmallMove(p){
	this.div.className = "navT1smallOn";
	mouseover( this.name + "Img" );
	setStatusHref(this.nav.path);
}
function thing_navSmallOut(p){
	this.div.className = "navT1small";
	mouseout( this.name + "Img" );
	setStatusHref('');
}





function navDropOver(who){
	setStatusHref(who.href);
	who.style.background = '#002c84';
}
function navDropOut(who){
	setStatusHref('');
	who.style.background = '#8AA8D8';
}



function setStatusHref(url){
	if( url != null && url != '' && url.indexOf("http://") != 0 ){
		url = 'http://' + location.hostname + url;
	}
	status = url;
}

