var step = 0, sSize = 4;
var run = true;
var stID = null;
var stSec = 1;

function fpOnload() {
  setFPTimeout(stSec);
}

window.onload = fpOnload;

function setFPTimeout(sec) {
  if (!run) return;
  
  if (stID != null) clearTimeout(stID);
  stID = setTimeout('fpTimeout()', (sec * 1000));
}

function fpTimeout() {
  if (!run) return;
  
  //setBorderColor(startID, '#C0C0C0');
  clearBorderColor();
  startID++;
  startID = startID % fpItems.length;
  changeImg(startID);
  
  
  setFPTimeout(stSec);
}

function fpMouseOver(id) {
  run = false;
  
  //setBorderColor(startID, '#C0C0C0');
  //setBorderColor(entryID, '#C0C0C0');
  clearBorderColor();
  entryID = id;
  changeImg(entryID);
}

function fpMouseOut(id) {
  run = true;
  setFPTimeout(stSec);
}

function fpMouseOver2() {
  run = false;
}

function fpMouseOut2() {
  fpMouseOut(0);
}

function changeImg(imgID) {
  var _bImg00  = document.getElementById('bImg00');
  var _pName00 = document.getElementById('pName00');
  var _url00   = document.getElementById('url00');
  
  //var re1 = /icons/ig;
  //var re2 = /\.gif/ig;
  //var re3 = /-pi/ig;
  var img = fpItems[imgID].i;
  //var img = img.replace(re1, 'photos');
  //var img = img.replace(re2, '.jpg');
  //var img = img.replace(re3, '-ps');
  _bImg00.src = img;
  _bImg00.title = fpItems[imgID].t;
  
  _pName00.innerHTML = fpItems[imgID].t;
  _pName00.title = fpItems[imgID].t;
  
  _url00.href = 'http://' + fpItems[imgID].u + '.' + d + fpItems[imgID].v;
  
  setBorderColor(imgID, '#ff0000');
}

function clearBorderColor() {
  var _fpList  = document.getElementById('fpList');
  
  for (var r=0; r<_fpList.rows.length; r++) {
    var row  = _fpList.rows[r];
    for (var c=0; c<row.cells.length; c++) {
      var cell = row.cells[c];
      cell.firstChild.rows[0].cells[0].firstChild.style.borderColor = '#C0C0C0';
      cell.firstChild.rows[0].cells[0].firstChild.style.borderWidth = 1;
    }
  }
}

function setBorderColor(id, color) {
  var _fpList  = document.getElementById('fpList');
  
  var rIndex = Math.floor(id / 4);
  var cIndex = id % 4;
  var row  = _fpList.rows[rIndex];
  var cell = row.cells[cIndex];
  cell.firstChild.rows[0].cells[0].firstChild.style.borderColor = color;
  cell.firstChild.rows[0].cells[0].firstChild.style.borderWidth = 2;
}

function showFPList() {
  for (var i=0; i<fpItems.length; i++) {
    var icon  = 'http://' + d + fpItems[i].i;
    var title = fpItems[i].t;
    var url   = 'http://' + fpItems[i].u + '.' + d + fpItems[i].v;
    
    if ((i % sSize) == 0) document.write("<tr>");
    
    document.write(
      "<td width='10%' align='center' valign='top'>" +
      "<table border='0' cellpadding='0' cellspacing='0'width='100%'>" +
      "<tr><td width='100%' align='center' valign='top'><table border='1' cellpadding='0' cellspacing='0'" +
      " style='border-collapse: collapse' bordercolor='#C0C0C0' width='60' height='60'>" +
      "<tr><td width='100%' valign='top'><a href='" + url + "' target='_blank' title='" + title + "'" +
      " onmouseover='fpMouseOver(" + i + ")' onmouseout='fpMouseOut(" + i + ")'" +
      "><img src='" + icon + "' border='0' width='60' height='60'></a></td></tr>" +
      "</table>" +
      "</td></tr>" +
      "</table>" +
      "</td>"
    );
    
    if ((i % sSize) == (sSize - 1)) document.write("</tr>");
  }
}

function showCatList() {
  for (var i=0; i<clItems.length; i++) {
    if ((i % 2) == 0) document.write("<tr>");
    
    document.write("<td class='cat1' width='50%' valign='top'>" +
      "<a class='cat1' href='" + catList.p + clItems[i].o + ",,' " +
      "onmouseover='window.status=\"" + clItems[i].t + "\"; return true;'>" + clItems[i].t + "</a>" +
      "(" + clItems[i].c + ")</td>");
 
    if ((i % 2) == 1) document.write("</tr>");
  }
}

function showSampleList() {
  for (var i=0; i<ssItems.length; i++) {
    if ((i % 5) == 0) document.write("<tr>");
    
    document.write("<td width='20%' align='center' valign='top'><table border='0' cellpadding='0' cellspacing='1' " +
      "style='border-collapse: collapse' bordercolor='#111111' width='80%'><tr><td width='100%' align='center' " +
      "valign='top'><table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse' " +
      "bordercolor='#C0C0C0' width='80' height='80'><tr><td width='100%' valign='top'>" +
      
      "<a href='" + ssList.p1 + ssList.p3 + ssItems[i].s + "' target='_blank' title='" + ssItems[i].t + "'>" +
      "<img src='" + ssList.p1 + ssList.p2 + ssItems[i].i + "' border='0' width='80' height='80'></a></td></tr>" +
      
      "</table></td></tr></table></td>");

    if ((i % 5) == 4) document.write("</tr>");
  }
}

function showNTLList() {
  for (var i=0; i<ntlItems.length; i++) {
    document.write("<tr><td nowrap width='100%'><div style='width:450px;overflow:hidden;'><a class='p2' " +
      "href='http://" + ntlItems[i].u + ntlList.d + ntlList.p + ntlItems[i].p + '&v=' + ntlItems[i].v + 
      "' target='_blank' title='" + ntlItems[i].t + "'>" + ((ntlItems[i].p=='s')?ntlList.s:ntlList.b) + 
      "<font class='font9'>" + ntlItems[i].c + "</font>&nbsp;" + ntlItems[i].t + "</a></div></td></tr>");
     
  }
}
