var curx = 0;
var agent = navigator.userAgent.toLowerCase();
var ie = (agent.indexOf('msie')!=-1);
var movetimer = null;

function OpenNote() {
  if (operating) return;
  clearInterval(a); clearInterval(b);
  operating = 1;
  not.style.display = 'none';
  big.style.display = '';
  max = parseInt(big.clientHeight) - 110;
  big.style.height = '80px';
  a = setInterval("if (parseInt(big.style.height) > max) {clearInterval(a);SetOperate(0);}else{big.style.height = (parseInt(big.style.height) + 10)+'px'}", 5);
}
function CloseNote() {
  if (operating) return;
  clearInterval(a); clearInterval(b);
  operating = 1;
  b = setInterval("if (parseInt(big.style.height) < 80 ) {clearInterval(b);SetOperate(0);not.style.display = '';big.style.display='none';big.style.height='';}else{ big.style.height = (parseInt(big.style.height) - 10)+'px'}", 5);
}
function SetOperate(val) {
  setTimeout('operating = '+val, 500);
}
function CursorX(e) {
  if (!e) e = window.event;
  var offsetx;
  if (ie) {
    offsetx = document.documentElement.scrollLeft;
  } else {
    offsetx = window.pageXOffset;
  }
  offsetx = 0;
  zoffset = 0;
  if (e && e.clientX) zoffset = e.clientX;
  return (offsetx + zoffset);
}

function PosX(obj)
{
  var curleft = 0;
  if(obj.offsetParent)
      while(1)
      {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.x)
      curleft += obj.x;
  return curleft;
}


function KbdNavigate(e)
{
  if (!e) e = window.event;

  if (e.ctrlKey) {
    var link = null;
    switch (e.keyCode ? e.keyCode : e.which ? e.which : null) {
      case 0x25:
        link = document.getElementById('headlink_prev');
        break;
      case 0x27:
        link = document.getElementById('headlink_next');
        break;
    }
    if (link && link.href) document.location = link.href;
  }
}
document.onkeydown = KbdNavigate;

function DatsOpera() {
  if (!!window.opera && document.getElementById('portfolio_ctrl')) {
    document.getElementById('portfolio_ctrl').innerHTML = 'shift+ctrl';
  }
}

function InitPaintMove(e) {
  if (!e) e = window.event;

  curx = CursorX(e);

  if (!p1.style.right) {
    SetInitPaintMove();
  }

  p1.style.cursor = p2.style.cursor = 'move';
  document.onmousemove = PaintMove;
  document.onmouseup = StopPaintMove;
  document.onselectstart = ReturnFalse;

  p1.ondblclick = p2.ondblclick = ReturnPaintMove;

  return false;
}
function ReturnFalse() {
  return false;
}


function SlowlyMove(posix, slower) {

  if (!this.moving) {
    this.speed = -5;
    this.acel = -2.4;
    if (slower) {
      this.speed = -1;
    }
    this.moving = 1;

  }

  if (p1.sright < 10)
    acel = 20;

  if (this.speed < 70)
    this.speed += acel;

  if (acel > 0 && p1.sright + this.speed > 2) {
    this.moving = false;
    SetInitPaintMove();
    return false;
  }

  p1.sright += this.speed;
  p2.sright += this.speed;
  psh.spostop += this.speed / 2;

  p1.style.right = p1.sright + 'px';
  p2.style.right = p2.sright + 'px';
  psh.style.top = psh.spostop + 'px';

  setTimeout('SlowlyMove(' + posix + ')', 1);
}

function SetInitPaintMove() {
  p1.sright = 2;
  p2.sright = 54;
  psh.spostop = 0;

  p1.style.right = p1.sright + 'px';
  p2.style.right = p2.sright + 'px';
  psh.style.top = psh.spostop + 'px';
}


function ReturnPaintMove(e) {
  movetimer = setTimeout('SlowlyMove(2);', 1);
}
function PaintMove(e) {
  if (!e) e = window.event;
  dif = curx - e.clientX;


  if (p1.sright + dif < 2 || e.clientX < 100) return;
  curx = e.clientX;

  p1.sright += dif;
  p2.sright += dif;
  psh.spostop += dif / 2;

  p1.style.right = p1.sright + 'px';
  p2.style.right = p2.sright + 'px';
  psh.style.top = psh.spostop + 'px';

}
function StopPaintMove(e) {
  if (!e) e = window.event;

  document.onmousemove = null;
  document.onmouseup = null;
  document.onselectstart = null;
  p1.style.cursor = p2.style.cursor = '';
  return false;
}

function FirstLook() {
  p1.sright = 22;
  p2.sright = 74;
  psh.spostop = 10;

  p1.style.right = p1.sright + 'px';
  p2.style.right = p2.sright + 'px';
  psh.style.top = psh.spostop + 'px';

  setTimeout('SlowlyMove(2, 1)', 2000);
}

function OpenPic(node, width, height) {
  ur = node.href;
  str = '';
  title = node.title;
  if (!title)
    title = node.firstChild.title;
  
  if (width) {
    str += ',width=' + (width + 53);
    str += ',left=' + parseInt((screen.availWidth - (width + 53)) / 2)
  }
  if (height) {
    str += ',height=' + (height + 66);
    str += ',top=' + parseInt((screen.availHeight - (height + 66)) / 2)
  }
  
  resWidth = 61;
  resHeight = 115;
  if (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1) {
    resWidth = 65;
    resHeight = 117;
  } else if (navigator.userAgent.toLowerCase().indexOf("msie 7.") != -1) {
    resWidth = 67;
    resHeight = 130;
  }
  
  opts = 'resizable=yes,location=no,menubar=no,titlebar=no,scrollbars=yes,status=no,toolbar=no,fullscreen=no,dependent=yes'+str;
  var a = window.open('about:blank','imagDetail',opts);
  var html = "<html><head><link type='text/css' rel='stylesheet' href='/css/main.css' /><\/head>";
  html += "<body style='margin:0px; text-align: center; vertical-align: middle'><div style='padding: 10px'>";
  html += "<img onclick='window.close()' ";
  html += "onload=\"window.resizeTo(Math.min(screen.availWidth+"+resWidth+",this.width+"+resWidth+"),Math.min(screen.availHeight+"+resHeight+",this.height+"+resHeight+"))\" ";
  html += "style='cursor:pointer; padding-bottom:10px' src='"+ur+"' alt='Закрыть' title='Закрыть' \/>";
  html += "<div>"+title+"<\/div>";
  html += "<\/div><\/body><\/html>";
  a.document.write(html);
  a.document.close();
  return false;
}


if (document.images) {       
// картинки после наведения курсора     
img1on = new Image();   
img1on.src = "images/clients.png"; 
// картинки после отведения курсора
img1off = new Image();        
img1off.src = "images/clients2.png"; 
}
function imgOn(imgName) {
if (document.images) {
item = document.getElementById(imgName);
item.src = eval(imgName + "on.src");        }}
function imgOff(imgName) {
if (document.images) {
item = document.getElementById(imgName);
item.src = eval(imgName + "off.src");        }}

/*

function hide(idName)
{
    var theMenu = document.getElementById(idName);
    theMenu.style.display = 'none';
}

function show(idName)
{
    var theMenu = document.getElementById(idName);
    theMenu.style.display = 'block';
}
 */