var relImgs=new Array();
var relCurrent=0;
function RelAddImage(Link,thmbLink,Title,Desc, Copy) {
  var img=new Object();
  img.Thumb=thmbLink;
  img.Large=Link;
  img.Title=Title;
  img.Desc=Desc;
  img.Copy=Copy;
  var i=relImgs.length;
  relImgs[i]=img
}
function ShowRelImage(i) {
   var id=document.getElementById('RelIcon');  
   if (i>=relImgs.length) {
    id=id.parentNode.parentNode.parentNode;
    id.style.display='none';
    return;
  }
 id.src=relImgs[i].Thumb;
  id.alt=relImgs[i].Title;
  var id=document.getElementById('relTitle');
  id.innerHTML=relImgs[i].Title;
}
function ShowRelNext(dr) {
  if (dr==0) {
//    relCurrent=Math.floor(Math.random()*relImgs.length);
      relCurrent=0;
  } else {
    relCurrent=(relImgs.length+relCurrent+dr) % relImgs.length;
  }
  ShowRelImage(relCurrent);
}
function ShowRelCurrent() {
  var i=relCurrent;
  LBoxShowPic(relImgs[i].Large, relImgs[i].Title, relImgs[i].Desc, relImgs[i].Copy, relImgs[i].Thumb);
}
function LBoxInit() {
   var divId;
   divId=document.createElement("div");
   LBoxAddAttr(divId, "id", "LBox");
   divId.innerHTML='<div id="LBoxContent" align="center"><div id="LBoxImageDiv"></div>' 
    + '<div id="LBoxTitle" class="LBox_Title"></div>'
    + '<div id="LBoxDesc" class="LBox_Desc"></div><div id="LBoxCopy" class="LBox_Copy"></div>'
    + '</div><div class="LBox_Close" onclick="LBoxClose();"></div>';
   var bdy=document.getElementsByTagName("body");
   bdy[0].appendChild(divId);  
 }

 function LBoxAddAttr(id, attr, vl) {
   var oattr
   oattr=document.createAttribute(attr);
   oattr.value=vl;
   id.attributes.setNamedItem(oattr);
 }
 function LBoxShowPic(img, ttl, desc, copy, altimg) {
   
   var id=document.getElementById('LBoxImageDiv'); 
    id.innerHTML='<img src="' + img + '" alt="' + ttl + '" id="LBoxImage" border="0" align="middle" style="margin-top:50px" '
     + ' onload="LBoxFitImage(this);" OnError="LBoxTryAlt(this, \'' + altimg + '\');"/>' 
  // LBoxShowText('LBoxTitle', ttl);
   LBoxShowText('LBoxDesc', desc);
   LBoxShowText('LBoxCopy', copy);
   id=document.getElementById('LBox');
   id.style.display='inline';
 }  


function LBoxTryAlt(id, img) {
  id.src=img;
}
 
 function LBoxFitImage(id) {
    var ht, maxWdth=1000;    
    if (id.width>maxWdth) {
      ht=id.height * maxWdth/id.width;    
      id.width=maxWdth;
      id.height=ht;
    }
 }

 function LBoxShowText(divID, txt) {
   var  id=document.getElementById(divID);
   if (txt=='') {
     id.style.display='none';
   } else {
     id.style.display='block';
     id.innerHTML=txt;
   }
 }
 function LBoxClose() {
   id=document.getElementById('LBox');
   id.style.display='none'; 
 }
