function diScroller(instance_name, obj, visible_width)
{
  this.obj = _ge(obj);
  if (this.obj)
  {
    this.obj.style.position = 'relative';
    this.obj.style.left = '0px';
    this.obj.style.top = '0px';
  }

  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('/wp-content/themes/sintec/img/contact_invert.gif','/wp-content/themes/sintec/img/go_invert.gif','/wp-content/themes/sintec/img/mention_invert.gif',
    '/wp-content/themes/sintec/img/more_invert.gif','/wp-content/themes/sintec/img/ark2_invert.jpg','/wp-content/themes/sintec/img/ark_invert.jpg');

  if (typeof project_what_to_display != 'undefined' && project_what_to_display)
    show_projects_list(project_what_to_display);

  setupZoom();
}

function rollover(obj,state,fn,ext,type)
{
  var suffix = '_invert';

  if (state)
  {
    var _end = fn.substr(fn.length - 3, 3);
    if (_end == '_en' || _end == '_de')
    {
      fn = fn.substr(0, fn.length - 3);
      suffix += _end;
    }
  }

  if (obj)
  {
    var fn2 = '/wp-content/themes/sintec/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 = '/wp-content/themes/sintec/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','finished','client','type'];

function show_projects_list(type)
{
  var date = new Date();
  date.setFullYear(date.getFullYear() + 1);
  setCookie('project_filter_type', type, date, '/');

  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';
    }
  }

  reinit_jscroller();

  return false;
}

function reinit_jscroller()
{
  var els = $.jScrollPane.active;
  for (var i=0; i<els.length; i++) {
      els[i].scrollTo = els[i].scrollBy = null;
  }

  $(function(){
   $('.scroll-body').jScrollPane({
    scrollbarWidth : 18
   });
  })
}

function toggle_popup(id)
{
  var e = _ge(id);

  if (e)
  {
    e.style.display = e.style.display != 'block' ? 'block' : 'none';
  }
}

function do_login()
{
  var login = document.forms.auth_form.username;
  var password = document.forms.auth_form.user_password;

  if (login.value == 'sintec' && password.value == 'sintec')
  {
    window.location.href = 'http://89.175.98.70/';

    //return true;
    return false;
  }

  //toggle_popup('popup_login');
  //login.value = 'Логин';
  //password.value = '';

  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
}

var oh_ar = [];

function s_popup_toggle(type, id, state)
{
  var e = _ge('s_popup['+type+']['+id+']');
  var e2 = _ge('li_'+type+'_'+id+'');

  if (!oh_ar[type+'_'+id])
    oh_ar[type+'_'+id] = e.offsetHeight;

  //if (!document.body.id) document.body.id = 'da_body';

  if (state)
  {
    //var p = document.body;
    var x = getLeft(e2);
    var y = getTop(e2) - oh_ar[type+'_'+id] + 12; //8

    var p = _ge('main_page_content');
    x -= getLeft(p);
    y -= getTop(p);

    if (is_ie4up)
    {
      x -= 30;
      y += 10;
    }

    e.style.left = x+'px';
    e.style.top = y+'px';

    //alert(e.innerHTML);
    //alert(e2.innerHTML);

    /*
    if (p && e.parentNode && e.parentNode.id != 'da_body')
    {
      e.parentNode.removeChild(e);
      p.appendChild(e);
    }
    */

    e.style.display = 'block';
  }
  else
  {
    e.style.display = 'none';
  }
}

