function __getElementById( id )
{
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}

function getViewport()
{
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
 var arr = new Array(viewportwidth-20, viewportheight);
 return arr;
}

function imgDispClose()
{
  var root;
  root = __getElementById('bboard_showimg_img');
  root.style.display = 'none';
  document.body.removeChild(root);
  root = __getElementById('bboard_loader_img');
  if (root)
    document.body.removeChild(root);
  root = __getElementById('bboard_showimg_idiv');
  document.body.removeChild(root);
  root = __getElementById('bboard_showimg_wrapper');
  document.body.removeChild(root);
  // opera refresh bug
  if (window.opera) {
    if (document.body.style.position == 'relative')
      document.body.style.position = '';
    else
      document.body.style.position = 'relative';
  }
}

function navImgLoaded()
{
  var root = __getElementById('bboard_loader_img');
  if (root)
    document.body.removeChild(root);
  var img = __getElementById('bboard_showimg_img');
  var size = getViewport();
  //var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  //var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  var width = img.width;
  var height = img.height;
  
  var old_width = width;
  var old_height = height;
  if (width > size[0] || height > size[1])
  {
    width = size[0]-30;
    height = height*((size[0]-30)/old_width);
    if (height > (size[1]-30))
    {
      height = size[1]-30;
      width = old_width*((size[1]-30)/old_height);
    }
  }
  
  var left = Math.round((size[0]-width)/2);
  var top = Math.round((size[1]-height)/2);
  var iidiv = __getElementById('bboard_showimg_idiv');
  iidiv.style.cssText = 'left:'+(left-15)+'px;top:'+(top-15)+'px;width:'+(width+30)+'px;height:'+(height+30)+'px';
  
  img.style.cssText = 'display:inline;left:'+(left)+'px;top:'+(top)+'px;width:'+width+'px;height:'+height+'px;z-index:103';
}

function navImg(url)
{
  var idiv = document.createElement('div');
  idiv.setAttribute('id', 'bboard_showimg_wrapper');
  var size = getViewport();
  //var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  //var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  idiv.style.cssText = 'width:'+(size[0])+'px;height:'+(size[1])+'px';
  idiv.onclick = imgDispClose;
  document.body.appendChild(idiv);
  
  var width = 56;
  var height = 21;
  var left = Math.round((size[0]-width)/2);
  var top = Math.round((size[1]-height)/2);
  var iidiv = document.createElement('div');
  iidiv.setAttribute('id', 'bboard_showimg_idiv');
  iidiv.style.cssText = 'left:'+(left-15)+'px;top:'+(top-15)+'px;width:'+(width+30)+'px;height:'+(height+30)+'px';
  iidiv.onclick = imgDispClose;
  document.body.appendChild(iidiv);

  iidiv = document.createElement('img');
  iidiv.setAttribute('id', 'bboard_loader_img');
  iidiv.setAttribute('src', '/images/ajax-loader.gif');
  iidiv.style.cssText = 'left:'+(left)+'px;top:'+(top)+'px;width:'+width+'px;height:'+height+'px';
  document.body.appendChild(iidiv);
  
  iidiv = document.createElement('img');
  iidiv.setAttribute('id', 'bboard_showimg_img');
  iidiv.style.cssText = 'left:-5000px;top:0';
  //if (iidiv.complete != true)
    iidiv.onload = navImgLoaded;
  iidiv.onclick = imgDispClose;
  iidiv.setAttribute('src', url);
  document.body.appendChild(iidiv);
  if (iidiv.complete) navImgLoaded();
  return false;
}
