  var wu_reflection = new function() {
   this.ielt7 = function() {
   	if (navigator.appName == 'Microsoft Internet Explorer') {
     var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
     if (re.exec(navigator.userAgent) != null)
     if (parseFloat(RegExp.$1) < 7) return true;
   	};
   	return false;
   }
   this.create = function(element, height, opacity) {
   	if (wu_reflection.ielt7()) return null;
	var times = (element.height * height);
	var dist = 1.0 / times;
	var samplediv = new Element('div').setStyles({height: '1px', overflow: 'hidden', 'margin': 0, 'padding': 0, 'border': 'none'});
	var sampleimg = element.clone().setProperty('id', '').setStyle('padding', 0);
   	var wrap = new Element('div').setStyles({'padding': 0, 'margin': 0, 'border': 'none', 'height': times + 'px'});
	for (var i = 0; i < times; i++) {
	 var h = samplediv.clone();
	 var img = sampleimg.clone();
	 img.style.marginTop = '-' + (element.height - i - 1) + 'px';
	 h.appendChild(img);
	 wrap.appendChild(h);
	 h.setOpacity((1 - dist * i) * opacity);
	}
	return wrap;
   }
  };
  
  wu_galleryimage = function(href, title, price) {
   this.href = href;
   this.title = title;
   this.price = price;
  };
  
  var wu_lightbox = new function() {
   var images = new Array();
   var current = null;
   var lb = null;
   var cimg = null;
   var showeff = null;
   var hideeff = null;
   var fastshoweff = null;
   var loadimg = null;
   var control = null;
   var lang_next = '';
   var lang_prev = '';
   var lang_price = '';
   var lang_priceprefix = '';
   var lang_currency = '';
   var picdir = '';
   var loadingimg = '';
   var extra = null;
   this.setcurrent = function(add) { current += add; }
   this.repos = function(width, height) {
    var setx = (Window.getWidth() - width) / 2;
    var sety = (Window.getHeight() - height) / 2 + Window.getScrollTop();
    if (Window.getHeight() < height) sety = (height - Window.getHeight()) / 2 + Window.getScrollTop();
    setx = (setx < 0 ) ? 0 : setx;
    sety = (sety < 0 ) ? 0 : sety;
    lb.setStyles({'left': setx + 'px', 'top': sety + 'px'});
   }
   this.show = function(e) {
    var curr = wu.target(e);
    if (!curr) return;
    current = parseInt(curr.parentNode.rel);
    wu_lightbox.loading();
    wulb.showbox('wu_lightbox', wu_lightbox.showpic);
    return wu.stop(e);
   }
   this.loading = function() {
    lb.setProperty('class', 'wu_lightbox_loading').setHTML('').setStyles({'display': 'block', 'width': loadimg.width + 'px', 'height': loadimg.height + 'px'}).adopt(loadimg);
    wu_lightbox.repos(loadimg.width, loadimg.height);
   }
   this.createcontrol = function() {
    control = new Element('div').setProperty('id', 'wu_lightbox_control');

    if (images[current].title != '') control.adopt(new Element('h6').appendText(images[current].title));
    var p = new Element('p').setProperty('id', 'wu_lightbox_pos').appendText(parseInt(current + 1) + '/' + images.length + ' ');
    control.adopt(p);

    if (current > 0) p.adopt(new Element('a').setProperties({'tabindex': '0', 'href': '#'}).appendText(lang_prev).addEvent('click', function(e) {
      wu_lightbox.setcurrent(-1);
      hideeff.start(1, 0);
      return wu.stop(e);
     })).appendText(' ');
    if (current + 1 < images.length) p.adopt(new Element('a').setProperties({'tabindex': '0', 'href': '#'}).appendText(lang_next).addEvent('click', function(e) {
      wu_lightbox.setcurrent(1);
      hideeff.start(1, 0);
      return wu.stop(e);
     })).appendText(' ');
    p.adopt(new Element('a').setProperties({'id': 'wu_lightbox_close', 'tabindex': '0', 'href': '#'}).appendText('x').addEvent('click', function(e) {
     wulb.hidebox();
     return wu.stop(e);
    }));

    var price = parseFloat(images[current].price);
    if (price > 0) control.adopt(new Element('p').setProperty('id', 'wu_lightbox_price').setHTML(lang_price + ': <strong>' + lang_priceprefix + price + '<' + '/strong> ' + lang_currency));

    control.adopt(new Element('div').setStyle('clear', 'both'));
   }
   this.extracontrol = function() {
    if (extra) extra();
   }
   this.onimgload = function() {
    showeff.hide();
    wu_lightbox.createcontrol();
    lb.setProperty('class', 'wu_lightbox').setHTML('').adopt(control).adopt(new Element('img').setProperties({'id': 'wu_lightbox_mainimg', 'src': images[current].href, 'title': images[current].title}).setStyle('clear', 'both'));
    wu_lightbox.extracontrol();

    lb.setStyles({'height': 'auto', 'width': 'auto'});
    var newheight = lb.offsetHeight;
    if (!wu_reflection.ielt7()) newheight = parseInt((newheight - cimg.height) + parseInt(cimg.height * 1.3));
    lb.setStyles({'height': newheight + 'px', 'width': cimg.width + 'px'});
    wu_lightbox.repos(cimg.width, newheight);

    showeff.start(0, 1);
   }
   this.reflection = function() {
   	var img = $('wu_lightbox_mainimg');
   	var wrap = wu_reflection.create(img, 0.3, 0.5).setProperty('id', 'wu_lightbox_reflection').setStyles({'height': '0px', 'overflow': 'hidden'});
    img.parentNode.adopt(wrap);
   	new Fx.Style(wrap, 'height', {duration: 1000}).start(0, (img.height * 0.3));
   }
   this.showpic = function() {
    cimg = null;
    cimg = new Image();
    cimg.onload = wu_lightbox.onimgload;
    cimg.src = images[current].href;
   }
   this.init = function(plang_next, plang_prev, plang_price, plang_priceprefix, plang_currency, ppicdir, ploadingimg, pextra) {
    lang_next = plang_next;
    lang_prev = plang_prev;
    lang_price = plang_price;
    lang_priceprefix = plang_priceprefix;
    lang_currency = plang_currency;
    picdir = ppicdir;
    loadingimg = ploadingimg;
    extra = pextra;

    var as = $('wu_gallery').getElementsByTagName('a');
    var aslen = as.length;
    var imnum = 0;
    for (var n = 0; n < aslen; n++) if (as.item(n).getAttribute('rel') == 'lightbox[gallery]') {
     as.item(n).setAttribute('rel', imnum);
     imnum++;
     var href = as.item(n).getAttribute('href');
     if (href.indexOf('images/show.php') > -1) href = unescape(picdir + href.substr(href.indexOf('folder=') + 7).replace('&file=', '/').replace('&lightbox=1', ''));
     images.push(new wu_galleryimage(href, as.item(n).getAttribute('title'), as.item(n).getAttribute('rev')));
     wu.ev(as.item(n), 'click', wu_lightbox.show);
    };

    lb = new Element('div').setProperty('id', 'wu_lightbox');
    document.body.appendChild(lb);

    hideeff = new Fx.Style(lb, 'opacity', {duration: 150, onComplete: function() {
     wu_lightbox.loading();
     fastshoweff.start(0, 1);
    }});
    fastshoweff = new Fx.Style(lb, 'opacity', {duration: 150, onComplete: wu_lightbox.showpic});
    showeff = new Fx.Style(lb, 'opacity', {duration: 300, onComplete: wu_lightbox.reflection});
    loadimg = new Element('img').setProperty('src', loadingimg);
   }
  };
