/** fleet **/
function FleetNav()
{
    this.parts = new Array();
    this.navDiv = null;
    this.curIdx = -1;
    this.spanNext = null;
    this.spanPrev = null;
}

FleetNav.prototype.hidePart = function(part)
{
    part.style.position = "absolute";
    part.style.display = "none";   
}

FleetNav.prototype.showPart = function(part)
{
    part.style.position = "";
    part.style.display = "";
}

FleetNav.prototype.updateNav = function()
{
    if( this.curIdx <= 0 ) {
	this.spanPrev.innerHTML = "<img src=\"/layout/noprev.gif\" width=\"19\" height=\"19\" border=\"0\" />";
    } else {
	this.spanPrev.innerHTML = "<A href=\"javascript:fln.prev()\"><img src=\"/layout/btnprev.gif\" width=\"19\" height=\"19\" border=\"0\" /></A>";
    }

    if( (this.curIdx + 1) >= this.parts.length ) {
	this.spanNext.innerHTML = "<img src=\"/layout/nonext.gif\" width=\"19\" height=\"19\" border=\"0\" />";
    } else {
	this.spanNext.innerHTML = "<A href=\"javascript:fln.next()\"><img src=\"/layout/btnnext.gif\" width=\"19\" height=\"19\" border=\"0\" /></A>";
    }
}

FleetNav.prototype.addPart = function(part)
{
    this.parts[ this.parts.length ] = part;
}

FleetNav.prototype.start = function()
{
    this.navDiv = document.getElementById( "divFleetNav" );

    if( !this.navDiv ) return;

    var elements = document.getElementsByTagName( "table" );

    if( !elements ) return;

    for( var j = 0; j < elements.length; j ++ ) {
	if( elements[j].className !== undefined ) {
	    if( elements[j].className == "fleet" ) {
		this.addPart( elements[j] );
	    }
	} else if( elements[j].getAttribute !== undefined ) {
	    if( elements[j].getAttribute( "class" ) == "fleet" ) {
		this.addPart( elements[j] );
	    }
	}
    }

    if( this.parts.length > 0 ) {
	this.spanNext = document.createElement( "SPAN" );
	if( this.spanNext.className !== undefined )
	    this.spanNext.className = "right";
	else
	    this.spanNext.setAttribute( "class", "right" );

	this.spanNext = this.navDiv.insertBefore( this.spanNext,
						  this.parts[0] );


	this.spanPrev = document.createElement( "SPAN" );
	if( this.spanPrev.className !== undefined )
	    this.spanPrev.className = "left";
	else
	    this.spanPrev.setAttribute( "class", "left" );
	this.spanPrev = this.navDiv.insertBefore( this.spanPrev,
						  this.spanNext );

   }

    for( j = 0; j < this.parts.length; j ++ ) {
	if( j == 0 ) {
	    this.showPart( this.parts[j] );
	    this.curIdx = j;
	} else {
	    this.hidePart( this.parts[j] );
	}
    }

    this.updateNav();
}


FleetNav.prototype.next = function()
{
    if( (this.curIdx != -1) && (this.curIdx < this.parts.length) ) {
	this.hidePart( this.parts[this.curIdx] );
	this.curIdx ++;
	this.showPart( this.parts[this.curIdx] );
    }

    this.updateNav();
}

FleetNav.prototype.prev = function()
{
    if( (this.curIdx != -1) && (this.curIdx > 0) ) {
	this.hidePart( this.parts[this.curIdx] );
	this.curIdx --;
	this.showPart( this.parts[this.curIdx] );
    }
    this.updateNav();
}

