var SimpleSlideshow = new Class({
  options: {
    showControls: true,
    showDuration: 3000,
    showTOC: false,
    tocWidth: 20,
    tocClass: 'toc',
    tocActiveClass: 'toc-active'
  },
  Implements: [Options,Events],
  initialize: function(container,elements,options) {
    //settings
    this.container = $(container);
    this.elements = $$(elements);
    this.currentIndex = 0;
    this.interval = '';
    if(this.options.showTOC) this.toc = [];
    //assign
    this.elements.each(function(el,i){
    	el.set('tween', {duration: 1500});
      if(this.options.showTOC) {
        this.toc.push(new Element('a',{
          text: i+1,
          href: '#',
          'class': this.options.tocClass + '' + (i == 0 ? ' ' + this.options.tocActiveClass : ''),
          events: {
            click: function(e) {
              if(e) e.stop();
              this.stop();
              this.show(i);
            }.bind(this)
          },
          styles: {
            left: ((i + 1) * (this.options.tocWidth + 10))
          }
        }).inject(this.container));
      }
      if(i > 0) el.set('opacity',0);
      if (el.getStyle('width').toInt()<311 && el.getStyle('left').toInt()==0) {
    	el.setStyle('left',
    		(320-el.getStyle('width').toInt())/2
    	);
    };
    if (el.getStyle('height').toInt()<311&& el.getStyle('top').toInt()==0) {
    	el.setStyle('top',
    		(320-el.getStyle('height').toInt())/2
    	)
    };
    },this);
    
    //next,previous links
    if(this.options.showControls) {
      this.createControls();
      
    }
    //events
    this.container.addEvents({
      mouseenter: function() { this.stop(); }.bind(this),
      mouseleave: function() { this.start(); }.bind(this)
    });

  },
  show: function(to) {
    this.elements[this.currentIndex].fade('out');
    if(this.options.showTOC) this.toc[this.currentIndex].removeClass(this.options.tocActiveClass);
    this.elements[this.currentIndex = ($defined(to) ? to : (this.currentIndex < this.elements.length - 1 ? this.currentIndex+1 : 0))].fade('in');
    if(this.options.showTOC) this.toc[this.currentIndex].addClass(this.options.tocActiveClass);
  },
  start: function() {
    this.interval = this.show.bind(this).periodical(this.options.showDuration);
  },
  stop: function() {
    $clear(this.interval);
  },
  //"private"
  createControls: function() {
    var next = new Element('a',{
      href: '#',
      'class': 'next',
      text: '>>',
      events: {
        click: function(e) {
          if(e) e.stop();
          this.stop(); 
          this.show();
        }.bind(this)
      }
    }).inject(this.container);
    var previous = new Element('a',{
      href: '#',
      'class': 'previous',
      text: '<<',
      events: {
        click: function(e) {
          if(e) e.stop();
          this.stop(); 
          this.show(this.currentIndex != 0 ? this.currentIndex -1 : this.elements.length-1);
        }.bind(this)
      }
    }).inject(this.container);
  }
});
function foto(did,uid){

	var nowe = '/gallery/watermark.php?pic=' + uid;
	document.getElementById(did).src = nowe;
}

window.addEvent('domready', function() {
	$$('a[rel=external]').each(function (el) {
	el.set('target','_blank');
	});
	var myMenu = new MenuMatic();

	$$('.readmore').each(function(el) {
		var toggle = el.getFirst('.descripttext');
		var full = el.getFirst('.readfull');
		var extended = new Fx.Slide(full);
		full.addEvent('click',function(event){
			extended.toggle();
			toggle.fade('in');
		});
		extended.hide();
		toggle.addEvent('click', function(event){
			event.stop();
			extended.toggle();
			toggle.fade('out');
		});
	});
});



