
window.addEvent('domready', function() {


	//team
	//all elements to hide
	var team_members = $$('#team section figure', '.team_links p');
	
	//all team_links
	var team_links = $$('.team_links h3');
	
	//check if the array is filled up
	if(team_members.length > 0){
	
		//display first person
		team_members[0].fade('in');
		team_members[1].fade('in');
		team_links[0].addClass('active');
		
		$$('h3').addEvent('mouseenter', function() {
	
			team_members.fade('out');
			team_links.removeClass('active');
			this.addClass('active');
			this.getSiblings().fade('in');
			
		});
	}
	
	
	//Gauch Gallery
	//all elements to hide
	var gauch_gallery_images = $$('.gauch_gallery_wrapper');

	
	//check if the array is filled up
	if(gauch_gallery_images.length > 0){

		//display first image
		gauch_gallery_images.fade('out');
		gauch_gallery_images[0].fade('in');
		
		$$('.gauch_gallery li').addEvent('mouseenter', function() {
		
			gauch_gallery_images.fade('out');
			this.getPrevious().fade('in');

		});
	}


	//Gauch Referenzen
	//all elements to hide
	var gauch_referenzen_images = $$('.referenzen #main section figure');
	
	//check if the array is filled up
	if(gauch_referenzen_images.length > 0){

		
		$$('.referenzen #main section').addEvent('mouseenter', function() {
		
			gauch_referenzen_images.fade('out');
			this.getElement('figure').fade('in');
			
		});

		$$('.referenzen #main section').addEvent('mouseleave', function() {
			gauch_referenzen_images.fade('out');
		});
	}


	//Gauch Links
	//all elements to hide
	var gauch_links_images = $$('.links #main section figure');
	
	//check if the array is filled up
	if(gauch_links_images.length > 0){

		//display first image
		//gauch_gallery_images[0].fade('in');
		
		$$('.links section p a').addEvent('mouseenter', function() {
		
			gauch_links_images.fade('out');
			this.getParent('section figure').fade('in');
			
		});

		$$('.links section p a').addEvent('mouseleave', function() {
			gauch_links_images.fade('out');
		});
	}

	//homepage

	var last_tween = null;

	$$('.ig_grid a').addEvent('mouseenter', function() {

		var img = this.getElement('img');
		var img_hover = this.getElement('img.hover');

		img.fade('out');
		img_hover.fade('in');


		// 
		// var height = img.getStyle('height').toInt();
		// img.set({style: 'top: -'+ height / 2 +'px'});

		// if (last_tween)
		// 	last_tween.stop();

		// last_tween = new Fx.Tween(img);
		// last_tween.start('opacity', 0.8).chain(
		// 	function() {
		// 		img.set({style: 'top: -'+ height / 2.0 +'px; opacity: 0.8'});
		// 		this.start('opacity',1);
		// });
	
	});

	$$('.ig_grid a').addEvent('mouseleave', function() {
		// if (last_tween)
		// 	last_tween.stop();

		// var img = this.getElement('img');
		// img.set({style: 'top: 0px;'});

		var img = this.getElement('img');
		var img_hover = this.getElement('img.hover');

		img_hover.fade('out');
		img.fade('in');
		
	});



	// iPad / i Phone

	if (navigator.userAgent.match(/iPad/i) != null
		|| navigator.userAgent.match(/iPhone/i) != null){

		$$('.gauch_gallery_projects li a').addEvent('click', function(e){
			e.preventDefault();
			return false;
		});
	}




});

