	
	var subactive = true;
	
	window.addEvent('domready', function() {
				

	    /* Agentur */
	    
	    $('jovanovic_info').setOpacity(0);
	    //$('jovanovic_info').show();
	    
	    var fx_fade = new Fx.Tween( $('jovanovic_info'), {
	    	
	    	property: 	'opacity',
	    	duration:	1000
	    		
	    });
	    	
	    $('jovanovic_info').store('fx', fx_fade);	    
	    
	    $('jovanovic_info').addEvent('mouseleave', function(event) {
	    
	    	var fx = $('jovanovic_info').retrieve('fx');
	    	fx.cancel();
	    	fx.start(0);		
	    });
	    
	    $('jovanovic').addEvent('click', function(event){
	    	
	    	$('jovanovic_info').show();
	    	event.preventDefault();
	    	
	    	var fx = $('jovanovic_info').retrieve('fx');
	    	fx.cancel();
	    	fx.start(1);	
	    });
	    
	    
	    /* Home */
	    if ($("date")) {
	    
	    	var currentTime = new Date()
			var day = currentTime.getDate()
			var month = currentTime.getMonth() + 1;
			var year = currentTime.getFullYear()
			
			$("date").set("html", day + " " + month + " " + year);
	    }
	    
	    
	    /* Gallerie */
	    
	    
	    // SLIDER 
	    
	    if ($('gallery')) {
	    
	    	//slider variables for making things easier below
			var myItems = $('gallery').getElements('.page');
			
			//controls for slider
			//var theControls = $('subPage');
			var thePrevBtn = $('previous');
			var theNextBtn = $('next');
			
			//create instance of the slider, and start it up		
			var mySlider = new Slider({
			    animateOnInit:	false,
			    loopSlides:		false,
			    slideTimer: 	10000,
			    transitionTime:	1000,
			    orientation: 	'horizontal',      //vertical, horizontal, or none: None will create a fading in/out transition.
			    fade: 			false,             //if true will fade the outgoing slide - only used if orientation is != None
			    isPaused: 		true,
			    container: 		$('gallery_pictures'),
			    items: 			myItems,
			    numNavActive: 	false,
			    //numNavHolder:	$('nav'),
			    prevBtn: 		thePrevBtn,
			    nextBtn: 		theNextBtn
			});
			
			mySlider.start();	
		}
		
		// FULLSCREEN
		
		if($('gallery')) {
		
			$('gallery').getElements('a.bigpicture').addEvent('click',
			
				function(event) {
		
					event.preventDefault();
					event.stopPropagation();
					
					var pos = 0;

					if (event.target.get('tag') != 'a') event.target = event.target.getParent('a');							
					pos = event.target.get('pos');
					
					var gallery = new Gallery(pos);
				}
			);
		
		}
		
		/* Kontaktformular */
		
		if ($('contactform')) {
		
			$('email').addEvents({
			
				'click': function(event) { if(event.target.get('value') == 'E-Mail Adresse') event.target.set('value', '');	},
				'blur': function(event)  { if(event.target.get('value') == '') event.target.set('value', 'E-Mail Adresse');	}
			});
			
			$('subject').addEvents({
			
				'click': function(event) { if(event.target.get('value') == 'Betreff') event.target.set('value', ''); },
				'blur': function(event) { if(event.target.get('value') == '') event.target.set('value', 'Betreff'); }
			});
		}
	});	
	
	
var Gallery = new Class({

	container:		null,
	bg:				null,
	
	btn_next:		null,
	btn_prev:		null,
	btn_close:		null,
	pictures:		null,
	
	buttonsEnabled:	true,
	
	current_index: 	0,
	first_index:	null,
	
	current_picture:null,
	latest_picture: null,
	
	picture_active:	null,
	picture_buffer:	null,
	
	loading:		false,
	c_load:			null,
	load_Animation:	null,

	initialize: function(selected) {
	
		this.pictures = new Array();

		this.bg = new Element('div', {
		
			'styles': {
			
				'z-index':	50,
			
				position:	'absolute',
				top:		0,
				bottom:		0,
				left:		0,
				right:		0,
				background:	'black'
			},
			'opacity':		0.95
		
		}).inject(document.body, 'top');
		
		this.container = new Element('div', {
			'id':	'picture_gallery',
			'html':	'<div id="first"><table cellpadding="0" cellspacing="0"><tbody><tr><td id="picture_active"></td></tr></tbody></table></div><div id="second"><table cellpadding="0" cellspacing="0"><tbody><tr><td id="picture_buffer"></td></tr></tbody></table></div>'
			
		}).inject(document.body, 'top');
		
		this.c_load = new Element('div', {
			'id':		'loadAnimation',
			'opacity':	0.7
		
		}).inject(document.body, 'top');
		
		this.loadAnimation = new Dotter( 'loadAnimation', {
				
		    message:	'',
		    property: 	'html',
		    dot: 		'<span class="dot">&nbsp;</span>',
		    periodical: 100,
		    numDots: 	10,

		    onStart: 	function() { this.container.setStyle('visibility','visible'); },
		    onStop: 	function() { this.container.setStyle('visibility','hidden'); }
		});
		
		this.setLoading(true);
		
		this.picture_buffer = $('picture_buffer');
		this.picture_active = $('picture_active');
		
		
		// Next-Button
		this.btn_next = new Element('div', {
		
			'id':	'next_button',
			'class':'button',
			'html': '<div><div class="navbutton"><span>NÄCHSTES &gt;</span></div></div>',
			'events': {
			
				'click': function(event) {
				
					this.show_next();
				
				}.bind(this)
			}
		
		}).inject(document.body, 'top');
		
		// Previous-Button
		this.btn_prev = new Element('div', {
		
			'id':	'previous_button',
			'class':'button',
			'html': '<div><div class="navbutton"><span>&lt; ZURÜCK</span></div></div>',
			'events': {
			
				'click': function(event) {
				
					this.show_previous();
				
				}.bind(this)
			}
		
		}).inject(document.body, 'top');
		
		
		// Close
		this.btn_close = new Element('div', {
		
			'id':	'close_button',
			'class':'button',
			'html':	'<a><span>&nbsp;</span></a>',
			
			'events': {
			
				'click': function(event) {
				
					this.bg.destroy();
					this.container.destroy();
					this.btn_next.destroy();
					this.btn_prev.destroy();
					this.btn_close.destroy();
				
				}.bind(this)
			}
		
		}).inject(document.body, 'top');
	
	
		// Alle Bilder einlesen
		$('gallery').getElements('a.bigpicture').each(function(link) {
		
			var pos = link.get('pos');
		
			if (this.first_index == null) this.first_index = pos;
			else if (this.first_index > pos) {

				this.first_index = pos;								
			}
		
			this.pictures[pos] = link.get('href');
			
		}, this);
		
		
		// Erstes Bild laden
		this.current_index = parseInt(selected);
		
		if (selected>=this.pictures.length-1) this.btn_next.hide();
		if (selected<=this.first_index) this.btn_prev.hide();
		
		new Asset.images( [this.pictures[selected]], { onComplete: function(event) {
		
				this.current_picture = new Element('img', { src: this.pictures[this.current_index] });
				this.current_picture.inject(this.picture_active);
				this.setLoading(false);
				
			}.bind(this)
		});
		
		this.buttonsEnabled = true;
	},
	
	show_next: function() {
	
		if(this.loading || (this.buttonsEnabled == false)) return;
		
		this.setLoading(true);
	
		this.btn_prev.show();
	
		this.current_index++;
		found = false;
		while ( ! found) {
		
			if (this.pictures[this.current_index]) found = true;
			else this.current_index++;
		}
		
		this.load_picture(this.current_index);
		
		if(this.current_index >= this.pictures.length-1) this.btn_next.hide();
	},
	
	show_previous: function() {
	
		if(this.loading || (this.buttonsEnabled == false)) return;
		
		this.setLoading(true);
	
		this.btn_next.show();
		this.current_index --;
		
		if(this.current_index <= this.first_index) this.btn_prev.hide();
		
		this.load_picture(this.current_index);
	},
	
	load_picture: function(index) {

		new Asset.images( [this.pictures[index]], { onComplete: function(event) {
				this.latest_picture = new Element('img', { src: this.pictures[index] });
				this.show_picture();
			}.bind(this)
		});
	},
	
	setLoading: function( loading, animate ) {
	
	    if( loading ) {
	    
	    	this.buttonsEnabled = false;
	    	
	    	this.loading = true;
	    	this.c_load.show();
	    	this.loadAnimation.start();		
	    	
	    } else {
	    
	    	this.loading = false;
	    	this.c_load.hide();
	    	this.loadAnimation.stop();	
	    }
	},
	
	show_picture: function() {
	
		this.latest_picture.setOpacity(0);
		this.latest_picture.inject(this.picture_buffer);
		
    	this.setLoading(false);
		
		var fadeout = new Fx.Tween(this.current_picture, {
		
		    'duration': 	1000,
		    
		    onComplete: function() {
		    
		    	// Altes Element entfernen
		    	this.current_picture.destroy();
		    	this.current_picture = this.latest_picture;
		    	this.picture_active.grab(this.latest_picture);

		    }.bind(this)
		    
		}).start('opacity', '1.0', '0.0');
		
		var fadein = new Fx.Tween(this.latest_picture, {
		
		    'duration': 	1000,
		    
		    onComplete: function() {
		    
			    this.buttonsEnabled = true;
		    	
		    }.bind(this)
		    
		}).start('opacity', '0.0', '1.0');	
	}
});
