if (typeof gebi == "undefined" || !gebi) {var gebi = function(pName){return document.getElementById(pName);}}
if (typeof KBSCRIPT == "undefined" || !KBSCRIPT) {var KBSCRIPT = {};}
if (typeof KBSCRIPT.script == "undefined" || !KBSCRIPT.script) {KBSCRIPT.script = {};}

(function () {
  KBSCRIPT.script.PhotoDisplay = function (oElement, oAttributes) {
		if (typeof oAttributes == "undefined" || !oAttributes){
			oAttributes = oElement;
			oElement = document.createElement('DIV');
			document.body.appendChild(oElement);
		}
    oElement.className="kb-photodisplay";

    var elTable = document.createElement('TABLE');
    elTable.className="kb-photodisplay-table";
    oElement.appendChild(elTable);


    if (!arrData){
      alert('Error no data is supplied');
    }
    else
    {
      var columnIndex = 0;
      var columnMax = 5;
      var rowIndex = 0;
      for (var i in arrData){
        oRow = arrData[i];

        // Begining of row
        if (columnIndex % columnMax == 0){
          var elRow = elTable.insertRow(rowIndex);
        }

        // Cells
        var elCell = elRow.insertCell(columnIndex);
        // Cell Content
        //Photo, Name, Url
        elPhoto = document.createElement('IMG');
        elPhoto.src=oRow.photo;
        elPhoto.className="kb-photo";
        elText = document.createElement('SPAN');
        elText.href=oRow.url;
        elText.className="kb-text";
        elText.innerHTML=oRow.name;
        elText.style.display='block';
        elCell.appendChild(elPhoto);
        elCell.appendChild(elText);

        columnIndex++;
        // End of Row
        if (columnIndex % columnMax == 0){
          rowIndex++;
          columnIndex=0;
        }
      }
    }
  }
})();
