var slideShow = new Class({

	initialize: function() {
		this._activated = true;
		this._activeSlide = new Array(1);
		this._activeSlide['Large'] = 0; 
		this._activeSlide['Small'] = -1;
	},
	
	InitOverlay: function() {
		var scroll = document.getScrollSize();
		$('overlay').style.height = scroll.y + "px";
		$('overlay').style.width = scroll.x + "px";
		this._activeSlide['Large'] = this._activeSlide['Small'];
		
		// Synchronizing Large Slide with the small one
		$('imgLarge').src = _thisImages['Large'][this._activeSlide['Large']];
		$('descTextLarge').innerHTML = _thisTexts['Large'][this._activeSlide['Large']];
		$('headlineLarge').innerHTML = _thisHeadlines['Large'][this._activeSlide['Large']];
		
		this.blendOverlay('overlay');
		this.blendIn('headlineLarge','descTextLarge','imgLarge','tourLayerLarge', 'tourImageContainerLarge');
	},
	
	blendIn: function() {
		var args = Array.prototype.slice.call(arguments);
		var fx = new Array(arguments.length);
		for(i=0; i<arguments.length; i++) {
			fx[i] = new Fx.Morph(args[i], { 'duration': 250});
			fx[i].set({'opacity': '0'});
			fx[i].start({'opacity': '1'});
			$(args[i]).style.zIndex = "30000"
		}
	},
	
	blendOverlay: function() {
		var args = Array.prototype.slice.call(arguments);
		var fx = new Array(arguments.length);
		for(i=0; i<arguments.length; i++) {
			fx[i] = new Fx.Morph(args[i], { 'duration': 250});
			fx[i].set({'opacity': '0'});
			fx[i].start({'opacity': '0.7'});
			$(args[i]).style.zIndex = "30000"
		}
	},
	
	blendOut: function() {
		var args = Array.prototype.slice.call(arguments);
		var fx = new Array(arguments.length);
		for(i=0; i<arguments.length; i++) {
			fx[i] = new Fx.Morph(args[i], { 'duration': 250});
			fx[i].start({'opacity': '0'});
		}
	},
	
	slideNext: function(type, Elements) {
		var args = Array.prototype.slice.call(arguments);
		
		var headline = Elements[0];
		var image = Elements[2];
		var text = Elements[1];
		
		if (this._activated == true) {
			this._activated = false;
			var fx1 = new Fx.Morph($(image), {
				'duration': 500
			});
			var fx2 = new Fx.Morph($(image), {
				'duration': 500
			});
			
			var fx3 = new Fx.Morph($(text), {
				'duration': 500
			});
			var fx4 = new Fx.Morph($(text), {
				'duration': 500
			});
			
			var fx5 = new Fx.Morph($(headline), {
				'duration': 500
			});
			var fx6 = new Fx.Morph($(headline), {
				'duration': 500
			});
			
			fx4.addEvent("complete", (function() {this._activated = true;}).bind(this));
			
			fx1.addEvent("complete", (function(){
				if (this._activeSlide[type] < _thisImages[type].length - 1) {
					this._activeSlide[type] = this._activeSlide[type] + 1;
					$(image).src = _thisImages[type][this._activeSlide[type]];
					$(text).innerHTML = _thisTexts[type][this._activeSlide[type]];
					$(headline).innerHTML = _thisHeadlines[type][this._activeSlide[type]];
					$('slideLink').href = 'javascript:_thisSlideShow.InitOverlay();';
					$('slideLinklarge').href = "javascript:void();";
					if(this._activeSlide[type] == _thisImages[type].length - 1) 
						$('slideLink').href = sContactLink;
						$('slideLinklarge').href = sContactLink;
				}
				else {
					this._activeSlide[type] = 0;
					$('slideLink').href = 'javascript:_thisSlideShow.InitOverlay();';
					$('slideLinklarge').href = "javascript:void();";
					$(image).src = _thisImages[type][this._activeSlide[type]];
					$(text).innerHTML = _thisTexts[type][this._activeSlide[type]];
					$(headline).innerHTML = _thisHeadlines[type][this._activeSlide[type]];
					this._activeSlide[type] = this._activeSlide[type] + 1;
				}
				fx2.start({
					'opacity': '1'
				});
				fx4.start({
					'opacity': '1'
				});
				fx6.start({
					'opacity': '1'
				});
				
			}).bind(this));
			
			fx1.start({
				'opacity': '0'
			});
			fx3.start({
				'opacity': '0'
			});
			fx5.start({
				'opacity': '0'
			});
			
		}
	},
	
	slidePrev: function(type, Elements) {
		
		var headline = Elements[0];
		var image = Elements[2];
		var text = Elements[1];
		
		if (this._activated == true) {
			this._activated = false;
			var fx1 = new Fx.Morph($(image), {
				'duration': 500
			});
			var fx2 = new Fx.Morph($(image), {
				'duration': 500
			});
			
			var fx3 = new Fx.Morph($('descText'), {
				'duration': 500
			});
			var fx4 = new Fx.Morph($('descText'), {
				'duration': 500
			});
			
			var fx5 = new Fx.Morph($(text), {
				'duration': 500
			});
			var fx6 = new Fx.Morph($(text), {
				'duration': 500
			});
			
			fx4.addEvent("complete", (function() {this._activated = true;}).bind(this));
			
			fx1.start({
				'opacity': '0'
			});
			fx3.start({
				'opacity': '0'
			});
			fx5.start({
				'opacity': '0'
			});
			fx1.addEvent("complete", (function(){
				if (this._activeSlide[type] != 0) {					
					this._activeSlide[type] = this._activeSlide[type] - 1;
					$('slideLink').href = 'javascript:_thisSlideShow.InitOverlay();';
					$('slideLinklarge').href = "javascript:void();";
					$(image).src = _thisImages[type][this._activeSlide[type]];
					$(text).innerHTML = _thisTexts[type][this._activeSlide[type]];
					$(headline).innerHTML = _thisHeadlines[type][this._activeSlide[type]];
				}
				else {
					this._activeSlide[type] = _thisTexts[type].length - 1;
					$('slideLink').href = 'javascript:_thisSlideShow.InitOverlay();';
					$('slideLinklarge').href = "javascript:void();";
					$(image).src = _thisImages[type][this._activeSlide[type]];
					$(text).innerHTML = _thisTexts[type][this._activeSlide[type]];
					$(headline).innerHTML = _thisHeadlines[type][this._activeSlide[type]];
					if(this._activeSlide[type] == _thisImages[type].length - 1) 
						$('slideLink').href = sContactLink;
						$('slideLinklarge').href = sContactLink;
				}
				fx2.start({
					'opacity': '1'
				});
				fx4.start({
					'opacity': '1'
				});
				fx6.start({
				'opacity': '1'
				});
				
			}).bind(this));
		}
	},
	
	resizeOverlay: function() {
		if($('overlay').style.visibility == "visible") {
			var scroll = document.getScrollSize();
			$('overlay').style.height = scroll.y + "px";
			$('overlay').style.width = scroll.x + "px";
		}
	}
});
