function correct_bg()
{
  var el = _ge('bottom-shadow-id');
  if(el.offsetHeight > 1166)
  {
    el.style.backgroundPosition= 'left bottom';
  }
  else
  {
    el.style.backgroundPosition= 'left top';
  }
}

//window.onresize = correct_bg;

function doc_onload()
{
  if (typeof document.getElementsByClassName == 'undefined')
  {
    document.getElementsByClassName = function(className)
    {
      var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
      var allElements = document.getElementsByTagName("*");
      var results = [];

      var element;
      for (var i = 0; (element = allElements[i]) != null; i++)
      {
        var elementClass = element.className;
        if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
          results.push(element);
      }

      return results;
    }
  }

  var t = _ge('top_menu');
  var td = is_gecko ? t.firstChild.nextSibling.firstChild.firstChild : t.firstChild.firstChild.firstChild;
  var id;

  do if (td.id) {
    id = td.id.substr(3);

    eval('addEvent(td, "mouseover", function() {show_submenu('+id+',1)});');
    eval('addEvent(td, "mouseout", function() {show_submenu('+id+',0)});');
  } while (td = td.nextSibling);

  var ar = document.getElementsByClassName('submenu1');

  for (var i = 0; i < ar.length; i++)
  {
    td = ar[i];
    id = td.id.substr(8);

    eval('addEvent(td, "mouseover", function() {show_submenu('+id+',1)});');
    eval('addEvent(td, "mouseout", function() {show_submenu('+id+',0)});');
  }
}

function show_submenu(a, flag)
{
  var e = _ge('submenu_'+a);

  if (e)
  {
    e.style.display = flag ? 'block' : 'none';
  }
}

function diScroller(instance_name, obj, visible_width, real_width)
{
  this.obj = _ge(obj);
  this.obj.style.position = 'relative';
  this.obj.style.left = '0px';
  this.obj.style.top = '0px';
  this.obj.style.width = real_width+'px';

  this.instance_name = instance_name;
  this.visible_width = visible_width;

  this.default_step = 2;
  this.step = this.default_step;
  this.timeout = 8;
  this.timer_up = null;
  this.timer_down = null;

  this.top = function()
  {
    this.obj.scrollTop = 0;
  }

  this.bottom = function()
  {
    this.obj.scrollTop = this.obj.scrollHeight;
  }

  this.left = function()
  {
    this.obj.scrollLeft = 0;
  }

  this.right = function()
  {
    this.obj.scrollLeft = this.obj.scrollWidth;
  }

  this.move_up = function()
  {
    this.obj.scrollTop -= this.step;
    this.timer_up = setTimeout(this.instance_name+'.move_up()', this.timeout);
  }

  this.move_down = function()
  {
    this.obj.scrollTop += this.step;
    this.timer_down = setTimeout(this.instance_name+'.move_down()', this.timeout);
  }

  this.move_left = function()
  {
    var l = parseInt(this.obj.style.left);

    if (l >= 0) return;

    this.obj.style.left = (l + this.step)+'px';
    this.timer_left = setTimeout(this.instance_name+'.move_left()', this.timeout);
  }

  this.move_right = function()
  {
    var l = parseInt(this.obj.style.left);

    if (l <= this.visible_width - this.obj.offsetWidth) return;

    this.obj.style.left = (l - this.step)+'px';
    this.timer_right = setTimeout(this.instance_name+'.move_right()', this.timeout);
  }

  this.point = function(x, y)
  {
    this.obj.scrollLeft = x;
    this.obj.scrollTop = y;
  }

  this.stop = function()
  {
    clearTimeout(this.timer_up);
    clearTimeout(this.timer_down);
    clearTimeout(this.timer_left);
    clearTimeout(this.timer_right);
  }
}

function init_height(bottom_logos_width)
{
  var left_menu = _ge('div-menu-side');
  var content = _ge('js-content');

  if (content)
  {
    var h = content.offsetHeight;

    if (left_menu)
      left_menu.style.minHeight = (h-200)+'px';
  }

  var e1 = _ge('bottom_logos');
  if (e1 && typeof bottom_logos_width != 'undefined')
  {
    e1.style.width = bottom_logos_width + 'px';
  }

  MM_preloadImages('/img/contact_invert.gif','/img/go_invert.gif','/img/mention_invert.gif',
    '/img/more_invert.gif','/img/ark2_invert.jpg','/img/ark_invert.jpg');

  setupZoom();
}

function rollover(obj,state,fn,ext,type)
{
  var suffix = '_invert';

  if (obj)
  {
    var fn2 = '/img/'+fn+(state?suffix:'')+'.'+ext;

    if (typeof type != 'undefined' && type == 'bg')
    {
      obj.style.backgroundImage = 'url('+fn2+')';
    }
    else
    {
      obj.src = fn2;
    }
  }
}

function rollover2(obj,state,fn,type)
{
  var dir = 'preview/';

  if (obj)
  {
    var fn2 = '/UserFiles/content/'+(!state?dir:'')+fn;

    if (typeof type != 'undefined' && type == 'bg')
    {
      obj.style.backgroundImage = 'url('+fn2+')';
    }
    else if (typeof obj.src != 'undefined')
    {
      obj.src = fn2;
    }
  }
}

var opacity_step = 5;
var big_img_height;

var pic_changer = function()
{
  if (opacity < 100)
  {
    opacity += opacity_step; // incresing new
    opacity2 -= opacity_step; // decreasing old

    di_set_opacity('project_div2', opacity);
    di_set_opacity('project_big_img', opacity2);

    _ge('project_big_img').style.height = Math.round(big_img_height + (opacity / 100) * (parseInt(_ge('project_img2').style.height) - big_img_height))+'px';
  }
  else
  {
    clearInterval(timer);

    opacity = 0;
    opacity2 = 100;

    var big_img = _ge('project_big_img');
    var img2 = _ge('project_img2');

    big_img.src = img2.src;
    big_img.style.width = img2.style.width;
    big_img.style.height = img2.style.height;
    di_set_opacity('project_big_img', 100);

    _ge('project_div2').style.display = 'none';
  }
}

function set_project_pic(id, pic, w, h)
{
  var big_img = _ge('project_big_img');
  var img2 = _ge('project_img2');

  di_set_opacity('project_div2', 0);
  _ge('project_div2').style.display = 'block'; // place another <img> w/ same pic over

  big_img_height = big_img.offsetHeight;

  clearInterval(timer);
  timer = setInterval(pic_changer, 50);

  if (img2)            // img2 has new photo inside
  {
    img2.src = pic;
    img2.style.width = w+'px';
    img2.style.height = h+'px';
  }

  if (pic_selected)
  {
    var old_img = _ge('project_img_'+pic_selected);
    if (old_img) old_img.className = 'closed';
  }

  pic_selected = id;

  var new_img = _ge('project_img_'+pic_selected);
  if (new_img) new_img.className = 'opened';

  return false;
}

var project_view_types = ['title','year','client','type'];

function show_div(id, flag)
{
  var e = _ge(id);

  if (e)
  {
    e.style.display = flag ? 'block' : 'none';
  }
}

function show_projects_list(type)
{
  for (var i = 0; i < project_view_types.length; i++)
  {
    var e_a = _ge('project_'+project_view_types[i]+'_a');
    var e_div = _ge('project_'+project_view_types[i]+'_block');

    if (project_view_types[i] == type)
    {
      e_a.className = 'b';
      e_div.style.display = 'block';
    }
    else
    {
      e_a.className = '';
      e_div.style.display = 'none';
    }
  }
}

function toggle_popup(id)
{
  var e = _ge(id);

  if (e)
  {
    e.style.display = e.style.display != 'block' ? 'block' : 'none';
  }
}

function do_login()
{
  var login = _ge('login');
  var password = _ge('password');

  if (login && password)
  {
    toggle_popup('popup_login');

    window.location.href = 'ftp://'+escape(login.value)+':'+escape(password.value)+'@ftp.ru';
  }

  return false;
}

/*
if (fadeAmount < 0) {
    setOpacity(Math.abs(zoomCurrent * fadeAmount), zoomdiv);
} else {
    setOpacity(100 - (zoomCurrent * fadeAmount), zoomdiv);
}
*/

function di_set_opacity(id, opacity)
{
  var object = _ge(id).style;

  if (navigator.userAgent.indexOf("Firefox") != -1)
  {
    if (opacity == 100) opacity = 99.9999;
  }

  object.filter = "alpha(opacity=" + opacity + ")"; // IE/Win
  object.opacity = (opacity / 100);                 // Safari 1.2, Firefox+Mozilla
}

function replace_elem(id1, id2)
{
  if (typeof id1 == 'string') id1 = [id1];
  if (typeof id2 == 'string') id2 = [id2];

  for (var i = 0; i < id1.length; i++)
  {
    var e1 = _ge(id1[i]);
    if (e1) e1.style.display = 'none';
  }

  for (var i = 0; i < id2.length; i++)
  {
    var e2 = _ge(id2[i]);
    if (e2) e2.style.display = '';
  }

  return false;
}

function show_reply_form(before_obj_id, parent)
{
  var a = _ge(before_obj_id);

  if (!a || !comment_reply_div || !comment_parent) return false;

  a.parentNode.insertBefore(comment_reply_div, a);
  comment_reply_div.style.display = 'block';

  comment_parent.value = parent;

  return false;
}

