// Массовая обработка событий
jQuery(function($) {
  // Your code using failsafe $ alias here...
	$(document).ready(function(){
		// Клики на скриншоты
		$(".screenshotlist a").click(function(){
//			alert((this).href);
			ShowImage((this).href);
			return false;
		});

		// Клики на отдельные скриншоты
		$(".screenshot").click(function(){
			alert((this).href);
			ShowImage((this).href);
			return false;
		});

	});

});	


function getStyle(b, a) {
    if (document.defaultView && document.defaultView.getComputedStyle) {
        return document.defaultView.getComputedStyle(b, "")[a]
    } else if (b.currentStyle) {
        return b.currentStyle[a]
    }
}	   

// Ширина и высота клиенской части браузера
// http://forum.ru-board.com/topic.cgi?forum=31&topic=11302
function get_ww() 
 {var frameWidth=800; 
 if (self.innerWidth) 
     frameWidth = self.innerWidth; 
 else if (document.documentElement && document.documentElement.clientWidth) 
     frameWidth = document.documentElement.clientWidth; 
 else if (document.body) 
     frameWidth = document.body.clientWidth; 
 return frameWidth; 
 } 
 
 function get_wh() 
 {var frameHeight=640; 
 if (self.innerHeight) 
     frameHeight = self.innerHeight; 
 else if (document.documentElement && document.documentElement.clientHeight) 
     frameHeight = document.documentElement.clientHeight; 
 else if (document.body) 
     frameHeight = document.body.clientHeight; 
 return frameHeight; 
 }

 // Показать картинку в форме
function ShowImage(FileName)
{
  var
    frmImageViewerObj, frmShadowObj, imgViewerObj,
    width, height, 
    xc, yc, 
    oldWndWidth, newWndWidth,
    scrollBarWidth;

//  alert(FileName);

  // Получение используемых форм
  frmImageViewerObj = document.getElementById('frmImageViewer');
  imgViewerObj = document.getElementById('imgViewer');
  frmShadowObj = document.getElementById('frmShadow');

  // Еслм почему-то формы не нашлись - выход
  if (!frmImageViewerObj || !frmShadowObj || !imgViewerObj)
    return; 

  // Загрузить в img рисунок
  imgViewer.src = FileName;

  imgViewer.onload = function()
  {

  // Вычислить ширину и высоту рисунка
  width =  frmImageViewerObj.offsetWidth;
  height = frmImageViewerObj.offsetHeight;

//  alert('Габариты ' + width + ' | ' + width);

  // Задание положение тени
  frmShadow.style.top = document.documentElement.scrollTop + 'px';

  // Вычислить координаты формы с рисунком - так, чтобы форма была в центре
  xc = Math.round((get_ww() - width) / 2);
  yc = Math.round((get_wh() - height) / 2) + parseInt(frmShadow.style.top);
  
//  alert('Координаты ' + xc + ' | ' + yc);

  // Задание положения окна - просмотрщика
  frmImageViewerObj.style.left = xc + 'px';
  frmImageViewerObj.style.top  = yc + 'px';

//  oldWndWidth = get_ww();

  // Запретить прокрутку
  document.body.style.overflow = 'hidden'; 

//  alert(oldWndWidth + ' | ' + newWndWidth + ' | ' + scrollBarWidth);

//  if (document.documentElement.scrollLeft) 
//    document.body.style.paddingRight = '16px';

//  document.body.onscroll = function(){return false};

  frmShadowObj.style.visibility = 'visible';
  frmImageViewerObj.style.visibility = 'visible'; 
  }
}

// Скрыть картинку с формой
function HideImage()
{
  var
    frmImageViewerObj, frmShadowObj;

  // Получение используемых форм
  frmImageViewerObj = document.getElementById('frmImageViewer');
  frmShadowObj = document.getElementById('frmShadow');

  // Еслм почему-то формы не нашлись - выход
  if (!frmImageViewerObj || !frmShadowObj)
    return;

  document.body.style.overflow = '';
//  document.body.style.paddingRight = '0px';

  window.onscroll = function(){};

  frmShadowObj.style.visibility = 'hidden';
  frmImageViewerObj.style.visibility = 'hidden';  	
}

/*
function test()
{
  alert('test');
}
*/
