m_root = "";
m_colcount = "";


function CreateGallery(root, colcount)
{
     m_root = root;
     m_colcount = colcount;

     var response = null;
     var url = "./gallery/" + root + "/gallery.xml";

     // code for IE
     if (window.ActiveXObject)
     {
          gal_req = new ActiveXObject("Microsoft.XMLDOM");
          gal_req.async = false;
          gal_req.load(url);
          gal_parseXML(gal_req);
     }
     // code for Mozilla, Firefox, Opera, etc.
     else if (document.implementation && document.implementation.createDocument)
     {
          gal_req = new XMLHttpRequest();
          gal_req.onreadystatechange = gal_proReqChange;
          gal_req.open("GET", url, true);
          gal_req.send("");
     }
     else
     {
          alert("Your browser cannot handle this script");
     }
}


function gal_proReqChange()
{
     if (gal_req.readyState == 4)
     {
          response = gal_req.responseXML;
          gal_parseXML(response);
     }
     else
     {}
}


function gal_parseXML(xmlDoc)
{
     var galobj = document.getElementById(m_root);
     
     galobj.innerHTML = "";

     gallery = xmlDoc.getElementsByTagName("gallery");

     if (gallery[0] == null)
          return ;

     title = gallery[0].getAttribute("title");

     images = xmlDoc.getElementsByTagName("image");
     imagecount = images.length;

     result = "";

     result += '<table width=100% bgcolor="#F0F4D0">';
     result += '<tr><td colspan=' + m_colcount + ' align=left><b>' + title + '</b></td></tr>';

     result += '<tr>';
     for (t = 0; t <= imagecount - 1; t++)
     {
          result += '<td align=center bgcolor="#f8ffef">';
          result += '<br><a href=JavaScript:ShowPic("' + m_root + '",' + t + ');>';
          result += '<img src="./gallery/' + m_root + '/' + images[t].getAttribute('thumb') + '" alt="' + images[t].getAttribute('text') + '" border=0>';
          result += '</a><br><br>';
          result += '</td>';

          if ((t + 1) % m_colcount == 0)
               result += '</tr><tr>';
     }

     while (t % m_colcount != 0)
     {
          result += '<td  align=center></td>';
          t++;
     }

     result += '</tr>';
     result += '</table>';
     
     galobj.innerHTML = result;
}

function ShowPic(root, index)
{
     window.open('./gallery/PicView.htm?root=' + root + '&index=' + index, 'PicView', 'resizable=yes,scrollbars=yes,locationbar=no,menubar=no, status=no,width=750,height=550');
}

