/*

var wm_imgzoom_bg_color = '#000000';// Hintergrundfarbe der Abblendmaske
var wm_imgzoom_bordercolor = '#000000' // Rahmenfarbe der Bilder

*/

var aktiv_img_id;



if(typeof wm_imgzoom_bg_color == 'undefined'){
  wm_imgzoom_bg_color = '#000000';
}

if(typeof wm_imgzoom_bordercolor == 'undefined'){
  wm_imgzoom_bordercolor = '#BFBFBF';
}

if(typeof wm_imgzoom_string_close == 'undefined'){
  wm_imgzoom_string_close = 'schließen';
}

if(typeof wm_imgzoom_string_newWindow == 'undefined'){
  wm_imgzoom_string_newWindow = 'Bild im neuen Fenster öffnen';
}

var wm_imgzoom_string_list_img;
var wm_imgzoom_img_aktiv_src;
var wm_imgzoom_img_dyndiv; // debugger für Dynamisches Bild

var wm_imgzoom_durchlauf = 0;
var wm_imgzoom_tmp_href;
var wm_imgzoom_img_res_timeout;

var wm_imgzoom_write_body;
var wm_imgzoom_new_height = 100;
var wm_imgzoom_new_width  = 100;

/*function screenHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  // window.alert( 'Width = ' + myWidth );
  // window.alert( 'Height = ' + myHeight );
  return myHeight;
}
*/

 Array.prototype.unique = function()

{

    var o = {};

    for(var i = 0 ; i < this.length; i++) o[this[i]] = true;

    var tmp = new Array();

    for(var i in o) tmp[tmp.length] = i;

    return tmp;

}



   function wm_imgzoom_image_resize(){


     max_img_height = document.body.clientHeight - 150;
     max_img_width = document.body.clientWidth - 60;

     differenz_img = max_img_width-max_img_height;

/*
     max_img_height = screenHeight() - 110;
     max_img_width = window.innerWidth - 60;
     alert('TEST' + window.innerHeight);
     alert('TEST' + document.body.offsetHeight);
     alert('TEST' + document.documentElement.offsetHeight);
*/


     ist_geladen   = wm_imgzoom_bigImg.complete;
     imgRealHeight = wm_imgzoom_bigImg.height;
     imgRealWidth  = wm_imgzoom_bigImg.width;




      if(ist_geladen == true){


         document.wmImgzoomDynBild.src = wm_imgzoom_img_aktiv_src;
         document.getElementById("wm_imgzoom_div_dynBild").style.display = '';
         document.getElementById("wm_imgzoom_div_dynBild_load").style.display = 'none';



        wm_imgzoom_new_width  = imgRealWidth;
        wm_imgzoom_new_height = imgRealHeight;

        if(wm_imgzoom_new_height > max_img_height){
         wm_imgzoom_new_width  = Math.round(wm_imgzoom_new_width / wm_imgzoom_new_height * max_img_height);
         wm_imgzoom_new_height = max_img_height;
        }

        if(wm_imgzoom_new_width >  max_img_width){
         wm_imgzoom_new_height = Math.round(wm_imgzoom_new_height / wm_imgzoom_new_width * max_img_width);
         wm_imgzoom_new_width  = max_img_width;
        }

         //document.getElementByID('wm_imgzoom_div_dynBild_load').style.height = wm_imgzoom_new_height;
         //document.getElementByID('wm_imgzoom_div_dynBild_load').style.width  = wm_imgzoom_new_width;

         document.wmImgzoomDynBild.height = wm_imgzoom_new_height;
         document.wmImgzoomDynBild.width  = wm_imgzoom_new_width;

       //document.getElementById('wm_imgzoom_list_img').style.width = document.wmImgzoomDynBild.offsetWidth + 'px';


     }

     else{
       wm_imgzoom_img_res_timeout =  window.setTimeout("wm_imgzoom_image_resize()",500);

     }



   }

   var wm_imgzoom_bigImg;

   function wm_imgzoom_zommlayer(){

      if(!document.getElementById('wm_imgzoom_zoom_bereich'))
        return;

      objecttag_ar = document.getElementsByTagName('object');
      if(objecttag_ar.length >= 1)
       for(i=0; i<objecttag_ar.length; i++) {
         objecttag_ar[i].style.visibility = 'hidden';
       }
      embed_ar = document.getElementsByTagName('embed');
      if(embed_ar.length >= 1)
       for(i=0; i<embed_ar.length; i++) {
         embed_ar[i].style.visibility = 'hidden';
       }

      var wm_imgzoom_loadstring = '<div style="width:'+wm_imgzoom_new_width+'px; height:'+wm_imgzoom_new_height+'px;color:#FFFFFF;font-wight:bold" id="wm_imgzoom_div_dynBild_load"><table height="'+wm_imgzoom_new_height+'" cellpadding="0" cellspaching="0" border="0"><tr><td style="color:#FFFFFF;font-wight:bold" valign="middle" align="center"><img src="'+wm_imgzoom_WEB_URL+'/cms_scripte/loading.gif" alt="loading ..." border="0" height="36" width="36" align="" class=""></td></tr></table></div>' +
                                  '<div style="display:none" id="wm_imgzoom_div_dynBild"><img name="wmImgzoomDynBild" src=""></div>';
      document.getElementById('wm_imgzoom_zoom_bereich_content').innerHTML =  wm_imgzoom_loadstring;


      document.getElementById('wm_imgzoom_dynLink').title = wm_imgzoom_string_newWindow;
      document.getElementById('wm_imgzoom_close_link').title = wm_imgzoom_string_close;

      document.getElementById('wm_imgzoom_border_layer').style.borderColor = wm_imgzoom_bordercolor;
      document.getElementById('wm_imgzoom_trans').style.backgroundColor = wm_imgzoom_bg_color;

      bild =  arguments[0]; // Optional schreibweise beachten
      text =  arguments[2]; // Optional schreibweise beachten

      document.getElementById('wm_imgzoom_trans').style.visibility = 'visible';
      document.getElementById('wm_imgzoom_trans').style.height = document.body.scrollHeight + 'px';
      document.getElementById('wm_imgzoom_trans').style.width  = document.body.scrollWidth + 'px';
      document.getElementById('wm_imgzoom_zoom_bereich').style.visibility = 'visible';
      document.getElementById('wm_imgzoom_zoom_bereich').style.top = (document.body.scrollTop + 10) + 'px';
      document.getElementById('wm_imgzoom_zoom_bereich').style.visibility = 'visible';
      document.getElementById('wm_imgzoom_zoom_bereich_content').style.display = '';
      document.getElementById('wm_imgzoom_dynLink').href = bild;

      if(text){
          document.getElementById('wm_imgzoom_zoom_bereich_content').innerHTML = text;
      }

      if(bild){
        wm_imgzoom_bigImg = new Image();
        wm_imgzoom_bigImg.src = bild;


        wm_imgzoom_tmp_href =  bild;
        wm_imgzoom_string_list_img = '';

        wm_imgzoom_img_array_neu = wm_imgzoom_img_array.unique();
        wm_imgzoom_img_array     = wm_imgzoom_img_array_neu;

        for(i=0; i< wm_imgzoom_img_array.length; i++){

          if(wm_imgzoom_img_array[i] == bild){
            aktiv_img_id = i;
            break;
          }
        }

        start_thumnail =  Math.round( aktiv_img_id - 4 ) ;
        if( start_thumnail < 0)
          start_thumnail =    0;

        end_thumnail   =  start_thumnail+9;
        if(end_thumnail > wm_imgzoom_img_array.length){
           end_thumnail   = wm_imgzoom_img_array.length;
           start_thumnail = end_thumnail-9;
        }

        if( start_thumnail < 0)
          start_thumnail =    0;


        for(i=start_thumnail; i<end_thumnail ; i++){
          borderWidth = '1';
          margin =  '2px';
          if(wm_imgzoom_img_array[i] == bild){
            borderWidth  = '2';
            margin       = '10px';
          }
          wm_imgzoom_string_list_img  += '<td><img src="'+ wm_imgzoom_img_array[i] +'_thumb.jpg" height="40" alt="" border="'+borderWidth+'" style="border-color:'+wm_imgzoom_bordercolor+';margin:0px '+ margin +' 0px '+ margin +'" onClick="wm_imgzoom_zommlayer(\''+ wm_imgzoom_img_array[i] +'\')"></td>' + "\r\n";
        }

        if(wm_imgzoom_img_array.length == 1)
          wm_imgzoom_string_list_img  = '';

        if(!wm_imgzoom_img_dyndiv)
          document.getElementById('wm_imgzoom_zoom_bereich_content').innerHTML =  wm_imgzoom_loadstring;
        wm_imgzoom_img_dyndiv = true;


        // Navi vor und zurück
        if(aktiv_img_id >=1){
          vorlink    = '<span onClick="wm_imgzoom_zommlayer(\''+ wm_imgzoom_img_array[(aktiv_img_id-1)] +'\')" style="cursor:pointer;color:#FFFFFF;font-size:20px"><b>&lt;</b></span>';
          anfanglink = '<span onClick="wm_imgzoom_zommlayer(\''+ wm_imgzoom_img_array[0] +'\')" style="cursor:pointer;color:#FFFFFF;font-size:20px"><b>|&lt;</b></span>';

        }else{
          vorlink    = '<span style="cursor:pointer;color:#535353;font-size:20px"><b>&lt;</b></span>';
          anfanglink = '<span style="cursor:pointer;color:#535353;font-size:20px"><b>|&lt;</b></span>';

        }
        if(aktiv_img_id <  (wm_imgzoom_img_array.length-1)){
          nachlink = '<span onClick="wm_imgzoom_zommlayer(\''+ wm_imgzoom_img_array[(aktiv_img_id+1)] +'\')" style="cursor:pointer;color:#FFFFFF;font-size:20px"><b>&gt;</b></span>';
          endlink  = '<span onClick="wm_imgzoom_zommlayer(\''+ wm_imgzoom_img_array[(wm_imgzoom_img_array.length - 1 )] +'\')" style="cursor:pointer;color:#FFFFFF;font-size:20px"><b>&gt;|</b></span>';
        }else{
          nachlink = '<span style="cursor:pointer;color:#535353;font-size:20px"><b>&gt;</b></span>';
          endlink  = '<span style="cursor:pointer;color:#535353;font-size:20px"><b>&gt;|</b></span>';
        }



        if(wm_imgzoom_string_list_img){
          document.getElementById('wm_imgzoom_list_img').innerHTML = '<table cellpadding="0" cellspacing="0" border="0"><tr><td width="25" align="center">'+ anfanglink+'</td><td width="25" align="center">'+ vorlink+'</td>' + wm_imgzoom_string_list_img +'<td width="25" align="center">'+ nachlink+' </td><td width="25" align="center">'+ endlink+'</td></tr></table>';
        }

        wm_imgzoom_img_aktiv_src = bild;
        wm_imgzoom_img_res_timeout =  window.setTimeout("wm_imgzoom_image_resize()",500);


      }





   }



   function wm_imgzoom_quickPlayer(src){
     wm_imgzoom_tmp_href =  src;
     document.getElementById('wm_imgzoom_trans').style.visibility = 'visible';
     document.getElementById('wm_imgzoom_trans').style.height = document.body.scrollHeight + 'px';
     document.getElementById('wm_imgzoom_trans').style.width  = document.body.scrollWidth + 'px';
     document.getElementById('wm_imgzoom_zoom_bereich').style.visibility = 'visible';
     document.getElementById('wm_imgzoom_zoom_bereich_content').innerHTML = '';
     document.getElementById('wm_imgzoom_zoom_bereich').style.top = (document.body.scrollTop + 10) + 'px';
     document.getElementById('wm_imgzoom_zoom_bereich_iframe').style.display = '';
     document.getElementById('wm_imgzoom_dynLink').href = src;
   }


   function wm_imgzoom_close_zoomlayer(){

    wm_imgzoom_new_height = 100;
    wm_imgzoom_new_width  = 100;

    wm_imgzoom_img_dyndiv = false;
    open_location =  arguments[0]; // Optional
    window.wmImgzoomDyniframe.location.href = wm_imgzoom_WEB_URL + '/cms_scripte/load.html';
    closeTimeout =  window.setTimeout('wm_imgzoom_close_zoomlayer_step2(open_location)',50);// muss abgefragt werden bei langsameren Systemen ;-(
   }

  function wm_imgzoom_close_zoomlayer_step2(open_location){


    if(window.wmImgzoomDyniframe.location.href == wm_imgzoom_WEB_URL + '/cms_scripte/load.html'){

      wm_imgzoom_durchlauf = 0;

      document.getElementById('wm_imgzoom_trans').style.visibility = 'hidden';
      document.getElementById('wm_imgzoom_zoom_bereich').style.visibility = 'hidden';
      document.getElementById('wm_imgzoom_zoom_bereich_content').style.display = 'none';
      document.getElementById('wm_imgzoom_zoom_bereich_iframe').style.display = 'none';
      document.getElementById('wm_imgzoom_zoom_bereich_content').innerHTML = '';

      objecttag_ar = document.getElementsByTagName('object');
      if(objecttag_ar.length >= 1)
       for(i=0; i<objecttag_ar.length; i++) {
         objecttag_ar[i].style.visibility = 'visible';
       }

      embed_ar = document.getElementsByTagName('embed');
      if(embed_ar.length >= 1)
       for(i=0; i<embed_ar.length; i++) {
         embed_ar[i].style.visibility = 'visible';
       }
    }

    else{

     if(wm_imgzoom_durchlauf < 50){
      wm_imgzoom_durchlauf++;
      closeTimeout =  window.setTimeout('wm_imgzoom_close_zoomlayer(open_location)',50);

     }else{
     //alert('ERROR');
     wm_imgzoom_durchlauf = 0;
    }
    }


   }// Ende function
