/*
<rde-dm:attribute mode="write" attribute="request:rdeResponseMimetype" op="set" value="text/javascript"/>
  Firma        : RedDot Solutions AG
  Erstellt von : Rafael J. Staib
  Erstellt am  : 26 Okt. 2005
  Projekt      : Up-And-Away 2
*/

/* Global Vars */
/* Browser check */
var _DOM = false, _All = false, _NS4 = false, _NS6 = false, _NS7 = false, _OP = false, _IE4 = false, 
    _IE5 = false, _IE6 = false, _OtherBrowser = false, _Mac = false, _Win = false, _OS2 = false, _FFox = false;

/* Image preloader */
var _preload = [];


/* Browser check */
function BrowserCheck()
{
  var navAgent = navigator.userAgent.toLowerCase();
  var appVer = navigator.appVersion.toLowerCase();
  var versMinor = parseFloat( appVer );
  var versMajor = parseInt( versMinor );
  _Mac = ( navAgent.indexOf( 'mac' ) != -1 );
  _Win = ( ( navAgent.indexOf( 'win' ) != -1 ) || ( navAgent.indexOf( '16bit' ) != -1 ) );
  _OS2 = ( navigator.platform == 'OS/2' ) ? true : false;
  _All = ( document.all ) ? true : false;
  _DOM = ( document.getElementById ) ? true : false;
  _OP = ( window.opera ) ? true : false;
  var iePos = appVer.indexOf( 'msie' );

  if ( iePos != -1 )
  {
    versMinor = parseFloat( appVer.substring( iePos + 5, appVer.indexOf( ';', iePos ) ) );
    versMajor = parseInt( versMinor );
  }

  nav6Pos = navAgent.indexOf( 'netscape6' );
  nav7Pos = navAgent.indexOf( 'netscape/7' );

  if ( nav6Pos != -1 )
  {
    versMinor = parseFloat( navAgent.substring( nav6Pos + 10 ) );
    versMajor = parseInt( versMinor );
  }

  var netsc = ( ( navAgent.indexOf( 'mozilla' ) != -1 ) && ( navAgent.indexOf( 'spoofer' ) == -1 ) 
              && ( navAgent.indexOf( 'compatible' ) == -1 ) && ( navAgent.indexOf( 'opera' ) == -1 ) 
              && ( navAgent.indexOf( 'webtv' ) == -1 ) );
  _NS4 = ( document.layers ) ? true : false;
  _NS6 = ( netsc&&versMajor == 6 );
  _NS7 = ( netsc );
  var msie = ( iePos != -1 );
  _IE4 = ( msie && versMajor == 4 );
  _IE5 = ( msie && versMajor == 5 );
  _IE6 = ( msie && versMajor == 6 );
  _OtherBrowser = ( !_NS4 && !_NS6 && !_OP && !_IE4 && !_IE5 && !_IE6 );
}

BrowserCheck();


/* Image preloader */
function Preload( id )
{
  this.Id = id || null;
  _preload[_preload.length] = this;
  if ( this.Id != null ) _preload[this.Id] = this;
  this.Images = [];
}

Preload.prototype.AddImage = function ( id, imgSource )
{
  var image = new Image();
  image.id  = id; image.src = imgSource;
  this.Images[this.Images.length] = image;
  this.Images[id] = image;
};

Preload.prototype.IsExist = function ( id )
{
  for ( var i = 0; i < this.Images.length; i++ )
    if ( id == this.Images[i].id ) return true;
  return false;
};


/* Banner */
function banner( obj, id )
{
  if ( !obj ) return;

  this.Obj = ( typeof ( obj ) != 'string' ) ? obj : document.getElementById( obj );
  this.Id = id.replace( /\s*/, '' ) || 'Default';

  if ( !_preload['Banner'].IsExist( this.Id ) ) this.Id = 'Default';

  this.Obj.src = _preload['Banner'].Images[this.Id].src;
}


/* Menu */
function menu( obj, id )
{
  if ( !obj ) return;

  this.Obj = ( typeof ( obj ) != 'string' ) ? obj : document.getElementById( obj );
  this.Id = id.replace( /\s*/, '' ) || 'Default';

  if ( !_preload['MenuBg'].IsExist( this.Id ) ) this.Id = 'Default';

  this.Obj.style.backgroundImage = 'url(' + _preload['MenuBg'].Images[this.Id].src + ')';
  this.Obj.style.backgroundRepeat =  'no-repeat';
}


/* Swap links */
function swapLink( obj, type, id )
{
  if ( !obj ) return;

  this.Obj = ( typeof ( obj ) != 'string' ) ? obj : document.getElementById( obj );
  this.Type = type || 0;
  this.Id = id.replace( /\s*/, '' ) || 'Default';

  if ( !_preload['Menu'].IsExist( this.Id ) )
    if ( this.Id.indexOf( 'Active' ) != -1 )
      this.Id = 'DefaultActive';
    else this.Id = 'Default';

  switch ( this.Type )
  {
    case 0: // Image-Tag
      this.Obj.parentNode.src = _preload['Menu'].Images[this.Id].src;
      break;
    case 1: // Li-Tag (CSS)
      this.Obj.parentNode.style.backgroundImage = 'url(' + _preload['Menu'].Images[this.Id].src + ')';
      this.Obj.parentNode.style.backgroundRepeat =  'no-repeat';
      break;
  }
}

/* Swap image by Id or Object (this) */
function swapImageById( id, imageSource )
{
  if ( !id || !imageSource ) return;
  this.Obj = ( typeof ( id ) != 'string' ) ? id : document.getElementById( id );
  this.Obj.src = imageSource;
}