///////////////////////////////////////////////////////////////////
// init_diashow (Dennis Bohn)                                    //
//                                                               //
// Erzeugt eine Diashow                                          //
///////////////////////////////////////////////////////////////////

function init_diashow () {

  diashow = new Object();

  diashow["name"] = escape(document.getElementById('diashow_headline').innerHTML);
  diashow["id"] = window.location.href.substr(window.location.href.lastIndexOf("/")).match(/[0-9]+/);
  diashow["position"] = 0;
  diashow["thumbposition"] = 0;
  diashow["scrolling"] = "";
  diashow["thumbscrolling"] = "";
  diashow["loadimg"] = new Image();
  diashow["loadimg"].src = "/pics/ruhr/diashow/diashow_loading.gif";
  diashow["thumbloadimg"] = new Image();
  diashow["thumbloadimg"].src = "/pics/ruhr/diashow/thumbnail_loading.gif";
  diashow["thumbspacing"] = 4;
  
  var str = '<table cellspacing="0" cellpadding="0" border="0" id="diatable"><tr>';

  var thumb_str = '<table cellspacing="0" cellpadding="0" border="0" id="diashow_thumbnailbox">';
  thumb_str += '<tr>';

  thumb_str += '<td style="padding: 4px 0px 4px 4px" id="diashow_links"><img width="11" height="60" onmouseout="this.src=\'/pics/ha/ha_diashow_thumbpfeil_links_inaktiv.gif\'" onmouseover="this.src=\'/pics/ha/ha_diashow_thumbpfeil_links_aktiv.gif\'" src="/pics/ha/ha_diashow_thumbpfeil_links_inaktiv.gif" style="cursor: pointer" onClick="scroll_diathumbs(\'left\')"/></td>';
  thumb_str += '<td><div id="diashow_thumbnails">';
  thumb_str += '<table cellspacing="'+diashow["thumbspacing"]+'" cellpadding="0" border="0" id="thumbtable"><tr>';

  fotostrecke = divTreeReader("clickme");

  if(typeof(fotostrecke) != "undefined"){
    for(i=0;i<fotostrecke.length;i++){
      str += '<td><img src="t.gif" style="width:482px;height:362px;cursor:pointer" onClick="scroll_diashow(\'right\')"></td>';
      thumb_str += '<td>';
      thumb_str += '<div style="width:60px;height:60px;opacity:0.5;filter:alpha(opacity=50)">';
      thumb_str += '<img src="t.gif" style="width:60px;height:60px;cursor:pointer" onClick="open_dia('+i+')" onMouseOver="thumb_alpha('+i+')" onMouseOut="thumb_alpha()">';
      thumb_str += '</div>';
      thumb_str += '</td>';
    }
  }

  thumb_str += '</tr></table>';
  thumb_str += '</div></td>';
  thumb_str += '<td style="padding: 4px 4px 4px 0px" id="diashow_rechts"><img width="11" height="60" onmouseout="this.src=\'/pics/ha/ha_diashow_thumbpfeil_rechts_inaktiv.gif\'" onmouseover="this.src=\'/pics/ha/ha_diashow_thumbpfeil_rechts_aktiv.gif\'" src="/pics/ha/ha_diashow_thumbpfeil_rechts_inaktiv.gif" style="cursor: pointer" onClick="scroll_diathumbs(\'right\')"/></td>';
  thumb_str += '</tr>';
  thumb_str += '</table>';


  str += "</tr></table>";

  document.getElementById('diathumb_container').innerHTML = thumb_str;
  document.getElementById('diashow_images').innerHTML = str;
  document.getElementById('diashow_pager').innerHTML = "1/"+fotostrecke.length;

  diashow["cellwidth"] = document.getElementById('diatable').getElementsByTagName('TD')[0].offsetWidth;
  diashow["thumbwidth"] = document.getElementById('thumbtable').getElementsByTagName('TD')[0].offsetWidth+diashow["thumbspacing"];

  document.getElementById('diashow_text').innerHTML = fotostrecke[diashow["position"]]["text"];

  if ( fotostrecke[diashow["position"]]["author"].length > 3 ) { 
    document.getElementById('diashow_text').innerHTML += " <nobr><i>("+fotostrecke[diashow["position"]]["author"]+")</i></nobr>";
  }

  thumb_alpha();
  loaddia(diashow["position"]);
  loadthumbs(diashow["thumbposition"]);

  if(fotostrecke.length <= 7){
    document.getElementById('diashow_links').innerHTML = '<img src="t.gif" width="11" height="60">';
    document.getElementById('diashow_rechts').innerHTML = '<img src="t.gif" width="11" height="60">';
    document.getElementById('diathumb_pager').style.display = 'none';
  } else {
    var thumbnail_pager_length = Math.ceil(fotostrecke.length/7);
    var thumbnail_pager_str = '<span onClick="goto_thumbnail(0)" style="color:#000000">&nbsp;1&nbsp;</span>';
    for (i=1;i<thumbnail_pager_length;i++){
      var thumbnail_pager_nr = i+1;
      thumbnail_pager_str += '<span onClick="goto_thumbnail('+i+')">&nbsp;'+thumbnail_pager_nr+'&nbsp;</span>';
    }
    document.getElementById('diathumb_pager').innerHTML = thumbnail_pager_str;
  }
  var gallery_text = document.getElementById('gal_text').innerHTML.split(":");
  gallery_text[0] = gallery_text[0].split(",");
  if(gallery_text[0][0].length > 0 && gallery_text[0][1].length > 0){
    gallery_text[0] = gallery_text[0][0]+", "+gallery_text[0][1];
  } else if (gallery_text[0][0].length + gallery_text[0][1].length > 0) {
    gallery_text[0] = gallery_text[0][0]+gallery_text[0][1];
  } else {
    gallery_text[0] = "";
  }
  gallery_text[1] = gallery_text.slice(1).join(":");
  if(gallery_text[0].length > 0 && gallery_text[1].length > 0){
    gallery_text = gallery_text[0]+": "+gallery_text[1];
  } else if(gallery_text[0].length + gallery_text[1].length > 0){
    gallery_text = gallery_text[0]+gallery_text[1];
  } else {
    gallery_text = "";
  }
  if(gallery_text == "") {
    document.getElementById('gal_text').style.display = "none";
  } else {  
    document.getElementById('gal_text').innerHTML = gallery_text;
  }
  countDiaClick();

}

///////////////////////////////////////////////////////////////////
// scroll_diashow (Dennis Bohn)                                  //
//                                                               //
// Scrollt die Diashow                                           //
///////////////////////////////////////////////////////////////////

function scroll_diashow ( position ) {
  if (position == "left" || position == "right") {
      if ( typeof(get_ivw) != "undefined" ) get_ivw();
      if ( diashow["scrolling"] != "" ) window.clearInterval(diashow["scrolling"]);
      diashow["scrolling"] = "";
  }
  if (position == "right") {
    document.getElementById('diashow_text').innerHTML = ""; 
    if (diashow["position"]+1 >= fotostrecke.length) {
      diashow["position"]=0;
    } else {
      diashow["position"]++;
    }
    thumb_alpha();
    document.getElementById('diashow_pager').innerHTML = diashow["position"]+1+"/"+fotostrecke.length;
    var scroll_position = diashow["position"]*diashow["cellwidth"];
    document.getElementById('diashow_images').scrollLeft = Math.ceil((document.getElementById('diashow_images').scrollLeft*2+scroll_position)/3);
    diashow["scrolling"] = window.setInterval("scroll_diashow("+scroll_position+")", 50);
    loaddia(diashow["position"]);
    if (diashow["position"] < diashow["thumbposition"] || diashow["position"] > diashow["thumbposition"]+6) goto_thumbnail(Math.floor(diashow["position"]/7)); 
    countDiaClick();
  } else if (position == "left") {
    document.getElementById('diashow_text').innerHTML = ""; 
    if (diashow["position"] == 0) {
      diashow["position"] = fotostrecke.length-1;
    } else {
      diashow["position"]--;
    }
    thumb_alpha();
    document.getElementById('diashow_pager').innerHTML = diashow["position"]+1+"/"+fotostrecke.length;
    var scroll_position = diashow["position"]*diashow["cellwidth"];
    document.getElementById('diashow_images').scrollLeft = Math.floor((document.getElementById('diashow_images').scrollLeft*2+scroll_position)/3);
    diashow["scrolling"] = window.setInterval("scroll_diashow("+scroll_position+")", 50);
    loaddia(diashow["position"]);
    if (diashow["position"] < diashow["thumbposition"] || diashow["position"] > diashow["thumbposition"]+6) goto_thumbnail(Math.floor(diashow["position"]/7)); 
    countDiaClick();
  } else if(position > document.getElementById('diashow_images').scrollLeft){
    document.getElementById('diashow_images').scrollLeft = Math.ceil((document.getElementById('diashow_images').scrollLeft*2+position)/3);
  } else if(position < document.getElementById('diashow_images').scrollLeft){
    document.getElementById('diashow_images').scrollLeft = Math.floor((document.getElementById('diashow_images').scrollLeft*2+position)/3);
  } else {
    document.getElementById('diashow_text').innerHTML = fotostrecke[diashow["position"]]["text"]; 
    if ( fotostrecke[diashow["position"]]["author"].length > 3 ) { 
      document.getElementById('diashow_text').innerHTML += " <nobr><i>("+fotostrecke[diashow["position"]]["author"]+")</i></nobr>";
    }
    document.getElementById('diashow_images').scrollLeft = position;
    if ( diashow["scrolling"] != "" ) window.clearInterval(diashow["scrolling"]);
    diashow["scrolling"] = "";
  }
}

///////////////////////////////////////////////////////////////////
// scroll_diathumbs (Dennis Bohn)                                //
//                                                               //
// Scrollt die Diashow Thumbnails                                //
///////////////////////////////////////////////////////////////////

function scroll_diathumbs ( position ) {
  if (position == "left" || position == "right") {
      if ( diashow["thumbscrolling"] != "" ) window.clearInterval(diashow["thumbscrolling"]);
      diashow["thumbscrolling"] = "";
  }
  if (position == "right") {
    if (fotostrecke.length > 7) {
      if (diashow["thumbposition"] < fotostrecke.length-13){
        diashow["thumbposition"] += 7;
      } else if (diashow["thumbposition"] < fotostrecke.length-7){
        diashow["thumbposition"] = fotostrecke.length-7;
      } else {
        diashow["thumbposition"]=0;        
      }
    }
    var scroll_position = diashow["thumbposition"]*diashow["thumbwidth"];
    document.getElementById('diashow_thumbnails').scrollLeft = Math.ceil((document.getElementById('diashow_thumbnails').scrollLeft*2+scroll_position)/3);
    diashow["thumbscrolling"] = window.setInterval("scroll_diathumbs("+scroll_position+")", 50);
    loadthumbs(diashow["thumbposition"]);
    change_thumbnumber(diashow["thumbposition"]);
  } else if (position == "left") {
    if (fotostrecke.length > 7) {
      if (diashow["thumbposition"] == 0){
        diashow["thumbposition"] = fotostrecke.length-7;
      } else if (diashow["thumbposition"] > 6){
        diashow["thumbposition"] -= 7;
      } else {
        diashow["thumbposition"]=0;
      }
    }
    var scroll_position = diashow["thumbposition"]*diashow["thumbwidth"];
    document.getElementById('diashow_thumbnails').scrollLeft = Math.floor((document.getElementById('diashow_thumbnails').scrollLeft*2+scroll_position)/3);
    diashow["thumbscrolling"] = window.setInterval("scroll_diathumbs("+scroll_position+")", 50);
    loadthumbs(diashow["thumbposition"]);
    change_thumbnumber(diashow["thumbposition"]);
  } else if(position > document.getElementById('diashow_thumbnails').scrollLeft){
    document.getElementById('diashow_thumbnails').scrollLeft = Math.ceil((document.getElementById('diashow_thumbnails').scrollLeft*2+position)/3);
  } else if(position < document.getElementById('diashow_thumbnails').scrollLeft){
    document.getElementById('diashow_thumbnails').scrollLeft = Math.floor((document.getElementById('diashow_thumbnails').scrollLeft*2+position)/3);
  } else {
    document.getElementById('diashow_thumbnails').scrollLeft = position;
    if ( diashow["thumbscrolling"] != "" ) window.clearInterval(diashow["thumbscrolling"]);
    diashow["thumbscrolling"] = "";
  }
}

///////////////////////////////////////////////////////////////////
// open_dia (Dennis Bohn)                                        //
//                                                               //
// Öffnet Bild in einer Fotostrecke                              //
///////////////////////////////////////////////////////////////////

function open_dia (dia) {
  if ( typeof(get_ivw) != "undefined" ) get_ivw();
  diashow["position"] = dia;
  thumb_alpha();
  document.getElementById('diashow_pager').innerHTML = diashow["position"]+1+"/"+fotostrecke.length;
  document.getElementById('diashow_text').innerHTML = ""; 
  var position = diashow["position"]*diashow["cellwidth"];
  scroll_diashow(position);
  if ( diashow["scrolling"] != "" ) window.clearInterval(diashow["scrolling"]);
  diashow["scrolling"] = "";
  diashow["scrolling"] = window.setInterval("scroll_diashow("+position+")", 50);
  loaddia(diashow["position"]);
  countDiaClick();
}

///////////////////////////////////////////////////////////////////
// thumb_alpha (Dennis Bohn)                                     //
//                                                               //
// Ändert die Transparenz der Thumbnails                         //
///////////////////////////////////////////////////////////////////

function thumb_alpha () {
  var thumbnails = document.getElementById('thumbtable').getElementsByTagName('div');
  for(i=0;i<thumbnails.length;i++){
    if(i == diashow["position"]) {
      thumbnails[i].style.opacity = 1;
      thumbnails[i].style.filter = "alpha(opacity=100)";
    } else {
      thumbnails[i].style.opacity = 0.5;
      thumbnails[i].style.filter = "alpha(opacity=50)";
    }
  }
  if(typeof(thumb_alpha.arguments[0]) != "undefined") {
      thumbnails[thumb_alpha.arguments[0]].style.opacity = 1;
      thumbnails[thumb_alpha.arguments[0]].style.filter = "alpha(opacity=100)";
  }
}

///////////////////////////////////////////////////////////////////
// loaddia (Dennis Bohn)                                         //
//                                                               //
// Lädt das Bild einer Fotostrecke                               //
///////////////////////////////////////////////////////////////////

function loaddia(pos) {
    if(typeof(fotostrecke[pos]["pic"]) == "undefined") {
      document.getElementById('diatable').getElementsByTagName('td')[pos].style.backgroundImage = "url("+diashow["loadimg"].src+")";
      fotostrecke[pos]["pic"] = new Image();
      fotostrecke[pos]["pic"].src = fotostrecke[pos]["picurl"];
      fotostrecke[pos]["picloader"] = window.setInterval("loaddiacheck("+pos+")",50);
    }
    
}

///////////////////////////////////////////////////////////////////
// loadthumbs (Dennis Bohn)                                      //
//                                                               //
// Lädt Thumbnails für die Bildauswahl                           //
///////////////////////////////////////////////////////////////////

function loadthumbs(pos) {
  for(i=pos;i<pos+7;i++){
    if(i==fotostrecke.length) break;
    if(typeof(fotostrecke[i]["thumb"]) == "undefined") {
      document.getElementById('thumbtable').getElementsByTagName('div')[i].style.backgroundImage = "url("+diashow["thumbloadimg"].src+")";
      fotostrecke[i]["thumb"] = new Image();
      fotostrecke[i]["thumb"].src = fotostrecke[i]["thumburl"];
      fotostrecke[i]["thumbloader"] = window.setInterval("loadthumbscheck("+i+")",50);
    }
  }
}

///////////////////////////////////////////////////////////////////
// loaddiacheck (Dennis Bohn)                                    //
//                                                               //
// Prüft, ob das Bild geladen wurde                              //
///////////////////////////////////////////////////////////////////

function loaddiacheck (pos) {
    if(fotostrecke[pos]["pic"].complete){
      window.clearInterval(fotostrecke[pos]["picloader"]);
      document.getElementById('diatable').getElementsByTagName('td')[pos].style.backgroundImage = "url("+fotostrecke[pos]["pic"].src+")";
    }
}

///////////////////////////////////////////////////////////////////
// loadthumbscheck (Dennis Bohn)                                 //
//                                                               //
// Prüft, ob das Thumb geladen wurde                             //
///////////////////////////////////////////////////////////////////

function loadthumbscheck (pos) {
    if(fotostrecke[pos]["thumb"].complete){
      window.clearInterval(fotostrecke[pos]["thumbloader"]);
      document.getElementById('thumbtable').getElementsByTagName('div')[pos].style.backgroundImage = "url("+fotostrecke[pos]["thumb"].src+")";
      document.getElementById('thumbtable').getElementsByTagName('div')[pos].style.backgroundPosition = "center";
    }
}

///////////////////////////////////////////////////////////////////
// goto_thumbnail (Dennis Bohn)                                  //
//                                                               //
// Springt über den Thumbnail-Pager zu bestimmten Thumbnails     //
///////////////////////////////////////////////////////////////////

function goto_thumbnail (pos) {
  diashow["thumbposition"] = pos*7;
  if (diashow["thumbposition"] > fotostrecke.length-7) diashow["thumbposition"] = fotostrecke.length-7;
  var scroll_position = diashow["thumbposition"]*diashow["thumbwidth"];
  document.getElementById('diashow_thumbnails').scrollLeft = Math.round((document.getElementById('diashow_thumbnails').scrollLeft*2+scroll_position)/3);
  if(diashow["thumbscrolling"] != ""){
    window.clearInterval(diashow["thumbscrolling"]);
    diashow["thumbscrolling"] = "";
  }
  diashow["thumbscrolling"] = window.setInterval("scroll_diathumbs("+scroll_position+")", 50);
  loadthumbs(diashow["thumbposition"]);
  change_thumbnumber(diashow["thumbposition"]);
}

///////////////////////////////////////////////////////////////////
// change_thumbnumber (Dennis Bohn)                              //
//                                                               //
// Ändert die Hervorhebung der Pagernummern                      //
///////////////////////////////////////////////////////////////////

function change_thumbnumber (pos) {
  var pagernumbers = document.getElementById('diathumb_pager').getElementsByTagName('span');
  var pager = Math.ceil(pos/7);
  for (i=0;i<pagernumbers.length;i++){
    if(i==pager){
      pagernumbers[i].style.color = "#000000";
    } else {
      pagernumbers[i].style.color = "#999999";      
    }
  }
}

///////////////////////////////////////////////////////////////////
// init_fotostrecken (Dennis Bohn)                               //
//                                                               //
// Erzeugt Ansicht für weitere Fotostrecken                      //
///////////////////////////////////////////////////////////////////

function init_fotostrecken(title) {

  if (typeof(gallerylist) == "undefined") { 
    fotostrecken_scrolling = new Array();
    gallerylist = new Array();
  }
  var glid = gallerylist.length;

  gallerylist.push(divTreeReader("dia_auswahl"))

  document.getElementById('dia_auswahl').id = 'dia_auswahl_'+glid;

  var str = '<table cellspacing="0" cellpadding="0" border="0" id="fotostrecken_auswahl_'+glid+'" class="fotostrecken_auswahl">';
  str += '<tr>';
  str += '<th valign="center">'+title+'</th>';
  str += '<th valign="center" class="fotostrecken_auswahl_pager">';

  var pages = Math.ceil(gallerylist[glid].length/6);

  str += '<table cellspacing="3" cellpadding="0" border="0" align="right" id="fotostrecken_auswahl_pages_'+glid+'">';
  str += '<tr>';
  str += '<td class="fotostrecken_pager_aktiv" onClick="goto_fotostrecken(0,'+glid+')">1</td>';
  for (i=1;i<pages;i++){
    var page_label = i+1;
    str += '<td onClick="goto_fotostrecken('+i+','+glid+')">'+page_label+'</td>';
  }
  str += '</tr>';
  str += '</table>';
  str += '</th>';
  str += '</tr>';
  str += '<tr>';
  str += '<td colspan="2" id="fotostrecken_auswahl_box_'+glid+'" class="fotostrecken_auswahl_box">';
  str += '<div style="width:483px;overflow:hidden" id="fotostrecke_auswahl_div_'+glid+'">';
  str += '<table cellspacing="0" cellpadding="0" border="0" id="fotostrecke_auswahl_page_'+glid+'">';
  for(i=0;i<gallerylist[glid].length;i+=6){
    str += '<td width="483" align="center">';
    str += '<table cellspacing="12" cellpadding="0" border="0" class="fotostrecke_auswahl_block">';
    str += '<tr>';
    for(x=0;x<6;x++){
      if (x==3) str += '</tr><tr>';
      if(i+x<gallerylist[glid].length){
        var picid = gallerylist[glid][i+x]["thumb_url"].substring( gallerylist[glid][i+x]["thumb_url"].lastIndexOf("/") + 1 );
        picid = picid.substring(0,picid.indexOf("_"));
        var link = 'cme'+gallerylist[glid][i+x]["id"]+','+picid+'.html';
        str += '<td class="gallerylist_element" align="center" valign="top" onMouseOver="fotostrecken_show_icon(this)" onMouseOut="fotostrecken_hide_icon(this)" onClick="window.location.href=this.getElementsByTagName(\'a\')[0].href">';
        str += '<div class="fotostrecken_auswahl_bild"><a href="'+link+'"><img src="/pics/ruhr/diashow/fotostrecken_icon.gif" width="133" height="100" border="0"></a></div>';
        str += '<div class="fotostrecken_auswahl_label">'+gallerylist[glid][i+x]["label"]+'</div>';
      } else {
        str += '<td style="cursor:default;border-color:#efefef"><img src="/pics/ruhr/diashow/t.gif" width="143" height="143">';
      }
      str += '</td>';
    }
    str += '</tr>';
    str += '</table>';
    str += '</td>';
  }
  str += '</table>';
  str += '</div>';
  str += '</td>';
  str += '</tr>';
  str += '</table>';

  document.write(str);

  fotostrecken_scrolling.push("");

  loadFotostreckenThumbs(0,glid);

}

///////////////////////////////////////////////////////////////////
// fotostrecken_show_icon (Dennis Bohn)                          //
//                                                               //
// Blendet das Fotostrecken-Icon ein                             //
///////////////////////////////////////////////////////////////////

function fotostrecken_show_icon (obj) {
  obj.getElementsByTagName('img')[0].style.visibility = "visible";
}

///////////////////////////////////////////////////////////////////
// fotostrecken_hide_icon (Dennis Bohn)                          //
//                                                               //
// Blendet das Fotostrecken-Icon aus                             //
///////////////////////////////////////////////////////////////////

function fotostrecken_hide_icon (obj) {
  obj.getElementsByTagName('img')[0].style.visibility = "hidden";
}

///////////////////////////////////////////////////////////////////
// goto_fotostrecken (Dennis Bohn)                               //
//                                                               //
// Springt in Fotostreckenauswahl auf eine bestimmte Seite       //
///////////////////////////////////////////////////////////////////

function goto_fotostrecken (page,glid) {
  var pagewidth = document.getElementById('fotostrecke_auswahl_page_'+glid).getElementsByTagName('td')[0].offsetWidth;
  var position = pagewidth*page;
  document.getElementById('fotostrecke_auswahl_div_'+glid).scrollLeft = Math.round((document.getElementById('fotostrecke_auswahl_div_'+glid).scrollLeft*2+position)/3);
  if(fotostrecken_scrolling[glid] != ""){
    window.clearInterval(fotostrecken_scrolling[glid]);
    fotostrecken_scrolling[glid] = "";
  }
  fotostrecken_scrolling[glid] = window.setInterval("fotostrecken_scroller("+position+","+glid+")",50);
  var pages = document.getElementById('fotostrecken_auswahl_pages_'+glid).getElementsByTagName('TD');
  for(i=0;i<pages.length;i++){
    if(i==page){
      pages[i].className = "fotostrecken_pager_aktiv";
    } else {
      pages[i].className = "fotostrecken_pager";
    }
  }
  loadFotostreckenThumbs(page,glid);
}

///////////////////////////////////////////////////////////////////
// fotostrecken_scroller (Dennis Bohn)                           //
//                                                               //
// Scrollt an die gewünschte Stelle der Fotostrecken-Auswahl     //
///////////////////////////////////////////////////////////////////

function fotostrecken_scroller (position,glid) {
  if(position > document.getElementById('fotostrecke_auswahl_div_'+glid).scrollLeft) {
    document.getElementById('fotostrecke_auswahl_div_'+glid).scrollLeft = Math.floor((document.getElementById('fotostrecke_auswahl_div_'+glid).scrollLeft*2+position)/3);
  } else if(position < document.getElementById('fotostrecke_auswahl_div_'+glid).scrollLeft){
    document.getElementById('fotostrecke_auswahl_div_'+glid).scrollLeft = Math.ceil((document.getElementById('fotostrecke_auswahl_div_'+glid).scrollLeft*2+position)/3);
  } else {
    window.clearInterval(fotostrecken_scrolling[glid]);
    fotostrecken_scrolling[glid] = "";    
  }
}

///////////////////////////////////////////////////////////////////
// loadFotostreckenThumbs (Dennis Bohn)                          //
//                                                               //
// Lädt Thumbnails für die Bildauswahl in der                    //
// Fotostreckenübersicht                                         //
///////////////////////////////////////////////////////////////////

function loadFotostreckenThumbs (page,glid) {
  for(i=0;i<6;i++){
    var element = page*6+i;
    if(element==gallerylist[glid].length) break;
    if(typeof(gallerylist[glid][element]["thumb"]) == "undefined") {
      var object = document.getElementById('fotostrecke_auswahl_page_'+glid).getElementsByTagName('table')[page].getElementsByTagName('td')[i].getElementsByTagName('div')[0];
      object.style.backgroundImage = "url("+diashow["thumbloadimg"].src+")";
      gallerylist[glid][element]["thumb"] = new Image();
      gallerylist[glid][element]["thumb"].src = gallerylist[glid][element]["thumb_url"];
      gallerylist[glid][element]["thumbloader"] = window.setInterval("loadFotostreckenThumbsCheck("+page+","+i+","+glid+")",50);
    }
  }
}

///////////////////////////////////////////////////////////////////
// loadFotostreckenThumbsCheck (Dennis Bohn)                     //
//                                                               //
// Checkt ob die Thumbs für die Fotostreckenauswahl geladen sind //
///////////////////////////////////////////////////////////////////

function loadFotostreckenThumbsCheck (page,pic,glid) {
    var pos = page*6+pic;
    if(gallerylist[glid][pos]["thumb"].complete){
      var obj = document.getElementById('fotostrecke_auswahl_page_'+glid).getElementsByTagName('table')[page].getElementsByTagName('td')[pic].getElementsByTagName('div')[0];
      window.clearInterval(gallerylist[glid][pos]["thumbloader"]);
      obj.style.backgroundImage = "url("+gallerylist[glid][pos]["thumb"].src+")";
      obj.style.backgroundPosition = "center";
    }
}

///////////////////////////////////////////////////////////////////
// countDiaClick (Michael Hochgartz, Dennis Bohn)                //
//                                                               //
// Zählt einen Klick in einer Diashow                            //
///////////////////////////////////////////////////////////////////

function countDiaClick() {
  if(typeof(diashow) != "undefined"){
    var cmeClick = new Image();
    cmeClick.src = "http://admin.ruhrnachrichten.de/_CPiX/cme-"+fotostrecke[diashow["position"]]["id"]+"-"+diashow["id"]+"/pixel.gif";
    var picClick = new Image();
    picClick.src = "http://admin.ruhrnachrichten.de/_CPiX/pic-"+fotostrecke[diashow["position"]]["id"]+"-"+diashow["id"]+"/pixel.gif";
    document.getElementById('fcmspixel').innerHTML = '<img src="'+cmeClick.src+'"><img src="'+picClick.src+'">';
  }
}

///////////////////////////////////////////////////////////////////
// init_diaindex (Dennis Bohn)                                   //
//                                                               //
// Generiert einen Pager                                         //
///////////////////////////////////////////////////////////////////

function init_diaindex(len,pos,page,glid) {
  var str = '<table id="fotostrecken_auswahl_pages" align="right" border="0" cellpadding="0" cellspacing="3">';
  str += '<tr>';
  if (len <= 9) {
    for(i=0; i<len; i++){
      var number = i+1;
      if (i == page) {
        str += '<td class="fotostrecken_pager_aktiv">'+number+'</td>';
      } else {
        var link = 'art'+id+',,1-pg'+i;
        str += '<td onClick="window.location.href=\''+link+'\'">'+number+'</td>';
     }
    }    
  } else {
    if (pos >= len) pos = page-3;
    if (pos < 0) pos = 0;
    if (pos > len-7) pos = len-7;
    if(len > 7 && pos > 0) {
      var prev = pos-1;
      str += '<td onClick="init_diaindex('+len+','+prev+','+page+','+glid+')">&laquo;</td>';
    } else {
      str += '<td>&nbsp;</td>';
    }
    for(i=pos; i<pos+7; i++){
      var number = i+1;
      if (i == page) {
        str += '<td style="color: rgb(0,0,0);">'+number+'</td>';
      } else {
        var link = 'art'+id+',,1-pg'+i;
        str += '<td onClick="window.location.href=\''+link+'\'">'+number+'</td>';
     }
    }
    if(len > 7 && pos < len-7) {
      var next = pos+1;
      str += '<td onClick="init_diaindex('+len+','+next+','+page+','+glid+')">&raquo;</td>';
    } else {
      str += '<td>&nbsp;</td>';
    }
  }
  str += '</tr>';
  str += '</table>';
  document.getElementById('pager_'+glid).innerHTML = str;
}

///////////////////////////////////////////////////////////////////
// divTreeReader (Dennis Bohn)                                   //
//                                                               //
// Hilft bei der Erzeugung von JS-Objekten                       //
///////////////////////////////////////////////////////////////////

function divTreeReader(id) {
  var arr = new Array();
  var tree = document.getElementById(id).getElementsByTagName('div');
  for(i=0;i<tree.length;i++){
    if(tree[i].getAttribute("name") == "fields") {
      var fields = tree[i].innerHTML.split(",");
    } else if(typeof(fields) != "undefined"){
      if(tree[i].getAttribute("name") == "element"){
        if(typeof(obj) != "undefined") {
          arr.push(obj);
          delete obj;
        }
        var field = 0;
        var obj = new Object();
        i++;
      }
      obj[fields[field]] = tree[i].innerHTML;
      field++;
    }
  }
  arr.push(obj);
  return arr;
}

// Ressortauswahl-Funktionen für die Diashow

function init_DiaRessortBox ( id, speed ) {
  DiaRessortBox = new Object();
  DiaRessortBox["interval"] = "";
  DiaRessortBox["obj"] = document.getElementById(id);
  DiaRessortBox["height"] = DiaRessortBox["obj"].offsetHeight;
  DiaRessortBox["speed"] = speed;
  DiaRessortBox["pos"] = 0;
  DiaRessortBox["obj"].style.height = "0px";
  DiaRessortBox["alpha"] = 0;
}


function showDiaRessorts() {
  if(DiaRessortBox["interval"] != ""){
    if (DiaRessortBox["pos"] < DiaRessortBox["speed"]) {
      DiaRessortBox["pos"]++;
      var form = DiaRessortBox["height"]*((Math.cos(Math.PI*(DiaRessortBox["pos"]/DiaRessortBox["speed"]-1))+1)/2);
      DiaRessortBox["obj"].style.height = form+"px";
    } else if (DiaRessortBox["alpha"] < 100) {
      DiaRessortBox["alpha"] += 5;
      DiaRessortBox["obj"].style.opacity = DiaRessortBox["alpha"]/100;
      DiaRessortBox["obj"].style.filter = 'alpha(opacity='+DiaRessortBox["alpha"]+')';
    } else {
      var form = DiaRessortBox["height"];
      window.clearInterval(DiaRessortBox["interval"]);
      DiaRessortBox["interval"] = "";
    }
  } else {
    if (DiaRessortBox["alpha"] != 0) {
      DiaRessortBox["interval"] = window.setInterval("hideDiaRessorts()",33);
      DiaRessortBox["alpha"] = 100;
      DiaRessortBox["obj"].style.opacity = DiaRessortBox["alpha"];
      DiaRessortBox["obj"].style.filter = 'alpha(opacity='+DiaRessortBox["alpha"]+')';
      DiaRessortBox["obj"].style.height = DiaRessortBox["height"]+"px";
    } else {
      DiaRessortBox["interval"] = window.setInterval("showDiaRessorts()",33);
      DiaRessortBox["alpha"] = 0;
      DiaRessortBox["obj"].style.opacity = DiaRessortBox["alpha"];
      DiaRessortBox["obj"].style.filter = 'alpha(opacity='+DiaRessortBox["alpha"]+')';
      DiaRessortBox["obj"].style.height = "0px";
    }
  }
}

function hideDiaRessorts() {
  if (DiaRessortBox["alpha"] > 0) {
    DiaRessortBox["alpha"] -= 5;
    DiaRessortBox["obj"].style.opacity = DiaRessortBox["alpha"]/100;
    DiaRessortBox["obj"].style.filter = 'alpha(opacity='+DiaRessortBox["alpha"]+')';
  } else if (DiaRessortBox["pos"] > 0) {
    DiaRessortBox["pos"]--;
    var form = DiaRessortBox["height"]*((Math.cos(Math.PI*(DiaRessortBox["pos"]/DiaRessortBox["speed"]-1))+1)/2);
    DiaRessortBox["obj"].style.height = form+"px";
  } else {
    window.clearInterval(DiaRessortBox["interval"]);
    DiaRessortBox["interval"] = "";
  }
}

///////////////////////////////////////////////////////////////////
// lbxCmeMod (Dennis Bohn)                                       //
//                                                               //
// Modifiziert CME-Links in Linkboxen um auf Fotostrecken im     //
// Inhaltsbereich zu verlinken                                   //
///////////////////////////////////////////////////////////////////

function lbxCmeMod(id) {
  var lbx_links = document.getElementById(id).getElementsByTagName('a');
  var cmeSearchString = "_CMTREE=";
  var cmeLinkRoot = "/bilder/fotostrecken";
  for(i=0;i<lbx_links.length;i++){
    var lbxlink = lbx_links[i].href;
    var cmeIndex = lbxlink.indexOf(cmeSearchString);
    if (cmeIndex != -1) {
      var cmeLinkStart = cmeIndex+cmeSearchString.length;
      var cmeLinkEnd = lbxlink.indexOf("&");
      if(cmeLinkStart < cmeLinkEnd) {
        var cmeId = lbxlink.substring(cmeLinkStart,cmeLinkEnd);
      } else {
        var cmeId = lbxlink.substring(cmeLinkStart);
      }
      for(x=0;x<document.getElementsByTagName('meta').length;x++){
        var metatag = document.getElementsByTagName('meta')[x];
        if (metatag.getAttribute('name') == "diatag") var cmePath = metatag.getAttribute('content');
      }
      var ref = window.location.href.substr(window.location.href.lastIndexOf("/"));
      if(ref.indexOf("/art") != -1 || ref.indexOf(";art") != -1) ref = "art";
      if(typeof(cmePath) != "undefined"){
        lbx_links[i].href = cmeLinkRoot+"/"+cmePath+"/cme"+cmeId+",1.html?ref="+ref;
      } else {
        lbx_links[i].href = cmeLinkRoot+"/cme"+cmeId+",1.html?ref="+ref;
      }
      lbx_links[i].setAttribute("onclick", "", 0);
      lbx_links[i].setAttribute("target", "_top", 0);
    }
    var cmeVoting = lbxlink.indexOf("/voting/");
    if ( cmeVoting == -1 ) lbx_links[i].href = lbx_links[i].href.replace(",0.html",",1.html");
  }
  if(document.getElementById(id+'_0')){
    var lbxCount = 1;
    while(document.getElementById(id+'_'+lbxCount)){
      lbxCount++;
    }
    document.getElementById(id).id = id+'_'+lbxCount;
  } else {
    document.getElementById(id).id = id+'_0';    
  }
}