/**
* @author André Dietisheim (dietisheim@sphere.ch)
* @version 1.0, 2005-06-05 (created on 2005-05-07)
* Copyright (c) 2001-2005 André Dietisheim
*/

function CompatibleXlayer( sParent, xlayerParent, x, y, offsetX, offsetY, w, h,  iClipTop, iClipRight, iClipBottom, iClipLeft, iZindex, bVisibility, sBgcolor, fading, events, src, sSpacerUrl, sText, bBold, sAlign, iTopTextBorder, iRightTextBorder, iBottomTextBorder, iLeftTextBorder, sFgcolor, sHref, sFontface, iFontsize, sIcon, iIconWidth, iIconHeight, iIconBorder )
{
  this.Xlayer( sParent, xlayerParent, x, y, offsetX, offsetY, w, h,  iClipTop, iClipRight, iClipBottom, iClipLeft, iZindex, bVisibility, sBgcolor, fading, events, src );

  this.sCaptionId = "CompatibleXlayerCaption" + this.id;
  this.sText = sText;
  this.bBold = bBold;
  this.sAlign = sAlign;
  this.iTopTextBorder = iTopTextBorder;
  this.iRightTextBorder = iRightTextBorder;
  this.iBottomTextBorder = iBottomTextBorder;
  this.iLeftTextBorder = iLeftTextBorder;
  this.sFgcolor = sFgcolor;
  this.sHref = ( is.nn4up )? "#" : null; // nn4 always need a href to process clicks
  this.sFontface = sFontface;
  this.iFontsize = iFontsize;
  this.sIcon = sIcon;
  this.iIconWidth = iIconWidth;
  this.iIconHeight = iIconHeight;
  this.iIconBorder = iIconBorder;
  this.sSpacerUrl = sSpacerUrl; 
}

CompatibleXlayer.prototype = new Xlayer;
CompatibleXlayer.prototype.Xlayer = Xlayer;

CompatibleXlayer.prototype.setFgColor = function( color )
{
  if ( this.sText )
  {
    this.sFgcolor = color;

    if ( is.nn4up )
      this.setBody( this.getCaption() );
    else if ( is.iewin5up || is.iemac5up || is.gk || is.sf  || is.kq3up || is.op6up )
      document.getElementById( this.sCaptionId ).style.color = color;
  }
}

CompatibleXlayer.prototype.getCaption = function()
{ 
  var tab_head = '<table style="table-layout:fixed;' + ( ( is.iewin5up )? 'cursor: hand;' : 'cursor: pointer;" ' ) + 'width="' + this.w + '" height="' + this.h + '" border="0" cellpadding="0" cellspacing="0">';
  var tab_foot = '</table>';

  if ( this.sText || this.sIcon )
  {
    // content ---
    var img = "", desc = "", html ="", tab_body = "", sTextCell = "";
    if ( this.sIcon )
      img = '<img src="' + this.sIcon + '" width="' + this.iIconWidth + '" height="' + this.iIconHeight + '">';
    if ( this.sText )
    {       
      if ( is.nn4up )
        sTextCell = '<font id="' + this.sCaptionId + '" color="' + this.sFgcolor + '" size="' + ( parseInt( "0" + ( this.iFontsize / 5 ), 10 ) ) + '" face="' + this.sFontface + '">' + ( ( this.bBold )? '<b>' : '' ) + this.sText + ( ( this.bBold )? '</b>' : '' ) + '</font>';
      else if ( is.iewin5up || is.gk || is.sf || is.kq3up || is.iemac5up || is.op6up )
        sTextCell = '<span id="' + this.sCaptionId + '" style="' + 'color:' + this.sFgcolor + ';' + 'font-size:' + this.iFontsize + 'px;' + 'font-family:' + this.sFontface + ';' + ( ( this.bBold )? ' font-weight:bold;' : '' ) + 'height:' +  this.iFontsize + 'px">' + this.sText + '</span>';
    }
    if (  this.sHref && is.nn4up ) // nn4 always needs a <a href...
      sTextCell = "<a href='" +  this.sHref + "' style='text-decoration: none;'>" + sTextCell + "</a>";

    // text cell -----
    var iTextCellWidth = this.w - this.iIconWidth - this.iIconBorder;
    var iTextCellHeight = this.h - this.iTopTextBorder - this.iBottomTextBorder;
    desc += '<table width="' + iTextCellWidth + '" height="' + this.h + '" cellpadding="0" cellspacing="0" border="0">';
    // top text border
    if ( this.iTopTextBorder > 0 )
    {
      desc += '<tr style="line-height: ' +  this.iTopTextBorder + 'px"><td';
      if ( is.iemac5 )
        desc += ' style ="position: absolute; top:0px; left:0px" ';
      desc += 'colspan="3" height="' + this.iTopTextBorder + '"><img src="' + this.sSpacerUrl + '" width="1" height="' + this.iTopTextBorder + '" border="0"></td></tr>';
    }
    // left border
    if ( this.iLeftTextBorder > 0 )
    {
      desc += '<td width="' + this.iLeftTextBorder + '';
      if ( is.iemac5 )
        desc += ' style ="position: absolute; top:' + ( ( this.h - iTextCellHeight ) / 2 + this.iTopTextBorder ) + 'px; left:0px" ';
      desc += '><img src="' + this.sSpacerUrl + '" width="' + this.iLeftTextBorder + '" height="1" border="0"></td>';
    }
    // text cell
    desc += '<td width="' + ( iTextCellWidth - this.iLeftTextBorder - this.iRightTextBorder ) + '" height="' + iTextCellHeight + '" valign="middle" align="' + this.sAlign + '"';
    if ( is.iemac5 )
      desc += ' style ="position: absolute; top:' + ( ( this.h - iTextCellHeight ) / 2 + this.iTopTextBorder ) + 'px; left:' + ( this.iLeftTextBorder ) + 'px"';
    desc += '>' + sTextCell + '</td>';
    // right border
    if ( this.iRightTextBorder > 0 )
    {
      desc += '<td width="' + this.iRightTextBorder + '"';
      if ( is.iemac5 )
        desc += ' style ="position: absolute; top:' + ( ( this.h - iTextCellHeight ) / 2 + iTopTextBorder ) + 'px; left:' + ( iTextCellWidth - this.iRightTextBorder ) + 'px"';
      desc += '><img src="' + this.sSpacerUrl + '" width="' + this.iRightTextBorder + '" height="1" border="0"></td>';
    }
    desc += '</tr>';
    // bottom text border
    if ( this.iBottomTextBorder > 0 )
    {
      desc += '<tr style="line-height: ' + this.iBottomTextBorder + 'px';
      if ( is.iemac5 )
        desc += ';position: absolute; top:' + ( this.h - this.iBottomTextBorder ) + 'px; left:0px';
      desc +='"><td colspan="3" height="' + this.iBottomTextBorder + '"><img src="' + this.sSpacerUrl + '" width="1" height="' + this.iBottomTextBorder + '" border="0"></td></tr>';
    }
    desc += '</table>';

    // text & icons ---
    if ( this.sText && this.sIcon || ( is.iemac5 && sText && !this.sIcon ) )
    {
      if ( ( is.iemac5 && sText && !sIcon ) )
      { // ie mac 5.0 renders cells only if there are 2 td's
        this.iIconWidth = 1; this.iIconHeight = 1; this.iIconBorder = 1; img = '<img src="' + this.sSpacerUrl + '" width="' + ( this.iIconWidth + this.iIconBorder ) + '" height="' + this.h + '" border="0">';
      }
      tab_body =
        '<tr>' +
          '<td nowrap ';
      if ( is.iemac5 )
      {
        tab_body += 'style="position: absolute; top: 0px; height: ' + this.iFontsize + 'px; width: ' + ( this.w - this.iIconWidth - this.iIconBorder ) + 'px; vertical-align: middle;" ';
      }
      tab_body +=
            'width="' + ( this.w - this.iIconWidth  - this.iIconBorder ) + '" height="' + this.h + '" align="' + this.sAlign + '" valign="middle">' +
            desc +
          '</td>' +
          '<td ';
      if ( is.iemac5 )
      {
        tab_body += 'style="position: absolute; top: ' + ( ( this.h - iIconHeight ) / 2 ) + 'px; left: ' + ( this.w - iIconWidth - iIconBorder ) + 'px; bottom: ' + iIconHeight + 'px; right:' + ( iIconWidth + iIconBorder ) + 'px;height: ' + iIconHeight + 'px; width: ' + ( iIconWidth + iIconBorder ) + 'px" ';
      }
      tab_body +=
          'width="' + ( this.iIconWidth + this.iIconBorder ) + '" height="' + this.h + '" align="center" valign="middle">' +
            img +
          '</td>' +
        '</tr>';
    }
    // text only ---
    else if ( this.sText && !this.sIcon )
    {
      tab_body =
        '<tr>' +
          '<td nowrap width="' + this.w + '" height="' + this.h + '" align="' + this.sAlign + '" valign="middle">' +
            desc +
          '</td>' +
        '</tr>';
    }
    // icon only ---
    else if ( this.sIcon && !this.sText )
    {
      tab_body = '<tr><td nowrap ';
      if ( is.iemac5 )
      {
        tab_body += 'style="position:absolute;top:0px;left:0px" ';
      }
      tab_body += 'width="' + this.w + '" height="' + this.h + '" align="' + this.sAlign + '" valign="middle">' + this.sIcon + '</td></tr>';
    }
    var html = tab_head + tab_body + tab_foot;
    return html;
  }
}
