
/*sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
			}
			}
			
			if (window.attachEvent) window.attachEvent("onload", sfHover);*/
	








document.onclick = handle;
function handle(e) {
	e=e||window.event;
	target=(e.target)?e.target:e.srcElement;
	//alert(target.href);
	//alert(target.id);
	//alert(target.id);
	//setImage(target.href);
	
	
	if (target.id=='conteyner_img')
	{
	ShowGlassWindow(false);
	return false;
	}
	
	if (target.id=='image_button')
	{
	ShowGlassWindow(false);
	return false;
	}	
		
	while (target && target.nodeType == 1 && target.tagName.toLowerCase() != 'html')
	{
		if (target.id=='showimage')
		{
		ShowGlassWindow(true);
		setImage(target.href);
		return false;
		}
    target = target.parentNode;
	}
	
	
return true; // т.е. проследить ссылку 
}
//setImage('./images/2222222.jpg');





function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}




function getClientWidth2(){
return (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
}

function getClientHeight2(){
return (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
}







function setImage(imgUrl)
    {
        var myImg = new Image();
        myImg.onload = function(){
             //alert(1);
			 //alert(myImg.width);
			 //alert(myImg.height);
			 //alert(clsize[0]);
			 //alert(clsize[1]);
			 clsize = getClientSize();
			 
					// Вписываем картинку в размер окна,
					// если она шире, чем окно
					/*if(myImg.width > clsize[0]) {
					imw = myImg.width;
					
						while(imw > clsize[0]) {
							imw--;
						}

						//myImg.width = imw;
					}*/
					
					
					//imh = myImg.height;
					//while(imh > clsize[1]-50){
					//imh--;}
					
					
					
					if ((myImg.width<=clsize[0]-50)&&(myImg.height<=clsize[1]-50))
					{
					imw=myImg.width;
					imh=myImg.height;
					}else
					{
						if (myImg.width>=myImg.height)ratio = myImg.width/myImg.height;
						if (myImg.width<myImg.height)ratio = myImg.height/myImg.width;
						
						//больше длина
						if ((myImg.width>clsize[0]-50)&&(myImg.height<=clsize[1]-50))
						{
						imw=clsize[0]-50;
							if (myImg.width>=myImg.height)imh=Math.round(imw/ratio);
							if (myImg.width<myImg.height)imh=Math.round(imw*ratio);
						}else
						//больше высота
						if ((myImg.width<=clsize[0]-50)&&(myImg.height>clsize[1]-50))
						{
						imh=clsize[1]-50;
							if (myImg.width>=myImg.height)imw=Math.round(imh*ratio);
							if (myImg.width<myImg.height)imw=Math.round(imh/ratio);
						}else												
						//больше длина и высота
						if ((myImg.width>clsize[0]-50)&&(myImg.height>clsize[1]-50))
						{

							//больше длина
							if (myImg.width>=myImg.height)
							{
							imw=clsize[0]-50;
								imh=Math.round(imw/ratio);						
							}else
							//больше высота
							{
							imh=clsize[1]-50;
								imw=Math.round(imh/ratio);							
							}
							

						}	
						
						//if (myImg.width>=myImg.height)
						//{
						//imw=clsize[0]-50;
						//imh=Math.round(imw/ratio);
						//}else
						//{
						//imh=clsize[1]-50;
						//imw=Math.round(imh/ratio);
						//}
						
						
					}
					
					
					
					
					iml = Math.round((clsize[0]-imw)/2);
					imt = Math.round((clsize[1]-imh)/2);


             document.getElementById('image_button').style.left = iml+imw-13+'px';
             document.getElementById('image_button').style.top = imt-11+'px';			 
			 
             document.getElementById('image').style.left = iml+'px';
             document.getElementById('image').style.top = imt+'px';
             document.getElementById('image').style.height = imh+'px';
             document.getElementById('image').style.width = imw+'px';
			 document.getElementById('image').src = myImg.src;
        }
        myImg.src = imgUrl;
    }


	/*
function rere(ee)
{
	ee=ee||window.event;
	target=(ee.target)?v.target:ee.srcElement;
	
return false;
}
	*/

	

	
	

	

var isIE = window.navigator.userAgent.indexOf("MSIE")>-1; //true, если браузер - Internet Explorer
var GlassWindow=null; //ссылка на "окно-экран"
var Dialog=null; //ссылка на "окно формы"


// функция ShowGlassWindow показывает/скрывает экран
function ShowGlassWindow(show){
/*if(GlassWindow==null){
// на первом проходе создаем элемент - "полупрозрачный экран"
GlassWindow=document.createElement('DIV');
//GlassWindow.onclick = rere;
GlassWindow.id = 'conteyner_div_img';
with(GlassWindow.style){
//стили экрана после создания
display='none'; //невидим
position='absolute'; //абсолютное позиционирование
height=0; width=0;//любые значения
zIndex=1; // слой выше основного слоя документа
if(isIE){// в Internet Explorer применяем фильтр Alpha (Opacity непрозрачность)
backgroundColor = '#000000';
filter="progid:DXImageTransform.Microsoft.Alpha(Opacity=40, Style=0)";
}
else //для остальных браузеров фон из полупрозрачного PNG
backgroundImage = 'url(alfa40-fon.png)';
}
// добавлем созданный элемент в структуру документа
document.body.appendChild(GlassWindow);
}
*/
/*
if(show){
//var s = alertSize(); //размеры документа
with(GlassWindow.style){
// позиционируем экран на всю площадь документа
left = top = 0;
width = getDocumentWidth3()+'px';
height = getDocumentHeight3()+'px';
}
}
GlassWindow.style.display=show?'block':'none';*/

var s = getClientSize();
document.getElementById('conteyner_img').style.width = s[0]+'px';
document.getElementById('conteyner_img').style.height = s[1]+'px';
if (show==false)
{
document.getElementById('conteyner_img').style.width =0+'px';
document.getElementById('conteyner_img').style.height = 0+'px';
}

document.getElementById('image').src = './images/loading.gif';
document.getElementById('image').style.left = '50%';
document.getElementById('image').style.top = '50%';
document.getElementById('image').style.width = '32px';
document.getElementById('image').style.height = '32px';
document.getElementById('conteyner_img').style.display = show?'block':'none';
}


// вычисление размеров документа 
var ua = navigator.userAgent.toLowerCase();
var isOpera = (ua.indexOf('opera')  > -1);
var isIE = (!isOpera && ua.indexOf('msie') > -1);

function getDocumentHeight3() {
  return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight, getViewportHeight3());
}

function getViewportHeight3() {
  return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
}

function getDocumentWidth3() {
  return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollWidth : document.documentElement.scrollWidth, getViewportWidth3());
}

function getViewportWidth3() {
  return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientWidth : document.body.clientWidth : (document.parentWindow || document.defaultView).innerWidth;
}













//функция ShowModalWindow показывает/скрывает форму
function ShowModalWindow(show){
ShowGlassWindow(show); //показываем/скрываем экран
// получим ссылку на форму диалога (элемент с id=modal)
/*if(Dialog==null) Dialog=document.getElementById('modal');
if(show){
//позиционируем по центру окна браузера и отображаем
var c = getClientCenter();
Dialog.style.left = (c[0]-150)+'px';
Dialog.style.top  = (c[1]-75)+'px';
Dialog.style.display='block';
Dialog.focus();
}
else Dialog.style.display='none';
*/
}
/* вспомогательные функции получения размеров */






// функция кроссбраузерного вычисления размеров рабочего окна браузера 
function getClientSize(){
if(document.compatMode=='CSS1Compat')
return [document.documentElement.clientWidth, document.documentElement.clientHeight];
else
return [document.body.clientWidth, document.body.clientHeight];
}



// функция кроссбраузерного вычисления значений скроллинга 
function getDocumentScroll(){
return [
self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) 
|| (document.body && document.body.scrollLeft),
self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) 
|| (document.body && document.body.scrollTop)
];
}


// функция получения центра экрана
function getClientCenter(){
var sizes = getClientSize();
var scrl = getDocumentScroll();
return [parseInt(sizes[0]/2)+scrl[0], parseInt(sizes[1]/2)+scrl[1]];
}


