var NS4           = (document.layers)   ? 1 : 0;
var IE4           = (document.all)      ? 1 : 0;
var isOver        = false;
var timer         = null;
var cardList      = new Array();
var menuWList     = new Array();

var cssCard         = "card"         ;
var cssCardHdr      = "cardHdr"      ;
var cssCardHLink    = "cardHdrLink"  ;
var cssCardHTitle   = "cardHdrTitle" ;
var cssCardData     = "cardData"     ;
var cssCardDataText = "cardDataText" ;
var cssCardMore     = "cardMore"     ;
var cssCardPopHdr   = "cardPopHdr"   ;
var cssCardPopData  = "cardPopData"  ;

var hdrBGColor    = '#000099';

// NS4 redraw on resize
if (NS4)
{
// origWidth  = innerWidth;
// origHeight = innerHeight;
// onresize   = reDo;
}


//======================================================================
//
//   SUBROUTINES
//
//======================================================================

//----------------------------------------------------------------------
//   buildCard()
//----------------------------------------------------------------------
function buildCard(iKey,
                   iWidth,
                   iFacts,
                   iCard,
                   iHdrArray,
                   iFactsArray,
                   iCardArray)
{

   addToArray(iKey, cardList);
   menuWList[iKey] = iWidth;

   var htmlObj      = "";

       htmlObj     += "<div"                                     +
                      "  class=" + cssCard                       +
                      "  id=" + iKey                             +
                      "  onMouseOver=OverLayer();"               +
                      "  onMouseOut=OutLayer('" + iKey + "');"   +
                      "  >\n";

       htmlObj     += "  <table"                                 +
                      "    class=" + cssCardHdr                  +
                      "    id=" + "'table_" + iKey + "'"         +
                      "    tagName=" + "'table_" + iKey + "'"    +
                      "    cellspacing=0"                        +
                      "    cellpadding=0"                        +
                      "    border=0"                             +
                      "    width=" + iWidth                      +
                      "    >\n";

// Begin of Header Portion of the card
      htmlObj      += "    <tr>\n";
      htmlObj      += "      <td>\n";

// Add Header Links Line
      htmlObj      += "        <div class=" + cssCardHLink + ">";
      htmlObj      += "          &nbsp\;";

      for ( j = 0 ; j < iHdrArray.length ; j++ )
      {
         htmlObj   += aCP_ObjBuild(cssCardPopHdr, iHdrArray[j][0], iHdrArray[j][1] ) + "\n";
         if ( j < iHdrArray.length-1) htmlObj += " &#183\; \n";
      }

      htmlObj      += "        </div>";


// Add Fast Facts Title
      htmlObj      += "        <div class=" + cssCardHTitle + ">";
      htmlObj      += "          &nbsp\;";
      htmlObj      +=            iFacts + "\n";
      htmlObj      += "          &nbsp\;";
      htmlObj      += "        </div>";


// Add Facts Links Line
      htmlObj      += "        <div class=" + cssCardHLink + ">";
      htmlObj      += "          &nbsp\;";

      for ( j = 0 ; j < iFactsArray.length ; j++ )
      {
         htmlObj   += aCP_ObjBuild(cssCardPopHdr, iFactsArray[j][0], iFactsArray[j][1] ) + "\n";
         if ( j < iFactsArray.length-1) htmlObj += " &#183\; \n";
      }

      htmlObj      += "        </div>";

      htmlObj      += "      </td>\n";
      htmlObj      += "    </tr>\n";
      htmlObj      += "  </table>\n";
// End of Header Portion of the card

// Add Text lines
      htmlObj      += "  <div class=" + cssCardData + ">";
      htmlObj      += "    &nbsp\;";
      htmlObj      +=      iCard + "<br>\n"
      htmlObj      += "    <font class=" + cssCardDataText + ">\n";

      for ( j = 0 ; j < iCardArray.length ; j++ )
      {
         htmlObj   += "    &nbsp\;&#183\;&nbsp\;";
         htmlObj   +=      aCP_ObjBuild('', iCardArray[j][0], iCardArray[j][1] ) ;
         htmlObj   += "    <br>\n";
      }

      htmlObj      += "    </font>";
      htmlObj      += "    <br>";
      htmlObj      += "  </div>";

      htmlObj      += "</div>";


/*
      alert("Before--->" + htmlObj);
      alert("host "     + location.host       + "\n" +
            "hostname " + location.hostname   + "\n" +
            "hash "     + location.hash       + "\n" +
            "pathname " + location.pathname   + "\n" +
            "port "     + location.port       + "\n" +
            "protocol " + location.protocol   + "\n" +
            "search "   + location.search     + "\n" +
            "href "     + location.href       + "\n"
           );
      alert("After--->" + htmlObj);
*/

      document.write(htmlObj);
}


//----------------------------------------------------------------------
//   BuildMore()
//----------------------------------------------------------------------
function buildMore(iKey,
                   iWidth,
                   iCardArray)
{
   addToArray(iKey, cardList);
   menuWList[iKey] = iWidth;

   var htmlObj   = "";

       htmlObj  += "<div"                                     +
                   "  class=" + cssCardMore                   +
                   "  id=" + iKey                             +
                   "  width=" + iWidth +
                   "  onMouseOver=OverLayer();"               +
                   "  onMouseOut=OutLayer('" + iKey   + "');" +
                   "  >\n";

       htmlObj  += "  <table"            +
                   "    id=" + "'table_" + iKey + "'"         +
                   "    cellspacing=0"   +
                   "    cellpadding=0"   +
                   "    border=0"        +
                   "    width=" + iWidth +
                   "    >\n"             +
                   "    <tr>"            +
                   "      <td>"          +
                   "      </td>"         +
                   "    </tr>"           +
                   "  </table>";

   for ( j = 0 ; j < iCardArray.length ; j++ )
   {
       htmlObj  += "  &nbsp\;";
       htmlObj  += "  <font color=White>&#183\;</font>";
       htmlObj  +=    aCP_ObjBuild(cssCardPopData, iCardArray[j][0], iCardArray[j][1] ) ;
       htmlObj  += "  <br>\n";
   }
       htmlObj  += "  <br>";
       htmlObj  += "</div>";

   document.write(htmlObj);

}

//----------------------------------------------------------------------
//   Build (A Object
//----------------------------------------------------------------------
function aCP_ObjBuild(iClass, iHref, iText )
{

   htmlaObj = "";

   if (iHref != "*" && iHref != "")
   {
      htmlaObj += "<a";

      if (iClass != "*" && iClass != "")
      {
         htmlaObj += " class='" + iClass + "'";
      }

      htmlaObj += " href='" + iHref + "'" ;
      htmlaObj += ">"                     ;
      htmlaObj += iText                   ;
      htmlaObj += "</a>"                  ;
   }
   else
   {
      htmlaObj  = iText ;
   }

   if (htmlaObj.indexOf("@hostname") >= 0)
   {
      htmlaObj = htmlaObj.replace("@hostname", location.protocol + "//" + location.hostname);
   }

   if (htmlaObj.indexOf("@httpshostname") >= 0)
   {
      htmlaObj = htmlaObj.replace("@hostname", "https://" + location.hostname);
   }

   return htmlaObj ;
}


//----------------------------------------------------------------------
//   ShowLayer(layer_name, event, offset_X, offset_Y)
//----------------------------------------------------------------------
function ShowLayer(showEl, event, iRAX, offX, iRAY, offY)
{
   clearTimeout(timer);
   HideAllLayers();
   var tableId        = "table_" + showEl;

   var whichTable     = (NS4) ? document.layers[showEl]    : document.all[tableId]      ;

   var whichEl        = (NS4) ? document.layers[showEl]    : document.all[showEl].style ;
   var eventLocX      = (NS4) ? event.pageX                : event.x                    ;
   var eventLocY      = (NS4) ? event.pageY                : event.y                    ;
   var screenWidth    = (NS4) ? document.width             : document.body.scrollWidth  ;
   var screenHeight   = (NS4) ? document.height            : document.body.scrollHeight ;
   var scrollTop      = (NS4) ? 0                          : document.body.scrollTop    ;
   var menuWidth      = menuWList[showEl] ;


   switch (iRAX)
   {
      case "A":
         popLocX   = offX;
         break;

      case "*":
         popLocX   = ( eventLocX - Math.round( menuWidth / 2 ));
         break;

      default:
         popLocX   = (eventLocX + offX);
         break;
   }

   switch (iRAY)
   {
      case "A":
         popLocY   = offY;
         break;

      case "*":
         popLocY   = offY;
         break;

      default:
         popLocY   = (eventLocY + offY + scrollTop);
         break;
   }

   if ((popLocX + menuWidth) > screenWidth) { popLocX = (screenWidth - menuWidth-10); }
   if (popLocX < 0){ popLocX = 5; }

/*

 alert("Layer="        + showEl       + "\n" +
       "LocX="         + eventLocX    + "\n" +
       "LocY="         + eventLocY    + "\n" +
       "screenWidth="  + screenWidth  + "\n" +
       "screenHeight=" + screenHeight + "\n" +
       "scrollTop="    + scrollTop    + "\n" +
       "menuWidth="    + menuWidth    + "\n" +
       "offX="         + offX         + "\n" +
       "offY="         + offY         + "\n" +
       "popLocX="      + popLocX      + "\n" +
       "popLocY="      + popLocY      + "\n" +
       " ");
*/

   whichEl.top        = popLocY;
   whichEl.left       = popLocX;
   whichEl.visibility = "visible";
}


//----------------------------------------------------------------------
//   HideAllLayers()
//----------------------------------------------------------------------
function HideAllLayers()
{
   for (i = 0; i < cardList.length; i++)
   {
      whichEl = cardList[i];
      var whichEl = (NS4) ? document.layers[whichEl] : document.all[whichEl].style;
      if (!isOver) whichEl.visibility = "hidden";
   }
}

//----------------------------------------------------------------------
//   OverLayer()
//----------------------------------------------------------------------
function OverLayer()
{
   clearTimeout(timer);
   isOver = true;
}

//----------------------------------------------------------------------
//   OutLayer()
//----------------------------------------------------------------------
function OutLayer()
{
        clearTimeout(timer);
        isOver = false;
        timer  = setTimeout("HideAllLayers()",300);
}

//----------------------------------------------------------------------
//   reDo()
//----------------------------------------------------------------------
function reDo()
{
   if (innerWidth != origWidth || innerHeight != origHeight)
   {
      location.reload();
   }
}

//----------------------------------------------------------------------
//   setupLayers()
//----------------------------------------------------------------------
function setupLayers()
{
   for (i = 0; i < cardList.length; i++)
   {
      whichEl = cardList[i];
      var whichEl         = (NS4) ? document.layers[whichEl] : document.all[whichEl].style;
      whichEl.onmouseover = OverLayer;
      whichEl.onmouseout  = OutLayer;
   }
}

//======================================================================
//
//  Add value to array
//
//  AddToArray ( value, array )
//
//======================================================================
function addToArray(iValue,iArray)
{
  n = iArray.length;
  iArray[n] = iValue;

}

