// This inst _needed_ as the included style-sheets are not req'd as all nesscary styles
// Are defined inline.
// However, it does keep the page looking a bit better ;))

// NOTE: Is 'MacOS' correct?

if( navigator.platform != "MacOS" )
{
  document.write("<link rel=\"stylesheet\" href=\"default.css\">");
}
else
{
  document.write("<link rel=\"stylesheet\" href=\"mac.css\">");
}

function TabApp_addTab(tab)
{
  var s = this.GetStyle( tab );
  this.tabs[ this.tabs.length ] = s;
}

function TabApp_initialize()
{
  this.SSD = this.GetObject( "SSD" );
  this.SSDStyle = this.GetStyle( "SSD" );
  this.x = this.GetPageX( this.SSD );
  this.y = this.GetPageY( this.SSD );
}

function TabApp_hideAll()
{
  for(var i=0;i<this.tabs.length;i++)
  {
    this.tabs[i].visibility = "hidden";
  }

  this.SSDStyle.visibility = "visible";
}

function TabApp_makeVisible(n)
{
  if(n<this.tabs.length)
  {
    this.SSDStyle.visibility = "hidden";
    this.SetObjectPosition( this.tabs[n], this.x, this.y );
    this.tabs[n].visibility = "visible"
  }
}

function TabApp_lastSlide()
{
  return this.tabs.length-1
}

function TabApp_jump(i)
{
  if( i < this.tabs.length )
  {
    this.hideAll()
    this.makeVisible( i )
  }
} 

function TabApp()
{
  this.x = 0
  this.y = 0
  
  this.tabs = new Array()
  this.addTab = TabApp_addTab
  this.initialize = TabApp_initialize
  this.hideAll = TabApp_hideAll
  this.makeVisible = TabApp_makeVisible
  this.lastSlide = TabApp_lastSlide
  this.jump = TabApp_jump

  // need this often.
  this.version = navigator.appVersion.split(' ')[0];

  // Set getter methods
  if( navigator.appName == "Netscape" )
  {
    if( this.version >= 5.0 )
    {
      this.GetObject = TabApp_Mozilla_GetObject;
      this.GetStyle = TabApp_Mozilla_GetStyle;
      this.GetPageX = TabApp_Mozilla_GetPageX;
      this.GetPageY = TabApp_Mozilla_GetPageY;
      this.SetObjectPosition = TabApp_Mozilla_SetObjectPosition;
    }
    else
    {
      this.GetObject = TabApp_Netscape_GetObject;
      this.GetStyle = TabApp_Netscape_GetStyle;
      this.GetPageX = TabApp_Netscape_GetPageX;
      this.GetPageY = TabApp_Netscape_GetPageY;
      this.SetObjectPosition = TabApp_Netscape_SetObjectPosition;
    }
  }
  else
  {
    // IE
    this.GetObject = TabApp_IE_GetObject;
    this.GetStyle = TabApp_IE_GetStyle;
    this.GetPageX = TabApp_IE_GetPageX;
    this.GetPageY = TabApp_IE_GetPageY;
    this.SetObjectPosition = TabApp_IE_SetObjectPosition;
  }
  
}

//
// Methods for getting objects in JS
//

//
// Netscape 4.x
//
function TabApp_Netscape_GetObject( name )
{
  return eval( 'document.' + name );
}

function TabApp_Netscape_GetStyle( name )
{
  return TabApp_Netscape_GetObject( name );
}

function TabApp_Netscape_GetPageX( obj )
{
  var x = 0;
  while( obj != window )
  {
    x += obj.pageX;
    obj = obj.parentLayer;
  }
  return x;
}

function TabApp_Netscape_GetPageY( obj )
{

  var y = 0;
  while( obj != window )
  {
    y += obj.pageY;
    obj = obj.parentLayer;
  }
  return y;
}

function TabApp_Netscape_SetObjectPosition(obj,x,y)
{
  obj.left = x;
  obj.top = y;
}
//
// Mozilla 
//
function TabApp_Mozilla_GetObject( name )
{
  return document.getElementById( name );
}

function TabApp_Mozilla_GetStyle( name )
{
  return document.getElementById( name ).style;
}

function TabApp_Mozilla_GetPageX( obj )
{
  var x = 0;
  while( obj != null )
  {
    x += obj.offsetLeft;
    obj = obj.offsetParent;
  }
  return x;
}

function TabApp_Mozilla_GetPageY( obj )
{
  var y = 0;
  while( obj != null )
  {
    y += obj.offsetTop;
    obj = obj.offsetParent;
  }
  return y;
}

function TabApp_Mozilla_SetObjectPosition(obj,x,y)
{
  obj.left = x;
  obj.top = y;
}
//
// IE 4.x +
//
function TabApp_IE_GetObject( name )
{
  return eval( 'document.all.' + name );
}

function TabApp_IE_GetStyle( name )
{
  return TabApp_IE_GetObject(name).style;
}

function TabApp_IE_GetPageX( obj )
{
  var x = 0;
  while( obj != null )
  {
    x += obj.offsetLeft;
    obj = obj.offsetParent;
  }
  return x;
}

function TabApp_IE_GetPageY( obj )
{
  var y = 0;
  while( obj != null )
  {
    y += obj.offsetTop;
    obj = obj.offsetParent;
  }
  return y;
}

function TabApp_IE_SetObjectPosition(obj,x,y)
{
  obj.posLeft = x;
  obj.posTop = y;
}

//
// Code for handling a window resize event
//
if(!window.saveInnerWidth)
{
  window.onresize = resize;
  window.saveInnerWidth = window.innerWidth;
  window.saveInnerHeight = window.innerHeight;
} 
    
function resize()
{
  if (saveInnerWidth < window.innerWidth ||
      saveInnerWidth > window.innerWidth ||
      saveInnerHeight > window.innerHeight ||
      saveInnerHeight < window.innerHeight )
  {
    window.history.go(0)
  }
  show.hideAll();
  show.makeVisible(show.current);
}
