var FOTO = new Class({
	initialize: function(parentWrapperID, sid, indx, date, headline, text, image, archive) {
		this.parentWrapperID = parentWrapperID;
		this.sid = sid;
		this.indx = indx;
		this.date = date;
		this.headline = headline;
		this.text = text;
		this.imageDir = './images/content/fotos/';
		this.image = null;
		if(image != '' && image != null) this.image = this.imageDir + image;
		this.archive = archive;
		
		this.newsWrapper = null;
		
		this.labels = {
			openGallery: 'zur Fotogalerie'
		};
	},
	
	showAsTextPicture: function(fxTime) {
		var _self = this;
		this.newsWrapper = new Element('div', {'class':'newsWrapper'}).setStyle('opacity', 0);
		if(this.indx == 0 && !this.archive) this.newsWrapper.setStyle('padding-top', 0);
		var textWrapper = new Element('div', {'class':'textWrapper'});
		var headlineWrapper = new Element('div', {'class':'headlineWrapper'});
		var dateWrapper = new Element('div', {'class':'newsDate'}).set('html', this.date);
		headlineWrapper.grab(dateWrapper).grab(new Element('div').set('html', this.headline));
		
		var icon = new Element('img', {'alt':this.labels.openGallery, 'src':this.imageDir + 'button-open-gallery.gif', 'title':this.labels.openGallery}).setStyles({'cursor':'pointer', 'margin':'0px 5px -2px 0px'});
		icon.addEvent('click', function() {
			lightgallery.getImages(_self.sid);
		});
		var link = new Element('span', {'class':'link-on'}).setStyles({'display':'inline'}).set('html', this.labels.openGallery);
		link.addEvent('mouseover', function() {
			this.setStyles({'text-decoration':'underline'});
		});
		link.addEvent('mouseout', function() {
			this.setStyles({'text-decoration':'none'});
		});
		link.addEvent('click', function() {
			lightgallery.getImages(_self.sid);
		});
		var text = new Element('div').set('html', this.text).grab(new Element('div').setStyles({'padding-top':20}).grab(icon).grab(link));
		
		textWrapper.grab(headlineWrapper).grab(text);
		var imageWrapper = new Element('div', {'class':'imageWrapper'});
		
		if(this.image != null) {
			var image = new Element('img', {'alt':this.date + ' - ' + this.headline, 'title':this.date + ' - ' + this.headline}).setStyles({'border':0, 'margin-left':30});
			image.addEvent('load', function() {
				new Fx.Morph(_self.newsWrapper, {duration:fxTime}).start({'opacity':1});
			});
			image.addEvent('error', function() {
				this.destroy();
				new Fx.Morph(_self.newsWrapper, {duration:fxTime}).start({'opacity':1});
			});
			imageWrapper.grab(image);
			this.newsWrapper.grab(textWrapper).grab(imageWrapper).grab(new Element('div', {'class':'clear'}));
			if($(this.parentWrapperID.toString())) $(this.parentWrapperID.toString()).grab(this.newsWrapper);
			if(this.image != '') image.src = this.image;
		} else {
			this.newsWrapper.grab(textWrapper).grab(imageWrapper).grab(new Element('div', {'class':'clear'}));
			if($(this.parentWrapperID.toString())) {
				$(this.parentWrapperID.toString()).grab(this.newsWrapper);
				new Fx.Morph(this.newsWrapper, {duration:fxTime}).start({'opacity':1});
			}
		}
	},
	
	showAsPicture: function(fxTime) {
		
	},
	
	showAsText: function(fxTime) {
		
	},
	
	hide: function(fxTime) {
		var _self = this;
		if(this.newsWrapper != null) {
			new Fx.Morph(this.newsWrapper, {duration:fxTime}).start({
				'opacity':0
			}).chain(function() {
				_self.newsWrapper.destroy();
				_self.newsWrapper = null;
			});
		}
	}
});