// JavaScript Document

var active_image = 2;
var active_image_old = 2;

$(document).ready(function() {		
	//Menüpunktanimation-----------------------------------------------------------------------------------------------
	$("#menu > ul > li > a[id!='aktiv']").mouseover(function() {
		$(this).stop();
		$(this).animate({
			backgroundPosition: '0px -40px'
		},150 );
	});
	
	$("#menu > ul > li > a[id!='aktiv']").mouseout(function() {
		$(this).stop();
		$(this).animate({
			backgroundPosition: '0px 0px'
		},150 );
	});
	
	//Coverflow--------------------------------------------------------------------------------------------------------	
	if($('#coverflow').length > 0){
		$('#content').addClass('short');
		$('#coverflow').css('display','block');
		var imgcount = 0;
		$('#gallery').children().each(function(i) {
    		imgcount++;
			$(this).addClass('imgnr'+i);
		});
		breite = ((imgcount - 1) * 210) + 283;
		$('#coverflow .images').css('width',breite);		
		
		galleryscroll = function(os){
			$('.imgnr'+active_image_old+' > img').animate({
				width: 180,
				height: 135,
				marginTop: 27
			}, {
				complete: function() {
				    $(this).removeClass('active');
			    }
			});
			
			$('.imgnr'+active_image+' > img').animate({
				width: 253,
				height: 190,
				marginTop: 0
			}, {
				complete: function() {
				    $(this).addClass('active');					
			    }
			});
			
			$('.imagecontainer').scrollTo( '.imgnr'+active_image, 500, {offset: {left: os, top: 0}})
			
			if(active_image < 1){
				$('.toggleleft a').fadeOut();
			} else {
				$('.toggleleft a').fadeIn();
			}
			if(active_image == (imgcount - 1)){
				$('.toggleright a').fadeOut();
			} else {
				$('.toggleright a').fadeIn();
			}
		}
		
		//Klick auf Bilder zu Gunsten der Fancybox deaktiviert
		/*$('#gallery').children().each(function(i) {
    		$(this).click(function() {
				if(active_image_old != active_image){
					active_image_old = active_image;
					active_image = Number($(this).attr('class').substr(5,1));
					if(active_image_old < active_image){
						galleryscroll(-312);
					} else {
						galleryscroll(-238);
					}
				}
			});
		});*/
		
		$('#gallery img').each(function(){
			$(this).fancybox({
				href: $(this).attr('src')
			});
		});
		
		$('.toggleleft').click(function() {
			if(active_image > 0){
				active_image_old = active_image;
				active_image -= 1;
				galleryscroll(-238);
			}
		});	
		
		$('.toggleright').click(function() {
			if(active_image < imgcount){
				active_image_old = active_image;
				active_image += 1;
				galleryscroll(-312);
			}
		});
	}
	
	var who;
	//Teamdarstellung--------------------------------------------------------------------------------------------------------
	if($('.teammembers').length > 0){
		$('.teammember').each(function(){
			$(this).css('cursor','pointer');
			$(this).click(function(){
				$('.teammembers').slideUp('fast');
				who = $(this).attr('rel');
				$("#"+who).slideDown('slow');
			});
		});
		
		showmembers = function(){
			$('.teammembers').delay(250).slideDown('slow', function(){
				whoto = $('.teammember[rel='+who+']');
				$(window).scrollTo(whoto,200);
			});
		}
		
		$('.teammember_detail > a.backlink').each(function(){
			$(this).click(function(){
				$(this).parent('.teammember_detail').fadeOut('fast', showmembers());				
			});
		});
	}
	
	//Kursplan Spielereien--------------------------------------------------------------------------------------------------
	if($('.kursplan').length > 0){
		$('.kurs').mouseenter(function() {
			if(!$(this).hasClass('leer')){
				$('.kurs').stop();
				$(this).css('opacity','1').addClass('nofadeout');	
				$('.kurs').each(function(){
					if(!$(this).hasClass('nofadeout')){
						$(this).animate({
							opacity: 0.5,
						}, 200 );
					}
				})		
			}
		});
		
		$('.kurs').mouseleave(function() {
			$('.kurs').stop();
			$(this).removeClass('nofadeout');	
			$('.kurs').animate({
				opacity: 1,
			}, 200 );
		});	
		
		$('.kurs').each(function(){
			if($(this).attr('rel') != ''){
				$(this).tinyTips('light', $(this).attr('rel'));
			}
		})
	}
	
	//Fancyvideo------------------------------------------------------------------------------------------------------------
	$("a[rel=fancyvideo]").click(function(){
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 640,
			'height'		: 385,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {'wmode' : 'transparent', 'allowfullscreen' : 'true'}
		});
		return false;
	});
});	

$(window).load(function() {
	if($('#coverflow').length > 0){
		galleryscroll(-238);
	}
});
