var smoothPop = {
  imgWidth: null,
  liWidth: null,
  imgHeight: null,
  liHeight: null,
  liOffset: null,
  picaktuellNeuUrl: null,
  picAktuellSmallLi: null,
  pixarenaWidth: null,
  pixarenaHeight: null,
  liOffsetLeft: null,

  init: function()
    {
      var pixarena = document.getElementById('pixarena').getElementsByTagName('ul')[0].getElementsByTagName('li');
      smoothPop.pixarenaWidth = Core.getComputedStyle(document.getElementById('gallery'), 'width');
      smoothPop.pixarenaHeight = Core.getComputedStyle(document.getElementById('gallery'), 'height');

      for(var i = 0; i < pixarena.length; i++) {
          if(Core.hasClass(pixarena[i], 'pix')) {
              Core.addEventListener(pixarena[i].getElementsByTagName('a')[0], 'click', smoothPop.clickHandlerOne);
          }else{
              Core.addEventListener(pixarena[i].getElementsByTagName('a')[0], 'click', smoothPop.clickHandlerTwo);
          }
      }
    },

    clickHandlerOne: function(event)
    {
      Core.preventDefault(event);
      Core.stopPropagation(event);
      //smoothPop.picaktuellNeuUrl = document.URL.slice(0, document.URL.lastIndexOf('/')).replace('/photographer', '') + this.firstChild.style.backgroundImage.slice(this.style.backgroundImage.indexOf('(') + 3, this.style.backgroundImage.indexOf(')')).replace('thumb', 'small');
      smoothPop.picaktuellNeuUrl = this.firstChild.src.replace("thumb", "small");
      if(smoothPop.picAktuellSmallLi) {
      smoothPop.picAktuellSmallLi.style.display = 'block';
      }
      smoothPop.picAktuellSmallLi = this.parentNode;
      var myImage = new Image();
      myImage.name = this.firstChild.nodeValue;
      Core.addEventListener(myImage, 'load', function() { smoothPop.getWidthAndHeight(myImage); });
      myImage.src = smoothPop.picaktuellNeuUrl;
    },

    clickHandlerTwo: function( event ) {
      Core.preventDefault(event);
      Core.stopPropagation(event);
      var thePic = document.getElementById('picaktuell');
      thePic.parentNode.removeChild(thePic);
      //smoothPop.picAktuellSmallLi.style.display = 'block';
    },

    getWidthAndHeight: function(myImage)
    {
      smoothPop.imgWidth = myImage.width;
      smoothPop.imgHeight = myImage.height;
      smoothPop.liWidth = smoothPop.imgWidth + 40;
      smoothPop.liHeight = smoothPop.imgHeight + 68;
      smoothPop.liOffset = Math.abs((parseInt(smoothPop.pixarenaHeight) - smoothPop.liHeight) / 2);
      smoothPop.liOffsetLeft = Math.abs((parseInt(smoothPop.pixarenaWidth) - smoothPop.liWidth) / 2) - 5;
      smoothPop.thepicTopOffset = smoothPop.imgHeight + 23;
      smoothPop.createPicAktuell(myImage);
      var picaktuell = document.getElementById('picaktuell');
      Core.addEventListener(picaktuell.getElementsByTagName('a')[0], 'click', smoothPop.clickHandlerTwo);
      //smoothPop.picAktuellSmallLi.style.display = 'none';
    },

    createPicAktuell: function(myImage)
    {
      var pixarena = document.getElementById('gallery');
      var picaktuell = document.getElementById('picaktuell');
      var frag = document.createDocumentFragment();
      var li = document.createElement('li');
      var liStyle = 'width:' + smoothPop.liWidth + 'px; top:' + smoothPop.liOffset + 'px; left:' + smoothPop.liOffsetLeft + 'px; margin-bottom:-' +  smoothPop.thepicTopOffset + 'px;';
      li.setAttribute('id', 'picaktuell');
      var dl = document.createElement('dl');
      var dlStyle = 'width:' + smoothPop.liWidth + 'px; height:' + smoothPop.liHeight + 'px;';
      var dt = document.createElement('dt');
      dtStyle = 'width:' + smoothPop.liWidth + 'px; height:' + smoothPop.liHeight+ 'px;';

      dtText = document.createTextNode(myImage.name);
      dt.appendChild(dtText);
      var dd1 = document.createElement('dd');
      dd1Style = 'z-index:1400000000; margin-bottom:-25px; top:-' +  (smoothPop.thepicTopOffset + 30) + 'px;';
      dd1.setAttribute('id', 'close');
      var close = document.createElement('a');
      close.setAttribute('href', document.URL);
      close.appendChild(document.createTextNode('close'));
      dd1.appendChild(close);
      var dd = document.createElement('dd');
      dd.setAttribute('id', 'thepic');
      var ddStyle = 'width:' + smoothPop.imgWidth + 'px; top:-' + smoothPop.thepicTopOffset + 'px; left:20px;">';

      if(document.all) {
          dl.style.setAttribute('cssText', dlStyle, 0);
          dt.style.setAttribute('cssText', dtStyle, 0);
          dd1.style.setAttribute('cssText', dd1Style, 0);
          dd.style.setAttribute('cssText', ddStyle, 0);
          li.style.setAttribute('cssText', liStyle, 0);
      } else {
          dl.setAttribute('style', dlStyle);
          dt.setAttribute('style', dtStyle);
          dd1.setAttribute('style', dd1Style);
          dd.setAttribute('style', ddStyle);
          li.setAttribute('style', liStyle);
      }

      var picaktuellNeu = document.createElement('img');
      picaktuellNeu.setAttribute('src', smoothPop.picaktuellNeuUrl);
      picaktuellNeu.setAttribute('width', smoothPop.imgWidth);
      picaktuellNeu.setAttribute('height', smoothPop.imgHeight);
      picaktuellNeu.setAttribute('alt', 'photo');
      dd.appendChild(picaktuellNeu);
      dl.appendChild(dt);
      dl.appendChild(dd1);
      dl.appendChild(dd);
      li.appendChild(dl);

      if(picaktuell === null) {
        	pixarena.appendChild(li);
      } else {
          pixarena.replaceChild(li, picaktuell);
      }
    }
};

Core.start(smoothPop);