function zm_toggle(div_id) {
   var el = document.getElementById(div_id);
   if ( el.style.display == 'none' ) { el.style.display = 'block';}
   else {el.style.display = 'none';}
}
function zm_blanket_size(popUpDivVar, halfheight) {
   // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
   if (typeof window.innerWidth != 'undefined') {
      viewportheight = window.innerHeight;
   // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
   } else if (typeof document.documentElement != 'undefined'
            && typeof document.documentElement.clientHeight !=
            'undefined' && document.documentElement.clientHeight != 0) {
      viewportheight = document.documentElement.clientHeight;
   // older versions of IE
   } else {
      viewportheight = document.getElementsByTagName('body')[0].clientHeight;
   }
   if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
      blanket_height = viewportheight;
   } else {
      if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
         blanket_height = document.body.parentNode.clientHeight;
      } else {
         blanket_height = document.body.parentNode.scrollHeight;
      }
   }

   var blanket = document.getElementById('zoomBlanket');
   blanket.style.height = blanket_height + 'px';
   var popUpDiv = document.getElementById(popUpDivVar);
   popUpDiv_height=viewportheight/2-halfheight; //half popup's height
   popUpDiv.style.top = popUpDiv_height + 'px';
}
function zm_window_pos(popUpDivVar, halfwidth) {
   if (typeof window.innerWidth != 'undefined') {
      viewportwidth = window.clientWidth;
   } else if (typeof document.documentElement != 'undefined'
            && typeof document.documentElement.clientWidth !=
            'undefined' && document.documentElement.clientWidth != 0) {
      viewportwidth = document.documentElement.clientWidth;
   } else {
      viewportwidth = document.documentElement.clientWidth;
   }
   if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
      window_width = viewportwidth;
   } else {
      if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
         window_width = document.body.parentNode.clientWidth;
      } else {
         window_width = document.body.parentNode.scrollWidth;
      }
   }
   var popUpDiv = document.getElementById(popUpDivVar);
   window_width=window_width/2-halfwidth;//half popup's width
   popUpDiv.style.left = window_width + 'px';
}
function zoom_popup(windowname, halfwidth, halfheight, tourPos, maxImages) {
   window.scrollTo(0,0);
   zm_blanket_size(windowname, halfheight);
   zm_window_pos(windowname, halfwidth);
   zm_toggle('zoomBlanket');
   zm_toggle(windowname);

   //if (maxImages >= 0) {
      //zoom_reset(maxImages);
      //if (parseInt(tourPos) == parseInt(maxImages)) {
      //   zoom_switch('zmId_1', 'down', maxImages);
      //} else {
      //   var position = parseInt(tourPos)+1;
      //   zoom_switch('zmId_' + position, 'down', maxImages);
      //}
   //}
}

function zoom_reset(maxImages) {
   var images = parseInt(maxImages)+1;
   for (cnt=1;cnt<=images;cnt=cnt+1) {
      var el = document.getElementById('zmId_' + cnt);
      el.style.display = 'none';
   }
}

function zoom_switch(div_id, direction, maxImages) {
   var el = document.getElementById(div_id);
   elNumber = Right(div_id, 1);

   if ((elNumber == maxImages) && (direction == 'up')) {
      elPlus1 = 'zmId_1';
      elMinus1 = 'zmId_' + (parseInt(elNumber) - 1);
   } else if ((elNumber == 1) && (direction == 'down')) {
      elPlus1 = 'zmId_' + (parseInt(elNumber) + 1);
      elMinus1 = 'zmId_' + maxImages;
   } else {
      elPlus1 = 'zmId_' + (parseInt(elNumber) + 1);
      elMinus1 = 'zmId_' + (parseInt(elNumber) - 1);
   }

   var elPlus = document.getElementById(elPlus1);
   var elMinus = document.getElementById(elMinus1);

   if (direction == 'down') {
      el.style.display = 'none';
      elMinus.style.display = 'block';
      document.getElementById("zm_lt").href = "javascript:zoom_switch('" + elMinus1 + "', 'down', '" + maxImages + "')";
      document.getElementById("zm_gt").href = "javascript:zoom_switch('" + elMinus1 + "', 'up', '" + maxImages + "')";
   } else if (direction == 'up') {
      el.style.display = 'none';
      elPlus.style.display = 'block';
      document.getElementById("zm_lt").href = "javascript:zoom_switch('" + elPlus1 + "', 'down', '" + maxImages + "')";
      document.getElementById("zm_gt").href = "javascript:zoom_switch('" + elPlus1 + "', 'up', '" + maxImages + "')";
   }
}

function Right(str, n) {
      if (n <= 0)
          return "";
      else if (n > String(str).length)
          return str;
      else
   {
          var iLen = String(str).length;
          return String(str).substring(iLen, iLen - n);
      }
}
