//resize popUp окна для схемы проезда 
function psPopImg2(obj)
{
	
				var new_chema = window.open(obj.href, "", "resizable=1,HEIGHT=200,WIDTH=200,scrollbar=1");
				with(new_chema.document)
				{
					open();
					write('<ht'+'ml><he'+'ad><ti'+'tle>Схема проезда</ti'+'tle><sc'+'ript language="javascript">function fitPic(){iWidth = document.body.clientWidth;iHeight = document.body.clientHeight;iWidth = document.images[0].width - iWidth;iHeight = document.images[0].height - iHeight;window.resizeBy(iWidth, iHeight-1);var sw=(document.body.clientWidth-iWidth)/2;var sh=(document.body.clientHeight-iHeight)/2;if (sh<0) sh=0; if (sw<0) sw=0;window.moveTo(sw,sh);self.focus();}</scr'+'ipt></he'+'ad><bo'+'dy onload="fitPic();" style="margin:0;padding:0;"><img src="'+obj.href+'" border="0" '+' alt="Схема проезда" title="Схема проезда" /></bo'+'dy></ht'+'ml>');
					close();
				}
			
  return false;	
}

/*оригинал во write
http://www.sitepoint.com/article/resize-popup-fit-images-size
function fitPic() {
				//размер окна
				iWidth = document.body.clientWidth;
				iHeight = document.body.clientHeight;
				iWidth = document.images[0].width - iWidth;
				iHeight = document.images[0].height - iHeight;
				window.resizeBy(iWidth, iHeight-1);
				//позиционирование окна в мониторе :D
				var sw=(document.body.clientWidth-iWidth)/2;
				var sh=(document.body.clientHeight-iHeight)/2;
				if (sh<0) sh=0; if (sw<0) sw=0;
				window.moveTo(sw,sh);
				self.focus();
			};

*/


var resId=0;
var imgWndw;
function psPopImg(imgLink, Title) {
  if (typeof(window.resizeBy)=='undefined') return true;
  var sl=(document.body.clientWidth-100)/2;
  var st=(document.body.clientHeight-100)/2;
  imgWndw=window.open(imgLink,'swnd','width=50,height=50,toolbar=no,menubar=no,location=no,status=no,resizable=yes,scrollbars=no,left='+sl+',top='+st);
  imgWndw.focus();
  with (imgWndw.document){
    open();
    write('<ht'+'ml><he'+'ad><ti'+'tle>'+Title+'</ti'+'tle>'+ '</he'+'ad><bo'+'dy leftmargin="0" topmargin="0" '+ 'rightmargin="0" bottommargin="0" marginwidth="0" '+ 'style="margin:0;padding:0;position:fixed;overflow:none;" '+ 'marginheight="0"><img src="'+imgLink+'" border="0" '+ ' alt="'+Title+'" title="'+Title+'" /></bo'+ 'dy></ht'+'ml>');
    close();
  }
  resId=setInterval('psImgResize()',100);
  return false
}

function psPopPage(pageLink,width,height,scrollShow,panelOption){
  width = (width && width !== 'auto')?width:(document.body.clientWidth-100)/1.4;
  height = (height && height !== 'auto')?height:(document.body.clientHeight-100)/1.4;
  scrollShow = (scrollShow == 'no')?'no':'yes';
  if (panelOption == 0 ) panel = 'toolbar=no,menubar=no,location=no';
  else if (panelOption == 2 ) panel = 'toolbar=yes,menubar=yes,location=yes';
  else panel = 'toolbar=no,menubar=yes,location=no';

  popupWin = window.open(pageLink, '', 'width='+width+',height='+height+','+panel+',status=yes,resizable=yes,scrollbars='+scrollShow+',left=50,top=50');
  popupWin.focus();
  return false
}

function psImgResize() {
  var w=imgWndw.document.images[0].width;
  if (w>screen.availWidth) w=screen.availWidth;
  var h=imgWndw.document.images[0].height;
  if (h>screen.availHeight) h=screen.availHeight;
  if (w>50 && h>50) {
    var ww=(imgWndw.innerWidth)?imgWndw.innerWidth:((document.body)? imgWndw.document.body.clientWidth:null);
    var wh=(imgWndw.innerHeight)?imgWndw.innerHeight:((document.body)? imgWndw.document.body.clientHeight:null);
    if (ww && wh) {imgWndw.resizeBy(w-ww,h-wh);
    var sw=(document.body.clientWidth-w)/2;
    var sh=(document.body.clientHeight-h)/2;
    if (sh<0) sh=0; if (sw<0) sw=0;
    imgWndw.moveTo(sw,sh);
    }
    imgWndw.focus();
    clearInterval(resId)
  }
}

function psShowHide(id){
	var showObj=document.getElementById(id).style
	if (showObj.display=="none")
		{showObj.display=""}
	else {showObj.display="none"}
}

function psPreloadImg(url){
	var image = new Image();
	image.src = url;	
}

isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;

function getelementbyid(myid) {
   if (isNS4){
        objElement = document.layers[myid];
     }else if (isIE4) {
        objElement = document.all[myid];
     }else if (isIE5 || isNS6) {
             objElement = document.getElementById(myid);
     }
return(objElement);
}


function getPos(el,sProp) {
	var iPos = 0;
	while (el!=null) {
		iPos+=el["offset" + sProp]
		el = el.offsetParent
	}
	return iPos

}



cm=null;
hide_delay=500;
tstat=0;



// Функция отображающая и скрывающая слои

// Вход:
// objElement - идентификатор(id) слоя;
// bolVisible - булева переменная:
// true  - отобразить слой;
// false - скрыть слой.

// Выход:
// 1


// P.S: В зависимости от типа браузера
// сценарий для манипуляции с видимостью слоёв
// несколько различается.

function switchDiv(objElement,bolVisible){
if(isNS4||isIE4){
     if(!bolVisible) {
       objElement.visibility ="hidden"
     } else {
       objElement.visibility ="visible"
     }     
 } else if (isIE5 || isNS6) {
      if(!bolVisible){
         objElement.style.display = "none";
         
      } else {
        objElement.style.display = "";
        
        }

      }

return 1;
}





// Функция отображающая|скрывающая
// ,а предварительно ещё и передвигающая
// должным образом слои.


// Вход:
// el - яйчейка таблицы на которой 
// находится указатель;
// m  - наименование слоя, который надо
// отобразить под этой яйчейкой.

function show(el,m) {

// Если имеется видимый слой,
// сделать его невидимым.

 if (cm!=null) {
 switchDiv(cm,false);
 }


// Если указано название слоя для отображения,
// то:
// 1) Получить его объект;
// 2) X слоя = X яйчейки;
// 3) Y слоя = Y яйчейки + высота яйчейки;
// 4) Сделать слой видимым;
// 5) Сохранить копию слоя в cm.  


 if (m!=null) {
 m=getelementbyid(m);
 m.style.left = getPos(el,"Left")+el.offsetWidth+"px";
 m.style.top =  getPos(el,"Top")+"px";
 switchDiv(m,true);
 cm=m;

 }

}




function hidemenu() {

timer12=setTimeout("show(null,null)",hide_delay);

tstat=1;

return 1;
}



function cancelhide() {
 if (tstat==1) {
 clearTimeout(timer12);
 tstat=0;
 }
return 1;
}

$(document).ready(function(){
    if($(".headerSlider").length>0)
    {
        $('.headerSlider').cycle({
            fx: 'fade',
            speed: 1500,
            timeout: 7000
        });
    } 
    
    if($(".fancy").length>0)
    {
        $(".fancy").fancybox({});
    }
});
