

//************************************************************
//************************************************************
//################################################
//## GALLERY-MODUL
//################################################
//## v2
//## Author: df
//## 02.09.2009
//************************************************************
//************************************************************

var undefined;
var IE;
var IE6;
var IE7;

if (window.ActiveXObject) {
  IE = true;
}

//************************************************************
//************************************************************
// ## Gallery
//************************************************************
//************************************************************

function Gallery(id) {
  this.id = undefined;
  this.config = GalleryConfig.createInstance();
  this.specification = GallerySpecification.createInstance();
  this.itemList = [];
  this.activeItemList = [];
  this.itemViewLength = 3;
  this.timeout = undefined;
  this.timeoutCloseDetail = undefined;
  this.rotationBreak = false;
  this._detailIDX = undefined;
  
  this._baseElem = undefined;
  this._displayElem = undefined;
  this._loadingElem = undefined;
  this._specificationElem = undefined;
  this._itemListElem = undefined;
  this._infoElem = undefined;
  this._navigationListElem = undefined;
  this._buttonDesc = undefined;
  this._buttonAsc = undefined;
  this._isBusy = false;
  this._isBusyDetail = false;
  
  this._setID(id);
  this._setBaseElem();
  this._setLoadingElem();
  this._setSpecificationsElem();
  this._setDisplayElem();
  this._setItemListElem();
  this._setNavigation();
}

//************************************************************

Gallery.prototype._setID = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('Gallery->_setID: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('Gallery->_setID: Argument str ist nicht vom Typ String!');
  }
  this.id = str;
} 

//************************************************************

Gallery.prototype._setLoadingElem = function () {
  if (! this._baseElem) {
    focus();
    throw new Error('Gallery->_setLoadingElem: Es existiert kein Base-HTML-Element!');
  }
  var img = new Image();
  img.src = '/kiosk/grafik/loading.gif';
  img.id = this.id + '_loading_';
  img.className = 'GALLERY_LOADING_IMG';
  this._loadingElem = img;
  this._baseElem.appendChild(this._loadingElem);
} 

//************************************************************

Gallery.prototype._setNavigation = function () {
  if (! this._baseElem) {
    focus();
    throw new Error('Gallery->_setDrawElem: Es existiert kein Base-HTML-Element!');
  }
  var buttonDesc  = document.createElement('a');
  buttonDesc.href = 'javascript:void(0);';
  buttonDesc.className = 'GALLERY_NAVIGATION_BACKBUTTON';
  var id = this.id;
  var backw = new Function ('','Gallery.getInstance(\'' + id + '\').backward();'); 
  GalleryTools.addEvent('click', buttonDesc, backw);
  var buttonAsc  = document.createElement('a');
  buttonAsc.href = 'javascript:void(0);';
  buttonAsc.className = 'GALLERY_NAVIGATION_FORWARDBUTTON';
  var forw = new Function ('','Gallery.getInstance(\'' + id + '\').forward();'); 
  GalleryTools.addEvent('click', buttonAsc, forw);
  var elem = document.createElement('div');
  elem.className = 'GALLERY_NAVIGATION_LIST';
  if (this.itemList.length <= this.config.activeItemLength) {
      elem.style.display = 'none';
  }
  this._baseElem.appendChild(elem);
  elem.appendChild(buttonDesc);
  elem.appendChild(buttonAsc);
  this._buttonAsc = buttonAsc;
  this._buttonDesc = buttonDesc;
  this._navigationListElem = elem;
} 

//************************************************************

Gallery.prototype.backward = function () {
  this.config.setDirection('descending');
  this.rotationBreak = false;
  this.rotate();
} 

//************************************************************

Gallery.prototype.forward = function () {
  this.config.setDirection('ascending');
  this.rotationBreak = false;
  this.rotate();
} 

//************************************************************

Gallery.prototype._setItemListElem = function () {
  if (! this._displayElem) {
    focus();
    throw new Error('Gallery->_setItemListElem: Es existiert kein Display-HTML-Element!');
  }
  var elem = document.createElement('div');
  elem.className = 'GALLERY_ITEM_LIST';
  this._displayElem.appendChild(elem);
  this._itemListElem = elem;
} 

//************************************************************

Gallery.prototype._setInfoElem = function () {
  if (! this._displayElem) {
    focus();
    throw new Error('Gallery->_setInfoElem: Es existiert kein Display-HTML-Element!');
  }
  var elem = document.createElement('div');
  elem.className = 'GALLERY_INFO';
  this._displayElem.appendChild(elem);
  this._infoElem = elem;
}

//************************************************************

Gallery.prototype._setInfo = function () {
  if (! this._infoElem) {
    focus();
    throw new Error('Gallery->_setInfo: Es existiert kein Info-HTML-Element!');
  }
  var txt = this.itemList.length;
  txt += ' Bilder';
  this._infoElem.innerHTML = txt;
}

//************************************************************

Gallery.prototype._setSpecificationsElem = function () {
  if (! this._baseElem) {
    focus();
    throw new Error('Gallery->_setSpecificationsElem: Es existiert kein Base-HTML-Element!');
  }
  var elem = document.createElement('div');
  elem.className = 'GALLERY_BOX_SPECIFICATIONS';
  this._baseElem.appendChild(elem);
  this._specificationElem = elem;
  this._setSpecificationMarker();
  this._setSpecificationModel();
} 

//************************************************************

Gallery.prototype._setSpecificationMarker = function () {
  if (! this._baseElem) {
    focus();
    throw new Error('Gallery->_setSpecificationMarker: Es existiert kein Base-HTML-Element!');
  }
  for (var i=0; i<this.specification.markerList.length; i++) {
    var mark = this.specification.markerList[i];
    var elem = document.createElement('div');
    elem.className = 'GALLERY_SPECIFICATIONS_MARKER_' + mark.posIdx;
    elem.id = 'GALLERY_SPECIFICATIONS_MARKER_' + mark.posIdx; 
    this._specificationElem.appendChild(elem);
    var w = parseFloat(elem.offsetWidth);
    mark._setWidth(w);
    var l = parseFloat(elem.offsetLeft);
    mark._setLeft(l);
    var h = parseFloat(elem.offsetHeight);
    mark._setHeight(h);
  }
} 

//************************************************************

Gallery.prototype._setSpecificationModel = function () {
  if (! this._baseElem) {
    focus();
    throw new Error('Gallery->_setSpecificationMarker: Es existiert kein Base-HTML-Element!');
  }
  for (var i=0; i<this.specification.modelList.length; i++) {
    var mod = this.specification.modelList[i];
    var elem = document.createElement('div');
    elem.className = 'GALLERY_SPECIFICATIONS_MODEL_' + mod.posIdx;
    this._specificationElem.appendChild(elem);
    var w = parseFloat(elem.offsetWidth);
    mod._setWidth(w);
    var h = parseFloat(elem.offsetHeight);
    mod._setHeight(h);
    mod._setClassName(elem.className);
  }
} 

//************************************************************

Gallery.prototype._setDisplayElem = function () {
  if (! this._baseElem) {
    focus();
    throw new Error('Gallery->_setDisplayElem: Es existiert kein Base-HTML-Element!');
  }
  var elem = document.createElement('div');
  elem.className = 'GALLERY_BOX_DISPLAY';
  this._baseElem.appendChild(elem);
  this._displayElem = elem;
} 

//************************************************************

Gallery.prototype._setBaseElem = function () {
  var elem = document.getElementById(this.id);
  if (! elem) {
    focus();
    throw new Error('Gallery->_setBaseElem: Es existiert kein HTML-Element mit id = '+ this.id +'!');
  }
  this._baseElem = elem;
} 

//************************************************************

Gallery.prototype.setItemViewLength = function (n) {
  if (arguments.length!=1) {
    throw new Error("Gallery->setItemViewLength: Falsche Anzahl von Argumenten!");
  }
  if (typeof n != "number") {
    throw new Error("Gallery->setItemViewLength: Argument ist nicht vom Typ number!");
  }
  this.itemViewLength = n;
} 

//************************************************************

Gallery.prototype.addItemList = function (obj) {
  if (arguments.length != 1) {
    focus();
    throw new Error('Gallery->addItemList: Falsche Anzahl von Argumenten!');
  }
  if (! (obj instanceof GalleryItem)) {
    focus();
    throw new Error('Gallery->addItemList: Argument obj ist keine Instance GalleryItem!');
  }
  obj._setListPosition(this.itemList.length);
  this.itemList.push(obj);
  if (this.config.activeItemLength >= (this.activeItemList.length-1)) {
    this.activeItemList.push(obj);
  }
} 

//************************************************************

Gallery.prototype._cloneItems = function () {
  var length = this.itemList.length;
  for (var i=0; i<length; i++) {
    var item = this.itemList[i];
    var newitem = GalleryItem.createInstance();
    if (item.srcPreview) {
      newitem.setSrcPreview(item.srcPreview);
    }
    if (item.srcStandard) {
      newitem.setSrcStandard(item.srcStandard);
    }
    if (item.title) {
      newitem.setTitle(item.title);
    }
    if (item.subtitle) {
      newitem.setSubtitle(item.subtitle);
    }
    if (item.description) {
      newitem.setDescription(item.description);
    }
    if (item.linkURL) {
      newitem.setLinkURL(item.linkURL);
    }
    this.addItemList(newitem);
  }
}  

//************************************************************

Gallery.prototype._closeDetail = function () {
  var id = this.id;
  if (this._isBusyDetail) {
    Gallery._tmpCloseDetail = function () {
      Gallery.getInstance(id)._closeDetail();   
    }  
    this.timeoutCloseDetail = window.setTimeout(Gallery._tmpCloseDetail, 100);
    return true;
  }
  if (this.timeoutCloseDetail) {
    window.clearTimeout(this.timeoutCloseDetail);
    this.timeoutCloseDetail = undefined;
  }
  var body = document.getElementsByTagName('body')[0];
  var gallery_detail = document.getElementById('GALLERY_DETAIL');
  if (gallery_detail) {
    body.removeChild(gallery_detail);
  }
}  

//************************************************************

Gallery.prototype.detailBackward = function () {
  if (this._isBusyDetail) {
    return true;
  }
  this._isBusyDetail = true;
  if (this._detailIDX == undefined) {
    return;
  }
  this._detailIDX--;
  if (this._detailIDX < 0) {
    this._detailIDX = this.itemList.length -1;
  }
  var id = this.id;
  var next = this.itemList[this._detailIDX];
  Gallery._tmpLoaderRotate = function () {
    Gallery.getInstance(id)._rotateDetail(next);
  }
  if (next.standard == undefined) {
    next._setStandard();
  }
  var _tI = new Image();
  _tI.onload = function () {
    var f = function () {
      Gallery.getInstance(id)._rotateDetail(next);
    }
    window.setTimeout(f, 10);
  }
  _tI.src = next.standard.src;
  if (! _tI.complete) {
    return;
  }
  this._rotateDetail(next);
}

//************************************************************

Gallery.prototype.detailForward = function () {
  if (this._isBusyDetail) {
    return true;
  }
  this._isBusyDetail = true;
  if (this._detailIDX == undefined) {
    return;
  }
  this._detailIDX++;
  if (this._detailIDX >= this.itemList.length) {
    this._detailIDX = 0;
  }
  var id = this.id;
  var next = this.itemList[this._detailIDX];
  Gallery._tmpLoaderRotate = function () {
    Gallery.getInstance(id)._rotateDetail(next);
  }
  if (next.standard == undefined) {
    next._setStandard();
  }
  var _tI = new Image();
  _tI.onload = function () {
    var f = function () {
      Gallery.getInstance(id)._rotateDetail(next);
    }
    window.setTimeout(f, 10);
  }
  _tI.src = next.standard.src;
  if (! _tI.complete) {
    return;
  }
  this._rotateDetail(next);
}

//************************************************************

Gallery.prototype._rotateDetail = function (next) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  var clone = document.getElementById('GALLERY_DETAIL_DISPLAY_IMG_CLONE');
  var old = document.getElementById('GALLERY_DETAIL_DISPLAY_IMG');
  var id = this.id;
  if (next) {
    if (! clone) {
      clone = old.cloneNode(true);
      clone.className = 'GALLERY_DETAIL_DISPLAY_IMG_CLONE';
      var parent = old.parentNode;
      parent.insertBefore(clone, old);
    }
    var alt = 'Bild ' + parseFloat(next.listPosition + 1) ;
    if (next.title) {
      alt += ' - ' + title;
    }
    if (next.standard == undefined) {
      next._setStandard();
    }
    clone.src = next.standard.src;
    if (document.all) {
      clone.height = next.standard.height;
      clone.width = next.standard.width;
    }
    clone.alt = alt;
    clone.title = alt;
    clone.id = 'GALLERY_DETAIL_DISPLAY_IMG_CLONE';
    var nrElem = document.getElementById('GALLERY_DETAIL_INFO_NUMBER');    
    nrElem.innerHTML =  'Bild ' + parseFloat(next.listPosition + 1)  + ' von ' + this.itemList.length;
    var title = '';
    if (next.title) {
      title = next.title
    }
    var titleElem = document.getElementById('GALLERY_DETAIL_INFO_TITLE');
    titleElem.innerHTML = title;
    var description = '';
    if (next.description) {
      description = next.description
    }
    var textElem = document.getElementById('GALLERY_DETAIL_INFO_TEXT');
    textElem.innerHTML = description;
    /*
    if (! clone.complete) {
      Gallery.prototype._tmpLoaderRotate2 = function () {
        Gallery.getInstance(id)._rotateDetail();
      }
      //clone.onload = Gallery.getInstance(id)._tmpLoaderRotate2;
      Tools.addEvent('load',clone,Gallery.getInstance(id)._tmpLoaderRotate2);
      return;
    }*/
  }
  if (clone.height < old.height) {
    var posh = parseFloat(old.height - clone.height) / 2;
    clone.style.top = GalleryTools.getCssUnit(posh);
  } else {
    //clone.style.top = '0';
  }
  if (clone.width < old.width) {
    var posw = parseFloat(old.width - clone.width) / 2;
    clone.style.left = GalleryTools.getCssUnit(posw);
  } else {
    //clone.style.left = '0';
  }
  var opac;
  if (clone.filters != undefined){
    // IE
    opac = parseFloat(clone.filters['Alpha']['opacity']);
  } else {
    // Other
    opac = parseFloat(clone.style.opacity);
  }
  if (! opac) {
    opac = 0;
  }
  var opac_reached = false;
  if (clone.filters != undefined){
    if (opac >= 100) {
        opac_reached = true;
    }
  } else {
    // Other
    if (opac >= 1) {
        opac_reached = true;
    }
  }
  if (opac_reached) {
    var o_par = old.parentNode;
    clone.id = old.id;
    clone.className = old.className;
    clone.removeAttribute('style');
    o_par.removeChild(old);
    this._updateDetailBox(clone);
    this._isBusyDetail = false;
    return;
  }
  if (clone.filters != undefined){
    opac += 5;
    clone.filters['Alpha']['opacity'] = opac;
    clone.filters['Alpha']['finishopacity'] = opac;
  } else {
    // Other
    opac += 0.05;
    clone.style.opacity = opac;
  }
  Gallery.prototype._tmpFunction = function() {
    if (IE6) {
      Gallery.getInstance(id)._rotateDetail(next);
    } else {
      Gallery.getInstance(id)._rotateDetail();
    }
  }
  this.timeout = window.setTimeout(this._tmpFunction, 50);
}
  
//************************************************************

Gallery.prototype._updateDetailBox = function (img) {
  var display = document.getElementById('GALLERY_DETAIL_DISPLAY');  
  var gallery_detail = document.getElementById('GALLERY_DETAIL');
  var curtain = document.getElementById('GALLERY_DETAIL_CURTAIN');
  var info = document.getElementById('GALLERY_DETAIL_INFO');        
  var width = img.width; 
  var height = img.height;
  display.style.width = GalleryTools.getCssUnit(width);
  display.style.height = GalleryTools.getCssUnit(parseFloat(height + parseFloat(info.offsetHeight)));
  var backw = document.getElementById('GALLERY_DETAIL_BACKWARD');
  backw.style.width = GalleryTools.getCssUnit(parseFloat(img.width / 2)); 
  backw.style.height = GalleryTools.getCssUnit(parseFloat(img.height)); 
  var forw = document.getElementById('GALLERY_DETAIL_FORWARD');
  forw.style.width = GalleryTools.getCssUnit(parseFloat(img.width / 2)); 
  forw.style.height = GalleryTools.getCssUnit(img.height); 
  forw.style.left = GalleryTools.getCssUnit(parseFloat(img.width / 2)); 
  var left = parseFloat(curtain.offsetWidth) - parseFloat(display.offsetWidth);
  left *= 0.5;
  display.style.left = GalleryTools.getCssUnit(left);
}
  
//************************************************************

Gallery.prototype.detailButtonAction = function () {
}
  
//************************************************************

Gallery.prototype._showDetail = function (idx) {
  if (! idx) {
    idx = this.itemList[0].id;
  }
  var body = document.getElementsByTagName('body')[0];
  var gallery_detail = document.getElementById('GALLERY_DETAIL');
  var display = document.getElementById('GALLERY_DETAIL_DISPLAY');
  var item = GalleryItem.getInstance(idx);
  this._detailIDX = item.listPosition;
  var id = this.id;
  if (! gallery_detail) {
    if (item.standard == undefined && item.srcStandard) {
      item._setStandard();
    }
    if (! item.standard) {
      return;
    }
    var display_img = item.standard;
    if (! display_img.complete) {
      Gallery.prototype._tmpLoader = function () {
        var sOF = function () {
          var obj = Gallery.getInstance(id);
          obj._showDetail(idx);
        }
        window.setTimeout(sOF, 5);
        //Gallery.getInstance(id)._showDetail(idx);
      }
      display_img.onload = this._tmpLoader;
      return;
    }
    gallery_detail = document.createElement('div');
    gallery_detail.style.visibility = 'hidden';
    gallery_detail.id = 'GALLERY_DETAIL';
    gallery_detail.className = 'GALLERY_DETAIL';
    gallery_detail.style.zIndex = '900';
    body.insertBefore(gallery_detail, body.firstChild);
    
    curtain = document.createElement('div');
    curtain.id = 'GALLERY_DETAIL_CURTAIN';
    curtain.className = 'GALLERY_DETAIL_CURTAIN';
    var sH = GalleryTools._getScreenHeight();
    curtain.style.height = GalleryTools.getCssUnit(sH);
    //var bH = GalleryTools._getElemHeight(GalleryTools._getBody());
    var bH = GalleryTools._getDocumentHeight();
    if (bH > sH) {
      curtain.style.height = GalleryTools.getCssUnit(bH);
    }
    curtain.style.zIndex = '1';
    gallery_detail.appendChild(curtain);
    
    display = document.createElement('div');
    display.id = 'GALLERY_DETAIL_DISPLAY'; 
    display.className = 'GALLERY_DETAIL_DISPLAY';
    display.style.zIndex = '2';
    gallery_detail.appendChild(display);
    
    var display_inner = document.createElement('div');
    display_inner.id = 'GALLERY_DETAIL_DISPLAY_INNER'; 
    display_inner.className = 'GALLERY_DETAIL_DISPLAY_INNER';
    display_inner.style.zIndex = '2';
    display_inner.style.visibility = 'hidden';
    display.appendChild(display_inner);
    
    var display_img_container = document.createElement('div');
    display_img_container.id = 'GALLERY_DETAIL_DISPLAY_IMG_CONTAINER'; 
    display_img_container.className = 'GALLERY_DETAIL_DISPLAY_IMG_CONTAINER';
    display_img_container.style.zIndex = '2';
    display_inner.appendChild(display_img_container);
    
    display_img.className = 'GALLERY_DETAIL_DISPLAY_IMG';
    display_img.id = 'GALLERY_DETAIL_DISPLAY_IMG';
    var alt = 'Bild ' + parseFloat(item.listPosition + 1) ;
    if (item.title) {
      alt += ' - ' + item.title;
    }
    display_img.alt = alt;
    if (item.title) {
      display_img.title = item.title;
    }
    display_img_container.appendChild(display_img);
    
    var innerIMGB = new Image();
    innerIMGB.src = 'http://rdts.de/grafik/trans.gif';
    var back = document.createElement('a');
    back.href = 'javascript:void(0);';
    var id = this.id;
    back.onclick = function() {
      Gallery.getInstance(id).detailBackward();            
    };
    back.title = 'Vorheriges Bild anzeigen';
    back.className = 'GALLERY_DETAIL_BACKWARD';
    back.id = 'GALLERY_DETAIL_BACKWARD';
    back.appendChild(innerIMGB);
    display_img_container.insertBefore(back, display_img);
    back.style.width = GalleryTools.getCssUnit(parseFloat(display_img.width / 2));
    back.style.height = GalleryTools.getCssUnit(parseFloat(display_img.height));
    
    var innerIMGF = new Image();
    innerIMGF.src = 'http://rdts.de/grafik/trans.gif';
    var forw = document.createElement('a');
    forw.href = 'javascript:void(0);';
    forw.onclick = function() {
      Gallery.getInstance(id).detailForward();
    };
    forw.title = 'Nächstes Bild anzeigen';
    forw.className = 'GALLERY_DETAIL_FORWARD';
    forw.id = 'GALLERY_DETAIL_FORWARD';
    forw.appendChild(innerIMGF);
    display_img_container.insertBefore(forw, display_img);
    forw.style.width = GalleryTools.getCssUnit(parseFloat(display_img.width / 2));
    forw.style.height = GalleryTools.getCssUnit(parseFloat(display_img.height));
    forw.style.left = GalleryTools.getCssUnit(parseFloat(display_img.offsetWidth / 2));
    
    var display_button = document.createElement('a');
    display_button.style.zIndex = '3';
    display_button.href = 'javascript:void(0);';
    display_button.onclick = function() {
      Gallery.getInstance(id).detailButtonAction();
    };
    display_button.className = 'GALLERY_BOX_DISPLAY_BUTTON';
    display_button.id = 'GALLERY_BOX_DISPLAY_BUTTON_ANKER';
    display_inner.appendChild(display_button);
    
    var info = document.createElement('div');
    info.className = 'GALLERY_DETAIL_INFO';
    info.id = 'GALLERY_DETAIL_INFO';
    display_inner.appendChild(info);
    
    var close = document.createElement('a');
    close.href = 'javascript:void(0);';
    close.onclick = function() {
      Gallery.getInstance(id)._closeDetail();
    };
    close.className = "GALLERY_DETAIL_CLOSE";
    close.id = "GALLERY_DETAIL_CLOSE";
    info.appendChild(close);
    
    var h4 = document.createElement('h4');
    h4.className = 'GALLERY_DETAIL_INFO_NUMBER';
    h4.id = 'GALLERY_DETAIL_INFO_NUMBER';
    info.appendChild(h4);
    h4.innerHTML =  'Bild ' + parseFloat(item.listPosition + 1)  + ' von ' + this.itemList.length;
    
    var h3 = document.createElement('h3');
    h3.className = 'GALLERY_DETAIL_INFO_TITLE';
    h3.id = 'GALLERY_DETAIL_INFO_TITLE';
    info.appendChild(h3);
    var tit = '';
    if (item.title) {
      tit = item.title;
    }
    h3.innerHTML = tit;
    
    var p = document.createElement('p');
    p.className = 'GALLERY_DETAIL_INFO_TEXT';
    p.id = 'GALLERY_DETAIL_INFO_TEXT';
    var text = '';
    if (item.subtitle) {
      //text += item.subtitle;
    }
    if (item.description) {
      if (item.subtitle) {
        //text += '<br />';
      }
      text += item.description;
    }
    p.innerHTML = text;
    info.appendChild(p);

    var floatBr = document.createElement('div');
    floatBr.className = 'float-aufheben';
    info.appendChild(floatBr);
  }
  
  gallery_detail.style.visibility = 'visible';    
  //gallery_detail.style.top = GalleryTools.getCssUnit(top);  
  
  this._updateDetailBox(display_img);
  
  //var d_width = parseFloat(display_img.offsetWidth);
  //var d_height = parseFloat(display_img.offsetHeight) +parseFloat(info.offsetHeight) ;
  //display.style.left = GalleryTools.getCssUnit(parseFloat((gallery_detail.offsetWidth / 2)));
  
  var d_width = parseFloat(display.offsetWidth);
  var d_height = parseFloat(display.offsetHeight); 
  var d_left = parseFloat(display.style.left);
  
  var dl = parseFloat(display.offsetWidth / 2) + parseFloat(display.style.left);
  display.style.left = GalleryTools.getCssUnit(dl);
  
  var top = 0;
  top = GalleryTools._getScreenHeight();
  top = top - GalleryTools._getElemHeight(display_img);
  top = top/2;
  top += GalleryTools._getScrollPositionTop();
  if (top - 100 > 0) {
    top -= 100;
  }
  display.style.top = GalleryTools.getCssUnit(top);
  //curtain.style.width = body.offsetWidth + 'px';
  //curtain.style.height = body.offsetHeight + 'px';
  display.style.width = '1px';
  display.style.height = '1px';
  this._moveInDetail(display, d_width, d_height, d_left);
} 

//************************************************************

Gallery.prototype._moveInDetail = function (elem, width, height, left) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  var tm = 5;
  if (IE) {
    tm = 5;
  }
  if (arguments.length != 4) {
    focus();
    throw new Error('Gallery->_moveInDetail: Falsche Anzahl von Argumten!');
  }
  var id = this.id;
  var _speedPx = 10;
  if (IE) {
      _speedPx *= 6;
  }
  if (parseFloat(elem.offsetHeight) < height) {
    //var func = new Function ('','Gallery.getInstance(\'' + id + '\')._moveInDetail('+ elem +',\'' +width+ '\',\'' +height+ '\');'); 
    Gallery.prototype._tmpMove = function () {
      Gallery.getInstance(id)._moveInDetail(elem,width,height, left);
    }
    var diffH  = _speedPx;
    if ((parseFloat(elem.offsetHeight) + diffH) > height) {
      diffH = height - parseFloat(elem.offsetHeight);
    }
    elem.style.height = GalleryTools.getCssUnit(parseFloat(elem.style.height) + diffH);
    this.timeout = window.setTimeout(this._tmpMove, tm);
    //func();
    return;
  }
  if (parseFloat(elem.offsetWidth) < width) {
    //var func = new Function ('','Gallery.getInstance(\'' + id + '\')._moveInDetail('+ elem +',\'' +width+ '\',\'' +height+ '\');'); 
    Gallery.prototype._tmpMove = function () {
      Gallery.getInstance(id)._moveInDetail(elem,width,height, left);
    }
    var diffW = _speedPx;
    if ((parseFloat(elem.offsetWidth) + diffW) > width) {
      diffW = width - parseFloat(elem.offsetWidth);
    }
    elem.style.width = GalleryTools.getCssUnit(parseFloat(elem.style.width) + diffW);
    var n_left = parseFloat(elem.style.left) - (diffW / 2);
    if (n_left < left) {
      n_left = left;
    }
    elem.style.left = GalleryTools.getCssUnit(n_left);
    this.timeout = window.setTimeout(this._tmpMove, tm);
    //func();
    return;
  }
  elem.style.left = GalleryTools.getCssUnit(left);
  elem.firstChild.style.visibility = 'visible';
} 

//************************************************************

Gallery.prototype._showAjaxLoader = function () {
  var elem = document.getElementById('GALLERY_AJAX_IMG_LOADER');
  if (! elem) {
    return;
  }
  elem.style.visibility = 'hidden';
  elem.style.display = 'block';
  var pWidht = elem.parentNode.offsetWidth;
  var l = parseFloat(pWidht / 2) - parseFloat(elem.offsetWidth / 2);
  elem.style.left = GalleryTools.getCssUnit(l);
  var pHeight = elem.parentNode.offsetHeight;
  var t = parseFloat(pHeight / 2) - parseFloat(elem.offsetHeight);
  elem.style.top = GalleryTools.getCssUnit(t);
  elem.style.visibility = 'visible';
}           

//************************************************************

Gallery.prototype._hideAjaxLoader = function () {
  var elem = document.getElementById('GALLERY_AJAX_IMG_LOADER');
  if (! elem) {
    return;
  }
  elem.style.display = 'none';
}

//************************************************************

Gallery.prototype.drawItemList = function () {
  if (! this._itemListElem) {
    focus();
    throw new Error('Gallery->drawItemList: Es existiert kein ItemList-HTML-Element!');
  }
  //alert(this.id);
  this._navigationListElem.style.display = 'block';
  //if (this.itemList.length > this.config.activeItemLength && this.itemList.length <= (this.config.activeItemLength) + 1) {
  if ( this.itemList.length <= (this.config.activeItemLength) + 1) {
    this._cloneItems();
  }
  if (this.config.type == 'type3') {
    if (this.itemList.length <= this.config.activeItemLength) {
        this._navigationListElem.style.display = 'none';
    }
  } else if (this.config.type == 'type2') {
    //alert(this.itemList.length);
    if (this.itemList.length <= (parseFloat(this.config.activeItemLength) + 1)) {
        this._navigationListElem.style.display = 'none';
    }
  } else {
    if (this.itemList.length <= (parseFloat(this.config.activeItemLength) + 1)) {
        this._navigationListElem.style.display = 'none';
    }
  }
  if (this._loadingElem) {
    this._baseElem.removeChild(this._loadingElem);
  }
  this._drawItemList(0);
} 

//************************************************************

Gallery.prototype._drawItemList = function (idx) {
  if (! arguments.length) {
    focus();
    throw new Error('Gallery->_drawItemList: Falsche Anzahl von Argumenten!');
  }
  var item = this.activeItemList[idx];
  if (! item) {
    return;
  }
  var id = this.id;
  Gallery._tmpThumbLoader = function () {
    var tOF = function () {
      var obj = Gallery.getInstance(id);
      obj._drawItem(item, idx);
      obj._drawItemList((idx + 1));
    }
    window.setTimeout(tOF, 5);
  }
  if (! item.preview) {
    item._setPreview();
  }
  if (! item.preview.complete) {
    item.preview.onload = Gallery._tmpThumbLoader;
    return;
  }
  Gallery._tmpThumbLoader();
} 

//************************************************************

Gallery.prototype._drawItem = function (item, pos) {
  if (! arguments.length) {
    focus();
    throw new Error('Gallery->drawItem: Falsche Anzahl von Argumenten!');
  }
  //alert(item + ' : ' + pos);
  if (this.config.type == 'type6') {
    return this._drawItem_type6(item, pos);
  } else if (this.config.type == 'type5') {
    return this._drawItem_type5(item, pos);
  } else if (this.config.type == 'type4') {
    return this._drawItem_type4(item, pos);
  } else if (this.config.type == 'type3') {
    return this._drawItem_type3(item, pos);
  } else if (this.config.type == 'type2') {
    return this._drawItem_type2(item, pos);
  } else {
    return this._drawItem_type1(item, pos);
  }
}  

//************************************************************

Gallery.prototype._drawItem_type1 = function (item, pos) {
  if (! arguments.length) {
    focus();
    throw new Error('Gallery->_drawItem_type1: Falsche Anzahl von Argumenten!');
  }
  if (! this._itemListElem) {
    focus();
    throw new Error('Gallery->_drawItem_type1: Es existiert kein ItemList-HTML-Element!');
  }
  var img = item.preview;
  if (! img ) {
    item._setPreview();
    img = item.preview;
  }
  var alt = 'Bild ' + parseFloat(item.listPosition + 1) ;
  if (item.title) {
    alt += ' - ' + item.title;
  }
  alt = '';
  img.alt = alt;
  if (item.title) {
    //img.title = item.title;
  }
  img.className = 'GALLERY_LIST_ITEM';
  var id = this.id;
  Gallery._tmpDrawItemLoader = function (){
    Gallery.getInstance(id )._drawItem_type1(item, pos);
  }
  if (! img.complete) {
    img.onload = Gallery._tmpDrawItemLoader;
    return;
  }
  var anc = document.createElement('a');
  anc.style.visibility = 'hidden';
  anc.href = "javascript:void(0);";
  anc.title = alt;
  anc.className = 'GALLERY_LIST_ITEM';
  var item_id = item.id;
  this._itemListElem.appendChild(anc);
  var m_over = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnmouseover(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('mouseover', anc, m_over);
  var m_out = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnmouseout(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('mouseout', anc, m_out);
  var m_click = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnclick(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('click', anc, m_click);
  anc.appendChild(img);
  if (pos != undefined) {
    pos = parseFloat(pos);
    if (this.config.dimension == 'vertical') {
      var top = parseFloat(img.parentNode.offsetHeight);
      top *= pos;
      img.parentNode.style.top = GalleryTools.getCssUnit(top);
    } else {
      var left = parseFloat(img.parentNode.offsetWidth);
      left *= pos;
      img.parentNode.style.left = GalleryTools.getCssUnit(left);
    }
  }
  img.parentNode.style.zIndex = parseFloat(item.listPosition + 1);
  img.parentNode.style.visibility = 'visible';
  return true;
} 

//************************************************************

Gallery.prototype._drawItem_type2 = function (item, pos) {
  if (! arguments.length) {
    focus();
    throw new Error('Gallery->_drawItem_type2: Falsche Anzahl von Argumenten!');
  }
  if (! this._itemListElem) {
    focus();
    throw new Error('Gallery->_drawItem_type2: Es existiert kein ItemList-HTML-Element!');
  }
  var img = item.preview;
  if (! img ) {
    item._setPreview();
    img = item.preview;
  }
  var alt = 'Bild ' + parseFloat(item.listPosition + 1) ;
  if (item.title) {
    alt += ' - ' + item.title;
  }
  img.alt = alt;
  if (item.title) {
    //img.title = item.title;
  }
  alt = '';
  img.className = 'GALLERY_LIST_ITEM';
  var anc = document.createElement('a');
  //anc.style.visibility = 'hidden';
  anc.href = "javascript:void(0);";
  anc.title = alt;
  anc.className = 'GALLERY_LIST_ITEM';
  var div = document.createElement('div');
  div.style.visibility = 'hidden';
  div.className = 'GALLERY_LIST_ITEM';
  div.appendChild(anc);
  var div_text =  document.createElement('div');
  div_text.className = 'GALLERY_LIST_ITEM_TEXT';
  var h5 =  document.createElement('h5');
  h5.className = 'GALLERY_LIST_ITEM_TEXT';
  h5.innerHTML = item.title;
  div_text.appendChild(h5);
  if (item.subtitle) {
    var p =  document.createElement('div');
    p.className = 'GALLERY_LIST_ITEM_TEXT';
    var subt = '';
    if (item.subtitle) {
      subt = item.subtitle;
    }
    p.innerHTML = subt;
    div_text.appendChild(p);
  }
  div.appendChild(div_text);
  
  var id = this.id;
  Gallery._tmpDrawItemLoader = function (){
    Gallery.getInstance(id )._drawItem_type2(item, pos);
  }
  //alert(this.id + ':' + item.id + ' = ' + img.complete);
  if (! img.complete) {
    img.onload = Gallery._tmpDrawItemLoader;
    return;
  } else {
    img.onload = '';
  }
  var item_id = item.id;
  this._itemListElem.appendChild(div);
  /*
  var m_over = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnmouseover(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('mouseover', anc, m_over);
  var m_out = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnmouseout(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('mouseout', anc, m_out);
  */
  var m_click = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnclick(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('click', anc, m_click);
  anc.appendChild(img);
  if (pos != undefined) {
    pos = parseFloat(pos);
    if (this.config.dimension == 'vertical') {
      var top = parseFloat(div.offsetHeight);
      top *= pos;
      div.style.top = GalleryTools.getCssUnit(top);
    } else {
      var left = parseFloat(div.offsetWidth);
      left *= pos;
      div.style.left = GalleryTools.getCssUnit(left);
    }
  }
  div.style.zIndex = parseFloat(item.listPosition + 1);
  div.style.visibility = 'visible';
  return true;
}  

//************************************************************

Gallery.prototype._drawItem_type3 = function (item, pos) {
  if (! arguments.length) {
    focus();
    throw new Error('Gallery->_drawItem_type3: Falsche Anzahl von Argumenten!');
  }
  if (! this._itemListElem) {
    focus();
    throw new Error('Gallery->_drawItem_type3: Es existiert kein ItemList-HTML-Element!');
  }
  var img = item.preview;
  if (! img ) {
    item._setPreview();
    img = item.preview;
  }
  var alt = 'Bild ' + parseFloat(item.listPosition + 1) ;
  if (item.title) {
    alt += ' - ' + item.title;
  }
  img.alt = alt;
  if (item.title) {
    //img.title = item.title;
  }
  alt = '';
  img.className = 'GALLERY_LIST_ITEM';
  var id = this.id;
  Gallery._tmpDrawItemLoader = function (){
    Gallery.getInstance(id )._drawItem_type3(item, pos);
  }
  if (! img.complete) {
    img.onload = Gallery._tmpDrawItemLoader;
    return;
  }
  var anc = document.createElement('a');
  anc.style.visibility = 'hidden';
  anc.href = "javascript:void(0);";
  anc.title = alt;
  anc.className = 'GALLERY_LIST_ITEM';
  var item_id = item.id;
  this._itemListElem.appendChild(anc);
  var m_over = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnmouseover(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('mouseover', anc, m_over);
  var m_out = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnmouseout(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('mouseout', anc, m_out);
  var m_click = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnclick(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('click', anc, m_click);
  anc.appendChild(img);
  if (pos != undefined) {
    pos = parseFloat(pos);
    if (this.config.dimension == 'vertical') {
      var top = parseFloat(img.parentNode.offsetHeight);
      top *= pos;
      img.parentNode.style.top = GalleryTools.getCssUnit(top);
    } else {
      var left = parseFloat(img.parentNode.offsetWidth);
      left *= pos;
      img.parentNode.style.left = GalleryTools.getCssUnit(left);
    }
  }
  img.parentNode.style.zIndex = parseFloat(item.listPosition + 1);
  img.parentNode.style.visibility = 'visible';
  return true;
} 

//************************************************************

Gallery.prototype._drawItem_type4 = function (item, pos) {
  if (! arguments.length) {
    focus();
    throw new Error('Gallery->_drawItem_type4: Falsche Anzahl von Argumenten!');
  }
  if (! this._itemListElem) {
    focus();
    throw new Error('Gallery->_drawItem_type4: Es existiert kein ItemList-HTML-Element!');
  }
  var img = item.preview;
  if (! img ) {
    item._setPreview();
    img = item.preview;
  }
  var alt = 'Bild ' + parseFloat(item.listPosition + 1) ;
  if (item.title) {
    alt += ' - ' + item.title;
  }
  img.alt = alt;
  if (item.title) {
    img.title = item.title;
  }
  img.className = 'GALLERY_LIST_ITEM';
  anc.className = 'GALLERY_LIST_ITEM';
  var id = this.id;
  Gallery._tmpDrawItemLoader = function (){
    Gallery.getInstance(id )._drawItem_type4(item, pos);
  }
  if (! img.complete) {
    img.onload = Gallery._tmpDrawItemLoader;
    return;
  }
  var anc = document.createElement('a');
  anc.style.visibility = 'hidden';
  anc.href = "javascript:void(0);";
  anc.title = alt;
  //var classN = 'GALLERY_LIST_ITEM';      
  //classN += ' ZOOM-CLASS-'  + parseFloat(pos + 1);
  //anc.className = classN;
  var item_id = item.id;
  this._itemListElem.appendChild(anc);
  var m_over = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnmouseover(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('mouseover', anc, m_over);
  var m_out = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnmouseout(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('mouseout', anc, m_out);
  var m_click = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnclick(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('click', anc, m_click);
  anc.appendChild(img);
  if (pos != undefined) {
    pos = parseFloat(pos);
    var prev = Gallery.prototype._getPreviousItem(img);
    if (this.config.dimension == 'vertical') {
      var top = 0;
      if (prev) {
        top = parseFloat(prev.offsetTop + prev.offsetHeight);
      }
      //top *= pos;
      img.parentNode.style.top = GalleryTools.getCssUnit(top);
    } else {
      var left = 0;
      if (prev) {
        left = parseFloat(prev.offsetLeft + prev.offsetWidth);
      }
      //left *= pos;
      img.parentNode.style.left = GalleryTools.getCssUnit(left);
    }
  }
  img.parentNode.style.zIndex = parseFloat(item.listPosition + 1);
  img.parentNode.style.visibility = 'visible';
  return true;
} 

//************************************************************

Gallery.prototype._drawItem_type5 = function (item, pos) {
  if (! arguments.length) {
    focus();
    throw new Error('Gallery->_drawItem_type5: Falsche Anzahl von Argumenten!');
  }
  if (! this._itemListElem) {
    focus();
    throw new Error('Gallery->_drawItem_type5: Es existiert kein ItemList-HTML-Element!');
  }
  var img = item.preview;
  if (! img ) {
    item._setPreview();
    img = item.preview;
  }
  var alt = 'Bild ' + parseFloat(item.listPosition + 1) ;
  if (item.title) {
    alt += ' - ' + item.title;
  }
  img.alt = alt;
  if (item.title) {
    img.title = item.title;
  }
  img.className = 'GALLERY_LIST_ITEM';
  var anc = document.createElement('a');
  anc.style.visibility = 'hidden';
  anc.href = "javascript:void(0);";
  anc.title = alt;
  anc.className = 'GALLERY_LIST_ITEM';
  var id = this.id;
  Gallery._tmpDrawItemLoader = function (){
    Gallery.getInstance(id )._drawItem_type5(item, pos);
  }
  if (! img.complete) {
    img.onload = Gallery._tmpDrawItemLoader;
    return;
  }
  var item_id = item.id;
  this._itemListElem.appendChild(anc);
  var m_over = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnmouseover(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('mouseover', anc, m_over);
  var m_out = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnmouseout(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('mouseout', anc, m_out);
  var m_click = new Function ('','return Gallery.getInstance(\'' + id + '\').rotate(this);'); 
  GalleryTools.addEvent('click', anc, m_click);
  anc.appendChild(img);
  //alert(pos);
  if (pos != undefined) {
    var mark = this.specification.markerList[pos];
    var mod = this.specification.modelList[pos];
    //alert(mod.className + ' : ' + mark.className);
    if (! mark || ! mod) {
      mark = this.specification.markerList[this.specification.markerList.length -1];
      mod = this.specification.modelList[this.specification.modelList.length -1];
      if (this.config.dimension == 'vertical') {
        var top = parseFloat(img.parentNode.offsetHeight);
        top *= pos + 1;
        img.parentNode.style.top = GalleryTools.getCssUnit(top);
      } else {
        img.style.width =  GalleryTools.getCssUnit(mod.width);
        var left = mark.left + mark.width;
        img.parentNode.style.left = GalleryTools.getCssUnit(left);
        var top = mark.height - parseFloat(mark.height / 2);
        top -= parseFloat(img.offsetHeight / 2);
        img.parentNode.style.top = GalleryTools.getCssUnit(top);
      }
    } else {
      img.parentNode.style.visibility = 'visible';
      if (this.config.dimension == 'vertical') {
        var top = parseFloat(img.parentNode.offsetHeight);
        top *= pos;
        img.parentNode.style.top = GalleryTools.getCssUnit(top);
      } else {
        img.style.width =  GalleryTools.getCssUnit(mod.width);
        var left = mark.left + parseFloat(mark.width / 2);
        left -= parseFloat(img.offsetWidth / 2);
        img.parentNode.style.left = GalleryTools.getCssUnit(left);
        var top = mark.height - parseFloat(mark.height / 2);
        top -= parseFloat(img.offsetHeight / 2);
        img.parentNode.style.top = GalleryTools.getCssUnit(top);
      }
    }
  }   
  //img.parentNode.style.zIndex = parseFloat(10 - item.listPosition);
  //alert(pos + ':' + item.listPosition);
  //img.parentNode.className += ' GALLERY_SPECIFICATIONS_MODEL_' + (item.listPosition + 1);    
  img.parentNode.className += ' ' + mod.className;
  return true;
} 

//************************************************************

Gallery.prototype._drawItem_type6 = function (item, pos) {
  if (! arguments.length) {
    focus();
    throw new Error('Gallery->_drawItem_type6: Falsche Anzahl von Argumenten!');
  }
  if (! this._itemListElem) {
    focus();
    throw new Error('Gallery->_drawItem_type6: Es existiert kein ItemList-HTML-Element!');
  }
  var img = item.preview;
  if (! img ) {
    item._setPreview();
    img = item.preview;
  }
  var alt = 'Bild ' + parseFloat(item.listPosition + 1) ;
  if (item.title) {
    alt += ' - ' + item.title;
  }
  img.alt = alt;
  if (item.title) {
    img.title = item.title;
  }
  img.className = 'GALLERY_LIST_ITEM';
  var anc = document.createElement('a');
  anc.style.visibility = 'hidden';
  anc.href = "javascript:void(0);";
  anc.title = alt;
  anc.className = 'GALLERY_LIST_ITEM';
  var id = this.id;
  Gallery._tmpDrawItemLoader = function (){
    Gallery.getInstance(id )._drawItem_type6(item, pos);
  }
  if (! img.complete) {
    img.onload = Gallery._tmpDrawItemLoader;
    return;
  }
  var item_id = item.id;
  this._itemListElem.appendChild(anc);
  var m_over = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnmouseover(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('mouseover', anc, m_over);
  var m_out = new Function ('','Gallery.getInstance(\'' + id + '\').itemOnmouseout(\'' +item_id+ '\');'); 
  GalleryTools.addEvent('mouseout', anc, m_out);
  var m_click = new Function ('','return Gallery.getInstance(\'' + id + '\').rotate(this);'); 
  GalleryTools.addEvent('click', anc, m_click);
  anc.appendChild(img);
  //alert(pos);
  if (pos != undefined) {
    var mark = this.specification.markerList[pos];
    var mod = this.specification.modelList[pos];
    //alert(mod.className + ' : ' + mark.className);
    if (! mark || ! mod) {
      mark = this.specification.markerList[this.specification.markerList.length -1];
      mod = this.specification.modelList[this.specification.modelList.length -1];
      if (this.config.dimension == 'vertical') {
        var top = parseFloat(img.parentNode.offsetHeight);
        top *= pos + 1;
        img.parentNode.style.top = GalleryTools.getCssUnit(top);
      } else {
        img.style.width =  GalleryTools.getCssUnit(mod.width);
        var left = mark.left + mark.width;
        img.parentNode.style.left = GalleryTools.getCssUnit(left);
        var top = mark.height - parseFloat(mark.height / 2);
        top -= parseFloat(img.offsetHeight / 2);
        img.parentNode.style.top = GalleryTools.getCssUnit(top);
      }
    } else {
      img.parentNode.style.visibility = 'visible';
      if (this.config.dimension == 'vertical') {
        var top = parseFloat(img.parentNode.offsetHeight);
        top *= pos;
        img.parentNode.style.top = GalleryTools.getCssUnit(top);
      } else {
        img.style.width =  GalleryTools.getCssUnit(mod.width);
        var left = mark.left + parseFloat(mark.width / 2);
        left -= parseFloat(img.offsetWidth / 2);
        img.parentNode.style.left = GalleryTools.getCssUnit(left);
        var top = mark.height - parseFloat(mark.height / 2);
        top -= parseFloat(img.offsetHeight / 2);
        img.parentNode.style.top = GalleryTools.getCssUnit(top);
      }
    }
  }   
  //img.parentNode.style.zIndex = parseFloat(10 - item.listPosition);
  //alert(pos + ':' + item.listPosition);
  //img.parentNode.className += ' GALLERY_SPECIFICATIONS_MODEL_' + (item.listPosition + 1);    
  img.parentNode.className += ' ' + mod.className;
  return true;
} 

//************************************************************

Gallery.prototype._getPreviousItem = function (elem) {
  if (! arguments.length) {
    return;
  } 
  var p = elem.parentNode;
  var prev = p.previousSibling;
  while (prev) {
    if (prev.className.toString().match(elem.className.toString())) {
      return prev;
    }
    prev = prev.previousSibling;
  }
  return undefined;
}

//************************************************************

Gallery.prototype.rotate = function (elem) {
  if (this.config.type == 'type4') {
      if (this.config.activeItemLength >= (this.itemList.length +1)) {
        return;
      }
      if (this._isBusy) {
        return;
      }
      this._isBusy = true;
      this._type4(elem);
  } else if (this.config.type == 'type6') {
      if (this._isBusy) {
        return;
      }
      this._isBusy = true;
      this._type6(elem);
  } else if (this.config.type == 'type5') {
      if (this._isBusy) {
        return;
      }
      this._isBusy = true;
      this._type5(elem);
  } else if (this.config.type == 'type3') {
      if (this.config.activeItemLength >= (this.itemList.length +1)) {
        return;
      }
      if (this._isBusy) {
        return;
      }
      this._isBusy = true;
      this._type3(elem);
  } else if (this.config.type == 'type2') {
      if (this.config.activeItemLength >= (this.itemList.length +1)) {
        return;
      }
      if (this._isBusy) {
        return;
      }
      this._isBusy = true;
      this._type2(elem);
  } else {
      if (this.config.activeItemLength >= (this.itemList.length +1)) {
        return;
      }
      if (this._isBusy) {
        return;
      }
      this._isBusy = true;
      this._type1(elem);
  }
}  

//************************************************************

Gallery.prototype._type1 = function () {
  if (this.config.direction == 'descending') {
      this._type1_descending();
  } else {
      this._type1_ascending();
  }
} 

//************************************************************

Gallery.prototype._type2 = function () {
  if (this.config.direction == 'descending') {
      this._type2_descending((this.activeItemList.length -2));
  } else {
      this._type2_ascending();
  }
} 

//************************************************************

Gallery.prototype._type3 = function () {
  if (this.config.direction == 'descending') {
      this._type3_descending();
  } else {
      this._type3_ascending();
  }
}  

//************************************************************

Gallery.prototype._type4 = function () {
  if (this.config.direction == 'descending') {
      this._type4_descending();
  } else {
      this._type4_ascending();
  }
} 

//************************************************************

Gallery.prototype._type5_alt = function (elem) {
  var idx = elem.className.replace(/.*.GALLERY_SPECIFICATIONS_MODEL_/,'');
  var middle = Math.ceil(this.config.activeItemLength / 2);
  var item = this.activeItemList[idx -1];
  if (idx  == middle) {
    if (item && item.linkURL)  {
      window.location = item.linkURL;
    }
    return false;
  }
  if (idx  < middle) {
      this.config.setDirection('descending'); 
  }
  if (idx  > middle) {
      this.config.setDirection('ascending'); 
  }
  if (this.config.direction == 'descending') {
      this._type5_descending();
  } else {
      this._type5_ascending();
  }
} 

//************************************************************

Gallery.prototype._type5 = function (elem) {
  var idx = elem.className.replace(/.*.GALLERY_SPECIFICATIONS_MODEL_/,'');
  var middle = Math.ceil(this.config.activeItemLength / 2);
  var item = this.activeItemList[idx];
  var middleIDX = idx-1;
  var middleItem = this.activeItemList[middleIDX];
  if (idx  == middle) {
    if (middleItem && middleItem.linkURL)  {
      window.location = middleItem.linkURL;
    }
    this._isBusy = false;
    return false;
  }
  /*
  if (idx  == middle) {
    if (item)  {
      this._showDetail(middleItem.id);
    }
    this._isBusy = false;
    return false;
  }*/
  if (idx  < middle) {
      this.config.setDirection('descending'); 
  }
  if (idx  > middle) {
      this.config.setDirection('ascending'); 
  }
  if (this.config.direction == 'descending') {
      this._type5_descending();
  } else {
      this._type5_ascending();
  }
} 

//************************************************************

Gallery.prototype._type6 = function (elem) {
  var idx = elem.className.replace(/.*.GALLERY_SPECIFICATIONS_MODEL_/,'');
  var middle = Math.ceil(this.config.activeItemLength / 2);
  var item = this.activeItemList[idx];
  var middleIDX = idx-1;
  var middleItem = this.activeItemList[middleIDX];
  if (idx  == middle) {
    if (middleItem)  {
      this._showDetail(middleItem.id);
    }
    this._isBusy = false;
    return false;
  }
  if (idx  < middle) {
      this.config.setDirection('descending'); 
  }
  if (idx  > middle) {
      this.config.setDirection('ascending'); 
  }
  if (this.config.direction == 'descending') {
      this._type6_descending();
  } else {
      this._type6_ascending();
  }
} 

//************************************************************

Gallery.prototype._type1_ascending = function (n, rest) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  if (this.rotationBreak == true) {
    return;
  }
  if (n == undefined) {
    n = 0;
  }
  if (rest == undefined) {
    rest = 0;
  }
  var _speedPix = this.config.speedPixel;
  if (IE) {
    _speedPix = Math.ceil(_speedPix * 4);        
  }
  var id = this.id;
  for (var i=n; i<this.activeItemList.length; i++) {
    var item = this.activeItemList[i];
    if (! item.preview.complete) {
      var lfunc = new Function ('','Gallery.getInstance(\'' + id + '\')._type1_ascending(\'' + i + '\');');  
      GalleryTools.addEvent('load', item.preview, lfunc);
      return;
    }
    var lastItem = this.activeItemList[this.activeItemList.length-1];
    var boundary;
    var diff;
    var pos;
    if (this.config.dimension == 'vertical') {
      // vertical
      boundary = parseFloat(item.preview.parentNode.offsetHeight) +1;
      boundary *= -1;
      var top = parseFloat(item.preview.style.top);
      var diff = top - boundary ;
      pos = _speedPix; 
      if (rest) {
         pos = rest;
      } else if (diff <= _speedPix) {
         pos = diff;
         rest = pos;
      } 
       top -=pos;
      item.preview.parentNode.style.top = GalleryTools.getCssUnit(top);
      if (top <= boundary) {
        if (rest) {
          if (this.config.rotate != 'auto') {  
            this.rotationBreak = true;
          }
          this._isBusy = false;
        }
        this.activeItemList.shift();
        this._itemListElem.removeChild(item.preview.parentNode);
        var newTop = parseFloat(parseFloat(lastItem.preview.parentNode.style.top) + parseFloat(lastItem.preview.parentNode.offsetHeight));
        var nextItem;
        if (lastItem.listPosition == (this.itemList.length-1)) {
          nextItem = this.itemList[0];
        } else {
          nextItem = this.itemList[lastItem.listPosition +1];
        }
        if (! nextItem.preview || ! nextItem.preview.parentNode) {
          if (! this._drawItem(nextItem))  {
             return;
          }
        }
        nextItem.preview.parentNode.style.top = GalleryTools.getCssUnit(newTop);
        this._itemListElem.appendChild(nextItem.preview.parentNode);
        this.activeItemList.push(nextItem);
        i--;
      }
    } else {
      // horizontal
      boundary = parseFloat(item.preview.parentNode.offsetWidth);
      boundary *= -1;
      var left = parseFloat(item.preview.parentNode.style.left);
      diff = left - boundary;
      pos = _speedPix; 
      if (rest) {
         pos = rest;
      } else if (diff <= _speedPix) {
         pos = diff;
         rest = pos;
      } 
      left -= pos;
      item.preview.parentNode.style.left = GalleryTools.getCssUnit(left);
      if (left <= boundary) {
        if (rest) {
          if (this.config.rotate != 'auto') {  
            this.rotationBreak = true;
          }
          this._isBusy = false;
        }
        this.activeItemList.shift();
        this._itemListElem.removeChild(item.preview.parentNode);
        var newLeft = parseFloat(parseFloat(lastItem.preview.parentNode.style.left) + parseFloat(lastItem.preview.parentNode.offsetWidth));
        var nextItem;
        if (lastItem.listPosition == (this.itemList.length-1)) {
          nextItem = this.itemList[0];
        } else {
          nextItem = this.itemList[lastItem.listPosition +1];
        }
        if (! nextItem.preview || ! nextItem.preview.parentNode) {
          if (! this._drawItem(nextItem))  {
             return;
          }
        }
        nextItem.preview.parentNode.style.left = GalleryTools.getCssUnit(newLeft);
        this._itemListElem.appendChild(nextItem.preview.parentNode);
        this.activeItemList.push(nextItem);
        i--;
      }
    }
  }
  var func = new Function ('','Gallery.getInstance(\'' + id + '\')._type1_ascending(undefined,'+ rest +');'); 
  this.timeout = window.setTimeout(func, this.config.speedTime);
} 

//************************************************************

Gallery.prototype._type1_descending = function (n, rest) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  if (this.rotationBreak == true) {
    return;
  }
  if (n == undefined) {
    n = this.activeItemList.length -1;
  }
  var id = this.id;
  var _speedPix = this.config.speedPixel;
  if (IE) {
    _speedPix = Math.ceil(_speedPix * 4);        
  }
  for (var i=n; i>=0; i--) {
    var item = this.activeItemList[i];
    if (! item.preview.complete) {
      var lfunc = new Function ('','Gallery.getInstance(\'' + id + '\')._type1_descending(\'' + i + '\');');  
      GalleryTools.addEvent('load', item.preview, lfunc);
      return;
    }
    var lastItem = this.activeItemList[0];
    var boundary;
    var pos;
    var diff;
    if (this.config.dimension == 'vertical') {
      // vertical
      var diffHeight = parseFloat(item.preview.parentNode.offsetHeight) - parseFloat(item.preview.offsetHeight);
      boundary = (parseFloat(item.preview.parentNode.offsetHeight) + parseFloat(this._displayElem.offsetHeight) ) + diffHeight;
      var top = parseFloat(item.preview.parentNode.style.top);  
      diff = boundary - top;
      pos = _speedPix; 
      if (rest) {
         pos = rest;
      } else if (diff <= _speedPix) {
         pos = diff;
         rest = pos;
      } 
      top += pos;
      item.preview.parentNode.style.top = GalleryTools.getCssUnit(top);
      if (top >= boundary) {
        if (rest) {
          if (this.config.rotate != 'auto') {  
            this.rotationBreak = true;
          }
          this._isBusy = false;
        } 
        this.activeItemList.pop();
        this._itemListElem.removeChild(item.preview.parentNode);
        var newTop = parseFloat(parseFloat(lastItem.preview.parentNode.style.top) - parseFloat(lastItem.preview.parentNode.offsetHeight));
        var nextItem;
        if (lastItem.listPosition == 0) {
          //alert(1 + ' _ ' + item.listPosition);
          nextItem = this.itemList[this.itemList.length-1];
        } else {
          nextItem = this.itemList[lastItem.listPosition -1];
        }
        if (! nextItem.preview || ! nextItem.preview.parentNode) {
          this._drawItem(nextItem);
        }
        nextItem.preview.parentNode.style.top = GalleryTools.getCssUnit(newTop);
        this._itemListElem.appendChild(nextItem.preview.parentNode);
        this.activeItemList.unshift(nextItem);
        i++;
      }
    } else {
      // horizontal
      var diffWidth = parseFloat(item.preview.parentNode.offsetWidth) - parseFloat(item.preview.offsetWidth);
      boundary = ( parseFloat(item.preview.parentNode.offsetWidth) + parseFloat(this._displayElem.offsetWidth) ) + diffWidth;
      //alert(boundary);
      var left = parseFloat(item.preview.parentNode.style.left);      
      diff = boundary - left;
      pos = _speedPix; 
      if (rest) {
         pos = rest;
      } else if (diff <= _speedPix) {
         pos = diff;
         rest = pos;
      } 
      left += pos;
      item.preview.parentNode.style.left = GalleryTools.getCssUnit(left);
      if (left >= boundary) {
        if (rest) {
          if (this.config.rotate != 'auto') {  
            this.rotationBreak = true;
          }
          this._isBusy = false;
        } 
        this.activeItemList.pop();
        this._itemListElem.removeChild(item.preview.parentNode);
        var newLeft = parseFloat(parseFloat(lastItem.preview.parentNode.style.left) - parseFloat(lastItem.preview.parentNode.offsetWidth));
        var nextItem;
        if (lastItem.listPosition == 0) {
          //alert(1 + ' _ ' + item.listPosition);
          nextItem = this.itemList[this.itemList.length-1];
        } else {
          nextItem = this.itemList[lastItem.listPosition -1];
        }
        if (! nextItem.preview || ! nextItem.preview.parentNode) {
          this._drawItem(nextItem);
        }
        //alert(nextItem.id + ' : ' + nextItem.preview.className + ' : ' + nextItem.preview.src);
        nextItem.preview.parentNode.style.left = GalleryTools.getCssUnit(newLeft);
        this._itemListElem.appendChild(nextItem.preview.parentNode);
        this.activeItemList.unshift(nextItem);
        i++;
      }
    }
  }
  var func = new Function ('','Gallery.getInstance(\'' + id + '\')._type1_descending(undefined,'+ rest +');'); 
  this.timeout = window.setTimeout(func, this.config.speedTime);
} 

//************************************************************

Gallery.prototype._type2_ascending = function (n, rest) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  if (this.rotationBreak == true) {
    return;
  }
  if (n == undefined) {
    n = 0;
  }
  if (rest == undefined) {
    rest = 0;
  }
  var id = this.id;
  var _speedPix = this.config.speedPixel;
  if (IE) {
    _speedPix = Math.ceil(_speedPix * 4);        
  }
  for (var i=n; i<this.activeItemList.length; i++) {
    var item = this.activeItemList[i];
    if (! item.preview.complete) {
      var lfunc = new Function ('','Gallery.getInstance(\'' + id + '\')._type2_ascending(\'' + i + '\');');  
      GalleryTools.addEvent('load', item.preview, lfunc);
      return;
    }
    var lastItem = this.activeItemList[this.activeItemList.length-1];
    var boundary;
    var diff;
    var pos;
    if (this.config.dimension == 'vertical') {
      // vertical
      boundary = parseFloat(item.preview.parentNode.parentNode.offsetHeight);
      boundary *= -1;
      var top = parseFloat(item.preview.parentNode.parentNode.style.top);
      var diff = top - boundary ;
      pos = _speedPix; 
      if (rest) {
         pos = rest;
      } else if (diff <= _speedPix) {
         pos = diff;
         rest = pos;
      } 
       top -=pos;
      item.preview.parentNode.parentNode.style.top = GalleryTools.getCssUnit(top);
      if (top <= boundary) {
        if (rest) {
          if (this.config.rotate != 'auto') {  
            this.rotationBreak = true;
          }
          this._isBusy = false;
        }
        this.activeItemList.shift();
        this._itemListElem.removeChild(item.preview.parentNode.parentNode);
        var newTop = parseFloat(parseFloat(lastItem.preview.parentNode.parentNode.style.top) + parseFloat(lastItem.preview.parentNode.parentNode.offsetHeight));
        var nextItem;
        if (lastItem.listPosition == (this.itemList.length-1)) {
          nextItem = this.itemList[0];
        } else {
          nextItem = this.itemList[lastItem.listPosition +1];
        }
        if (! nextItem.preview || ! nextItem.preview.parentNode || ! nextItem.preview.parentNode.parentNode) {
          if (! this._drawItem(nextItem))  {
             return;
          }
        }
        nextItem.preview.parentNode.parentNode.style.top = GalleryTools.getCssUnit(newTop);
        this._itemListElem.appendChild(nextItem.preview.parentNode.parentNode);
        this.activeItemList.push(nextItem);
        i--;
      }
    } else {
      // horizontal
      boundary = parseFloat(item.preview.parentNode.parentNode.offsetWidth);
      boundary *= -1;
      var left = parseFloat(item.preview.parentNode.parentNode.style.left);
      diff = left - boundary;
      pos = _speedPix; 
      if (rest) {
         pos = rest;
      } else if (diff <= _speedPix) {
         pos = diff;
         rest = pos;
      } 
      left -= pos;
      item.preview.parentNode.parentNode.style.left = GalleryTools.getCssUnit(left);
      if (left <= boundary) {
        if (rest) {
          if (this.config.rotate != 'auto') {  
            this.rotationBreak = true;
          }
          this._isBusy = false;
        }
        this.activeItemList.shift();
        //alert(item.preview.parentNode.parentNode.innerHTML);
        this._itemListElem.removeChild(item.preview.parentNode.parentNode);
        var newLeft = parseFloat(parseFloat(lastItem.preview.parentNode.parentNode.style.left) + parseFloat(lastItem.preview.parentNode.parentNode.offsetWidth));
        var nextItem;
        if (lastItem.listPosition == (this.itemList.length-1)) {
          nextItem = this.itemList[0];
        } else {
          nextItem = this.itemList[lastItem.listPosition +1];
        }
        if (! nextItem.preview || ! nextItem.preview.parentNode || ! nextItem.preview.parentNode.parentNode) {
          if (! this._drawItem(nextItem))  {
             return;
          }
        }
        nextItem.preview.parentNode.parentNode.style.left = GalleryTools.getCssUnit(newLeft);
        this._itemListElem.appendChild(nextItem.preview.parentNode.parentNode);
        this.activeItemList.push(nextItem);
        i--;
      }
    }
  }
  var func = new Function ('','Gallery.getInstance(\'' + id + '\')._type2_ascending(undefined,'+ rest +');'); 
  this.timeout = window.setTimeout(func, this.config.speedTime);
} 

//************************************************************

Gallery.prototype._type2_descending = function (n, rest) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  if (this.rotationBreak == true) {
    return;
  }
  if (n == undefined) {
    n = this.activeItemList.length -1;
  }
  var id = this.id;
  var _speedPix = this.config.speedPixel;
  if (IE) {
    _speedPix = Math.ceil(_speedPix * 4);        
  }
  for (var i=n; i>=0; i--) {
    var item = this.activeItemList[i];
    if (! (item.preview || item.preview.complete)) {
      var lfunc = new Function ('','Gallery.getInstance(\'' + id + '\')._type2_descending(\'' + i + '\');');  
      GalleryTools.addEvent('load', item.preview, lfunc);
      return;
    }
    lastItem = this.activeItemList[0];
    var boundary;
    var pos;
    var diff;
    if (this.config.dimension == 'vertical') {
      // vertical
      //var diffHeight = parseFloat(item.preview.parentNode.parentNode.offsetHeight) - parseFloat(item.preview.offsetHeight);
      var diffHeight = -1 * _speedPix;
      boundary = (parseFloat(item.preview.parentNode.parentNode.offsetHeight) + parseFloat(this._displayElem.offsetHeight) ) + diffHeight;
      var top = parseFloat(item.preview.parentNode.parentNode.style.top);  
      diff = boundary - top;
      pos = _speedPix; 
      if (rest) {
         pos = rest;
      } else if (diff <= _speedPix) {
         pos = diff;
         rest = pos;
      } 
      top += pos;
      item.preview.parentNode.parentNode.style.top = GalleryTools.getCssUnit(top);
      if (top >= boundary) {
        if (rest) {
          if (this.config.rotate != 'auto') {  
            this.rotationBreak = true;
          }
          this._isBusy = false;
        } 
        this.activeItemList.pop();
        this._itemListElem.removeChild(item.preview.parentNode.parentNode);
        var newTop = parseFloat(parseFloat(lastItem.preview.parentNode.parentNode.style.top) - parseFloat(lastItem.preview.parentNode.parentNode.offsetHeight) - _speedPix);
        var nextItem;
        if (lastItem.listPosition == 0) {
          nextItem = this.itemList[this.itemList.length-1];
        } else {
          nextItem = this.itemList[lastItem.listPosition -1];
        }
        if (! nextItem.preview || ! nextItem.preview.parentNode || ! nextItem.preview.parentNode.parentNode) {
          this._drawItem(nextItem);
        }
        nextItem.preview.parentNode.parentNode.style.top = GalleryTools.getCssUnit(newTop);
        this._itemListElem.appendChild(nextItem.preview.parentNode.parentNode);
        this.activeItemList.unshift(nextItem);
        i++;
      }
    } else {
      // horizontal
      //var diffWidth = parseFloat(item.preview.parentNode.parentNode.offsetWidth) - parseFloat(item.preview.offsetWidth);
      var diffWidth = -1 * _speedPix;
      var margin = parseFloat(item.preview.parentNode.parentNode.offsetWidth - item.preview.width);
      if (margin) {
        margin /= 2;
      } else {
        margin = 0;
      }
      boundary = ( parseFloat(item.preview.parentNode.parentNode.offsetWidth) + parseFloat(this._displayElem.offsetWidth) ) + diffWidth + margin;
      //alert(boundary);
      var left = parseFloat(item.preview.parentNode.parentNode.style.left);      
      diff = boundary - left;
      pos = _speedPix; 
      if (rest) {
         pos = rest;
      } else if (diff <= _speedPix) {
         pos = diff;
         rest = pos;
      } 
      left += pos;
      item.preview.parentNode.parentNode.style.left = GalleryTools.getCssUnit(left);
      if (left >= boundary) {
        if (rest) {
          if (this.config.rotate != 'auto') {  
            this.rotationBreak = true;
          }
          this._isBusy = false;
        } 
        this.activeItemList.pop();
        this._itemListElem.removeChild(item.preview.parentNode.parentNode);
        var newLeft = parseFloat(parseFloat(lastItem.preview.parentNode.parentNode.style.left) - parseFloat(lastItem.preview.parentNode.parentNode.offsetWidth) );
        var nextItem;
        if (lastItem.listPosition == 0) {
          nextItem = this.itemList[this.itemList.length -1];
        } else {
          nextItem = this.itemList[lastItem.listPosition -1];
        }
        if (! nextItem.preview || ! nextItem.preview.parentNode || ! nextItem.preview.parentNode.parentNode) {
          this._drawItem(nextItem);
        } 
        nextItem.preview.parentNode.parentNode.style.left = GalleryTools.getCssUnit(newLeft );
        this._itemListElem.appendChild(nextItem.preview.parentNode.parentNode);
        this.activeItemList.unshift(nextItem);
        i++;
      }
    }
  }
  if (! rest) {
    rest = 'undefined';
  }
  var func = new Function ('','Gallery.getInstance(\'' + id + '\')._type2_descending(undefined,'+ rest +');'); 
  this.timeout = window.setTimeout(func, this.config.speedTime);
} 

//************************************************************

Gallery.prototype._type3_ascending = function (n, rest) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  if (this.rotationBreak == true) {
    return;
  }
  if (n == undefined) {
    n = 0;
  }
  if (rest == undefined) {
    rest = 0;
  }
  var id = this.id;
  var _speedPix = this.config.speedPixel;
  if (IE) {
    _speedPix = Math.ceil(_speedPix * 4);        
  }
  this._itemListElem.innerHTML = '';
  for (var i=n; i<this.activeItemList.length; i++) {
    var item = this.activeItemList[i];
    var nextItem = this.itemList[item.listPosition + 3];
    if (! nextItem) {
      nextItem = this.itemList[(item.listPosition + 3) - this.itemList.length];
    }
    this.activeItemList.splice(i, 1, nextItem);
  }
  this._isBusy = false;
  this.drawItemList();
} 

//************************************************************

Gallery.prototype._type3_descending = function (n, rest) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  if (this.rotationBreak == true) {
    return;
  }
  if (n == undefined) {
    n = 0;
  }
  if (rest == undefined) {
    rest = 0;
  }
  var id = this.id;
  var _speedPix = this.config.speedPixel;
  if (IE) {
    _speedPix = Math.ceil(_speedPix * 4);        
  }
  this._itemListElem.innerHTML = '';
  for (var i=this.activeItemList.length-1; i>=0; i--) {
    var item = this.activeItemList[i];
    var nextItem = this.itemList[item.listPosition - 3];
    if (! nextItem) {
      nextItem = this.itemList[(item.listPosition - 3) + this.itemList.length];
    }
    this.activeItemList.splice(i, 1, nextItem);
  }
  this._isBusy = false;
  this.drawItemList();
} 

//************************************************************

Gallery.prototype._type4_ascending = function (n, rest) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  if (this.rotationBreak == true) {
    return;
  }
  if (n == undefined) {
    n = 0;
  }
  if (rest == undefined) {
    rest = 0;
  }
  var id = this.id;
  var _speedPix = this.config.speedPixel;
  if (IE) {
    _speedPix = Math.ceil(_speedPix * 4);        
  }
  for (var i=n; i<this.activeItemList.length; i++) {
    var item = this.activeItemList[i];
    if (! item.preview.complete) {
      var lfunc = new Function ('','Gallery.getInstance(\'' + id + '\')._type4_ascending(\'' + i + '\');');  
      GalleryTools.addEvent('load', item.preview, lfunc);
      return;
    }
    var lastItem = this.activeItemList[this.activeItemList.length-1];
    var boundary;
    var diff;
    var pos;
    if (this.config.dimension == 'vertical') {
      // vertical
      boundary = parseFloat(item.preview.parentNode.offsetHeight) +1;
      boundary *= -1;
      var top = parseFloat(item.preview.style.top);
      var diff = top - boundary ;
      pos = _speedPix; 
      if (rest) {
         pos = rest;
      } else if (diff <= _speedPix) {
         pos = diff;
         rest = pos;
      } 
       top -=pos;
      item.preview.parentNode.style.top = GalleryTools.getCssUnit(top);
      if (top <= boundary) {
        if (rest) {
          if (this.config.rotate != 'auto') {  
            this.rotationBreak = true;
          }
          this._isBusy = false;
        }
        this.activeItemList.shift();
        this._itemListElem.removeChild(item.preview.parentNode);
        var newTop = parseFloat(parseFloat(lastItem.preview.parentNode.style.top) + parseFloat(lastItem.preview.parentNode.offsetHeight));
        var nextItem;
        if (lastItem.listPosition == (this.itemList.length-1)) {
          nextItem = this.itemList[0];
        } else {
          nextItem = this.itemList[lastItem.listPosition +1];
        }
        if (! nextItem.preview || ! nextItem.preview.parentNode) {
          if (! this._drawItem(nextItem, i))  {
             return;
          }
        }
        nextItem.preview.parentNode.style.top = GalleryTools.getCssUnit(newTop);
        this._itemListElem.appendChild(nextItem.preview.parentNode);
        this.activeItemList.push(nextItem);
        i--;
      }
    } else {
      // horizontal
      boundary = parseFloat(item.preview.parentNode.offsetWidth);
      boundary *= -1;
      var left = parseFloat(item.preview.parentNode.style.left);
      diff = left - boundary;
      pos = _speedPix; 
      if (rest) {
         pos = rest;
      } else if (diff <= _speedPix) {
         pos = diff;
         rest = pos;
      } 
      left -= pos;
      var height = parseFloat(item.preview.height);
      var dw = parseFloat(this._displayElem.offsetWidth);
      var top = parseFloat(item.preview.parentNode.offsetTop);
      var vertex = Math.round(dw - (parseFloat(dw * ( this.config.vertex / 100 ))));
      if (left <= vertex) {
        height += 1;
        top += 1;
      } else {
        if (parseFloat(left + item.preview.offsetWidth)  <= dw) {
          if (item.preview.parentNode.offsetTop > 0) {
            top -= 1;
          }
          height -=  1;
          left += 1;
        }
      }
      item.preview.style.height = GalleryTools.getCssUnit(height);
      item.preview.style.width = 'auto';
      item.preview.parentNode.style.left = GalleryTools.getCssUnit(left);
      item.preview.parentNode.style.top = GalleryTools.getCssUnit(top);
      if (left <= boundary) {
        if (rest) {
          if (this.config.rotate != 'auto') {  
            this.rotationBreak = true;
          }
          this._isBusy = false;
        }
        item.preview.removeAttribute('style');
        item.preview.parentNode.removeAttribute('style');
        // item.preview.style.height = 'auto';
        this.activeItemList.shift();
        this._itemListElem.removeChild(item.preview.parentNode);
        var newLeft = parseFloat(parseFloat(lastItem.preview.parentNode.style.left) + parseFloat(lastItem.preview.parentNode.offsetWidth));
        var nextItem;
        if (lastItem.listPosition == (this.itemList.length-1)) {
          nextItem = this.itemList[0];
        } else {
          nextItem = this.itemList[lastItem.listPosition +1];
        }
        if (! nextItem.preview || ! nextItem.preview.parentNode) {
          if (! this._drawItem(nextItem, i))  {
             return;
          }
        }
        nextItem.preview.parentNode.style.left = GalleryTools.getCssUnit(newLeft);
        this._itemListElem.appendChild(nextItem.preview.parentNode);
        this.activeItemList.push(nextItem);
        i--;
      }
    }
  }
  var func = new Function ('','Gallery.getInstance(\'' + id + '\')._type4_ascending(undefined,'+ rest +');'); 
  this.timeout = window.setTimeout(func, this.config.speedTime);
} 

//************************************************************

Gallery.prototype._type4_descending = function (n, rest) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  if (this.rotationBreak == true) {
    return;
  }
  if (n == undefined) {
    n = this.activeItemList.length -1;
  }
  var id = this.id;
  var _speedPix = this.config.speedPixel;
  if (IE) {
    _speedPix = Math.ceil(_speedPix * 4);        
  }
  for (var i=n; i>=0; i--) {
    var item = this.activeItemList[i];
    if (! item.preview.complete) {
      var lfunc = new Function ('','Gallery.getInstance(\'' + id + '\')._type4_descending(\'' + i + '\');');  
      GalleryTools.addEvent('load', item.preview, lfunc);
      return;
    }
    var lastItem = this.activeItemList[0];
    var boundary;
    var pos;
    var diff;
    if (this.config.dimension == 'vertical') {
      // vertical
      var diffHeight = parseFloat(item.preview.parentNode.offsetHeight) - parseFloat(item.preview.offsetHeight);
      boundary = (parseFloat(item.preview.parentNode.offsetHeight) + parseFloat(this._displayElem.offsetHeight) ) + diffHeight;
      var top = parseFloat(item.preview.parentNode.style.top);  
      diff = boundary - top;
      pos = _speedPix; 
      if (rest) {
         pos = rest;
      } else if (diff <= _speedPix) {
         pos = diff;
         rest = pos;
      } 
      top += pos;
      item.preview.parentNode.style.top = GalleryTools.getCssUnit(top);
      if (top >= boundary) {
        if (rest) {
          if (this.config.rotate != 'auto') {  
            this.rotationBreak = true;
          }
          this._isBusy = false;
        } 
        this.activeItemList.pop();
        this._itemListElem.removeChild(item.preview.parentNode);
        var newTop = parseFloat(parseFloat(lastItem.preview.parentNode.style.top) - parseFloat(lastItem.preview.parentNode.offsetHeight));
        var nextItem;
        if (lastItem.listPosition == 0) {
          //alert(1 + ' _ ' + item.listPosition);
          nextItem = this.itemList[this.itemList.length-1];
        } else {
          nextItem = this.itemList[lastItem.listPosition -1];
        }
        if (! nextItem.preview || ! nextItem.preview.parentNode) {
          this._drawItem(nextItem, i);
        }
        nextItem.preview.parentNode.style.top = GalleryTools.getCssUnit(newTop);
        this._itemListElem.appendChild(nextItem.preview.parentNode);
        this.activeItemList.unshift(nextItem);
        i++;
      }
    } else {
      // horizontal
      var diffWidth = parseFloat(item.preview.parentNode.offsetWidth) - parseFloat(item.preview.offsetWidth);
      boundary = ( parseFloat(item.preview.parentNode.offsetWidth) + parseFloat(this._displayElem.offsetWidth) ) + diffWidth;
      var left = parseFloat(item.preview.parentNode.style.left);
      diff = boundary - left ;
      pos = _speedPix; 
      if (rest) {
         pos = rest;
      } else if (diff <= _speedPix) {
         pos = diff;
         rest = pos;
      } 
      left += pos;
      var height = parseFloat(item.preview.height);
      var dw = parseFloat(this._displayElem.offsetWidth);
      var top = parseFloat(item.preview.parentNode.offsetTop);
      var vertex = Math.round(dw * ( this.config.vertex / 100 ));
      if (left >= vertex) {
        height += 1;
        top += 1;
      } else {
        if (parseFloat(left + item.preview.offsetWidth)  >= 0) {
          if (item.preview.parentNode.offsetTop > 0) {
            top -= 1;
          }
          height -=  1;
          left -= 1;
        }
      }
      item.preview.style.height = GalleryTools.getCssUnit(height);
      item.preview.style.width = 'auto';
      item.preview.parentNode.style.left = GalleryTools.getCssUnit(left);
      item.preview.parentNode.style.top = GalleryTools.getCssUnit(top);
      if (left >= boundary) {
        if (rest) {
          if (this.config.rotate != 'auto') {  
            this.rotationBreak = true;
          }
          this._isBusy = false;
        } 
        item.preview.removeAttribute('style');
        item.preview.parentNode.removeAttribute('style');
        // item.preview.style.height = 'auto';
        this.activeItemList.pop();
        this._itemListElem.removeChild(item.preview.parentNode);
        var newLeft = parseFloat(parseFloat(lastItem.preview.parentNode.style.left) - parseFloat(lastItem.preview.parentNode.offsetWidth));
        var nextItem;
        if (lastItem.listPosition == 0) {
          //alert(1 + ' _ ' + item.listPosition);
          nextItem = this.itemList[this.itemList.length-1];
        } else {
          nextItem = this.itemList[lastItem.listPosition -1];
        }
        if (! nextItem.preview || ! nextItem.preview.parentNode) {
          this._drawItem(nextItem, i);
        }
        //alert(nextItem.id + ' : ' + nextItem.preview.className + ' : ' + nextItem.preview.src);
        nextItem.preview.parentNode.style.left = GalleryTools.getCssUnit(newLeft);
        this._itemListElem.appendChild(nextItem.preview.parentNode);
        this.activeItemList.unshift(nextItem);
        i++;
      }
    }
  }
  var func = new Function ('','Gallery.getInstance(\'' + id + '\')._type4_descending(undefined,'+ rest +');'); 
  this.timeout = window.setTimeout(func, this.config.speedTime);
}

//************************************************************

Gallery.prototype._type5_ascending = function (n, rest, lap) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  if (this.rotationBreak == true) {
    return;
  }
  if (n == undefined) {
    n = 0;
  }
  if (rest == undefined) {
    rest = 0;
  }
  var _speedPix = this.config.speedPixel;
  if (IE) {
    _speedPix = Math.ceil(_speedPix / 4);
  }
  if (lap == undefined) {
    lap = _speedPix;
  }
  var id = this.id;
  var reachedTarget = this.config.activeItemLength;
  for (var i=n; i<this.activeItemList.length; i++) {
    var item = this.activeItemList[i];
    if (! item.preview.complete) {
      //alert(item.preview.src);
      var lfunc = new Function ('',' alert(1); Gallery.getInstance(\'' + id + '\')._type5_ascending(\'' + i + '\');');  
      GalleryTools.addEvent('load', item.preview, lfunc);
      return;
    }
    var lastItem = this.activeItemList[this.activeItemList.length-1];
    var mIdx = i;
    var marker = this.specification.markerList[mIdx];
    var tMarker = this.specification.markerList[mIdx - 1];
    var targetWidth = 1;
    var lapToTarget = 0;
    var targetLeft  = undefined;
    var targetBaseTop = 0;
    var className = '';
    var speedPixel = _speedPix;
    item.preview.parentNode.className = item.preview.parentNode.className.replace(/\s?GALLERY_SPECIFICATIONS_MODEL_\d\d?/,'');
    if (! item.preview.parentNode.className.match(/\s?GALLERY_SPECIFICATIONS_MODEL_\d\d?/)) {
      item.preview.parentNode.className += className;
    }
    if (marker) {
      var model = this.specification.modelList[marker.pos];
      className = ' ' + model.className;
      targetLeft = marker.left - item.preview.parentNode.offsetWidth;
      targetLeft = Math.floor(targetLeft);
      targetBaseTop = (marker.height / 2) ;
      lapToTarget = (item.preview.parentNode.offsetLeft - targetLeft) / _speedPix;
    }
    if (tMarker) {
      var tModel = this.specification.modelList[tMarker.pos];
      className = ' ' + tModel.className;
      if (! item.preview.parentNode.className.match(/\s?GALLERY_SPECIFICATIONS_MODEL_\d\d?/)) {
        item.preview.parentNode.className += className;
      }
      targetLeft = ( (tMarker.width / 2) + tMarker.left ) - (tModel.width / 2);
      targetLeft = Math.floor(targetLeft);
      targetWidth = tModel.width;
      targetBaseTop = (tMarker.height / 2) ;
      lapToTarget = (item.preview.parentNode.offsetLeft - targetLeft) / _speedPix;
    }
    if (marker || tMarker) {
      var nextTargetWidth = targetWidth;
      if (item.preview.width != targetWidth) {
        nextTargetWidth = Math.floor(parseFloat(item.preview.width - ((item.preview.width - targetWidth) / lap)) ) ;
      }
      item.preview.style.width = GalleryTools.getCssUnit( nextTargetWidth );
      item.preview.parentNode.style.top = GalleryTools.getCssUnit( targetBaseTop  - (item.preview.parentNode.offsetHeight / 2) );
      var nextTargetLeft = targetLeft;
      if (item.preview.parentNode.offsetLeft != targetLeft) {
        nextTargetLeft = Math.floor(parseFloat(item.preview.parentNode.offsetLeft - ((item.preview.parentNode.offsetLeft - targetLeft) / lap)) );
        if (nextTargetLeft < targetLeft) {
          nextTargetLeft = targetLeft;
        }
      }
      item.preview.parentNode.style.left = GalleryTools.getCssUnit( nextTargetLeft );
      item.preview.parentNode.style.visibility = 'visible';
      if (item.preview.parentNode.offsetLeft != targetLeft) {
        reachedTarget--;
      }
    }
  }  
  if (reachedTarget == this.config.activeItemLength) {
    var tmp = this.activeItemList.shift(); 
    this._itemListElem.removeChild(tmp.preview.parentNode);
    var newLeft = parseFloat(parseFloat(lastItem.preview.parentNode.style.left) + parseFloat(lastItem.preview.parentNode.offsetWidth));
    var nextItem;
    if (lastItem.listPosition == (this.itemList.length-1)) {
      nextItem = this.itemList[0];
    } else {
      nextItem = this.itemList[lastItem.listPosition +1];
    }
    if (! this._drawItem(nextItem,  this.activeItemList.length -1))  {
       //return;
    }
    nextItem.preview.parentNode.style.left = GalleryTools.getCssUnit(newLeft);
    this._itemListElem.appendChild(nextItem.preview.parentNode);
    this.activeItemList.push(nextItem);
    this._isBusy = false;
    return;
  }
  lap--;
  var func = new Function ('','Gallery.getInstance(\'' + id + '\')._type5_ascending(undefined, undefined, '+ lap +');'); 
  this.timeout = window.setTimeout(func, this.config.speedTime);
  return;
} 

//************************************************************

Gallery.prototype._type5_descending = function (n, rest, lap) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  if (this.rotationBreak == true) {
    return;
  }
  if (n == undefined) {
    n = this.activeItemList.length -1;
  }
  if (rest == undefined) {
    rest = 0;
  }
  var _speedPix = this.config.speedPixel;
  if (IE) {
    _speedPix = Math.ceil(_speedPix / 4);
  }
  if (lap == undefined) {
    lap = _speedPix;
  }
  var id = this.id;
  var reachedTarget = this.config.activeItemLength;
  for (var i=n; i>=0; i--) {
    var item = this.activeItemList[i];
    if (! item.preview.complete) {
      var lfunc = new Function ('','Gallery.getInstance(\'' + id + '\')._type5_ascending(\'' + i + '\');');  
      GalleryTools.addEvent('load', item.preview, lfunc);
      return;
    }
    var lastItem = this.activeItemList[0];
    var mIdx = i;
    var marker = this.specification.markerList[mIdx];
    var tMarker = this.specification.markerList[mIdx + 1];
    var targetWidth = 1;
    var lapToTarget = 0;
    var targetLeft  = undefined;
    var className = '';
    var targetBaseTop = 0;
    var speedPixel = _speedPix;  
    if (marker) {
      var model = this.specification.modelList[marker.pos];
      className = ' ' + model.className;
      targetLeft = marker.getRight() + item.preview.parentNode.offsetWidth;
      targetLeft = Math.floor(targetLeft);
      targetBaseTop = (marker.height / 2) ;
      lapToTarget = (item.preview.parentNode.offsetLeft - targetLeft) / _speedPix;
    }
    if (tMarker) {
      var tModel = this.specification.modelList[tMarker.pos];
      className = ' ' + tModel.className;
      targetLeft = ( (tMarker.width / 2) + tMarker.left ) - (tModel.width / 2);
      targetLeft = Math.floor(targetLeft);
      targetWidth = tModel.width;
      targetBaseTop = (tMarker.height / 2) ;
      lapToTarget = (item.preview.parentNode.offsetLeft - targetLeft) / _speedPix;
    }
    if (marker || tMarker) {
      var nextTargetWidth = targetWidth;
      if (item.preview.width != targetWidth) {
        nextTargetWidth = Math.floor(parseFloat(item.preview.width - ((item.preview.width - targetWidth) / lap)) ) ;
      }
      item.preview.style.width = GalleryTools.getCssUnit( nextTargetWidth );
      item.preview.parentNode.style.top = GalleryTools.getCssUnit( targetBaseTop  - (item.preview.parentNode.offsetHeight / 2) );
      var nextTargetLeft = targetLeft;
      if (item.preview.parentNode.offsetLeft != targetLeft) {
        nextTargetLeft = Math.floor(parseFloat(item.preview.parentNode.offsetLeft - ((item.preview.parentNode.offsetLeft - targetLeft) / lap)) );
        if (nextTargetLeft > targetLeft) {
          nextTargetLeft = targetLeft;
        }
      }
      item.preview.parentNode.style.left = GalleryTools.getCssUnit( nextTargetLeft );
      item.preview.parentNode.style.visibility = 'visible';
      if (item.preview.parentNode.offsetLeft != targetLeft) {
        reachedTarget--;
      } else {        
        item.preview.parentNode.className = item.preview.parentNode.className.replace(/\s?GALLERY_SPECIFICATIONS_MODEL_\d\d?/,'');
      }
      if (! item.preview.parentNode.className.match(/\s?GALLERY_SPECIFICATIONS_MODEL_\d\d?/)) {
        item.preview.parentNode.className += className;
      }
    }
  }  
  if (reachedTarget == this.config.activeItemLength) {
    var tmp = this.activeItemList.pop(); 
    this._itemListElem.removeChild(tmp.preview.parentNode);
    var newLeft = parseFloat(parseFloat(lastItem.preview.parentNode.style.left) - parseFloat(lastItem.preview.parentNode.offsetWidth / 2));
    var nextItem;
    if (lastItem.listPosition == 0) {
      nextItem = this.itemList[this.itemList.length-1];
    } else {
      nextItem = this.itemList[lastItem.listPosition -1];
    } 
    if (! this._drawItem(nextItem, 0))  {
       //return;
    }
    //nextItem.preview.parentNode.style.left = GalleryTools.getCssUnit(newLeft);
    //nextItem.preview.parentNode.style.left = '';
    this._itemListElem.appendChild(nextItem.preview.parentNode);
    this.activeItemList.unshift(nextItem);
    this._isBusy = false;
    return;
  }
  lap--;
  var func = new Function ('','Gallery.getInstance(\'' + id + '\')._type5_descending(undefined, undefined, '+ lap +');'); 
  this.timeout = window.setTimeout(func, this.config.speedTime);
  return;
}  

//************************************************************

Gallery.prototype._type6_ascending = function (n, rest, lap) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  if (this.rotationBreak == true) {
    return;
  }
  if (n == undefined) {
    n = 0;
  }
  if (rest == undefined) {
    rest = 0;
  }
  var _speedPix = this.config.speedPixel;
  if (IE) {
    _speedPix = Math.ceil(_speedPix / 4);        
  }
  if (lap == undefined) {
    lap = _speedPix;
  }
  var id = this.id;
  var reachedTarget = this.config.activeItemLength;
  for (var i=n; i<this.activeItemList.length; i++) {
    var item = this.activeItemList[i];
    if (! item.preview.complete) {
      var lfunc = new Function ('','Gallery.getInstance(\'' + id + '\')._type6_ascending(\'' + i + '\');');  
      GalleryTools.addEvent('load', item.preview, lfunc);
      return;
    }
    var lastItem = this.activeItemList[this.activeItemList.length-1];
    var mIdx = i;
    var marker = this.specification.markerList[mIdx];
    var tMarker = this.specification.markerList[mIdx - 1];
    var targetWidth = 1;
    var lapToTarget = 0;
    var targetLeft  = undefined;
    var targetBaseTop = 0;
    var className = '';
    var speedPixel = _speedPix;
    item.preview.parentNode.className = item.preview.parentNode.className.replace(/\s?GALLERY_SPECIFICATIONS_MODEL_\d\d?/,'');
    if (! item.preview.parentNode.className.match(/\s?GALLERY_SPECIFICATIONS_MODEL_\d\d?/)) {
      item.preview.parentNode.className += className;
    }
    if (marker) {
      var model = this.specification.modelList[marker.pos];
      className = ' ' + model.className;
      targetLeft = marker.left - item.preview.parentNode.offsetWidth;
      targetLeft = Math.floor(targetLeft);
      targetBaseTop = (marker.height / 2) ;
      lapToTarget = (item.preview.parentNode.offsetLeft - targetLeft) / _speedPix;
    }
    if (tMarker) {
      var tModel = this.specification.modelList[tMarker.pos];
      className = ' ' + tModel.className;
      if (! item.preview.parentNode.className.match(/\s?GALLERY_SPECIFICATIONS_MODEL_\d\d?/)) {
        item.preview.parentNode.className += className;
      }
      targetLeft = ( (tMarker.width / 2) + tMarker.left ) - (tModel.width / 2);
      targetLeft = Math.floor(targetLeft);
      targetWidth = tModel.width;
      targetBaseTop = (tMarker.height / 2) ;
      lapToTarget = (item.preview.parentNode.offsetLeft - targetLeft) / _speedPix;
    }
    if (marker || tMarker) {
      var nextTargetWidth = targetWidth;
      if (item.preview.width != targetWidth) {
        nextTargetWidth = Math.floor(parseFloat(item.preview.width - ((item.preview.width - targetWidth) / lap)) ) ;
      }
      item.preview.style.width = GalleryTools.getCssUnit( nextTargetWidth );
      item.preview.parentNode.style.top = GalleryTools.getCssUnit( targetBaseTop  - (item.preview.parentNode.offsetHeight / 2) );
      var nextTargetLeft = targetLeft;
      if (item.preview.parentNode.offsetLeft != targetLeft) {
        nextTargetLeft = Math.floor(parseFloat(item.preview.parentNode.offsetLeft - ((item.preview.parentNode.offsetLeft - targetLeft) / lap)) );
        if (nextTargetLeft < targetLeft) {
          nextTargetLeft = targetLeft;
        }
      }
      item.preview.parentNode.style.left = GalleryTools.getCssUnit( nextTargetLeft );
      item.preview.parentNode.style.visibility = 'visible';
      if (item.preview.parentNode.offsetLeft != targetLeft) {
        reachedTarget--;
      }
    }
  }  
  if (reachedTarget == this.config.activeItemLength) {
    var tmp = this.activeItemList.shift(); 
    this._itemListElem.removeChild(tmp.preview.parentNode);
    var newLeft = parseFloat(parseFloat(lastItem.preview.parentNode.style.left) + parseFloat(lastItem.preview.parentNode.offsetWidth));
    var nextItem;
    if (lastItem.listPosition == (this.itemList.length-1)) {
      nextItem = this.itemList[0];
    } else {
      nextItem = this.itemList[lastItem.listPosition +1];
    }
    if (! this._drawItem(nextItem,  this.activeItemList.length -1))  {
       //return;
    }
    //alert(nextItem.preview.parentNode.className);
    nextItem.preview.parentNode.style.left = GalleryTools.getCssUnit(newLeft);
    this._itemListElem.appendChild(nextItem.preview.parentNode);
    this.activeItemList.push(nextItem);
    this._isBusy = false;
    return;
  }
  lap--;
  var func = new Function ('','Gallery.getInstance(\'' + id + '\')._type6_ascending(undefined, undefined, '+ lap +');'); 
  this.timeout = window.setTimeout(func, this.config.speedTime);
  return;
} 

//************************************************************

Gallery.prototype._type6_descending = function (n, rest, lap) {
  if (this.timeout) {
    window.clearTimeout(this.timeout);
    this.timeout = undefined;
  }
  if (this.rotationBreak == true) {
    return;
  }
  if (n == undefined) {
    n = this.activeItemList.length -1;
  }
  if (rest == undefined) {
    rest = 0;
  }
  var _speedPix = this.config.speedPixel;
  if (IE) {
    _speedPix = Math.ceil(_speedPix / 4);
  }
  if (lap == undefined) {
    lap = _speedPix;
  }
  var id = this.id;
  var reachedTarget = this.config.activeItemLength;
  for (var i=n; i>=0; i--) {
    var item = this.activeItemList[i];
    if (! item.preview.complete) {
      var lfunc = new Function ('','Gallery.getInstance(\'' + id + '\')._type6_ascending(\'' + i + '\');');  
      GalleryTools.addEvent('load', item.preview, lfunc);
      return;
    }
    var lastItem = this.activeItemList[0];
    var mIdx = i;
    var marker = this.specification.markerList[mIdx];
    var tMarker = this.specification.markerList[mIdx + 1];
    var targetWidth = 1;
    var lapToTarget = 0;
    var targetLeft  = undefined;
    var className = '';
    var targetBaseTop = 0;
    var speedPixel = _speedPix;  
    if (marker) {
      var model = this.specification.modelList[marker.pos];
      className = ' ' + model.className;
      targetLeft = marker.getRight() + item.preview.parentNode.offsetWidth;
      targetLeft = Math.floor(targetLeft);
      targetBaseTop = (marker.height / 2) ;
      lapToTarget = (item.preview.parentNode.offsetLeft - targetLeft) / _speedPix;
    }
    if (tMarker) {
      var tModel = this.specification.modelList[tMarker.pos];
      className = ' ' + tModel.className;
      targetLeft = ( (tMarker.width / 2) + tMarker.left ) - (tModel.width / 2);
      targetLeft = Math.floor(targetLeft);
      targetWidth = tModel.width;
      targetBaseTop = (tMarker.height / 2) ;
      lapToTarget = (item.preview.parentNode.offsetLeft - targetLeft) / _speedPix;
    }
    if (marker || tMarker) {
      var nextTargetWidth = targetWidth;
      if (item.preview.width != targetWidth) {
        nextTargetWidth = Math.floor(parseFloat(item.preview.width - ((item.preview.width - targetWidth) / lap)) ) ;
      }
      item.preview.style.width = GalleryTools.getCssUnit( nextTargetWidth );
      item.preview.parentNode.style.top = GalleryTools.getCssUnit( targetBaseTop  - (item.preview.parentNode.offsetHeight / 2) );
      var nextTargetLeft = targetLeft;
      if (item.preview.parentNode.offsetLeft != targetLeft) {
        nextTargetLeft = Math.floor(parseFloat(item.preview.parentNode.offsetLeft - ((item.preview.parentNode.offsetLeft - targetLeft) / lap)) );
        if (nextTargetLeft > targetLeft) {
          nextTargetLeft = targetLeft;
        }
      }
      item.preview.parentNode.style.left = GalleryTools.getCssUnit( nextTargetLeft );
      item.preview.parentNode.style.visibility = 'visible';
      if (item.preview.parentNode.offsetLeft != targetLeft) {
        reachedTarget--;
      } else {        
        item.preview.parentNode.className = item.preview.parentNode.className.replace(/\s?GALLERY_SPECIFICATIONS_MODEL_\d\d?/,'');
      }
      if (! item.preview.parentNode.className.match(/\s?GALLERY_SPECIFICATIONS_MODEL_\d\d?/)) {
        item.preview.parentNode.className += className;
      }
    }
  }  
  if (reachedTarget == this.config.activeItemLength) {
    var tmp = this.activeItemList.pop(); 
    this._itemListElem.removeChild(tmp.preview.parentNode);
    var newLeft = parseFloat(parseFloat(lastItem.preview.parentNode.style.left) - parseFloat(lastItem.preview.parentNode.offsetWidth / 2));
    var nextItem;
    if (lastItem.listPosition == 0) {
      nextItem = this.itemList[this.itemList.length-1];
    } else {
      nextItem = this.itemList[lastItem.listPosition -1];
    } 
    if (! this._drawItem(nextItem, 0))  {
       //return;
    }
    //nextItem.preview.parentNode.style.left = GalleryTools.getCssUnit(newLeft);
    //nextItem.preview.parentNode.style.left = '';
    this._itemListElem.appendChild(nextItem.preview.parentNode);
    this.activeItemList.unshift(nextItem);
    this._isBusy = false;
    return;
  }
  lap--;
  var func = new Function ('','Gallery.getInstance(\'' + id + '\')._type6_descending(undefined, undefined, '+ lap +');'); 
  this.timeout = window.setTimeout(func, this.config.speedTime);
  return;
}  

//************************************************************

Gallery.prototype.itemOnmouseover = function (id) {
  //alert(id);  
} 

//************************************************************

Gallery.prototype.itemOnmouseout = function (id) {
  //alert(id);  
} 

//************************************************************

Gallery.prototype.itemOnclick = function (id) {
  //alert(id);  
  this._showDetail(id);
} 

//************************************************************

Gallery._increment = [];
Gallery._autoIdxPrefix = '_Gallery_';
Gallery._registerInstance = {};
Gallery._registerInstanceLength = [];

//************************************************************

Gallery.getInstance = function(id) {
  if (arguments.length!=1) {
    focus();
    throw new Error('Gallery.getInstance: Falsche Anzahl von Argumenten!');
  }
  if (! (Gallery._registerInstance[id])){
    //alert(Gallery.getInstance.caller);
    focus();
    throw new Error('Gallery.getInstance: Es ist keine Gallery.Instance mit id=' + id + ' registriert!');
  }
  return Gallery._registerInstance[id];
}

//************************************************************

Gallery.createInstance = function(id) {
  if (!arguments.length) {
    id = Gallery._autoIdxPrefix + Gallery._increment.length;
    Gallery._increment.push(1);
  }
  if (! (Gallery._registerInstance[id])){
    Gallery._registerInstance[id] = new Gallery(id);
    Gallery._registerInstanceLength.push(id);
  } else {
    focus();
    throw new Error('Gallery.createInstance: ID schon vorhanden!');
  }
  var baseElem = document.getElementById(id);
  if (! baseElem) {
    focus();
    throw new Error('Gallery.createInstance: Es existiert kein Basis-HTML-Element mit id = '+ id +'!');
  }
  return Gallery.getInstance(id);
}

//************************************************************

//************************************************************
//************************************************************
// ## GalleryConfig
//************************************************************
//************************************************************

function GalleryConfig(id) {
  this.id = undefined;
  this.type = 'type1'; // type1|type2|type3|...
  this.rotate = 'manual'; // manual|auto
  this.speedTime = 10; 
  this.speedPixel = 2; 
  this.direction = 'ascending'; // ascending|descending
  this.dimension = 'horizontal'; // horizontal|vertical
  this.activeItemLength = 3;
  this.vertex = 80; // prozentangaben an welcher stelle auf der x oder y achse der zoom gegenteilig wird
  
  this._setID(id);
}

//************************************************************

GalleryConfig.prototype._setID = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryConfig->_setID: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GalleryConfig->_setID: Argument str ist nicht vom Typ String!');
  }
  this.id = str;
} 

//************************************************************

GalleryConfig.prototype.setActiveItemLength = function (n) {
  if (arguments.length!=1) {
    throw new Error("Gallery->setActiveItemLength: Falsche Anzahl von Argumenten!");
  }
  if (typeof n != "number") {
    throw new Error("Gallery->setActiveItemLength: Argument ist nicht vom Typ number!");
  }
  this.activeItemLength = n;
}  

//************************************************************

GalleryConfig.prototype.setSpeedTime = function (n) {
  if (arguments.length!=1) {
    throw new Error("Gallery->setSpeedTime: Falsche Anzahl von Argumenten!");
  }
  if (typeof n != "number") {
    throw new Error("Gallery->setSpeedTime: Argument ist nicht vom Typ number!");
  }
  this.speedTime = n;
}  

//************************************************************

GalleryConfig.prototype.setSpeedPixel = function (n) {
  if (arguments.length!=1) {
    throw new Error("Gallery->setSpeedPixel: Falsche Anzahl von Argumenten!");
  }
  if (typeof n != "number") {
    throw new Error("Gallery->setSpeedPixel: Argument ist nicht vom Typ number!");
  }
  this.speedPixel = n;
}  

//************************************************************

GalleryConfig.prototype.setType = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryConfig->setType: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GalleryConfig->setType: Argument str ist nicht vom Typ String!');
  }
  this.type = str;
}  

//************************************************************

GalleryConfig.prototype.setRotate = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryConfig->setRotate: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GalleryConfig->setRotate: Argument str ist nicht vom Typ String!');
  }
  this.rotate = str;
}  

//************************************************************

GalleryConfig.prototype.setDirection = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryConfig->setDirection: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GalleryConfig->setDirection: Argument str ist nicht vom Typ String!');
  }
  this.direction = str;
} 

//************************************************************

GalleryConfig.prototype.setDimension = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryConfig->setDimension: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GalleryConfig->setDimension: Argument str ist nicht vom Typ String!');
  }
  this.dimension = str;
} 

//************************************************************

GalleryConfig.prototype.setVertex = function (n) {
  if (arguments.length!=1) {
    throw new Error("Gallery->setVertex: Falsche Anzahl von Argumenten!");
  }
  if (typeof n != "number") {
    throw new Error("Gallery->setVertex: Argument ist nicht vom Typ number!");
  }
  this.vertex = n;
} 

//************************************************************

GalleryConfig._increment = [];
GalleryConfig._autoIdxPrefix = '_GalleryConfig_';
GalleryConfig._registerInstance = {};
GalleryConfig._registerInstanceLength = [];

//************************************************************

GalleryConfig.getInstance = function(id) {
  if (arguments.length!=1) {
    focus();
    throw new Error('GalleryConfig.getInstance: Falsche Anzahl von Argumenten!');
  }
  if (! (GalleryConfig._registerInstance[id])){
    focus();
    throw new Error('GalleryConfig.getInstance: Es ist keine GalleryConfig.Instance mit id=' + id + ' registriert!');
  }
  return GalleryConfig._registerInstance[id];
}

//************************************************************

GalleryConfig.createInstance = function(id) {
  if (!arguments.length) {
    id = GalleryConfig._autoIdxPrefix + GalleryConfig._increment.length;
    GalleryConfig._increment.push(1);
  }
  if (! (GalleryConfig._registerInstance[id])){
    GalleryConfig._registerInstance[id] = new GalleryConfig(id);
    GalleryConfig._registerInstanceLength.push(id);
  } else {
    focus();
    throw new Error('GalleryConfig.createInstance: ID schon vorhanden!');
  }
  return GalleryConfig.getInstance(id);
}

//************************************************************

//************************************************************
//************************************************************
// ## GallerySpecification
//************************************************************
//************************************************************

function GallerySpecification(id) {
  this.id = undefined;
  this.markerList = [];
  this.modelList = [];
  
  this._setID(id);
  this._setMarkerAndModel();
}

//************************************************************

GallerySpecification.prototype._setID = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecification->_setID: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GallerySpecification->_setID: Argument str ist nicht vom Typ String!');
  }
  this.id = str;
} 

//************************************************************

GallerySpecification.prototype._setMarkerAndModel = function () {
  for (var i=0; i<7; i++) {
    var posIdx = (i + 1);
    var marker = GallerySpecificationMarker.createInstance();
    marker._setPosIdx(posIdx);
    marker._setPos(i);
    this._addMarkerList(marker);
    var model = GallerySpecificationModel.createInstance();
    model._setPosIdx(posIdx);
    model._setPos(i);
    this._addModelList(model);
  }
}

//************************************************************

GallerySpecification.prototype._addMarkerList = function (obj) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecification->_addMarkerList: Falsche Anzahl von Argumenten!');
  }
  this.markerList.push(obj);
} 

//************************************************************

GallerySpecification.prototype._addModelList = function (obj) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecification->_addModelList: Falsche Anzahl von Argumenten!');
  }
  this.modelList.push(obj);
} 

//************************************************************

GallerySpecification._increment = [];
GallerySpecification._autoIdxPrefix = '_GallerySpecification_';
GallerySpecification._registerInstance = {};
GallerySpecification._registerInstanceLength = [];

//************************************************************

GallerySpecification.getInstance = function(id) {
  if (arguments.length!=1) {
    focus();
    throw new Error('GallerySpecification.getInstance: Falsche Anzahl von Argumenten!');
  }
  if (! (GallerySpecification._registerInstance[id])){
    focus();
    throw new Error('GallerySpecification.getInstance: Es ist keine GallerySpecification.Instance mit id=' + id + ' registriert!');
  }
  return GallerySpecification._registerInstance[id];
}

//************************************************************

GallerySpecification.createInstance = function(id) {
  if (!arguments.length) {
    id = GallerySpecification._autoIdxPrefix + GallerySpecification._increment.length;
    GallerySpecification._increment.push(1);
  }
  if (! (GallerySpecification._registerInstance[id])){
    GallerySpecification._registerInstance[id] = new GallerySpecification(id);
    GallerySpecification._registerInstanceLength.push(id);
  } else {
    focus();
    throw new Error('GallerySpecification.createInstance: ID schon vorhanden!');
  }
  return GallerySpecification.getInstance(id);
}

//************************************************************

//************************************************************
//************************************************************
// ## GallerySpecificationMarker
//************************************************************
//************************************************************

function GallerySpecificationMarker(id) {
  this.id = undefined;
  this.width = undefined;
  this.height = undefined;
  this.posIdx = undefined;
  this.pos = undefined;
  this.left = undefined;
  
  this._setID(id);
}

//************************************************************

GallerySpecificationMarker.prototype._setID = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecificationMarker->_setID: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GallerySpecificationMarker->_setID: Argument str ist nicht vom Typ String!');
  }
  this.id = str;
} 

//************************************************************

GallerySpecificationMarker.prototype._setLeft = function (n) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecificationMarker->_setLeft: Falsche Anzahl von Argumenten!');
  }
  if (typeof n != "number") {
    focus();
    throw new Error('GallerySpecificationMarker->_setLeft: Argument n ist nicht vom Typ Number!');
  }
  //alert(n);
  this.left = n;
} 

//************************************************************

GallerySpecificationMarker.prototype._setWidth = function (n) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecificationMarker->_setWidth: Falsche Anzahl von Argumenten!');
  }
  if (typeof n != "number") {
    focus();
    throw new Error('GallerySpecificationMarker->_setWidth: Argument n ist nicht vom Typ Number!');
  }
  this.width = n;
} 

//************************************************************

GallerySpecificationMarker.prototype._setHeight = function (n) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecificationMarker->_setHeight: Falsche Anzahl von Argumenten!');
  }
  if (typeof n != "number") {
    focus();
    throw new Error('GallerySpecificationMarker->_setHeight: Argument n ist nicht vom Typ Number!');
  }
  this.height = n;
} 

//************************************************************

GallerySpecificationMarker.prototype._setPosIdx = function (n) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecificationMarker->_posIdx: Falsche Anzahl von Argumenten!');
  }
  if (typeof n != "number") {
    focus();
    throw new Error('GallerySpecificationMarker->_posIdx: Argument n ist nicht vom Typ Number!');
  }
  this.posIdx = n;
} 

//************************************************************

GallerySpecificationMarker.prototype._setPos = function (n) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecificationMarker->_posIdx: Falsche Anzahl von Argumenten!');
  }
  if (typeof n != "number") {
    focus();
    throw new Error('GallerySpecificationMarker->_posIdx: Argument n ist nicht vom Typ Number!');
  }
  this.pos = n;
} 

//************************************************************

GallerySpecificationMarker.prototype.getRight = function () {
  if (this.width == undefined) {
    focus();
    throw new Error('GallerySpecificationMarker->getRight: this.width ist undefined!');
  }
  if (this.left == undefined) {
    focus();
    throw new Error('GallerySpecificationMarker->getRight: this.left ist undefined!');
  }
  var right = parseFloat(this.width + this.left);
  return right;
} 

//************************************************************

GallerySpecificationMarker._increment = [];
GallerySpecificationMarker._autoIdxPrefix = '_GallerySpecificationMarker_';
GallerySpecificationMarker._registerInstance = {};
GallerySpecificationMarker._registerInstanceLength = [];

//************************************************************

GallerySpecificationMarker.getInstance = function(id) {
  if (arguments.length!=1) {
    focus();
    throw new Error('GallerySpecificationMarker.getInstance: Falsche Anzahl von Argumenten!');
  }
  if (! (GallerySpecificationMarker._registerInstance[id])){
    focus();
    throw new Error('GallerySpecificationMarker.getInstance: Es ist keine GallerySpecificationMarker.Instance mit id=' + id + ' registriert!');
  }
  return GallerySpecificationMarker._registerInstance[id];
}

//************************************************************

GallerySpecificationMarker.createInstance = function(id) {
  if (!arguments.length) {
    id = GallerySpecificationMarker._autoIdxPrefix + GallerySpecificationMarker._increment.length;
    GallerySpecificationMarker._increment.push(1);
  }
  if (! (GallerySpecificationMarker._registerInstance[id])){
    GallerySpecificationMarker._registerInstance[id] = new GallerySpecificationMarker(id);
    GallerySpecificationMarker._registerInstanceLength.push(id);
  } else {
    focus();
    throw new Error('GallerySpecificationMarker.createInstance: ID schon vorhanden!');
  }
  return GallerySpecificationMarker.getInstance(id);
}

//************************************************************

//************************************************************
//************************************************************
// ## GallerySpecificationModel
//************************************************************
//************************************************************

function GallerySpecificationModel(id) {
  this.id = undefined;
  this.width = undefined;
  this.height = undefined;
  this.posIdx = undefined;
  this.pos = undefined;
  this.className = undefined;
  
  this._setID(id);
}

//************************************************************

GallerySpecificationModel.prototype._setID = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecificationModel->_setID: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GallerySpecificationModel->_setID: Argument str ist nicht vom Typ String!');
  }
  this.id = str;
} 

//************************************************************

GallerySpecificationModel.prototype._setClassName = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecificationModel->_ClassName: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GallerySpecificationModel->_ClassName: Argument str ist nicht vom Typ String!');
  }
  this.className = str;
} 

//************************************************************

GallerySpecificationModel.prototype._setWidth = function (n) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecificationModel->_setWidth: Falsche Anzahl von Argumenten!');
  }
  if (typeof n != "number") {
    focus();
    throw new Error('GallerySpecificationModel->_setWidth: Argument n ist nicht vom Typ Number!');
  }
  this.width = n;
} 

//************************************************************

GallerySpecificationModel.prototype._setHeight = function (n) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecificationModel->_setHeight: Falsche Anzahl von Argumenten!');
  }
  if (typeof n != "number") {
    focus();
    throw new Error('GallerySpecificationModel->_setHeight: Argument n ist nicht vom Typ Number!');
  }
  this.height = n;
} 

//************************************************************

GallerySpecificationModel.prototype._setPosIdx = function (n) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecificationModel->_posIdx: Falsche Anzahl von Argumenten!');
  }
  if (typeof n != "number") {
    focus();
    throw new Error('GallerySpecificationModel->_posIdx: Argument n ist nicht vom Typ Number!');
  }
  this.posIdx = n;
} 

//************************************************************

GallerySpecificationModel.prototype._setPos = function (n) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GallerySpecificationModel->_pos: Falsche Anzahl von Argumenten!');
  }
  if (typeof n != "number") {
    focus();
    throw new Error('GallerySpecificationModel->_pos: Argument n ist nicht vom Typ Number!');
  }
  this.pos = n;
} 

//************************************************************

GallerySpecificationModel._increment = [];
GallerySpecificationModel._autoIdxPrefix = '_GallerySpecificationModel_';
GallerySpecificationModel._registerInstance = {};
GallerySpecificationModel._registerInstanceLength = [];

//************************************************************

GallerySpecificationModel.getInstance = function(id) {
  if (arguments.length!=1) {
    focus();
    throw new Error('GallerySpecificationModel.getInstance: Falsche Anzahl von Argumenten!');
  }
  if (! (GallerySpecificationModel._registerInstance[id])){
    focus();
    throw new Error('GallerySpecificationModel.getInstance: Es ist keine GallerySpecificationModel.Instance mit id=' + id + ' registriert!');
  }
  return GallerySpecificationModel._registerInstance[id];
}

//************************************************************

GallerySpecificationModel.createInstance = function(id) {
  if (!arguments.length) {
    id = GallerySpecificationModel._autoIdxPrefix + GallerySpecificationModel._increment.length;
    GallerySpecificationModel._increment.push(1);
  }
  if (! (GallerySpecificationModel._registerInstance[id])){
    GallerySpecificationModel._registerInstance[id] = new GallerySpecificationModel(id);
    GallerySpecificationModel._registerInstanceLength.push(id);
  } else {
    focus();
    throw new Error('GallerySpecificationModel.createInstance: ID schon vorhanden!');
  }
  return GallerySpecificationModel.getInstance(id);
}

//************************************************************


//************************************************************
//************************************************************
// ## GalleryItem
//************************************************************
//************************************************************

function GalleryItem(id) {
  this.id = undefined;
  this.srcPreview = undefined;
  this.srcStandard = undefined;
  this.preview = undefined;
  this.standard = undefined;
  this.title = undefined;
  this.subtitle = undefined;
  this.description = undefined;
  this.linkURL = undefined;
  this.listPosition = undefined;
  
  this._setID(id);
}

//************************************************************

GalleryItem.prototype._setID = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryItem->_setID: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GalleryItem->_setID: Argument str ist nicht vom Typ String!');
  }
  this.id = str;
} 

//************************************************************

GalleryItem.prototype._setPreview = function () {
  var img = document.createElement('img');
  img.src = this.srcPreview;
  this.preview = img;
} 

//************************************************************

GalleryItem.prototype._setStandard = function () {
  var img = document.createElement('img');
  img.src = this.srcStandard;
  this.standard = img;
} 

//************************************************************

GalleryItem.prototype._setListPosition = function (n) {
  if (arguments.length!=1) {
    throw new Error("Gallery->_setListPosition: Falsche Anzahl von Argumenten!");
  }
  if (typeof n != "number") {
    throw new Error("Gallery->_setListPosition: Argument ist nicht vom Typ number!");
  }
  this.listPosition = n;
} 

//************************************************************

GalleryItem.prototype.setSrcPreview = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryItem->setSrcPreview: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GalleryItem->setSrcPreview: Argument str ist nicht vom Typ String!');
  }
  if (! GalleryTools.validateImgURL(str)) {
    alert('String : ' + str + ' ist keine valide Bild-URL.');
    return;
  }
  this.srcPreview = str;
  this._setPreview();
} 

//************************************************************

GalleryItem.prototype.setSrcStandard = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryItem->setSrcStandard: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GalleryItem->setSrcStandard: Argument str ist nicht vom Typ String!');
  }
  if (! GalleryTools.validateImgURL(str)) {
    alert('String : ' + str + ' ist keine valide Bild-URL.');
    return;
  }
  this.srcStandard = str;
  //this._setStandard();
} 

//************************************************************

GalleryItem.prototype.setTitle = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryItem->setTitle: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GalleryItem->setTitle: Argument str ist nicht vom Typ String!');
  }
  this.title = str;
} 

//************************************************************

GalleryItem.prototype.setSubtitle = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryItem->setSubtitle: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GalleryItem->setSubtitle: Argument str ist nicht vom Typ String!');
  }
  this.subtitle = str;
} 

//************************************************************

GalleryItem.prototype.setDescription = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryItem->setDescription: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GalleryItem->setDescription: Argument str ist nicht vom Typ String!');
  }
  this.description = str;
} 

//************************************************************

GalleryItem.prototype.setLinkURL = function (str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryItem->setLinkURL: Falsche Anzahl von Argumenten!');
  }
  if (typeof str != 'string') {
    focus();
    throw new Error('GalleryItem->setLinkURL: Argument str ist nicht vom Typ String!');
  }
  var regEx = new RegExp(/\D/);
  if (! (regEx.exec(str))) {
    str = CMS_PREFIX_FULL + '&_bereich=artikel&_aktion=detail&idartikel=' + str;
    str += '&_sprache='+ CMS_SPRACHE;
    if (CMS_TEMPLATE_VARIANT) {
      str += '&_template_variant='+ CMS_TEMPLATE_VARIANT;
    }
    if (CMS_TEMPLATE_VARIANT2) {
      str += '&_template_variant2='+ CMS_TEMPLATE_VARIANT2;
    }
    if (CMS_TEMPLATE_VARIANT3) {
      str += '&_template_variant3='+ CMS_TEMPLATE_VARIANT3;
    }
  }
  if (! GalleryTools.validateURL(str)) {
    alert('String : ' + str + ' ist keine valide URL.');
    return;
  }
  this.linkURL = str;
} 

//************************************************************

GalleryItem._increment = [];
GalleryItem._autoIdxPrefix = '_GalleryItem_';
GalleryItem._registerInstance = {};
GalleryItem._registerInstanceLength = [];

//************************************************************

GalleryItem.getInstance = function(id) {
  if (arguments.length!=1) {
    focus();
    throw new Error('GalleryItem.getInstance: Falsche Anzahl von Argumenten!');
  }
  if (! (GalleryItem._registerInstance[id])){
    focus();
    throw new Error('GalleryItem.getInstance: Es ist keine GalleryItem.Instance mit id=' + id + ' registriert!');
  }
  return GalleryItem._registerInstance[id];
}

//************************************************************

GalleryItem.createInstance = function(id) {
  if (!arguments.length) {
    id = GalleryItem._autoIdxPrefix + GalleryItem._increment.length;
    GalleryItem._increment.push(1);
  }
  if (! (GalleryItem._registerInstance[id])){
    GalleryItem._registerInstance[id] = new GalleryItem(id);
    GalleryItem._registerInstanceLength.push(id);
  } else {
    focus();
    throw new Error('GalleryItem.createInstance: ID schon vorhanden!');
  }
  return GalleryItem.getInstance(id);
}

//************************************************************


//************************************************************
//************************************************************
//************************************************************
// ## GalleryTools
//************************************************************
//************************************************************


function GalleryTools(id) {
}

//************************************************************

GalleryTools.validateURL = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryTools.validateURL: Falsche Anzahl von Argumenten!');
  }
  var reg = new RegExp('^(http:\/\/|https:\/\/|ftp:\/\/|\/)');
  if (reg.exec(str)) {
    return true;
  }
  return false;
}

//************************************************************

GalleryTools.getCssUnit = function(n) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryTools.validateURL: Falsche Anzahl von Argumenten!');
  }
  var n = parseFloat(n);
  if (typeof n != "number") {
    return "";
  }
  if (n > 0) {
    n += 'px';
  } else {
    n += 'px';
  }
  return n;
}

//************************************************************

GalleryTools.validateImgURL = function(str) {
  if (arguments.length != 1) {
    focus();
    throw new Error('GalleryTools.validateImgURL: Falsche Anzahl von Argumenten!');
  }
  var reg = new RegExp('(\.jpg|\.JPG|\.jpeg|\.JPEG|\.gif|\.GIF|\.png|\.PNG)$');
  if (reg.exec(str)) {
    return true;
  }
  var reg_app = new RegExp('MODULE=Frontend.Media');
  if (reg_app.exec(str)) {
    return true;
  }
  return false;
}

//************************************************************

GalleryTools.addEvent = function(oneEvent, obj, handler, bol, ieWindow){
  if (arguments.length < 3) {
    focus();
    throw new Error('GalleryTools.addEvent: Falsche Anzahl von Argumenten!');
  }
  if(window.addEventListener){
    // Other
    obj.addEventListener(oneEvent, handler, bol);
  } else if(obj.attachEvent){
    // IE
    var win = window;
    if (ieWindow) {
      win = ieWindow;
    }
    obj['e' + oneEvent + handler] = handler;
    obj[oneEvent + handler] = function() { obj['e' + oneEvent + handler] ( win.event ); win.event.cancelBubble = true;};
    obj.attachEvent('on' + oneEvent, obj[oneEvent + handler]);
  }
  return true;
}

//************************************************************

GalleryTools.removeEvent = function(oneEvent, obj, handler, bol){
  if (arguments.length < 3) {
    focus();
    throw new Error('GalleryTools.removeEvent: Falsche Anzahl von Argumenten!');
  }
  if(window.removeEventListener){
    // Other
    obj.removeEventListener(oneEvent, handler, bol);
  } else if(obj.detachEvent){
    // IE
    obj.detachEvent( "on"+ oneEvent, obj[oneEvent + handler] );
    obj[oneEvent + handler] = undefined;
    obj["e" + oneEvent + handler] = undefined;
  }
  return true;
}

//************************************************************

GalleryTools._getBody = function() {
  var body = document.getElementsByTagName('body')[0];
  return body;
}

//************************************************************

GalleryTools._getScreenHeight = function () {
  var height = 0;
  if (IE) {
     height = parseFloat(document.documentElement.clientHeight);
  } else {
     height = parseFloat(window.innerHeight);
  }
  return height;
}

//************************************************************
  
GalleryTools._getScrollPositionTop = function () {
  var pos = 0;
  //if (document.documentElement != undefined && document.documentElement.scrollTop != undefined) {
  if (IE) {
    if (document.body.scrollTop != undefined && document.body.scrollTop) {
     pos = parseFloat(document.body.scrollTop);
    } else {
     pos = parseFloat(document.documentElement.scrollTop);
    }
  } else {
     pos = parseFloat(window.pageYOffset);
  }
  return pos;
}   

//************************************************************

GalleryTools._getDocumentHeight = function() {
  var body = GalleryTools._getBody();
  //var innerHeight = GalleryTools._getScreenHeight();
  if (! document.compatMode || document.compatMode=="CSS1Compat") {
    return Math.max(body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight);
  }
  return Math.max(body.scrollHeight, body.clientHeight);
} 

//************************************************************

GalleryTools._getElemHeight = function(elem) {
  var height = 0;
  if (!elem){
    return height;
  }
   height = parseFloat(elem.offsetHeight); 
   return height;
} 

//************************************************************

GalleryTools._getElemWidth = function(elem) {
  var width = 0;
  if (!elem){
    return width;
  }
   width = parseFloat(elem.offsetWidth); 
   return width;
}

//************************************************************

GalleryTools._getElemLeft = function(elem) {
  var left = 0;
  if (!elem){
    return left;
  }
   left = parseFloat(elem.offsetLeft); 
   return left;
}

//************************************************************


