// JavaScript Document
// Copyright 2008 "DM-soft" company limited
 waitpic = new Image();
 waitpic.src='html/slices/wait.gif';

 htpic = new Image();
 htpic.src='html/slices/halftranspix.png';

 htdpic = new Image();
 htdpic.src='html/slices/halftransdarkpix.png';


 function GetElOffset(el)
 {
	  var offset = [];
	  
	  pleft=0;
      ptop=0;  
   
      pNode=el; 
	  
      while(pNode&&pNode.tagName!='BODY')
      {
	   	if(pNode.tagName!='TR')
	   	{
		   pleft+=pNode.offsetLeft;
		   ptop+=pNode.offsetTop;		  	   
		}
		pNode=pNode.parentNode;
      }	
	  
	  offset[0]=pleft;
	  offset[1]=ptop;
	  
	  return offset;
 }

 function AlignTabBG(tabname)
 {
  var oTable = document.getElementById(tabname);
  if(oTable)
  {
   var pleft=0;
   var ptop=0;  
   var pNode;
  
   var RowsLength = oTable.rows.length;
   for (var i=0; i < RowsLength; i++)
   {
    var oCells = oTable.rows.item(i).cells;
    var CellsLength = oCells.length;
    for (var j=0; j < CellsLength; j++) 
    {
     var el=oCells.item(j); 
     if(el.className=='dots')
     {
	  
	  var offset=GetElOffset(el);
	  
	  var posit=(-offset[0])+'px '+(-offset[1])+'px';
	  el.style.backgroundPosition=posit;
	  //el.innerHTML="<div style=\"background-color:#ff0000; position: absolute;\">"+posit+"</div>"+el.innerHTML;
	 } 
    }
   }  
  } 
 }

 function ResizeAll()
 {
  AlignTabBG('premaintab');
  AlignTabBG('maintab');
  AlignTabBG('menutab');
  AlignTabBG('logotab');  
  AlignTabBG('contenttab');
 }
 
 function ShowTitle(project,x,y)
 {
  var el=document.getElementById('title'+project);
  var pic=document.getElementById('pic'+project);
  var offset=GetElOffset(pic);
  
  if(document.all)
  {
	  if(location.href=='http://menmachines.ru/index.htm' || location.href=='http://menmachines.ru/index.htm#')
	   offset[0]-=6;
	  else
	   offset[0]-=8;
	  offset[1]+=40;
  }
  else
  {
	  if(location.href=='http://menmachines.ru/index.htm' || location.href=='http://menmachines.ru/index.htm#')
	   offset[0]-=5;
  }
   
  el.style.display='';  
  el.style.left=(offset[0]+5)+'px';
  el.style.top=(offset[1]+7-el.offsetHeight/2)+'px';    
 }
 
 function HideTitle(project)
 {
  var el=document.getElementById('title'+project);
  el.style.display='none';
 }  
 
 function SubMenu(num)
 {
  MainMenu(num);
  var el=document.getElementById('menu'+num);

  if(num==1)el.innerHTML="<div style=\"height:60px; width:157px;\" align=\"center\" OnMouseOver=\"smover=true;\" OnMouseOut=\"smover=false;\"><div style=\"width:75; padding-top:8;\" align=\"left\" OnMouseOver=\"smover=true;\" OnMouseOut=\"smover=false;\"><a href=\"index.htm\">приветствие</a><br><a href=\"mission.htm\">миссия</a><br><a href=\"news.htm\">новости</a></div></div>"; 

  if(num==2)el.innerHTML="<div style=\"height:60px; width:157px;\" align=\"center\" OnMouseOver=\"smover=true;\" OnMouseOut=\"smover=false;\"><div style=\"width:90; padding-top:8;\" align=\"left\" OnMouseOver=\"smover=true;\" OnMouseOut=\"smover=false;\"><a href=\"portfolio.htm\">автоматизация</a><br><a href=\"portfolio.htm?sites\">сайты</a><br><a href=\"portfolio.htm?other\">кое-что еще</a></div></div>";    
  
  if(num==3)el.innerHTML="<div style=\"height:60px; width:157px;\" align=\"center\" OnMouseOver=\"smover=true;\" OnMouseOut=\"smover=false;\"><div style=\"width:90; padding-top:0;\" align=\"left\" OnMouseOver=\"smover=true;\" OnMouseOut=\"smover=false;\"><a href=\"automation.htm\">автоматизация</a><br><a href=\"program.htm\">разработка ПО</a><br><a href=\"sites.htm\">сайты и другое</a><br><a href=\"tech.htm\"><b>технологии</b></a></div></div>";

  window.setTimeout("document.getElementById('maintab').onmouseover=function(){MainMenu("+num+");}",20);
 }	  
 
 function MainMenu(num)
 {
  if(!smover)
  {
   //var el=document.getElementById('menu'+num);
   document.getElementById('menu1').innerHTML="<a href=\"index.htm\" onMouseOver=\"SubMenu(1);\">о компании</a>";
   document.getElementById('menu2').innerHTML="<a href=\"portfolio.htm\" onMouseOver=\"SubMenu(2);\">портфолио</a>";
   document.getElementById('menu3').innerHTML="<a href=\"services.htm\" onMouseOver=\"SubMenu(3);\">услуги</a>";   
   window.setTimeout("document.getElementById('maintab').onmouseover=function(){}",20);
  } 
 }	  
 
 function ShowPageWin(source,w,h)
 {
  var posx=(screen.width-w)/2
  var posy=(screen.height-h)/2
  var wnd=window.open(source,'_blank','top='+posy+',left='+posx+',status=no,toolbar=no,menubar=no,location=no,width='+w+'pt,height='+h+'pt');
  wnd.focus();
 }
 
 function PortHeight()
 {
  var el=document.getElementById('portdiv');
  var padd=el.style.paddingTop;
  var padding=padd.replace('px','');
  
  if(document.all)
   return el.offsetHeight;
  else
   return (el.offsetHeight+(padding-0));  
  
 }
 
 function SetPortHeight(val)
 {
  var el=document.getElementById('portdiv');
  var padd=el.style.paddingTop;
  var padding=padd.replace('px','');

  if(document.all)
   el.style.height=val;
  else
   el.style.height=val-padding;
 }
 
 function AlignPageDiv()
 {
  var el=document.getElementById('portdiv');
  var premaintab=document.getElementById('premaintab');
  var winheight=0;

  if(premaintab.offsetHeight>el.offsetHeight)
   SetPortHeight(premaintab.offsetHeight);
  else
   premaintab.style.height=el.offsetHeight;

  ResizeAll();
 }
 
 function ShowPageDiv(source, minoffset)
 {
  var el=document.getElementById('portdiv');
  var premaintab=document.getElementById('premaintab');
  if(!minoffset)minoffset=0;
  var scrollTop=document.body.scrollTop;
  
  var escript=document.createElement("SCRIPT");
  escript.src=source;
  document.body.appendChild(escript);
  
  el.style.paddingTop=Math.max(scrollTop,minoffset)+'px';   
  el.style.display='';
  
  AlignPageDiv();
 }   
 
 function ShowPortDiv(id,wtype)
 {
  ShowPageDiv('html/html/showwork.php?'+wtype+'='+id+'&rand=<? echo rand(); ?>',5);
 } 
 
 function ShowNewsDiv(id)
 {
  ShowPageDiv('html/html/shownews.php?news='+id+'&rand=<? echo rand(); ?>',105);
 }  
 
 function ClosePortDiv()
 {
  //if(!dontclose)
  {
   var premaintab=document.getElementById('premaintab');
   var el=document.getElementById('portdiv')
   el.innerHTML='';
   el.style.height='';
   el.style.display='none';
   premaintab.style.height='100%';  
  }
  dontclose=false; 
  ResizeAll();
 }
 
 function NextPic()
 {
  //dontclose=true;
  
  if(picscount>cpnum)
  {
   cpnum++;
   document.getElementById('wpicture').src=pic[cpnum].src;
  }
  
  if(cpnum>1)
   document.getElementById('larrovdiv').style.display='';
  else
   document.getElementById('larrovdiv').style.display='none';

  if(picscount>cpnum)
   document.getElementById('rarrovdiv').style.display='';
  else
   document.getElementById('rarrovdiv').style.display='none';
  
 }
 
 function PrevPic()
 {
  //dontclose=true; 
  
  if(cpnum>1)
  {
   cpnum--;
   document.getElementById('wpicture').src=pic[cpnum].src;
  }
  
  if(cpnum>1)
   document.getElementById('larrovdiv').style.display='';
  else
   document.getElementById('larrovdiv').style.display='none';

  if(picscount>cpnum)
   document.getElementById('rarrovdiv').style.display='';
  else
   document.getElementById('rarrovdiv').style.display='none';  
 }
 
 var smover=false;
 var smdover=false;
 var dontclose=false;