// JavaScript Document
// Copyright 2008 Ladislav Brychta

function webStart() {
  return true;
}

/* --- simpleGallery --- */

function simpleGalleryCallback(instance,method) {
  return function() {
    return method.apply(instance,arguments);
  }
}

function simpleGalleryFunctions(objName,elemsID) {
  this.objName = objName;
  this.bigImg = null;
  this.bigImgTemp = null;
  this.lastImgElem = null;
  this.loadingImg = null;
  this.elemsID = elemsID;

  this.reset = function() {
    //alert('reset');
    this.bigImgTemp = new Image;
    this.bigImgTemp.onload = simpleGalleryCallback(this,this.bigSwap);
    this.bigImg = document.getElementById('gallery-bigimg'+this.elemsID);
    this.loadingImg = document.getElementById('gallery-loading'+this.elemsID);
  }
  
  this.init = function() {
    //alert('init');
    this.reset();
  }

  this.bigShow = function(elem) {
    //alert('bigShow');
    this.loadingImg.className = 'loading';
    this.lastImgElem = elem;
    this.bigImgTemp.src = elem.firstChild.src.replace('/thumbnails/','/images/');
    this.lastImgElem.blur();
  }

  this.bigSwap = function() {
    //alert('bigSwap');
    if (this.bigImg.hasChildNodes()) {
      this.bigHide();
    }
    var elemImg = document.createElement('img');
    elemImg.src = this.bigImgTemp.src;
    elemImg.onclick = simpleGalleryCallback(this,this.bigHide);
    //var newleft = Math.round((this.bigImg.parentNode.parentNode.offsetWidth/2)-(elemImg.width/2));
    var newleft = Math.round((this.bigImg.parentNode.parentNode.offsetWidth/2)-(elemImg.width/2));
    //var newtop = this.lastImgElem.parentNode.offsetTop-elemImg.height;
    var newtop = this.lastImgElem.offsetTop-elemImg.height;
    this.loadingImg.className = 'hidden';
    this.bigImg.appendChild(elemImg);
    this.bigImg.className = 'big';
    this.bigImg.style.left = newleft+'px';
    this.bigImg.style.top = (newtop<0?0:newtop)+'px';
    //this.showOtherInfo(1);
  }

  this.bigHide = function() {
    //alert('bigHide');
    this.bigImg.className = 'hidden';
    this.bigImg.removeChild(this.bigImg.firstChild);
    //this.showOtherInfo(0);
  }
  
  this.showOtherInfo = function(what) {
    /*var elemsDiv = this.lastImgElem.parentNode.getElementsByTagName('div');
    if (!elemsDiv[0]) return false;
    if (what==0) {
      elemsDiv[0].className = 'hidden';
    } else {
      elemsDiv[0].className = '';
    }*/
    return true;
  }

  this.init();
}

/* ---  --- */

function swapEquipment(elemsID) {
  smallElem = document.getElementById('small-equipment-'+elemsID);
  bigElem = document.getElementById('big-equipment-'+elemsID);
  if (!smallElem || !bigElem) return false;
  if (bigElem.className == 'hidden') {
    bigElem.src = smallElem.src.replace('/thumbnails/','/images/');
    bigElem.className = 'equipment';
  } else {
    bigElem.className = 'hidden';
    bigElem.src = link+'images/loading.gif';
  }
  return true;
}

/* ---  --- */

