// --- Common ---

function $(el) {
  return (typeof(el) == 'string' ? document.getElementById(el) : el);
}

function $_(id, container, tag) {
  if (typeof(id) != 'string') return id;
  if (!container) return document.getElementById(id); 
  var list = container.getElementsByTagName(tag ? tag.toUpperCase() : '*');
  for (var i = 0, l = list.length; i < l; i++) {
    var el = list[i];
    if (el.id == id) return el;
  }
  return null;
}

function getAbsPos(el) {
  var pos = {left:0, top:0};
  while (el && el.tagName != 'BODY') {
    pos.left += el.offsetLeft;
    pos.top += el.offsetTop;
    el = el.offsetParent;
  }
  return pos;
}

function getAbsTop(el) {
  var top = 0;
  while (el && el != document.body) {
    top += el.offsetTop;
    el = el.offsetParent;
  }
  return top;
}

function findSubChild(element, tag, className) {
  var list = element.getElementsByTagName(tag.toUpperCase());
  if (className == null) return (list.length > 0 ? list[0] : null);
  for (var i = 0, l = list.length; i < l; i++) {
    var el = list[i];
    if (el.className == className) return el;
  }
  return null;
}

function findParentNode(el, tag) {
  if (el == null) return null;
  tag = tag.toUpperCase();
  do {
    el = el.parentNode;
  } while (el != null && el.tagName != tag)
  return el;
}

function trim(s) { return s.replace(/^\s+/, '').replace(/\s+$/, '') }

var
  userAgent = navigator.userAgent,
  isKHTML = (userAgent.indexOf('KHTML') >= 0),
  isOpera = (userAgent.indexOf('Opera') >= 0),
  isIE = (!isOpera && userAgent.indexOf('MSIE') >= 0),
  isIE50 = (isIE && /MSIE 5\.0/.test(userAgent) && navigator.platform == 'Win32'),
  isMozilla = (!isKHTML && !isOpera &&  userAgent.indexOf('Gecko') >= 0);

function setupEvent(el, eventType, handler, capture) {
  if (el.attachEvent) el.attachEvent('on'+eventType, handler)
  else if (el.addEventListener) el.addEventListener(eventType, handler, capture);
}

function removeEvent(el, eventType, handler, capture) {
  if (el.detachEvent) el.detachEvent('on'+eventType, handler)
  else if (el.removeEventListener) el.removeEventListener(eventType, handler, capture);
}

function cancelEvent(event) {
  event.returnValue = false;
  if (event.preventDefault) event.preventDefault();
  event.cancelBubble = true;
  if (event.stopPropagation) event.stopPropagation();
}

function isLeftButtonEvent(event) {
  if (isIE) {
    if (event.button == 1) return true;
  } else 
    if (event.button == 0) return true;
  return false;
}

var
  mouseMoveListeners = [],
  mouseAbsPosX = 0,
  mouseAbsPosY = 0;

function addMouseMoveListener(handler, object) {
  var i, o;
  for (i = 0; i < mouseMoveListeners.length; i++) {
    o = mouseMoveListeners[i];
    if (o.method == handler && o.instance == object) return false;
  }
  if (mouseMoveListeners.length == 0)
    setupEvent(document, 'mousemove', mouseMoveEventHandler);
  mouseMoveListeners.push({method: handler, instance: object});
  return true;
}

function removeMouseMoveListener(handler, object) {
  var i, o;
  for (i = 0; i < mouseMoveListeners.length; i++) {
    o = mouseMoveListeners[i];
    if (o.method == handler && o.instance == object) {
      mouseMoveListeners.splice(i, 1);
      if (mouseMoveListeners.length == 0)
        removeEvent(document, 'mousemove', mouseMoveEventHandler);
      return;
    }
  }
}

function mouseMoveEventHandler(event) {
  if (document.body == null) return;
  mouseAbsPosX = event.clientX + document.body.scrollLeft;
  mouseAbsPosY = event.clientY + document.body.scrollTop;
  var i, o;
  for (i = 0; i < mouseMoveListeners.length; i++) {
    o = mouseMoveListeners[i];
    if (o.method) o.method.call(o.instance || window, event);
  }
}


function isNumber(prm) {
  return (typeof(prm.valueOf()) == 'number');
}

function isString(prm) {
  return (typeof(prm.valueOf()) == 'string');
}

function isFunction(prm) {
  return (typeof(prm.valueOf()) == 'function');
}

function isArray(prm) {
  return (typeof(prm.valueOf()) == 'array' || (typeof(prm) == 'object' && 'join' in prm));
}


if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function(item, first) {
    for (var i = first || 0; i < this.length; i++) {
      if (this[i] == item) return i;
    }
    return -1;
  }
}

Array.prototype.addItem = function(item) {
  var i = this.indexOf(item);
  if (i < 0) {
    i = this.length;
    this.push(item);
  }
  return i;
}

Array.prototype.removeItem = function(item) {
  var i = this.indexOf(item);
  if (i >= 0) this.removeItemByIndex(i, true);
  return i;
}

Array.prototype.removeItemByIndex = function(i, shrink) {
  if (shrink) {
    if (this.splice) this.splice(i, 1)
    else {
      for (var j = i+1; j < this.length; j++) this[j-1] = this[j];
      this.length = this.length-1;
    }
  } else {
    if (i < this.length-1) this[i] = null
    else {
      do { this.length = (i--) } while (i >= 0 && this[i] == null);
    }
  }
  return true;
}

//-- Zoom --

var
  zoomingElements = [],
  zoomingFastToSlow = true;

// grow: D - down, R - right, F - fast to slow, S - slow to fast, '+' - open, '-' - close
function zoom(el, grow, delta, delay) {
  el = $(el);
  if (el.zoomIntervalId) {
    clearInterval(el.zoomIntervalId);
    el.zoomIntervalId = null;
    el.zooming = false;
  }
  var direction = '', action = '', fast = null;
  if (grow) {
    grow = grow.toUpperCase();
    if (grow.indexOf('R') >= 0) direction = 'R'
    else if (grow.indexOf('D') >= 0) direction = 'D';
    if (grow.indexOf('+') >= 0) action = '+'
    else if (grow.indexOf('-') >= 0) action = '-';
    if (grow.indexOf('F') >= 0) fast = true
    else if (grow.indexOf('S') >= 0) fast = false;
  }
  if (direction == '') direction = (el.zoomDirection || 'D');  // down
  el.zoomDirection = direction;
  var offsetProp = (direction == 'D' ? 'offsetHeight' : 'offsetWidth');
  var styleProp = (direction == 'D' ? 'height' : 'width');
  if (action == '') {
    if (el.zoomAction) action = (el.zoomAction == '+' ? '-' : '+')
    else action = (el[offsetProp] > 0 ? '-' : '+');
  }
  el.zoomAction = action;
  if (fast == null) fast = el.zoomingFastToSlow || zoomingFastToSlow;
  el.zoomingFastToSlow = fast;
  if (delta == 'quick') {
    if (action == '+') {
      el.style.display = 'block';
      el.style.visibility = 'visible';
      el.style[styleProp] = (el.zoomMaxSize ? el.zoomMaxSize+'px' : '');
    } else {
      el.style.display = 'none';
    }
    el.zoomCurSize = el[offsetProp];
    if (el.afterZoom) {
      var i = zoomingElements.addItem(el);
      setTimeout('callAfterZoom('+i+')', 0);
    }
    el.zoomed = (action == '+');
    return;
  }
  el.zoomAlpha = 1.4;
  el.style.overflow = 'hidden';
  if (action == '+') {
    el.style.display = 'block';
    if (el.zoomMaxSize) el.zoomNewSize = el.zoomMaxSize
    else {
      el.style[styleProp] = '';
      el.zoomNewSize = el[offsetProp];
    }
    if (fast) {
      el.zoomCurEzis = el.zoomNewSize/el.zoomAlpha;
      el.zoomCurSize = el.zoomNewSize - el.zoomCurEzis;
    } else {
      if (!el.zoomCurSize) el.zoomCurSize = 1;
    }
  } else {
    if (fast) {
      if (!('zoomCurSize' in el)) el.zoomCurSize = el[offsetProp]/el.zoomAlpha;
      else el.zoomCurSize = el.zoomCurSize/el.zoomAlpha;
    } else {
      el.zoomCurEzis = 1;
      if (!('zoomCurSize' in el)) el.zoomCurSize = el[offsetProp];
      el.zoomCurSize -= el.zoomCurEzis;
    }
    el.zoomNewSize = 0;
  }
  el.zoomDelta = delta;
  el.style.visibility = 'visible';
  el.style[styleProp] = Math.round(el.zoomCurSize)+'px';
  var h = el[offsetProp];  // to prevent show full block in Fx
  el.zoomed = false;
  el.zooming = true;
  var i = zoomingElements.addItem(el);
  el.zoomIntervalId = setInterval('stepZooming('+i+')', delay || 50);
}

function stepZooming(i) {
  var el = zoomingElements[i];
  if (!el) return;
  var styleProp = (el.zoomDirection == 'D' ? 'height' : 'width');
  var finished = false;
  if (el.zoomDelta) {
    if (el.zoomAction == '+') {
      el.zoomCurSize += el.zoomDelta;
      if (el.zoomCurSize >= el.zoomNewSize) {
        el.zoomCurSize = el.zoomNewSize;
        finished = true;
      }
    } else {
      el.zoomCurSize -= el.zoomDelta;
      if (el.zoomCurSize < 1) {
        el.zoomCurSize = 0;
        finished = true;
      }
    }
  } else {
    if (el.zoomAction == '+') {
      if (el.zoomingFastToSlow) {
        var prevSize = el.zoomCurSize;
        el.zoomCurEzis = el.zoomCurEzis/el.zoomAlpha;
        el.zoomCurSize = el.zoomNewSize - el.zoomCurEzis;
        if (Math.round(el.zoomCurSize) == Math.round(prevSize)) {
          el.zoomCurSize = el.zoomNewSize;
          finished = true;
        }
      } else {
        el.zoomCurSize = el.zoomCurSize*el.zoomAlpha;
        if (el.zoomCurSize >= el.zoomNewSize) {
          el.zoomCurSize = el.zoomNewSize;
          finished = true;
        }
      }
    } else {
      if (el.zoomingFastToSlow) {
        el.zoomCurSize = el.zoomCurSize/el.zoomAlpha;
      } else {
        el.zoomCurEzis = el.zoomCurEzis*el.zoomAlpha;
        el.zoomCurSize -= el.zoomCurEzis;
      }
      if (el.zoomCurSize < 1) {
        el.zoomCurSize = 0;
        finished = true;
      }
    }
  }
  if (!finished) {
    el.style[styleProp] = Math.round(el.zoomCurSize)+'px';
  } else {
    clearInterval(el.zoomIntervalId);
    el.zoomIntervalId = null;
    el.zooming = false;
    el.zoomed = (el.zoomCurSize > 0);
    if (el.zoomCurSize == 0) el.style.display = 'none';
    el.style[styleProp] = (el.zoomMaxSize ? el.zoomMaxSize+'px' : '');
    el.style.overflow = '';
    if (el.afterZoom) setTimeout('callAfterZoom('+i+')', 0)
    else zoomingElements.removeItemByIndex(i);
  }
}

function callAfterZoom(i) {
  var el = zoomingElements[i];
  zoomingElements.removeItemByIndex(i);
  callEventHandler(el.afterZoom, el);
}

function callEventHandler(method, object) {
  if (method == null)     return false;
  if (!object) object = window;
  if (isFunction(method)) return method.call(object);
  if (isArray(method))    return method[0].apply(object, method.slice(1));
  if (isString(method))   return eval(method);
  return false;
}

//-- body events handler --

var bodyEventHandlers = {};

function setupBodyEvent(eventType, handler) {
  eventType = 'on'+eventType;
  var info = bodyEventHandlers[eventType];
  if (!info) {
    bodyEventHandlers[eventType] = {defHandler: document.body.getAttribute(eventType), handlers: [handler]};
    document.body.setAttribute(eventType, (isIE ? bodyEventWrapper : 'bodyEventWrapper(event)'));
  } else {
    info.handlers.push(handler);
  }
}

function bodyEventWrapper(event) {
  if (!event) event = window.event;
  var info = bodyEventHandlers['on'+event.type];
  for (var i = 0, l = info.handlers.length; i < l; i++) {
    callEventHandler(info.handlers[i]);
  }
  if (info.defHandler) callEventHandler(info.defHandler);
}



function initZoom(zoomEl, toggleEl){
  var zEl = $(zoomEl);
  if (zEl == null) throw 'initZoom('+zoomEl+'): element not found';
  zEl.afterZoom = function() { 
   toggleEl.innerHTML = (zEl.zoomAction == '+' ? 'Закрыть' : 'Ответить');
  }
  zoom(zEl);
//toggleEl.src = 'i/'+(zEl.zoomAction == '+' ? 'close' : 'open')+'.gif';
  return false
}


//-- Fade -----------------------------------------------

var DEF_FADE_TIME    = 20;

var DEF_FADE_STEPS   = 4;

var DEF_DISPLAY_MODE = 'blank';   // 'visible' / 'block' / 'blank' / false

function fadeIn(el, time, steps, displayMode) {
  fade(el, 'in', time, steps, displayMode);
}

function fadeOut(el, time, steps, displayMode) {
  fade(el, 'out', time, steps, displayMode);
}

var
  fadingElements = [];

function fade(el, how, time, steps, displayMode) {
  el = $(el);
  if (time == undefined) time = DEF_FADE_TIME;
  if (steps == undefined) steps = DEF_FADE_STEPS; else if (steps <= 0) steps = 1;
  if (el.fadeIntervalId) {
    clearTimeout(el.fadeIntervalId);
    el.fadeIntervalId = null;
  }
  el.fadeStep = ((how == 'in' ? 1 : -1)/steps);
  if (!('fadeValue' in el)) el.fadeValue = (how == 'in' ? 0 : 1);
  el.fadeValue += el.fadeStep;
  el.fadeDisplayMode = displayMode; 
  if (hasAlpha(el)) setAlpha(el, el.fadeValue);
  if (!el.alphaMode || steps == 1) {
    setVisible(el, how == 'in', displayMode);
    if (el.afterFade) callEventHandler(el.afterFade, el);
    if (el.afterFadeEnd) {
      var i = fadingElements.addItem(el);
      setTimeout('callAfterFadeEnd('+i+')', 0);
    }
    return;
  }
  if (how == 'in') setVisible(el, true, displayMode);
  var i = fadingElements.addItem(el);
  el.fadeIntervalId = setInterval('stepFading('+i+')', time/(steps-1));
}

function stepFading(i) {
  var el = fadingElements[i];
  if (el == null) return;
  el.fadeValue += el.fadeStep;
  if (el.fadeValue > 1) el.fadeValue = 1; else if (el.fadeValue < 0) el.fadeValue = 0;
  setAlpha(el, el.fadeValue);
  if (el.fadeValue <= 0 || el.fadeValue >= 1) {
    clearInterval(el.fadeIntervalId);
    el.fadeIntervalId = null;
    if (el.fadeValue <= 0) setVisible(el, false, el.fadeDisplayMode);
    if (el.afterFade) callEventHandler(el.afterFade, el);
    if (el.afterFadeEnd) setTimeout('callAfterFadeEnd('+i+')', 0);
    else fadingElements.removeItemByIndex(i);
  }
}

function callAfterFadeEnd(i) {
  var el = fadingElements[i];
  fadingElements.removeItemByIndex(i);
  callEventHandler(el.afterFadeEnd, el);
}


function hasAlpha(el) {
  if (!('alphaMode' in el))
    el.alphaMode = ('opacity' in el.style ? 'opacity' : 
                     ('filter' in el.style ? 'filter' : false));
  return el.alphaMode;
}

function getAlpha(el) {
  return ('alphaValue' in el ? el.alphaValue : 1);
}

function setAlpha(el, value) {
  if (el.alphaValue != value) {
    if (value < 0.01) value = 0;
    else if (value > 0.99) value = 1;
    el.alphaValue = value;
    if (!('alphaMode' in el)) hasAlpha(el);
    if (el.alphaMode == 'opacity')
      el.style.opacity = el.alphaValue
    else if (el.alphaMode == 'filter') 
      el.style.filter = 'alpha(opacity='+Math.round(el.alphaValue*100)+')';
  }
}

function setVisible(el, value, displayMode) {
  if (displayMode != undefined) el.displayMode = displayMode;
  else if ('displayMode' in el) displayMode = el.displayMode;
  else displayMode = DEF_DISPLAY_MODE;
  if (displayMode != false) {
    if (displayMode == 'visible') el.style.visibility = (value ? 'visible' : 'hidden');
    else el.style.display = (value ? (displayMode == 'blank' ? '' : displayMode) : 'none');
  }
}

//-- Hint --

var
  HintContainerId = 'abs_container';

function Hint(type, defContent, w, h) {
  this.hintContainer = document.createElement('DIV');
  this.hintContainer.className = 'hint';
  this.type = type || 'text';
  this.defContent = defContent;
  this.width = w;
  this.height = h;
  this.zIndex = 2000;
  this.inContainer = false;
  this.visible = false;
  this.fastShow = true;
  this.show = Hint_show;
  this.hide = Hint_hide;
  this.updatePos = Hint_updatePos;
  if (mouseMoveListeners.length == 0) addMouseMoveListener(null);  // add null handler to know mouse pos
}

function Hint_show(content, w, h) {
  if (content == null) content = this.defContent;
  if (w == null) w = this.width;
  if (h == null) h = this.height;
  var hintCont = this.hintContainer;

  hintCont.innerHTML = 
   '<table border="0" cellspacing="0" cellpadding="0"><tr><td>'+
     (this.type == 'image' ?
       '<img src="'+content+'"'+(w ? ' width="'+w+'"' : '')+(h ? ' height="'+h+'"' : '')+'>' :
       '<b></b><div>'+content+'</div><b></b>') +
   '</td></tr></table>';
  if (w) hintCont.style.width = w;
  if (h) hintCint.style.height = h;

  if (this.visible) return;
  hintCont.hintObject = this;
  if (!this.mouseHandlerAdded) {
    addMouseMoveListener(Hint_updatePos, this);
    this.mouseHandlerAdded = true;
  }

  if (!this.inContainer) {
    (document.getElementById(HintContainerId) || document.body).appendChild(hintCont);
    this.inContainer = true;
  }
  if (this.zIndex) hintCont.style.zIndex = this.zIndex;
  if (this.width) hintCont.style.width = this.width;
  if (this.fastShow) 
    setVisible(hintCont, true)
  else
    fade(hintCont, 'in');
  this.visible = true;
  var t = hintCont.getElementsByTagName('TABLE')[0];
  this.hintWidth = t.offsetWidth;
  this.hintHeight = t.offsetHeight;
  this.updatePos();
}

function Hint_hide(how) {
  if (!this.visible) return;
  this.visible = false;
  var hintCont = this.hintContainer;
  if (how == 'fast' || this.fastShow) {
    setVisible(hintCont, false);
    if (this.mouseHandlerAdded) {
      removeMouseMoveListener(Hint_updatePos, this);
      this.mouseHandlerAdded = false;
    }
    hintCont.hintObject = null;
  } else {
    if (this.mouseHandlerAdded) hintCont.afterFade = Hint_afterFadeOut;
    fade(hintCont, 'out');
  }
}

function Hint_afterFadeOut() {
  this.afterFade = null;
  var obj = this.hintObject;
  this.hintObject = null;
  obj.mouseHandlerAdded = false;
  removeMouseMoveListener(Hint_updatePos, obj);
}

function Hint_updatePos() {
  var body = document.body;
  var d = (body.clientWidth + body.scrollLeft) - this.hintWidth;
  var x = Math.min(mouseAbsPosX, d);
  var y = mouseAbsPosY + 20;
  var h = this.hintHeight;
  var ch = body.clientHeight + body.scrollTop;
  if (y + h >= ch) y = Math.min(mouseAbsPosY, ch) - h;
  with (this.hintContainer.style) {
    left = x;
    top  = y;
  }
}

var
  hint = new Hint('text');

function hintHide() {
  hint.hide();
}

//-- Preload images --

var
  preloadedImgs = [];

function preloadImg(src, path) {
  if (path == null) path = '';
  if (isArray(src)) {
    var res = [];
    for (var i = 0, l = src.length; i < l; i++) {
      var img = new Image();
      img.src = path + src[i];
      preloadedImgs.push(img);
      res.push(img.src);
    }
    return res;
  }
  var img = new Image();
  img.src = path + src;
  preloadedImgs.push(img);
  return img.src;
}

//preloadImg('/i/logo_bkg.gif');
//preloadImg('/i/logo_bkg_top.gif');

//-- loadData / submitData --

function loadData(url, id, onCopyContent, resend, showIndicator) {
  sendRequest(id, onCopyContent, url, null, resend, showIndicator);
}

function submitData(form, id, event, onCopyContent, resend, showIndicator) {
  sendRequest(id, onCopyContent, form, event, resend, showIndicator);
}

var
  dataRequest = null,
  dataRequestResendDef = true;

function sendRequest(id, onCopyContent, urlForm, event, resend, showIndicator) {
  if (!dataRequest) {
    dataRequest = new RemoteFileLoader('dataRequest');
    dataRequest.onCopyContent = dataRequest_onCopyContent;
    dataRequest.onCopyContentEvents = {};
    dataRequest.requestDlgs = {};
    dataRequest.showIndicator = {};
    dataRequest.showRequestIndicator = true;
    dataRequest.onRequestIndicator = dataRequest_onRequestIndicator;
  }
  if (id in dataRequest.onCopyContentEvents) {
    if (resend != null ? resend : dataRequestResendDef) {
      dataRequest.cancel(id);
    } else {
      return false;
    }
  }
  dataRequest.onCopyContentEvents[id] = onCopyContent;
  dataRequest.showIndicator[id] = showIndicator;
  if (event) {
    var dlg = dataRequest.requestDlgs[id] = getWindowByElement(urlForm);
    if (dlg) dlg.dataRequestActive = true;
    dataRequest.submitInto(urlForm, id, event);
  } else {
    dataRequest.loadInto(urlForm, id);
  }
  return true;
}

function dataRequest_onCopyContent(doc, text, id) {
  if (!(id in dataRequest.onCopyContentEvents)) return false;
  var callback = dataRequest.onCopyContentEvents[id];
  delete dataRequest.onCopyContentEvents[id];
  if (id in dataRequest.requestDlgs) {
    var dlg = dataRequest.requestDlgs[id];
    delete dataRequest.requestDlgs[id];
    if (dlg) dlg.dataRequestActive = false;
  }
  return (callback ? callback(doc, text, id) : false);
}

function dataRequest_onRequestIndicator(uri, id, action) {
  return (dataRequest.showIndicator[id] != false);
}

function cancelDataRequest(id) {
  if (dataRequest && (id in dataRequest.onCopyContentEvents)) {
    delete dataRequest.onCopyContentEvents[id]
    dataRequest.cancel(id);
  }
}

//-- Input Placeholder --

function initInputPlaceholder(input, emptyText, filledClass, emptyClass) {
  input.inputPlaceholderInfo = {emptyText: emptyText, filledClass: filledClass, emptyClass: emptyClass};
  setupEvent(input, 'focus', InputPlaceholder_onFocus);
  setupEvent(input, 'blur', InputPlaceholder_onBlur);
  var value = trim(input.value);
  if (value == '' || value == emptyText) {
    input.className = emptyClass;
    if (value == '') input.value = emptyText;
  } else {
    input.className = filledClass;
  }
}

function InputPlaceholder_onFocus(event) {
  var input = (event.srcElement || event.target);
  var info = input.inputPlaceholderInfo;
  if (input.className == info.emptyClass) {
    input.className = info.filledClass;
    input.value = '';
  }
}

function InputPlaceholder_onBlur(event) {
  var input = (event.srcElement || event.target);
  var info = input.inputPlaceholderInfo;
  if (trim(input.value) == '') {
    input.className = info.emptyClass;
    input.value = info.emptyText;
  }
}

//-- Favorites --

function addPageBookmark(title, url) {
  title = title || document.title; 
  url = url || location.href;
  if (window.sidebar) { // Firefox
    window.sidebar.addPanel(title, url, '');
  } else if (window.external) { // IE
    window.external.AddFavorite(url, title);
  } else if (window.opera) { // Opera
    var el = document.createElement('A');
    el.setAttribute('href', url);
    el.setAttribute('title', title);
    el.setAttribute('rel', 'sidebar');
    el.click();
  } else {
    alert('Ваш браузер не поддерживает автоматическое добавление в избранное. Добавьте ссылку вручную через меню.')
    return false;
  }
  return true;
}

/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

//-- Lipka, 18.02.08---------------------------------------------------------------

function png(id, src_png, src_gif, sizingMethod){  
  var image = document.getElementById(id);
  if (isIE50) image.src = src_gif;
  else if (!isIE) image.src = src_png;
  else image.runtimeStyle.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src_png + '",sizingMethod="'+(sizingMethod || 'image')+'")';
  return 1;
}

function doUpdateColumns() {
  if (window.updateRightColumn && window.updateBottomColumn) {
    updateRightColumn();
    updateBottomColumn();
  } else setTimeout(doUpdateColumns, 250);
}

function doUpdateRightColumn() {
  if (window.updateRightColumn) updateRightColumn();
  else setTimeout(doUpdateRightColumn, 250);
}

//-- Comments block --

function formComment(id, toggle) {
  var r = $('response'+id);
  if (!r.isFilled) {
    r.innerHTML = $('form_comment').innerHTML;
    var body = $_('body', r, 'TEXTAREA');
    body.id = 'body'+id;
    var s = $('msg'+id).innerHTML.replace(/<(.|\s)+?>/g, '').substr(0, 200);
    if (s.length == 200) s = s.replace(/\S+$/, '');
    body.value = ' << '+trim(s)+' >> \n';
    var name = $_('name', r, 'INPUT');
    name.id = 'name'+id;
    name.value = $('name').value;
    initInputPlaceholder(name, 'Ваше имя', '', 'empty');
    var submit = $_('submit', r, 'INPUT');
    submit.id = 'submit'+id;
    var form = submit.form;
    form.commentId = id;
    r.isFilled = true;
  }
  initZoom($('response'+id), toggle);
  return false
}

function chkSubmitCommentForm(form, event) {
  var id = form.commentId || '';
  var body = $('body'+id);
  if (trim(body.value) == '') {
    alert('Вы не ввели сообщение.');
    body.focus();
    cancelEvent(event);
    return;
  }
  var name = $('name'+id);
  if (trim(name.value) == '' || name.className == 'empty') {
    alert('Вы не ввели имя.');
    name.focus();
    cancelEvent(event);
    return;
  }
  var subj = $('subj'+id);
  if (trim(subj.value) == '' || subj.className == 'empty') subj.value = '';
  $('submit'+id).disabled = true;
}

function toggle(suffix, current) {
  var itm = $('toggle_'+suffix).getElementsByTagName('TD');
  var td = findParentNode(current, 'TD');
  var n = -1;
  for (var i = 0, l = itm.length; i < l; i++) { 
    itm[i].className = '';
    $('box_'+suffix+i).style.display = 'none';
    $('frm_'+suffix+i).style.display = 'none';
    if (itm[i] == td) n = i
  }
  td.className = 'current';
  $('box_'+suffix+n).style.display = '';
  $('frm_'+suffix+n).style.display = '';
  return false
}

//-- Glavred block --

function initGlavredForm() {
  var forms = document.body.getElementsByTagName('FORM');
  for (var i = forms.length-1; i >= 0; i--) {
    var form = forms[i];
    if (form.className != 'glavred_form' || form.glavredBylTut) continue;
    form.messageInput = findSubChild(form, 'TEXTAREA');
    var inps = form.getElementsByTagName('INPUT');
    for (var j = 0, l = inps.length; j < l; j++) {
      var inp = inps[j];
      if (inp.name == 'name') {
        initInputPlaceholder(inp, 'Ваше имя', '', 'empty');
        form.nameInput = inp;
      } else if (inp.type == 'submit') {
        form.submitBtn = inp;
      }
    }
    setupEvent(form, 'submit', GlavredForm_onSubmit);
    form.glavredBylTut = true;
  }
}

function GlavredForm_onSubmit(event) {
  var form = (event.srcElement || event.target);
  var messageInput = form.messageInput;
  if (trim(messageInput.value) == '') {
    alert('Вы не ввели сообщение.');
    messageInput.focus();
    cancelEvent(event);
    return;
  }
  var nameInput = form.nameInput;
  if (trim(nameInput.value) == '' || nameInput.className == 'empty') {
    alert('Вы не ввели имя.');
    nameInput.focus();
    cancelEvent(event);
    return;
  }
  form.submitBtn.disabled = true;
}

//-- More photos --

var 
  photoBlock,
  previewsBlock,
  containerBlock,
  moveIntervalId;

function showMorePhotos() {
  if (photoBlock) return;
  photoBlock = $('photo_block');
  previewsBlock = $('previews');
  containerBlock = photoBlock.parentNode;
  containerBlock.style.width = containerBlock.offsetWidth+'px';
  containerBlock.style.height = containerBlock.offsetHeight+'px';
  containerBlock.style.overflow = 'hidden';
  photoBlock.style.width = photoBlock.offsetWidth+'px';
  photoBlock.style.position = 'relative';
  photoBlock.curPos = 0;
  photoBlock.endPos = -(photoBlock.offsetWidth + getAbsPos(photoBlock).left);
  photoBlock.incVal = 2;
  moveIntervalId = setInterval(movingBlockIterator, 50);
  setTimeout(movingBlockIterator, 0);
}

function movingBlockIterator() {
  if (photoBlock.curPos != photoBlock.endPos) {
    photoBlock.incVal *= 2;
    photoBlock.curPos -= photoBlock.incVal;
    if (photoBlock.curPos < photoBlock.endPos) photoBlock.curPos = photoBlock.endPos;
    photoBlock.style.left = photoBlock.curPos+'px';
  } else if (previewsBlock.curPos == null) {
    previewsBlock.style.display = 'block';
    previewsBlock.style.width = previewsBlock.offsetWidth+'px';
    previewsBlock.style.position = 'relative';
    previewsBlock.style.left = (-previewsBlock.offsetWidth)+'px';
    previewsBlock.curPos = -previewsBlock.offsetWidth;
    previewsBlock.endPos = 0;
  } else if (previewsBlock.curPos != previewsBlock.endPos) {
    previewsBlock.curPos = Math.round(previewsBlock.curPos + previewsBlock.endPos)/2;
    if (Math.abs(previewsBlock.curPos - previewsBlock.endPos) <= 1) previewsBlock.curPos = previewsBlock.endPos;
    previewsBlock.style.left = previewsBlock.curPos+'px';
  } else if (containerBlock.curPos == null) {
    containerBlock.curPos = containerBlock.offsetHeight;
    containerBlock.endPos = previewsBlock.offsetHeight;
  } else if (containerBlock.curPos != containerBlock.endPos) {
    containerBlock.curPos = Math.round(containerBlock.curPos + containerBlock.endPos)/2;
    if (Math.abs(containerBlock.curPos - containerBlock.endPos) <= 1) containerBlock.curPos = containerBlock.endPos;
    containerBlock.style.height = containerBlock.curPos;
  } else {
    clearInterval(moveIntervalId);
    moveIntervalId = null;
    photoBlock.style.display = 'none';
    previewsBlock.style.width = '';
    previewsBlock.style.position = '';
    previewsBlock.style.left = '';
    containerBlock.style.width = '';
    containerBlock.style.height = '';
    containerBlock.style.overflow = '';
  }
}
