$(document).ready(function(){

$('.fancybox').fancybox({
	'titleShow':false
});

/* Accordion *************************************/


	$('.accordion h3').each(function(){
		$(this).siblings().wrapAll('<div></div>');
	});
	$('.accordion:first').before('<div class="theAccordion"></div>');
	$('.accordion').appendTo('.theAccordion');
	if ($('.accordion').hasClass('withPreview')) {
		$('.theAccordion').addClass('withPreview');
	}
	$('.theAccordion h3').unwrap();
	$(".theAccordion").accordion({header: 'h3', autoHeight: false, active: 'h3:first', collapsible: false});



/* Accordion Bildvorschau ************************/
	
	if(!$.browser.msie || ($.browser.msie && $.browser.version > 7)) {
		$('.tab-container').wrapAll('<div id="tabs"></div>');
		$('.tab-container:first').before('<ul class="bildvorschau"></ul>');
		
		var counter = 1;
		$('.tab-container h3').each(function(){
			var tabId = 'tabs-'+counter;
			$(this).parent().attr('id', tabId);
			counter++;
			var name = $(this).text();
			var img = $(this).next().find('.imageWithCaption a').html();	
			var html = '<li class="preview"><a href="#'+tabId+'">'+img+'<p>'+name+'</p></a></li>';
			$('.bildvorschau').append(html);
		});
		
/* 		$('.bildvorschau').append('<div class="clearfix"></div>'); */
		
		var previewIndex = 0;
		$('.bildvorschau img').each(function(){
			var x = previewIndex;
			previewIndex++;
		});
		
		$( "#tabs" ).tabs();
	}


/* Accordion Bildvorschau ************************/
/*

if ($('.theAccordion').hasClass('withPreview')) {
	$('.theAccordion').prepend('<div class="bildvorschau"></div>');
	
	$('.theAccordion h3').each(function(){
		var name = $(this).text();
		var img = $(this).next().find('.imageWithCaption a').html();	
		var html = '<div class="preview">'+img+'<p>'+name+'</p></div>';
		$('.bildvorschau').append(html);
	});
	
	$('.bildvorschau').append('<div class="clearfix"></div>');
	
	var previewIndex = 0;
	$('.bildvorschau img').each(function(){
		var x = previewIndex;
		$(this).click(function(){
			$('.theAccordion').accordion('option', 'active', x);
		});
		previewIndex++;
	});
}

*/
	
/* Navi ******************************************/
	
	$('#mainNavi').find('li').find('.dropdown').hide();
	$('#mainNavi').find('li').hover(function(){
		$(this).find('.dropdown').css('opacity','0').show().animate({
			opacity: 1
		},200);
	},function() {
		$(this).find('.dropdown').animate({
			opacity: 0
		},0, function(){
			$(this).hide()
		});
	});


/* Header *****************************************/

$('#toiSlider').toiSlider();


/* MailForm ***************************************/
$('#mailForm').find('input, textarea, select').focus(function() {
	$(this).attr('style', '');
})


/* Layout fixes ***********************************/
var startBoxHeight = 0;
$('#startBoxen').find('.csc-default').each(function() {
	tmpHeight = $(this).height();
	startBoxHeight = (tmpHeight > startBoxHeight) ? tmpHeight : startBoxHeight;
});
$('#startBoxen').find('.csc-default').css('height', startBoxHeight);
	
var teamBoxHeight = 0;
$('.bildvorschau').find('li').each(function() {
	tmpHeight = $(this).height();
	teamBoxHeight = (tmpHeight > teamBoxHeight) ? tmpHeight : teamBoxHeight;
});
$('.bildvorschau').find('li').css('height', teamBoxHeight);

});
