/* Teil des Bildergalerie-Moduls des CMS */

/* Das Script ermöglicht einen Bildwechsel, ohne die Seite neu zu laden.
   Bild und Bildunterschrift werden ersetzt, danach werden die Steuerelemente gelöscht und die benötigten neu erzeugt. */

gallery_href = new Array();
gallery_current = new Array();
gallery_imgs = new Array();
gallery_txts = new Array();

function gallery_init(p_url, p_id, p_current, p_imgs, p_txts)
{
  gallery_href[p_id] = p_url + (p_url.search(/\?/) == -1 ? "?" : "&") + p_id + "_";
  gallery_current[p_id] = p_current;
  gallery_imgs[p_id] = p_imgs;
  gallery_txts[p_id] = p_txts;
  txt = document.getElementById("gallery" + p_id + "_text");
  if(txt && !txt.hastChildNodes)
  {
    t = document.createTextNode("");
    txt.appendChild(t);
  }
  gallery_refresh(p_id);
}

function gallery_refresh(p_id)
{
  document.getElementById("gallery" + p_id + "_img").src = gallery_imgs[p_id][gallery_current[p_id]];
  txt = document.getElementById("gallery" + p_id + "_text");
  if(txt) txt.firstChild.nodeValue = gallery_txts[p_id][gallery_current[p_id]];

  controlpanel = document.getElementById("gallery" + p_id + "_control");
  while(controlpanel.firstChild) controlpanel.removeChild(controlpanel.firstChild);

  if(gallery_current[p_id] > 0)
  {
    t = document.createTextNode("|<");
    a = document.createElement("abbr");
    a.appendChild(t);
    a.title = "erstes Bild";
    l = document.createElement("a");
    l.appendChild(a);
    l.className = "gallery_first";
    l.href = gallery_href[p_id] + "0" + "#gallery" + p_id;
    l.onclick = function() { return gallery_first(p_id) };
    controlpanel.appendChild(l);

    t = document.createTextNode("<<");
    a = document.createElement("abbr");
    a.appendChild(t);
    a.title = "vorheriges Bild";
    l = document.createElement("a");
    l.appendChild(a);
    l.className = "gallery_previous";
    l.href = gallery_href[p_id] + (gallery_current[p_id] - 1) + "#gallery" + p_id;
    l.onclick = function() { return gallery_previous(p_id) };
    controlpanel.appendChild(l);
  }

  if(gallery_current[p_id] < gallery_imgs[p_id].length - 1)
  {
    t = document.createTextNode(">|");
    a = document.createElement("abbr");
    a.appendChild(t);
    a.title = "letztes Bild";
    l = document.createElement("a");
    l.appendChild(a);
    l.className = "gallery_last";
    l.href = gallery_href[p_id] + (gallery_imgs[p_id].length - 1) + "#gallery" + p_id;
    l.onclick = function() { return gallery_last(p_id) };
    controlpanel.appendChild(l);

    t = document.createTextNode(">>");
    a = document.createElement("abbr");
    a.appendChild(t);
    a.title = "nächstes Bild";
    l = document.createElement("a");
    l.appendChild(a);
    l.className = "gallery_next";
    l.href = gallery_href[p_id] + (gallery_current[p_id] + 1) + "#gallery" + p_id;
    l.onclick = function() { return gallery_next(p_id) };
    controlpanel.appendChild(l);
  }
}

function gallery_first(p_id)
{
  gallery_current[p_id] = 0;
  gallery_refresh(p_id);
  return false;
}

function gallery_previous(p_id)
{
  gallery_current[p_id] -= 1;
  gallery_refresh(p_id);
  return false;
}

function gallery_next(p_id)
{
  gallery_current[p_id] += 1;
  gallery_refresh(p_id);
  return false;
}

function gallery_last(p_id)
{
  gallery_current[p_id] = gallery_imgs[p_id].length - 1;
  gallery_refresh(p_id);
  return false;
}

