var no_hide_image = false;
var last_width = '';
var last_height = '';

function show_image(href, width, height){  
  if ((obj1 = document.getElementById('ImagePanel')) && (obj2 = document.getElementById('ImagePanelBG'))){
    last_width = width;
    last_height = height;
                          
    obj1.style.display = 'block'; 
    obj1.innerHTML = '<img src="'+href+'" width="'+width+'" height="'+height+'">';
    
    window_resize();         
    
    no_hide_image = true;
    
    return false;        
  }
  else window.open(href, '_blank');    
}

function window_resize(){
  if (no_hide_image || ((last_width == '') && (last_height == ''))) return;
  
  if ((obj1 = document.getElementById('ImagePanel')) && (obj2 = document.getElementById('ImagePanelBG'))){
    var objs = document.getElementsByTagName('object');
    for(a = 0; a < objs.length; a++ ){
      objs[a].style.visibility = 'hidden';
    }
    
    obj2.style.display = 'block';
    obj2.style.width = Math.max(document.documentElement.clientWidth, document.body.clientWidth) + 'px';
    obj2.style.height = Math.max(document.documentElement.clientHeight, document.body.clientHeight) + 'px';         
    
    obj1.style.top = (window.pageYOffset != undefined ? window.pageYOffset + Math.floor((window.innerHeight - last_height) / 2) : document.documentElement.scrollTop  + Math.floor((document.documentElement.clientHeight - last_height - 15) / 2)) + 'px';
    obj1.style.left = (window.pageXOffset != undefined ? window.pageXOffset + Math.floor((window.innerWidth - last_width) / 2) : document.documentElement.scrollLeft  + Math.floor((document.documentElement.clientWidth - last_width - 15) / 2)) + 'px';

    if (parseInt(obj1.style.top) + last_height + 30 > Math.max(document.documentElement.clientHeight, document.body.clientHeight)) obj1.style.top = (Math.max(document.documentElement.clientHeight, document.body.clientHeight) - last_height - 30) + 'px';
    if (parseInt(obj1.style.top) < 0) obj1.style.top = '15px';
    
    if (parseInt(obj1.style.top) + last_height + 30 > parseInt(obj2.style.height)) obj2.style.height = parseInt(obj1.style.top) + last_height + 30 + 'px';          
  }
}

function hide_image(){ 
  if (no_hide_image) {    
    no_hide_image = false;
    
    return;
  } 
  
  if ((obj1 = document.getElementById('ImagePanel')) && (obj2 = document.getElementById('ImagePanelBG'))){
    last_width = '';
    last_height = '';
    obj1.style.display = 'none';  
    obj2.style.display = 'none';
    
    var objs = document.getElementsByTagName('object');
    for(a = 0; a < objs.length; a++ ){
      objs[a].style.visibility = 'visible';
    }
  }
}

window.onresize = window_resize;

