/* logger function with failsafe for browser without console */
var debug = true;
function logger(message) {
	if (debug && typeof(console) != 'undefined') 
	console.log(message);
}

function showPreview(image)
{
	document.getElementById('previewImage').src=image;
}

function vCardOver(element)
{
	element.src='fileadmin/templates/images/vCardRoll.gif';
}

function vCardOut(element)
{
	element.src='fileadmin/templates/images/vCard.gif';
}


function setEvents() {
	for(var index = 0; index < $$('.images').length; index++) {	
		var elements = $$('#images'+index);
		elements.each(function(teaser) {
			teaser.observe('mouseover', function() {
				//elements.without(teaser).each(function(el) { el.down('.textLayerDiv').setStyle({ dispaly: 'none' }) });
				teaser.down('.textLayerDiv').appear();
			});
		});
	}
}


News = Class.create({
	initialize: function(element,pagi) {
		this.element = $(element);
		this.pagi = $(pagi);
		this.counter = 0;
		this.buildInterface();
		this.switchPage(0);
		this.addEvents();
	},
  
	buildInterface: function() {
		if($$('.newsEntry').length > 3){
			for (var index = 0; index < $$('.newsEntry').length; index++) {
				if(index % 3 == 0){
					var pagination = new Element('span',{'class':'pagispan'}).update((index/3)+1);
					this.pagi.appendChild(pagination);
				}
				this.switchPage(0);
			}
		}else{
			var pagination = new Element('span',{'class':'pagispan'}).update("&nbsp;");
			this.pagi.appendChild(pagination);
		}
	},

	addEvents: function() {
		this.element.observe('click', this.handleClicks.bind(this));
	},
  
	handleClicks: function(event) {
		/*event.stop();*/
		var element = event.element();
				
		if (element.tagName.toLowerCase() == 'span') {
			$$('.pagispan').invoke('removeClassName', 'active');
			var index = parseInt(element.innerHTML) - 1;
			this.switchPage(index);
		}				
	},
  
	switchPage: function(offset) {
		$$('.newsEntry').invoke('hide');
		for(var i = offset * 3; i < (offset+1)*3 && i < $$('.newsEntry').length; i++){
			$$('.newsEntry')[i].show();
		}
		$$('.pagispan')[offset].addClassName('active');
		//$$('.newsEntry')[(offset * 3 + 1)].show();
		//$$('.newsEntry')[(offset * 3 + 2)].show();
		//this.hideAndShowContents(index);
	},
  
	hideAndShowContents: function(index) {
		$$('.newsPages').invoke('hide');
		$$('.newsPages')[index].show();
	}
});








Ausstellung = Class.create({
	initialize: function(element, contents) {
		this.element = $(element);
		this.contents = contents || [];
		this.buildInterface();
		this.addEvents();
		this.index = 1;
	},
  
	buildInterface: function() {
		var count = 0;
		var page = 0;
		
		var self = this;
		$$(".team").invoke("observe", "mouseover", function(event) {
			self.doShow(event);
		});
		
	},
	
	doShow: function(event){
		var index = parseInt(Event.findElement(event,'div').id.split("_")[1]);
		if(!isNaN(index))
		{
			showPreview(this.contents[index-1]);
		}
	},

	addEvents: function() {
		//this.element.observe('click', this.handleClicks.bind(this));
	},
  
	handleClicks: function(event) {
		event.stop();
		var element = event.element();				
	},
  
	switchPage: function(index) {
		this.hideAndShowContents(index);
	},
  
	hideAndShowContents: function(index) {
		$$('.images').invoke('hide');
		$$('.images')[index].show();
	}
});








Imageswitch = Class.create({
	initialize: function(element,contents) {
		this.element = $(element);
		//this.pagi = $(pagi);
		this.contents = contents || [];
		this.currentPage = 0;
		this.counter = 0;
		this.buildInterface();
		this.addEvents();
		this.index = 1;
		this.appearDurationClick = 1;
		this.appearDuration = 3;
		this.timeoutCounterOrgValue = 3 + this.appearDuration;
		this.timeoutCounter = 3;//this.timeoutCounterOrgValue;
		//this.hideAndShowPage(this.index);	
	},
  
  
	buildInterface: function() {
		var minus = 1;
		var interval = 1;
		var self = this;
		new PeriodicalExecuter(function ( pe ) {
			self.timeoutCounter -= minus;
			if(self.timeoutCounter <= 0){
				self.hidePage(self.index, self.appearDuration);
				self.index++;
				if(self.index > $$('.image').length)
					self.index = 1;
				self.ShowPage(self.index, self.appearDuration);
               			self.timeoutCounter = self.timeoutCounterOrgValue;
			}
		}, interval);
		
		self = this;
		new PeriodicalExecuter(function ( pe ) {
			self.element.hide();
			self.element.show();
		}, interval);
		
	},
  
	addEvents: function() {
		this.element.observe('click', this.handleClicks.bind(this));
	},
  
	handleClicks: function(event) {
		event.stop();
		var element = event.element();
	    	
		if (element.tagName.toLowerCase() == 'span') {
			this.hidePage(this.index, this.appearDurationClick);
			var index = parseInt(element.innerHTML);
			this.ShowPage(index, this.appearDurationClick);
			this.timeoutCounter = this.timeoutCounterOrgValue;
			this.index = index;
		}
	},
	
	hidePage: function(index, appearDuration) {
		$$('.image')[index-1].fade({duration: appearDuration});
	},
	
	ShowPage: function(index, appearDuration) {
		this.index = index;
		$$('.image')[index-1].appear({duration: appearDuration});
	}
});







NewImageswitch = Class.create({
	initialize: function(element,contents) {
		this.element = $(element);
		this.contents = contents || [];
		this.currentPage = 0;
		this.counter = 0;
		this.elementWidth = 17;
		this.buildInterface();
		this.addEvents();
		this.appearDurationClick = 1;
		this.appearDuration = 3;
		this.imageIndexBefore = 0;
		this.imageIndex = 0;

		this.timeoutCounterOrgValue = 3 + this.appearDuration;
		this.timeoutCounter = this.timeoutCounterOrgValue;
		$('nextImageImages_'+this.imageIndex).src = 'fileadmin/templates/images/full.gif';
		this.ShowPage(this.imageIndex,1);
		this.recheck();	
	},
  
  
	buildInterface: function() {
		var minus = 1;
		var interval = 1;
		var self = this;
		new PeriodicalExecuter(function ( pe ) {
			self.timeoutCounter -= minus;
			if(self.timeoutCounter <= 0){
				self.imageIndexBefore = self.imageIndex;
				self.imageIndex++;
				if(self.imageIndex > (self.contents.length-1))
					self.imageIndex = 0;			
				self.recheck();
				self.timeoutCounter = self.timeoutCounterOrgValue;
			}
		}, interval);

		var main = new Element('div',{'style':'position:relative', 'class':'main'});
		this.element.appendChild(main);

		self = this;
		new PeriodicalExecuter(function ( pe ) {
			main.hide();
			main.show();
			//self.recheck();
		}, interval);

			
		for(var i = 0; i < this.contents.length; i++)
		{
			var image = new Element('img',{'src':this.contents[i], 'style':'display:none; position:absolute', 'class':'image', 'id':'current_'+i});
			main.appendChild(image);
		}
			var width = 0;
			var elementCount = 0;
			if(this.contents.length > 5)
			{
				width = 5 * this.elementWidth;
				elementCount = 0;
			}
			else{
				width = this.contents.length * this.elementWidth;
				elementCount = 5 - this.contents.length;
			}
			
			var scrollAllDivImages = new Element('div',{
				id:'scrollImageAllImages_',
				'class':'scrollImagesAllImages',
				style:'width:'+(24+(((5-elementCount)*this.elementWidth))+24)+'px; overflow:hidden; position:absolute; top:323px; left:'+(503+(elementCount * this.elementWidth))+'px; height:32px'
			});

			var scrollFrameDivImages = new Element('div',{
				id:'scrollImageFrameImages',
				'class':'scrollImagesFrameImages',
				style:'float:left; height:32px; width:'+(width)+'px; overflow:hidden'
			});
			var imgLeftImages = new Element('img',{
				src:'fileadmin/templates/images/arrow_left.gif',
				'class':'prevImage',
				'id':'prevImage_',
				style:'width:24px;height:32px;'
			});
			var scrollMeDivImages = new Element('div',{
				id:'scrollMeImages_',
				'class':'scrollMeImages',
				style:'height:32px; float:left; width:800px;'
			});
			
			for(var indexImages = 0; indexImages < this.contents.length; indexImages++)
			{
				var imgImages = new Element('img',{
					src:'fileadmin/templates/images/empty.gif',
					'id':'nextImageImages_'+(indexImages),
					'class':'nextImageImages'
				});
				scrollMeDivImages.appendChild(imgImages);
			}

			
			var imgRightImages = new Element('img',{
				src:'fileadmin/templates/images/arrow_right.gif',
				style:'float:left; width:24px; height:32px;',
				'class':'nextImage',
				'id':'nextImage_'
			});
						
			scrollFrameDivImages.appendChild(scrollMeDivImages);
			scrollAllDivImages.appendChild(imgLeftImages);
			scrollAllDivImages.appendChild(scrollFrameDivImages);

			scrollAllDivImages.appendChild(imgRightImages);
			main.appendChild(scrollAllDivImages);
	},
  
	addEvents: function() {
		this.element.observe('click', this.handleClicks.bind(this));
	},
  
	handleClicks: function(event) {
		event.stop();
		var element = event.element();
	    	
		if (element.tagName.toLowerCase() == 'span') {
			//this.hidePage(this.index, this.appearDurationClick);
			this.hidePage(this.imageIndex, this.appearDurationClick);
			var index = parseInt(element.innerHTML);
			this.ShowPage(index, this.appearDurationClick);
			this.timeoutCounter = this.timeoutCounterOrgValue;
			this.index = index;
			this.imageIndex = this.imageIndex;
			//this.imageIndex = index;
		}


		//handle click for image pagination
		if (element.className == 'nextImage') {
			this.timeoutCounter = this.timeoutCounterOrgValue;
			this.imageIndexBefore = this.imageIndex;
			this.imageIndex++;
			if(this.imageIndex > (this.contents.length-1)){
				this.imageIndex = this.contents.length-1;
			}
			if(this.imageIndexBefore != this.imageIndex )
			{
				this.recheck();
			}
		}
		else if (element.className == 'prevImage') {
			this.timeoutCounter = this.timeoutCounterOrgValue;
			this.imageIndexBefore = this.imageIndex;
			this.imageIndex--;
			if(this.imageIndex < 0){
				this.imageIndex = 0;
			}

			if(this.imageIndexBefore != this.imageIndex )
			{
				this.recheck();
			}
		}
		
		if(element.className == 'nextImageImages')
		{
			var toImage = element.id.split('_')[1];
			this.imageIndexBefore = this.imageIndex;
			this.imageIndex = toImage;
			if(this.imageIndexBefore != this.imageIndex )
			{
				this.recheck();
				this.timeoutCounter = 30;
			}
		}
	},



	recheck: function()
	{
		//reset automatic counter
		this.timeoutCounter = this.timeoutCounterOrgValue;
		//Page we currently are on
		var toPage = this.imageIndex;
		var move = 0;
		if(this.contents.length > 5)
		{
			//not moving on the first and last 2 pages
			if(toPage >= 2 && toPage < this.contents.length-2)
			{
				move = (toPage-2) * (-1*this.elementWidth); //amount we should move
			}
			else
			{
				if(toPage < 2)
				{
					move = 0;
				}
				else if(toPage >= this.contents.length-2)
				{
					move = (this.contents.length-2-3)*(-1*this.elementWidth);
				}
			}
			var self = this;
			new Effect.Move($('scrollMeImages_'), {
				x:move,
				y:0,
				duration: 0.2,

				mode: "absolute",
				queue : {
					scope : $('scrollMeImages_').identify() + '-scope',
					limit : 1
				},
				afterFinish : function() {
					//self.state = 0;
					//$('textLayer'+self.referenzNumber).style.left = '636px';
				}.bind(self)
			});
		}
		

		this.deactivateArrows();


		
		if(this.imageIndexBefore != this.imageIndex)
		{
			$('nextImageImages_'+this.imageIndexBefore).src = 'fileadmin/templates/images/empty.gif';
			$('nextImageImages_'+this.imageIndex).src = 'fileadmin/templates/images/full.gif';
			$('current_'+this.imageIndexBefore).fade();
			$('current_'+this.imageIndex).appear();
		}
	},

	deactivateArrows: function()
	{
		var max = this.contents.length-1;
		if(this.imageIndex == 0)
		{
			$('prevImage_').src = 'fileadmin/templates/images/arrow_left_grey.gif';
			$('prevImage_').addClassName('deactivated');
		}
		else
		{
			$('prevImage_').src = 'fileadmin/templates/images/arrow_left.gif';
			$('prevImage_').removeClassName('deactivated');
		}
		if(this.imageIndex >= max)
		{
			$('nextImage_').src = 'fileadmin/templates/images/arrow_right_grey.gif';
			$('nextImage_').addClassName('deactivated');
		}
		else
		{
			$('nextImage_').src = 'fileadmin/templates/images/arrow_right.gif';
			$('nextImage_').removeClassName('deactivated');
		}
	},
	
	hidePage: function(index, appearDuration) {
		//$$('.nextImageImages')[index].fade({duration: appearDuration});
		

	},
	
	ShowPage: function(index, appearDuration) {
		//this.index = index;
		$('current_'+index).appear({duration: appearDuration});

	}
});






















Referenzen = Class.create({
	initialize: function(element,contents) {
		this.element = $(element);
		this.currentPage = 0;
		this.counter = 0;
		this.contents = contents || [];
		this.referenzNumber = 1;
		this.referenzNumberBefore = 1;
		this.imageIndex = 0;
		this.state = 0;
		this.imageIndex=0;
		this.imageIndexBefore = 0;
		this.referenzPageIndex=0;
		this.referenzPageIndexBefore=0;
		this.switchImageSpeed = 1;
		this.counterMax = 4;
		this.counter = this.counterMax;
		this.numberOfPages = 0;
		this.elementWidth = 17;

		this.buildInterface();
		this.addEvents();
		this.hideAndShowPage(this.referenzNumber);
		this.switchPage(0,0);

	},
  
	buildInterface: function() {
	
		var self = this;
		new PeriodicalExecuter(function ( pe ) {
			$('unterseite_content_left').hide();
			$('unterseite_content_left').show();
			$('unterseite_content_right_middle').hide();
			$('unterseite_content_right_middle').show();
		}, 1);

		new PeriodicalExecuter(function ( pe ) {
			//counter counted down
			if(self.counter > self.counterMax)
			{
				self.imageIndexBefore = self.imageIndex;
				self.imageIndex++;
				if(self.imageIndex >= self.contents[self.referenzNumber]['images'].length)
				{
					self.imageIndex = 0;
				}
				if(self.imageIndexBefore != self.imageIndex)
				{
					self.recheck();
				}
				
				//self.showImage(before,self.imageIndex)
				self.counter = 0;
			}else{
				self.counter++;
			}
		}, this.switchImageSpeed);
		
		var mainmain= new Element('div',{
			id:'mainmain',
			'class':'mainmain',
			style:'position:relative; z-index:100'
		});
		$('unterseite_content_right_middle').appendChild(mainmain);
			
		var main = this.element;
		
		var pagination = new Element('div',{
			id:'pagination',
			'class':'pagination'
		});
		
		var page = new Element('div',{
			'class':'page',
			style:'display:none'
		});
		main.appendChild(pagination);
		//main.appendChild(page);
		
		
		var imageNameDiv = new Element('div',{
			id:'imageNames',
			'class':'imageNames'
		});
		

		for(var index = 0; index < this.contents.length; index++) {
			if(index % 9 == 0){
				this.numberOfPages++;
				//new page for the referenze names
				page = new Element('div',{
					'class':'page',
					style:'display:none'
				});
				main.appendChild(page);

			//new pagination entry
			/*
				if(index != 0){
					var pagespan = new Element('span').update((index/9)+1);
					pagination.appendChild(pagespan);
				}
				else{
					var pagespan = new Element('span').update("&nbsp;");
					pagination.appendChild(pagespan);
				}
		 */
			}
		
			var name = new Element('p',{
				id:'referenz_'+index,
				'class':'referenzName'
			}).update(this.contents[index]['name']);
			
			if(this.contents[index]['images'].length < 1 ) {
				name.addClassName('noContent');
			}
			
			page.appendChild(name);
		
			// create new element for images
			var imageDiv = new Element('div',{
				id:'images'+index,
				'class':'images',
				'style':'background-color:#464646;'
			});
			mainmain.appendChild(imageDiv);

			for(var indexImages = 0; indexImages < this.contents[index]['images'].length; indexImages++) {
				var singleImage = new Element('div',{
					style:'display:none',
					id:'current'+index+'_'+indexImages,
					'class':'refNr_'+index
				});
				/*
				var a = new Element('a',{
					'href':this.contents[index]['lytebox'][indexImages],
					'rel':'lytebox[refNr_'+index+']',
					'title':this.contents[index]['imageNames'][indexImages]
				})
				*/
				var img = new Element('img',{
					'src': this.contents[index]['images'][indexImages],
					'border':0,
					'alt':this.contents[index]['name']+' '+indexImages
				});
				//a.appendChild(img);
				singleImage.appendChild(img);
				imageDiv.appendChild(singleImage);
				
			}

			
			for(var indexImagesNames = 0; indexImagesNames < this.contents[index]['images'].length; indexImagesNames++) {
				var singleImageName = new Element('div',{
					style:'display:none',
					id:'currentName'+index+'_'+indexImagesNames,
					'class':'imageNamesrefNr_'+index
				});
				var text = new Element('span').update(this.contents[index]['images'][indexImagesNames]);
				singleImageName .appendChild(text);
				imageNameDiv.appendChild(singleImageName);
			}

			var width = 0;
			var elementCount = 0;
			if(this.contents[index]['images'].length > 5)
			{
				width = 5 * this.elementWidth;
				elementCount = 0;
			}
			else{
				width = this.contents[index]['images'].length * this.elementWidth;
				elementCount = 5 - this.contents[index]['images'].length;
			}

			var scrollAllDivImages = new Element('div',{
				id:'scrollImageAllImages_'+index,
				'class':'scrollImagesAllImages',
				style:'background-color:#000000; opacity:0.72; display:none; width:'+(24+((5-elementCount)*this.elementWidth)+24)+'px; overflow:hidden; position:absolute; top:323px; left:'+(446+(elementCount*this.elementWidth))+'px; height:32px'
			});

			var scrollFrameDivImages = new Element('div',{
				id:'scrollImageFrameImages',
				'class':'scrollImagesFrameImages',
				style:'float:left; height:32px; width:'+(width)+'px; overflow:hidden'
			});
			var imgLeftImages = new Element('img',{
				src:'fileadmin/templates/images/arrow_left.gif',
				style:'float:left; width:24px;height:32px;',
				'class':'prevImage',
				'id':'prevImage_'+index
			});
			var scrollMeDivImages = new Element('div',{
				id:'scrollMeImages_'+index,
				'class':'scrollMeImages',
				style:'height:32px; float:left; width:'+(this.contents[index]['images'].length*this.elementWidth)+'px;'
			});
			
			for(var indexImages = 0; indexImages < this.contents[index]['images'].length; indexImages++)
			{
				var imgImages = new Element('img',{
					src:'fileadmin/templates/images/empty.gif',
					'style':'float:left',
					'id':'nextImageImages_'+index+'_'+(indexImages),
					'class':'nextImageImages'
				});
				scrollMeDivImages.appendChild(imgImages);
			}

			
			var imgRightImages = new Element('img',{
				src:'fileadmin/templates/images/arrow_right.gif',
				style:'float:left; width:24px;height:32px;',
				'class':'nextImage',
				'id':'nextImage_'+index
			});
						
			scrollFrameDivImages.appendChild(scrollMeDivImages);
			scrollAllDivImages.appendChild(imgLeftImages);
			scrollAllDivImages.appendChild(scrollFrameDivImages);

			scrollAllDivImages.appendChild(imgRightImages);
			mainmain.appendChild(scrollAllDivImages);


		
			var textLayerDivBackground = new Element('div',{
				id:'textLayerBackground'+index,
				'class':'textLayerBackgroundDiv'
			});
			var textLayerDiv = new Element('div',{
				style:'position:absolute; top:0px; left:636px; width:318px; height:355px;',
				id:'textLayer'+index,
				'class':'textLayerDiv'
			});
			var textDiv = new Element('div',{
				style:'display:none;',
				id:'text'+index,
				'class':'textDiv'
			}).update(this.contents[index]['infoText']);
			textLayerDiv.appendChild(textLayerDivBackground );
			textLayerDiv.appendChild(textDiv);
			imageDiv.appendChild(textLayerDiv);
		}

		
		var scrollAllDiv = new Element('div',{
			id:'scrollImageAll',
			'class':'scrollImagesAll',
			style:'width:230px; overflow:hidden'
		});
		var scrollFrameDiv = new Element('div',{
			id:'scrollImageFrame',
			'class':'scrollImagesFrame',
			style:'float:left; height:32px; width:119px; overflow:hidden'
		});
		var imgLeft = new Element('img',{
			src:'fileadmin/templates/images/arrow_left.gif',
			'id':'prevReferenz',
			style:'float:left; width:24px;height:32px;'
		});
		var scrollMeDiv = new Element('div',{
			id:'scrollMe',
			'class':'scrollMe',
			style:'height:32px; float:left; width:800px;'
		});
		for(var i = 0; i < this.contents.length; i++)
		{
			if(i % 9 == 0)
			{
				var img = new Element('img',{
					src:'fileadmin/templates/images/empty.gif',
					style:'float:left;',
					'id':'referenzImage_'+(i / 9),
					'class':'referenzImage'
				});
				scrollMeDiv.appendChild(img);
			}
		}
		var imgRight = new Element('img',{
			src:'fileadmin/templates/images/arrow_right.gif',
			style:'float:left; width:24px;height:32px;',
			'id':'nextReferenz'
		});
		scrollFrameDiv.appendChild(scrollMeDiv);
		scrollAllDiv.appendChild(imgLeft);
		scrollAllDiv.appendChild(scrollFrameDiv);
		
		scrollAllDiv.appendChild(imgRight);
		main.appendChild(scrollAllDiv);
		
		
		
		var button = new Element('div',{
			'class':'button'
		});
		mainmain.appendChild(button);

		var buttonText = new Element('div',{
			'id':'buttonText',
			style:'padding-top:7px; padding-left:10px;font-size:14px'
		}).update('Info');
		mainmain.appendChild(buttonText);

		this.menu_element = mainmain;
		this.state = 0; // the state of the menu
		//this.mouseover_callback =  this.mouseOver.bindAsEventListener(this); //callbacks
		//this.mouseout_callback = this.mouseOut.bindAsEventListener(this);
		//this.menu_element.observe('mouseover', this.mouseover_callback);
		//this.menu_element.observe('mouseout', this.mouseout_callback);
		this.queue = Effect.Queues.get(this.menu_element.identify() + '-scope');
	////create a queue with a unique name
		
	},

	switchPage: function(from, to){

		if(to >= (this.numberOfPages-1)){
			$('nextReferenz').src = 'fileadmin/templates/images/arrow_right_grey.gif';
			$('nextReferenz').addClassName('deactivated');
		}
		else
		{
			$('nextReferenz').src = 'fileadmin/templates/images/arrow_right.gif';
			$('nextReferenz').removeClassName('deactivated');
		}
		if(to <= 0){
			$('prevReferenz').src = 'fileadmin/templates/images/arrow_left_grey.gif';
			$('prevReferenz').addClassName('deactivated');
		}
		else
		{
			$('prevReferenz').src = 'fileadmin/templates/images/arrow_left.gif';
			$('prevReferenz').removeClassName('deactivated');
		}
		$$('.page').invoke('hide');
		$$('.page')[to].show();
		$$('#referenzImage_'+from)[0].src = 'fileadmin/templates/images/empty.gif';
		$$('#referenzImage_'+to)[0].src = 'fileadmin/templates/images/full.gif';
	},




	displayCurrentText: function() {
		$$('#textLayer'+this.referenzNumber).invoke('appear');
	},
  
	addEvents: function() {
		this.element.observe('click', this.handleClicks.bind(this));
		$('unterseite_content_right_middle').observe('click', this.handleClicks.bind(this));
	},
  
	handleClicks: function(event) {
		event.stop();
		var element = event.element();
		
		if (element.tagName.toLowerCase() == 'p') {
			if(!element.hasClassName('noContent')) {
			var index = parseInt(element.id.split("_")[1]);
				if(this.referenzNumber != index)
				{
				if(this.state == 1)
				{
					var self = this;
					new Effect.Move($('textLayer'+self.referenzNumber), {
						x:636,
						y:0,
						duration: 0.1,
						mode: "absolute",
						queue : {
							scope :  $('textLayer'+self.referenzNumber).identify() + '-scope',
							limit : 1
						},
						afterFinish : function() {
							self.state = 0;
						}.bind(self)
					});
					/*
					new Effect.Move($('textLayerBackground'+self.referenzNumber), {
						x:0,
						y:0,
						duration: 0.1,
						mode: "absolute",
						queue : {
							scope :  $('textLayerBackground'+self.referenzNumber).identify() + '-scope',
							limit : 1
						},
						afterFinish : function() {
							self.state = 0;
						}.bind(self)
					});
					*/
				}

				//this.hideImage(this.imageIndex);
				//var index = parseInt(element.id.split("_")[1]);
				$$('.imageNamesrefNr_'+this.referenzNumber).invoke('hide');
				this.referenzNumberBefore = this.referenzNumber;
				$('nextImageImages_'+this.referenzNumber+'_'+this.imageIndex).src = 'fileadmin/templates/images/empty.gif';

				this.referenzNumber = index;
				this.imageIndex = 0;


				this.hideAndShowPage(index);
				}
			}
		}
		else if (element.id == 'nextReferenz') {
			
			var refBefore = this.referenzPageIndex;
			this.referenzPageIndex++;
			if( this.referenzPageIndex >= (this.numberOfPages)){
				this.referenzPageIndex = this.numberOfPages-1;
			}
			if(refBefore != this.referenzPageIndex)
			{
				$('textLayer'+this.referenzPageIndexBefore).style.left = '636px';
			}
			this.switchReferenz();
			this.switchPage(refBefore, this.referenzPageIndex);
		}
		else if (element.id == 'prevReferenz') {
			var refBefore = this.referenzPageIndex;
			this.referenzPageIndex--;
			if(this.referenzPageIndex < 0){
				this.referenzPageIndex = 0;
			}
			if(refBefore != this.referenzPageIndex)
			{
				$('textLayer'+this.referenzPageIndexBefore).style.left = '636px';
			}
			this.switchReferenz();			
			this.switchPage(refBefore, this.referenzPageIndex);
		}
		
		//handle click for image pagination
		if (element.className == 'nextImage') {
			this.counter = 0;
			//var imgBefore = this.imageIndex;
			this.imageIndexBefore = this.imageIndex;
			this.imageIndex++;
			if(this.imageIndex > (this.contents[this.referenzNumber]['images'].length-1)){
				this.imageIndex = this.contents[this.referenzNumber]['images'].length-1;
			}
			if(this.imageIndexBefore != this.imageIndex )
			{
				this.recheck();
			}
		}
		else if (element.className == 'prevImage') {
			this.counter = 0;
			//var imgBefore = this.imageIndex;

			this.imageIndexBefore = this.imageIndex;
			this.imageIndex--;
			if(this.imageIndex < 0){
				this.imageIndex = 0;
			}
			if(this.imageIndexBefore != this.imageIndex )
			{
				this.recheck();
			}
		}


		if(element.className == 'nextImageImages')
		{
			var toImage = element.id.split('_')[2];
			//this.showImage(this.imageIndex, toImage);
			this.imageIndexBefore = this.imageIndex;
			this.imageIndex = toImage;
			if(this.imageIndexBefore != this.imageIndex )
			{
				this.recheck();
				this.counter = -25;
			}
		}
		
		if(element.className == 'referenzImage')
		{
			var toImage = element.id.split('_')[1];
			this.referenzPageIndexBefore = this.referenzPageIndex;
			this.referenzPageIndex = toImage;
			if(this.referenzPageIndexBefore != this.referenzPageIndex)
			{
				$('textLayer'+this.referenzPageIndexBefore).style.left = '636px';
				this.switchReferenz();
				this.switchPage(this.referenzPageIndexBefore,this.referenzPageIndex);
			}
		}


		if (element.id == 'buttonText') {

			if(this.state == 1)
			{
				var self = this;
				new Effect.Move($('textLayer'+self.referenzNumber), {
					x:636,
					y:0,
					duration: 1.2,
					mode: "absolute",
					queue : {
						scope :  $('textLayer'+self.referenzNumber).identify() + '-scope',
						limit : 1
					},
					afterFinish : function() {
						self.state = 0;
					}.bind(self)
				});
				/*
				new Effect.Move($('textLayerBackground'+self.referenzNumber), {
					x:0,
					y:0,
					duration: 1.2,
					mode: "absolute",
					queue : {
						scope :  $('textLayerBackground'+self.referenzNumber).identify() + '-scope',
						limit : 1
					},
					afterFinish : function() {
						self.state = 0;
					}.bind(self)
				});
				*/
			}
			else if(this.state == 0)
			{

				var self = this;
				new Effect.Move($('textLayer'+self.referenzNumber), {
					x:318,
					y:0,
					duration: 1.2,
					mode: "absolute",
					queue : {
						scope : $('textLayer'+self.referenzNumber).identify() + '-scope',
						limit : 1
					},
					afterFinish : function() {
						self.state = 1;
					}.bind(self)
				});
				/*
				new Effect.Move($('textLayerBackground'+self.referenzNumber), {
					x:0,
					y:0,
					duration: 1.2,
					mode: "absolute",
					queue : {
						scope : $('textLayerBackground'+self.referenzNumber).identify() + '-scope',
						limit : 1
					},
					afterFinish : function() {
						self.state = 1;
					}.bind(self)
				});
				*/
			}
		}

	},
	
	switchReferenz: function()
	{
		var move = 0;
		this.counter = 0;
		//Page we currently are on
		var toPage = this.referenzPageIndex;

		//not moving on the first and last 2 pages
		/*
		var left = $('scrollMe').style.left;
		if(left == '')
		{
			left = 0;
		}
		else
		{
			left = left.split('px')[0];
		}
		*/

		if(toPage >= 3 && toPage < (this.numberOfPages-3) )
		{

			move = ((toPage-3) * (-1*this.elementWidth)); //- left; //amount we should move
		}
		else
		{
			if(toPage < 3)
			{

				move = 0;
				//move = left * (-1);
			}
			else if(toPage >= (this.numberOfPages-3-2))
			{
				move = (this.numberOfPages-3-3-1)*(-1*this.elementWidth);
			}
		}
		var self = this;
		new Effect.Move($('scrollMe'), {
			x:move,
			y:0,
			duration: 0.2,
			mode: "absolute",
			queue : {
				scope : $('textLayerBackground'+self.referenzNumber).identify() + '-scope',
				limit : 1
			},
			afterFinish : function() {
				//self.state = 1;
				//$('textLayer'+self.referenzNumber).style.left = '636px';
			}.bind(self)
			//transition: Effect.Transitions.sinoidal,
			//queue: "end"
		});
	},




	recheck: function()
	{
		//reset automatic counter
		this.counter = 0;
		//Page we currently are on
		var toPage = this.imageIndex;
		var move = 0;
		if(this.contents[this.referenzNumber]['images'].length > 5)
		{
			//not moving on the first and last 2 pages
			if(toPage >= 2 && toPage < (this.contents[this.referenzNumber]['images'].length-2))
			{
				move = (toPage-2) * (-1*this.elementWidth); //amount we should move
			}
			else
			{
				if(toPage < 2)
				{
					move = 0;
				}
				else if(toPage >= this.contents[this.referenzNumber]['images'].length-2)
				{
					move = (this.contents[this.referenzNumber]['images'].length-2-3)*(-1*this.elementWidth);
				}
			}
			var self = this;
			new Effect.Move($('scrollMeImages_'+this.referenzNumber), {
				x:move,
				y:0,
				duration: 0.2,

				mode: "absolute",
				queue : {
					scope : $('scrollMeImages_'+self.referenzNumber).identify() + '-scope',
					limit : 1
				},
				afterFinish : function() {
					//self.state = 0;
					//$('textLayer'+self.referenzNumber).style.left = '636px';
				}.bind(self)
			});
		}
		

		this.deactivateArrows();

		$('nextImageImages_'+this.referenzNumberBefore+'_'+this.imageIndexBefore).src = 'fileadmin/templates/images/empty.gif';
		$('nextImageImages_'+this.referenzNumber+'_'+this.imageIndex).src = 'fileadmin/templates/images/full.gif';
		$$('.refNr_'+this.referenzNumber).invoke('hide');
		$$('.imageNamesrefNr_'+this.referenzNumber).invoke('hide');
		if(this.contents[this.referenzNumber]['images'].length > 0)
			$('current'+this.referenzNumber+'_'+this.imageIndex).appear();
	},

	deactivateArrows: function()
	{
		var max = this.contents[this.referenzNumber]['images'].length-1;
		if(this.imageIndex == 0)
		{
			$('prevImage_'+this.referenzNumber).src = 'fileadmin/templates/images/arrow_left_grey.gif';
			$('prevImage_'+this.referenzNumber).addClassName('deactivated');
		}
		else
		{
			$('prevImage_'+this.referenzNumber).src = 'fileadmin/templates/images/arrow_left.gif';
			$('prevImage_'+this.referenzNumber).removeClassName('deactivated');
		}
		if(this.imageIndex >= max)
		{
			$('nextImage_'+this.referenzNumber).src = 'fileadmin/templates/images/arrow_right_grey.gif';
			$('nextImage_'+this.referenzNumber).addClassName('deactivated');
		}
		else
		{
			$('nextImage_'+this.referenzNumber).src = 'fileadmin/templates/images/arrow_right.gif';
			$('nextImage_'+this.referenzNumber).removeClassName('deactivated');
		}
	},


	

	showText: function(imageIndex) {
		if(this.contents[this.referenzNumber]['text'] != '')
			$('text'+this.referenzNumber).appear();
	},
 	
	hideAndShowPage: function(index) {

		if(this.imageIndex >= $$('.refNr_'+this.referenzNumber).length-1){
		//$$('.nextImage').invoke('hide');
		}else{
		//$$('.nextImage').invoke('show');
		}
		if(this.imageIndex <= 0){
		//$$('.prevImage').invoke('hide');
		}else{
		//$$('.prevImage').invoke('show');
		}
		$$('.referenzName').invoke('removeClassName', 'active');
		$$('.referenzName')[index].addClassName('active');
		$$('.images').invoke('hide');
		$$('.textDiv').invoke('hide');
		$$('.imageNamesrefNr_'+this.referenzNumber).invoke('hide');
		//this.showImage(0,0);
		this.imageIndexBefore = this.imageIndex;
		this.imageIndex = 0;
		this.recheck();
		this.referenzNumberBefore = index;
		$('images'+index).appear();
		$('text'+index).appear();
		$$('.scrollImagesAllImages').invoke('hide');
		//if(this.contents[this.referenzNumber]['images'].length > 1)
		//{ //show only if this referenz has more than one image
			$$('#scrollImageAllImages_'+index).invoke('show');
		//}
	//$$('#currentName'+this.referenzNumber+'_'+index).invoke('show');
	}
});























// extern eingebunden js file
Home = Class.create({
	initialize: function(element, right, contents) {
		this.element = $(element);
		this.right = $(right);
		this.contents = contents || [];
		this.currentPage = 0;
		this.counter = 0;
		this.elementWidth = 17;
		this.buildInterface();
		this.addEvents();
		this.index = 1;
		this.imageIndexBefore = 0;
		this.imageIndex = 0;
		this.appearDurationClick = 1;
		this.appearDuration = 3;
		this.timeoutCounterOrgValue = 5 + this.appearDuration;
		this.timeoutCounter = this.timeoutCounterOrgValue;
		this.recheck();
	},
  
  
	buildInterface: function() {

		var minus = 1;
		var interval = 1;
		var index = 0;
		for(var i = 0; i < this.contents[index]['images'].length; i++)
		{
			var image = new Element('img',{'src':this.contents[index]['images'][i], 'style':'width:532px; height:320px; display:none; position:absolute', 'class':'image', 'id':'current_'+i});
			this.element.appendChild(image);
		}
		var self = this;
		new PeriodicalExecuter(function ( pe ) {
			self.timeoutCounter -= minus;
			if(self.timeoutCounter <= 0){
				self.imageIndexBefore = self.imageIndex;
				self.imageIndex++;
				if(self.imageIndex >= self.contents[0]['images'].length)
				{
					self.imageIndex = 0;
				}
				self.recheck();
				//self.hidePage(self.index, self.appearDuration);
				//self.index++;
				//if(self.index > $$('.image').length)
				//	self.index = 1;
				//self.showPage(self.index, self.appearDuration);
               			self.timeoutCounter = self.timeoutCounterOrgValue;
			}
		}, interval);
		
		self = this;
		new PeriodicalExecuter(function ( pe ) {
			$('start_content_left').hide();
			$('start_content_left').show();
		}, interval);
		
		var width = 0;
		var elementCount = 0;
		if(this.contents[index]['images'].length > 5)
		{
			width = 5 * this.elementWidth;
			elementCount = 0;
		}
		else{
			width = this.contents[index]['images'].length * this.elementWidth;
			elementCount = 5 - this.contents[index]['images'].length;
		}
		
		var scrollAllDivImages = new Element('div',{
			id:'scrollImageAllImages_'+index,
			'class':'scrollImagesAllImages',
			style:'background-color:#000000; opacity:0.72; width:'+(24+((5-elementCount)*this.elementWidth)+24)+'px; overflow:hidden; position:absolute; top:288px; left:'+(398+(elementCount*this.elementWidth))+'px; height:32px'
		});
		
		var scrollFrameDivImages = new Element('div',{
			id:'scrollImageFrameImages',
			'class':'scrollImagesFrameImages',
			style:'float:left; height:32px; width:'+(width)+'px; overflow:hidden'
		});
		
		var imgLeftImages = new Element('img',{
			src:'fileadmin/templates/images/arrow_left.gif',
			style:'float:left; width:24px;height:32px;',
			'class':'prevImage',
			'id':'prevImage_'+index
		});
		
		var scrollMeDivImages = new Element('div',{
			id:'scrollMeImages_'+index,
			'class':'scrollMeImages',
			style:'height:32px; float:left; width:'+(this.contents[index]['images'].length*this.elementWidth)+'px;'
		});
			
		for(var indexImages = 0; indexImages < this.contents[index]['images'].length; indexImages++)
		{
			var imgImages = new Element('img',{
				src:'fileadmin/templates/images/empty.gif',
				'style':'float:left',
				'id':'nextImageImages_'+index+'_'+(indexImages),
				'class':'nextImageImages'
			});
			scrollMeDivImages.appendChild(imgImages);
		}
		var div = new Element('div',{'style':'width:435px; position:absolute'});
		//for(var text = 0; text < this.contents[index]['infoText'].length; text++)
		for(var text = 0; text < 1; text++)		
		{
		
			//var div2 = new Element('div',{'style':'padding:20px; display:none','id':'textcontent_'+text, 'class':'text_content lineheight'}).update(this.contents[index]['infoText'][text]);
			var div2 = new Element('div',{'style':'padding:20px;','id':'textcontent_'+text, 'class':'text_content lineheight'}).update(this.contents[index]['infoText'][text]);
			div.appendChild(div2);
			
		}
		this.right.appendChild(div);
		var imgRightImages = new Element('img',{
			src:'fileadmin/templates/images/arrow_right.gif',
			style:'float:left; width:24px;height:32px;',
			'class':'nextImage',
			'id':'nextImage_'+index
		});
						
		scrollFrameDivImages.appendChild(scrollMeDivImages);
		scrollAllDivImages.appendChild(imgLeftImages);
		scrollAllDivImages.appendChild(scrollFrameDivImages);
		scrollAllDivImages.appendChild(imgRightImages);
		this.element.appendChild(scrollAllDivImages);

		
	},
  
	addEvents: function() {
		this.element.observe('click', this.handleClicks.bind(this));
	},
  
	handleClicks: function(event) {
		event.stop();
		var element = event.element();
	    	
		if (element.tagName.toLowerCase() == 'span') {
			var index = parseInt(element.innerHTML);
			if(index != this.index){
				this.hidePage(this.index, this.appearDurationClick);
				this.showPage(index, this.appearDurationClick);
				this.timeoutCounter = this.timeoutCounterOrgValue;
				this.index = index;
			}
		}
		if (element.className == 'nextImage') {
			this.counter = 0;
			//var imgBefore = this.imageIndex;
			this.imageIndexBefore = this.imageIndex;
			this.imageIndex++;
			if(this.imageIndex > (this.contents[0]['images'].length-1)){
				this.imageIndex = this.contents[0]['images'].length-1;
			}
			if(this.imageIndexBefore != this.imageIndex )
			{
				this.recheck();
			}
		}
		else if (element.className == 'prevImage') {
			this.counter = 0;
			//var imgBefore = this.imageIndex;

			this.imageIndexBefore = this.imageIndex;
			this.imageIndex--;
			if(this.imageIndex < 0){
				this.imageIndex = 0;
			}
			if(this.imageIndexBefore != this.imageIndex )
			{
				this.recheck();
			}
		}


		if(element.className == 'nextImageImages')
		{
			var toImage = element.id.split('_')[2];
			//this.showImage(this.imageIndex, toImage);
			this.imageIndexBefore = this.imageIndex;
			this.imageIndex = toImage;
			if(this.imageIndexBefore != this.imageIndex )
			{
				this.recheck();
				this.timeoutCounter = 30;
			}
		}
		

	},
	
	recheck: function()
	{
		//reset automatic counter
		this.counter = 0;
		//Page we currently are on
		var toPage = this.imageIndex;
		var move = 0;
		if(this.contents[0]['images'].length > 5)
		{
			//not moving on the first and last 2 pages
			if(toPage >= 2 && toPage < (this.contents[0]['images'].length-2))
			{
				move = (toPage-2) * (-1*this.elementWidth); //amount we should move
			}
			else
			{
				if(toPage < 2)
				{
					move = 0;
				}
				else if(toPage >= this.contents[0]['images'].length-2)
				{
					move = (this.contents[0]['images'].length-2-3)*(-1*this.elementWidth);
				}
			}
			var self = this;
			new Effect.Move($('scrollMeImages_'+this.referenzNumber), {
				x:move,
				y:0,
				duration: 0.2,

				mode: "absolute",
				queue : {
					scope : $('scrollMeImages_'+self.referenzNumber).identify() + '-scope',
					limit : 1
				},
				afterFinish : function() {
				}.bind(self)
			});
		}
		

		this.deactivateArrows();

		$('nextImageImages_0_'+this.imageIndexBefore).src = 'fileadmin/templates/images/empty.gif';
		$('nextImageImages_0_'+this.imageIndex).src = 'fileadmin/templates/images/full.gif';
		//$$('.refNr_0').invoke('hide');
		//$$('.imageNamesrefNr_0').invoke('hide');
		//$('textcontent_'+this.imageIndexBefore).hide();
		$('current_'+this.imageIndexBefore).hide();
		if(this.contents[0]['images'].length > 0){
			$('current_'+this.imageIndex).appear();
			//$('textcontent_'+this.imageIndex).appear();
		}
	},
	
	deactivateArrows: function()
	{
		var max = this.contents[0]['images'].length-1;
		if(this.imageIndex == 0)
		{
			$('prevImage_0').src = 'fileadmin/templates/images/arrow_left_grey.gif';
			$('prevImage_0').addClassName('deactivated');
		}
		else
		{
			$('prevImage_0').src = 'fileadmin/templates/images/arrow_left.gif';
			$('prevImage_0').removeClassName('deactivated');
		}
		if(this.imageIndex >= max)
		{
			$('nextImage_0').src = 'fileadmin/templates/images/arrow_right_grey.gif';
			$('nextImage_0').addClassName('deactivated');
		}
		else
		{
			$('nextImage_0').src = 'fileadmin/templates/images/arrow_right.gif';
			$('nextImage_0').removeClassName('deactivated');
		}
	},
 
 	hidePage: function(index, appearDuration) {
		$('image'+index).fade({duration: appearDuration});
		//$('text_content'+index).fade({duration: appearDuration});

	},
	showPage: function(index, appearDuration) {
		this.index = index;
		$('image'+index).appear({duration: appearDuration});
		//$('text_content'+index).appear({duration: appearDuration});
	}
	/*
	hideAndShowPage: function(index) {
		this.index = index;
		//$$('.image').invoke('hide');
		$$('.image').invoke('fade',{duration: this.appearDuration});
		//$$('.text_content').invoke('hide');
		$('image'+index).appear({duration: this.appearDuration});
		//$('text_content'+index).appear({duration: this.appearDuration});
	}
	*/
});






// auf der jew. seite
/*
document.observe('dom:loaded', function() {
  blubb = new Bla('element_id', [{ name: 'lala', element_id: 'blabla', infoText: 'fjshjdf hjsdf ' }]);
})
*/

