
var undefined;

//************************************************************
// Gallery
//************************************************************

function Gallery(id) {
  this.id = undefined;
  this.title = undefined;
  this._init = undefined;
  this.type = 'standard'; // str: 'standard','move'
  this.subTitle = undefined;
  this.description = undefined;
  this.direction = 0;
  this.previewLength = 0;
  this.previewStartIdx = 0;
  this.timeOut = undefined;
  this.timeOutDelay = 100;
  this.fadeStatus = false;
  this.detailByFadingMode = false;
  this.imageMap = [];  
  this._setID(id);
  this._timeOut;
}

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._setPreviewElementProperties = function(){
  var thumbsElemID = '_'+ this.id +'_Gallery_Thumbs_';
  var thumbsInnerElemID = '_'+ this.id +'_Gallery_Thumbs_Inner';
  var elem = document.getElementById(thumbsElemID);
  var innerElem = document.getElementById(thumbsInnerElemID);
  if (! elem) {
    focus();
    throw new Error("Gallery->_setPreviewElementProperties: Es existiert kein HTML-Element mit ID = "+ thumbsElemID +"!");
  }
  if (! innerElem) {
    focus();
    throw new Error("Gallery->_setPreviewElementProperties: Es existiert kein HTML-Element mit ID = "+ thumbsInnerElemID +"!");
  }
  elem.style.height = parseFloat(elem.offsetHeight) + 'px';
  elem.style.position = 'relative';
  elem.style.overflow = 'hidden';
  innerElem.style.position = 'relative';
}

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

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

Gallery.prototype.setDetailByFading = function(bol){
  if (arguments.length != 1) {
    focus();
    throw new Error("Gallery->setDetailByFading: Falsche Anzahl von Argumenten!");
  }
  if (typeof bol != "boolean") {
    focus();
    throw new Error("Gallery->setDetailByFading: Argument bol ist nicht vom Typ Boolean!");
  }
  this.detailByFadingMode = bol;
}

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

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

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

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

Gallery.prototype.addImageMap = function(obj){
  if (arguments.length != 1) {
    focus();
    throw new Error("Gallery.addImageMap: Falsche Anzahl von Argumenten!");
  }
  if (! (obj instanceof GalleryImage)) {
    focus();
    throw new Error("Gallery.addImageMap: Argument obj ist keine Instance von GalleryImage!");
  }
  this.imageMap.push(obj);
}

Gallery.prototype.getXHTML = function(str){
  if (arguments.length != 1) {
    focus();
    throw new Error("Gallery->getXHTML: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Gallery->getXHTML: Argument str ist nicht vom Typ String!");
  }
  var xhtml = '';
  xhtml += '<div class="fotogalerie-thumbs">\n';  
  xhtml += '<div id="_'+ this.id +'_Gallery_Thumbs_">\n';
  xhtml += '<div id="_'+ this.id +'_Gallery_Thumbs_Inner">\n';

  xhtml += this.getInnerXHTML(str);
  
  xhtml += '</div>\n';
  xhtml += '</div>\n';
  xhtml += '<div class="fotogalerie-thumbs-navi">\n';
  xhtml += '<div class="fotogalerie-thumbs-navi-oben">\n';
  xhtml += '<a href="javascript:void(0);" onclick="Gallery.getInstance(\''+ this.id +'\').previewBackward(\''+ str +'\');" title="zurück"> </a><br />\n';
  xhtml += '</div>\n';
  xhtml += '<div class="fotogalerie-thumbs-navi-text">\n';
  xhtml += 'Weiterblättern<br />\n';
  xhtml += '</div>\n';
  xhtml += '<div class="fotogalerie-thumbs-navi-unten">\n';
  xhtml += '<a href="javascript:void(0);" onclick="Gallery.getInstance(\''+ this.id +'\').previewForward(\''+ str +'\');" title="vor"> </a><br />\n';
  xhtml += '</div>\n';
  xhtml += '</div>\n';
  
  //xhtml += '<div class="float-aufheben"><br /></div>\n';
  xhtml += '</div>\n';
  return xhtml;
}

Gallery.prototype.getInnerXHTML = function(str){
  if (arguments.length != 1) {
    focus();
    throw new Error("Gallery->getInnerXHTML: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Gallery->getInnerXHTML: Argument str ist nicht vom Typ String!");
  }
  var xhtml = '';
  
  var idxImg = this.previewStartIdx;
  for (var i=(this.previewStartIdx-1); i<((this.previewStartIdx-1)+this.previewLength); i++){
    if (i== ((this.previewStartIdx-1)+this.previewLength) -1 ){
      xhtml += '<div id="_'+ this.id +'_Gallery_Thumbs_LASTELEMENT" class="fotogalerie-thumbs-eintrag-last">\n';
    } else {
      xhtml += '<div class="fotogalerie-thumbs-eintrag">\n';
    }
    
    if (idxImg >= this.imageMap.length){
      idxImg = 0;
    } else if (idxImg < 0){
      idxImg = this.imageMap.length -1;
    }
    if (! this.imageMap[idxImg]){
      focus();
      throw new Error("Gallery.getXHTML: Kein Image mit in Array this.imageMap["+ idxImg +"]!");
      return;
    }
    
    xhtml += '<a href="javascript:void(0);" onclick="Gallery.getInstance(\''+ this.id +'\').drawDetail(\''+ idxImg +'\');">';
   
    var _img = this.imageMap[idxImg];
    var _src = _img.normalSrc;
    var _title = _img.title;
    if (_img.previewSrc){
      var _src = _img.previewSrc
    }
    xhtml += '<img src="'+ _src +'" style="width: 254px; height: 254px;" id="picture" alt="Bild: '+idxImg+'" title="Bild '+ _title +' '+idxImg+'" />';
    
    xhtml += '</a><br />\n';
    xhtml += '</div>\n';
    idxImg++;
  }
  
  return xhtml;
}

Gallery.prototype.getDetailXHTML = function(str){
  if (arguments.length != 1) {
    focus();
    throw new Error("Gallery->getDetailXHTML: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Gallery->getDetailXHTML: Argument str ist nicht vom Typ String!");
  }
  var idxImg = str; 
  var _img = this.imageMap[idxImg];  
  if (! _img){
    focus();
    throw new Error("Gallery.getDetailXHTML: Kein Image mit in Array this.imageMap["+ idxImg +"]!");
    return;
  }
  var _src = _img.normalSrc;
  var _title = _img.title;
  var _description = _img.description;
  var xhtml = '';
  xhtml += '<div class="fotogalerie-detail-bild" id="bild">\n';
  xhtml += '<img src="'+ _src +'" alt="Bild: '+ _title +'" title="Bild: '+ _title +'" /><br />\n';
  xhtml += '</div>\n';
  xhtml += '<div class="fotogalerie-detail-beschreibung" id="beschreibung">\n';
  xhtml += _description + '<br />\n';
  xhtml += '</div>\n';
  return xhtml;
}

Gallery.prototype.drawPreview = function(str){
  if (arguments.length != 1) {
    focus();
    throw new Error("Gallery->drawPreview: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Gallery->drawPreview: Argument str ist nicht vom Typ String!");
  }
  var elem = document.getElementById(str);
  if (! elem) {
    focus();
    throw new Error("Gallery->drawPreview: Es existiert kein HTML-Element mit ID = "+ str +"!");
  }
  elem.innerHTML = this.getXHTML(str);
  if (this.type == 'move' && (! this._init)){
    this._setPreviewElementProperties(str);
    this._init = true;
  } 
}

Gallery.prototype.drawDetail = function(str){
  if (arguments.length != 1) {
    focus();
    throw new Error("Gallery->drawDetail: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Gallery->drawDetail: Argument str ist nicht vom Typ String!");
  }
  var elem = document.getElementById('detail-view');
  if (! elem) {
    focus();
    throw new Error("Gallery->drawDetail: Es existiert kein HTML-Element mit ID = "+ str +"!");
  }
  if (this.detailByFadingMode){
    this.drawDetailByFading(str);
    return;
  }
  elem.innerHTML = this.getDetailXHTML(str);
}

Gallery.prototype.drawDetailByFading = function(str){
  if (this.fadeStatus){
    return;
  }
  if (arguments.length != 1) {
    focus();
    throw new Error("Gallery->drawDetailByFading: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Gallery->drawDetailByFading: Argument str ist nicht vom Typ String!");
  }
  var elem = document.getElementById('detail-view');
  var opacityElem = document.getElementById('fotogalerie-detail-opacity');
  if (! elem) {
    focus();
    throw new Error("Gallery->drawDetailByFading: Es existiert kein HTML-Element mit ID = "+ str +"!");
  }
  if (! opacityElem) {
    focus();
    throw new Error("Gallery->drawDetailByFading: Es existiert kein HTML-Element mit ID = fotogalerie-detail-opacity!");
  }
  var idxImg = str; 
  var _img = this.imageMap[idxImg];  
  if (! _img){
    focus();
    throw new Error("Gallery.getDetailXHTML: Kein Image mit in Array this.imageMap["+ idxImg +"]!");
    return;
  }
  var img = new Image();
  img.src = _img.normalSrc;
  var idx = this.id;
  var func = function () {
    var _src = _img.normalSrc;
    var _title = _img.title;
    var _description = _img.description;
    var xhtml = '';
    xhtml += '<div class="fotogalerie-detail-bild">\n';
    xhtml += '<img src="'+ _src +'" alt="Bild: '+ _title +'" title="Bild: '+ _title +'" /><br />\n';
    xhtml += '</div>\n';
    opacityElem.innerHTML = xhtml;
    Gallery.getInstance(idx).fadeStatus = true;
    Gallery.getInstance(idx).fadingDetail(0, str);
  }
  if(! img.complete){
    img.onload = func;
    return;
  }
  func();
}

Gallery.prototype.fadingDetail = function(diff, str){
  if (this.timeOut){
    window.clearTimeout(this.timeOut);
  }
  if (arguments.length != 2) {
    focus();
    throw new Error("Gallery->fadingDetail: Falsche Anzahl von Argumenten!");
  }
  if (typeof diff != "number") {
    focus();
    throw new Error("Gallery->fadingDetail: Argument diff ist nicht vom Typ Number!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Gallery->fadingDetail: Argument str ist nicht vom Typ String!");
  }
  var idx = this.id;
  var opacityElem = document.getElementById('fotogalerie-detail-opacity');
  var opac;
  var opacGrenzwert = 1;
  if (opacityElem.filters != undefined){
    // IE
    opacGrenzwert = 100;
    opac = parseFloat(0 + parseFloat(diff));
    opac = parseInt(opac * 100) / 100;
    if (opac > 100){
      opac = 100;
    }
    if (opacityElem.filters['Alpha']) {
      opacityElem.filters['Alpha']['opacity'] = opac;
      opacityElem.filters['Alpha']['finishopacity'] = opac;
    }
    diff += 8;
  } else {
    // Other
    var opac = parseFloat(0 + parseFloat(diff));
    opac = parseInt(opac * 100) / 100;
    if (opac > 1){
      opac = 1;
    }
    opacityElem.style.opacity = opac;
    diff += 0.08;
  }
  if (opac < opacGrenzwert){
    var funcFade = function () {Gallery.getInstance(idx).fadingDetail(diff, str);}
    Gallery.getInstance(idx).timeOut = window.setTimeout(funcFade, Gallery.getInstance(idx).timeOutDelay);
    return;
  }
  this.resetFadingDetail(str);
}

Gallery.prototype.resetFadingDetail = function(str){
  if (arguments.length != 1) {
    focus();
    throw new Error("Gallery->resetFadingDetail: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Gallery->resetFadingDetail: Argument str ist nicht vom Typ String!");
  }
  var elem = document.getElementById('detail-view');
  var opacityElem = document.getElementById('fotogalerie-detail-opacity');
  if (! elem) {
    focus();
    throw new Error("Gallery->resetFadingDetail: Es existiert kein HTML-Element mit ID = "+ str +"!");
  }
  elem.innerHTML = this.getDetailXHTML(str);
  if (opacityElem.filters != undefined){
    if (opacityElem.filters['Alpha']) {
      opacityElem.filters['Alpha']['opacity'] = 0;
      opacityElem.filters['Alpha']['finishopacity'] = 0;
    }
  } else {
    opacityElem.style.opacity = 0;
  }
  this.fadeStatus = false;
}

Gallery.prototype.previewBackward = function(str){
  if (arguments.length != 1) {
    focus();
    throw new Error("Gallery->previewBackward: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Gallery->previewBackward: Argument str ist nicht vom Typ String!");
  }
  this.setPreviewStartIdx(this.previewStartIdx - 1);
  if (this.previewStartIdx < 0){
    this.setPreviewStartIdx(this.imageMap.length + this.previewStartIdx);
  }
  this.direction = 'backward';
  if (this.type == 'move') {
    this.movePreview(str);
  } else {
    this.drawPreview(str);
  }
}

Gallery.prototype.previewForward = function(str){
  if (arguments.length != 1) {
    focus();
    throw new Error("Gallery->previewForward: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Gallery->previewForward: Argument str ist nicht vom Typ String!");
  }
  this.setPreviewStartIdx(this.previewStartIdx + 1);
  if (this.previewStartIdx >= this.imageMap.length){
    this.setPreviewStartIdx(this.imageMap.length - this.previewStartIdx);
  }
  this.direction = 'forward';
  if (this.type == 'move') {
    this.movePreview(str);
  } else {
    this.drawPreview(str);
  }
}

Gallery.prototype.movePreview = function(str){
  if (arguments.length != 1) {
    focus();
    throw new Error("Gallery->movePreview: Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Gallery->movePreview: Argument str ist nicht vom Typ String!");
  }
  if (this.direction == 'backward'){
    var idxImg = this.previewStartIdx;
  } else {
    var idxImg = parseFloat(this.previewStartIdx + (this.previewLength -1));
  }
  //alert('this.previewStartIdx = ' + this.previewStartIdx + ' : idxImg = ' +  idxImg);
  if (idxImg >= this.imageMap.length){
    idxImg = idxImg - (this.imageMap.length);
  } else if (idxImg < 0){
    idxImg = this.imageMap.length -1;
  }
  var idx = this.id;
  var img = new Image();
  img.src = this.imageMap[idxImg].previewSrc;
  if (! img.complete){
    img.onload = function () {Gallery.getInstance(idx).movePreview(str)};
    return;
  }
  var thumbsInnerElemID = '_'+ this.id +'_Gallery_Thumbs_Inner';
  var innerElem = document.getElementById(thumbsInnerElemID);
  if (! innerElem) {
    focus();
    throw new Error("Gallery->movePreview: Es existiert kein HTML-Element mit ID = "+ thumbsInnerElemID +"!");
  }
  var lastElementID = '_'+ this.id +'_Gallery_Thumbs_LASTELEMENT';
  var lastElement = document.getElementById(lastElementID);
  innerElem.style.left = '0';
  var topPos;
  var imgItem = document.createElement('div');
  imgItem.className = "fotogalerie-thumbs-eintrag-last";
  if (this.direction == 'backward'){
    imgItem.className = "fotogalerie-thumbs-eintrag";
  }
  var xhtml = '<a href="javascript:void(0);" onclick="Gallery.getInstance(\''+ this.id +'\').drawDetail(\''+ idxImg +'\');">';
  var _img = this.imageMap[idxImg];
  var _src = _img.normalSrc;
  var _title = _img.title;
  if (_img.previewSrc){
    var _src = _img.previewSrc
  }
  xhtml += '<img src="'+ _src +'" style="width: 254px; height: 254px;" id="picture" alt="Bild: '+idxImg+'" title="Bild '+ _title +' '+idxImg+'" />';
  xhtml += '</a><br />\n';
  imgItem.innerHTML = xhtml;
  if (this.direction == 'backward'){
    topPos = 5;
    innerElem.insertBefore(imgItem, innerElem.childNodes[0]);
    innerElem.style.left = parseFloat(parseFloat(innerElem.style.left) - (imgItem.offsetWidth)) + 'px';
    this.move(topPos, 0);
  } else {
    innerElem.appendChild(imgItem);
    topPos = -5;
    if (lastElement){
      lastElement.className = 'fotogalerie-thumbs-eintrag';
      lastElement.id = '';
    }
    imgItem.id = lastElementID;
    this.move(topPos, imgItem.offsetWidth);
  }  
}

Gallery.prototype.move = function(topPos, max){
  //alert('topPos = ' + topPos + ' : max = ' + max);
  if (arguments.length!=2) {
    throw new Error("Gallery->move: Falsche Anzahl von Argumenten!");
  }
  var thumbsInnerElemID = '_'+ this.id +'_Gallery_Thumbs_Inner';
  var innerElem = document.getElementById(thumbsInnerElemID);
  if (! innerElem) {
    focus();
    throw new Error("Gallery->move: Es existiert kein HTML-Element mit ID = "+ thumbsInnerElemID +"!");
  }
  if (this._timeOut){
    window.clearTimeout(this._timeOut);
  }
  var pos = parseFloat(innerElem.style.left) + topPos;
  if (this.direction == 'backward'){
    if (pos > max){
      pos = parseFloat(innerElem.style.left) + parseFloat(max - parseFloat(innerElem.style.left));
    }
  } else {
    if (Math.abs(pos) > max){
      pos = parseFloat(innerElem.style.left) + parseFloat(max - parseFloat(innerElem.style.left));
    }
  }
  innerElem.style.left = pos + 'px';
  var instanceID = new String(this.id);
  var func = function(){Gallery.getInstance(instanceID).move(topPos, max);}; 
  if (Math.abs(pos) == max){
    if (this.direction == 'backward'){
      for (var i=innerElem.childNodes.length-1; i>=0; i--){
        var child = innerElem.childNodes[i];
        if (! (child.nodeType == 1 && child.className == 'fotogalerie-thumbs-eintrag-last')){
          continue;
        }
        innerElem.removeChild(child);
        break;
      }   
      var lastElementID = '_'+ this.id +'_Gallery_Thumbs_LASTELEMENT';
      for (var i=innerElem.childNodes.length-1; i>=0; i--){
        var child = innerElem.childNodes[i];
        if (! (child.nodeType == 1 && child.className == 'fotogalerie-thumbs-eintrag')){
          continue;
        }
        innerElem.style.left = '0';
        child.id = lastElementID;
        child.className = 'fotogalerie-thumbs-eintrag-last';    
        return;
      } 
    } else {
      for (var i=0; i<innerElem.childNodes.length; i++){
        var child = innerElem.childNodes[i];
        if (! (child.nodeType == 1 && child.className == 'fotogalerie-thumbs-eintrag')){
          continue;
        }
        innerElem.removeChild(child);
        innerElem.style.left = '0'; 
        return;  
      }
    }  
    return;
  }
  this._timeOut = window.setTimeout(func, '15');
}

Gallery._increment = [];
Gallery._registerInstance = {};
Gallery._registerInstanceLength = [];

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

Gallery.createInstance = function(id) {
  if (!arguments.length) {
    id = 'Gallery' + 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!");
  }
  return Gallery.getInstance(id);
}

//************************************************************
// GalleryImage
//************************************************************

function GalleryImage(id) {
  this.id = undefined;
  this.title = '';
  this.subTitle = '';
  this.description = '';
  this.previewSrc = undefined;
  this.normalSrc = undefined;
  this.printSrc = undefined;
  
  this._setID(id);
}

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

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

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

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

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

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

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

GalleryImage._increment = [];
GalleryImage._registerInstance = {};
GalleryImage._registerInstanceLength = [];

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

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

/*
function setImage() {
  alert('xxxx');
  var bildElem = document.getElementById('bild');
  var beschreibungElem = document.getElementById('beschreibung');
  bildElem.innerHTML = '<img src="'+ _img.normalSrc +'" alt="'+ _img.title +'" title="'+ _img.title +'" /><br />';
  beschreibungElem.innerHTML = _img.description + '<br />';
}
*/

