// Schalter für Content-Fade
var mouseoncontent = false;
var mouseonlogo = false;
var mouseondata = false;

// Speed für Content-Fade
//var anim_speed = 'fast';
var anim_speed = 600; 
var ieopacity = "0.75";


$(document).ready(function(){

/*	gleiche höhe für content zwei und dreispalter
*****************/

jQuery.fn.equalHeight = function () {
    var height        = 0;
    var maxHeight    = 0;

    // Store the tallest element's height
    this.each(function () {
	//alert(jQuery(this).outerHeight());
        height        = jQuery(this).outerHeight();
        maxHeight    = (height > maxHeight) ? height : maxHeight;
    });

    // Set element's min-height to tallest element's height
    return this.each(function () {
        var t            = jQuery(this);
        var minHeight    = maxHeight - (t.outerHeight() - t.height());
        var property    = jQuery.browser.msie && jQuery.browser.version < 7 ? 'height' : 'min-height';

        t.css(property, minHeight + 'px');
    });
};


jQuery('#content_zweispalter_1, #content_zweispalter_2').equalHeight(); 
jQuery('#content_dreispalter_1, #content_dreispalter_2, #content_dreispalter_3').equalHeight(); 
jQuery('#otab1 div.infoblock1, #otab2 div.infoblock2, #otab3 div.infoblock3').equalHeight();




	/* Slideshow
	***********/
	$('#slidetop').bxSlider({
		mode: 'fade',  
		infiniteLoop: true, 
		captions: false,
		speed: 1000,    
		pause: 3500,    
		auto: true,
		pager: true,
		controls: false
	});
	
	$('#slidetopeinspalter').bxSlider({
		mode: 'fade',  
		infiniteLoop: true, 
		captions: false,
		speed: 1000,    
		pause: 3500,    
		auto: true,
		pager: true,
		controls: false,
		tickerHover: true 		
	});
	
	$('#slidetopzweispalter').bxSlider({
		mode: 'fade',  
		infiniteLoop: true, 
		captions: false,
		speed: 1000,    
		pause: 3500,    
		auto: true,
		pager: true,
		controls: false,
		tickerHover: true 				
	});
	
	$('#slidetopdreispalter').bxSlider({
		mode: 'fade',  
		infiniteLoop: true, 
		captions: false,
		speed: 1000,    
		pause: 3500,    
		auto: true,
		pager: true,
		controls: false,
		tickerHover: true 		
	});	
	
	//alert($('#content .bx-pager a').length);
	if ($('#content .bx-pager a').length<2)
	{
		$('#content .bx-pager a').hide();
	}
    
	/*	Accordion / News
	*******************/
	$('.newsaccordionueberschrift').click(function() {

		$('.newsaccordionueberschrift').removeClass('aktiv');
	 	$('.newsaccordioninhalt').slideUp(300);
   
		if ($(this).next().is(':hidden') == true) {
			$(this).addClass('aktiv');				
			$(this).next().slideDown(300);
		} 
		
	});
	  
	$('.newsaccordionueberschrift').mouseover(function() {
		$(this).addClass('hover');
	}).mouseout(function() {
		$(this).removeClass('hover');										
	});
	$('.newsaccordioninhalt').hide();

	$('.newsaccordionueberschrift.first').click();


	/*	Accordion
	************/
	$('.accordionueberschrift').click(function() {

		$('.accordionueberschrift').removeClass('aktiv');
	 	$('.accordioninhalt').slideUp(300);
   
		if ($(this).next().is(':hidden') == true) {
			$(this).addClass('aktiv');
			$(this).next().slideDown(300);
		} 
	});
	  
	$('.accordionueberschrift').mouseover(function() {
		$(this).addClass('hover');
	}).mouseout(function() {
		$(this).removeClass('hover');										
	});
	$('.accordioninhalt').hide();


	/* Suchfeld */
	$(".sucheingabe").mouseover(function () {
		$(this).animate({ width: 230 }, 300);
		$(".suchfeld").fadeOut(0);
		$(".sucheingabe #rexsearch_form").fadeIn(100);
	});


	/*	Content Fade
	***************/
	$('#header').trigger('mousemove');

	$("#header, #hauptnavigation").mousemove(function(){
		mouseoncontent = true;
		mouseonlogo = true;
	});
	$("#content, #footer").mousemove(function(){
		mouseoncontent = true;
		mouseondata = true;
	});

	$("#header, #hauptnavigation").hover(function(){
		mouseoncontent = true;
		mouseonlogo = true;
	});
	$("#content, #footer").hover(function(){
		mouseoncontent = true;
		mouseondata = true;
	});

	$("#header, #hauptnavigation").mouseenter(function(){
		mouseoncontent = true;
		mouseonlogo = true;
		pageFadeInOut();
	}).mouseleave(function(){
		mouseoncontent = false;
		mouseonlogo = false;
		pageFadeInOut();
	});
	
	$("#content, #footer").mouseenter(function(){
		mouseoncontent = true;
		mouseondata = true;
		pageFadeInOut();
	}).mouseleave(function(){
		mouseoncontent = false;
		mouseondata = false;
		pageFadeInOut();
	});	

	setTimeout(function(){ pageFadeInOut(); }, 7500);

	// Fix für IE7+8
	if ($.browser.msie && $.browser.version < 9.0)
	{
		$("#header, #hauptnavigation, #content, #footer").stop().animate({"opacity": ieopacity}, 10);
	}

}); // ende document ready


/* Content und Logo Fade */
function pageFadeInOut() 
{
	// nur content
	if (pagefade=="2")
	{
		// einblenden
		if (mouseondata == true)
		{
			if ($.browser.msie && $.browser.version < 9.0) 
			{
				$("#refcontainer .refelement").stop().animate({"opacity": ieopacity}, anim_speed, function(){
					$("#refcontainer .refelement").removeClass('reflow');
				});				
				$("#refwrapper ul.subcatnavi").stop().animate({"opacity": ieopacity}, anim_speed, function(){
					$("#refwrapper ul.subcatnavi").removeClass('reflow');
				});					

				$("#map_route").stop().animate({"opacity": "1.0"}, anim_speed, function(){
					$("#map_route").removeClass('reflow');
				});				
				
				$("#slidetop img, .bx-pager, #contenteinspalter").stop().animate({"opacity": "1.0"}, anim_speed);
	
				$("#content, #refcontainer, #footer").stop().animate({"opacity": ieopacity}, anim_speed);
			}
			else 
			{
				$("#content, #refcontainer, #footer").stop().animate({"opacity": "1.0"}, anim_speed);
			}
		}
		// ausblenden
		else
		{
			if ($.browser.msie && $.browser.version < 9.0) 
			{
				$("#refcontainer .refelement").stop().animate({"opacity": "0.1"}, anim_speed, function(){
					$("#refcontainer .refelement").addClass('reflow');
				});				
				$("#refwrapper ul.subcatnavi").stop().animate({"opacity": "0.1"}, anim_speed, function(){
					$("#refwrapper ul.subcatnavi").addClass('reflow');
				});				
								
				$("#map_route").stop().animate({"opacity": "0.1"}, anim_speed, function(){
					$("#map_route").addClass('reflow');
				});

				$("#slidetop img, .bx-pager, #contenteinspalter").stop().animate({"opacity": "0.1"}, anim_speed);
			}			

			$("#content, #footer").stop().animate({"opacity": "0.1"}, anim_speed);
		}
		
	}

	// logo und content
	if (pagefade=="3")
	{
		// einblenden
		if (mouseoncontent == true)
		{
			if ($.browser.msie && $.browser.version < 9.0) 
			{
				if (mouseonlogo == true){
					$("#header, #hauptnavigation").stop().animate({"opacity": ieopacity}, anim_speed);
				}
				
				if (mouseondata == true){
					$("#refcontainer .refelement").stop().animate({"opacity": ieopacity}, anim_speed, function(){
						$("#refcontainer .refelement").removeClass('reflow');
					});				
					$("#refwrapper ul.subcatnavi").stop().animate({"opacity": ieopacity}, anim_speed, function(){
						$("#refwrapper ul.subcatnavi").removeClass('reflow');
					});					

					$("#map_route").stop().animate({"opacity": "1.0"}, anim_speed, function(){
						$("#map_route").removeClass('reflow');
					});		
					$("#otabs, #oldtabs").stop().animate({"opacity": "1.0"}, anim_speed, function(){
						$("#otabs, #oldtabs").removeClass('reflow');
					});						
					
					$("#slidetop img, .bx-pager, #contenteinspalter").stop().animate({"opacity": "1.0"}, anim_speed);
		
					$("#content, #refcontainer, #footer").stop().animate({"opacity": ieopacity}, anim_speed);
				}
			}
			else 
			{
				if (mouseonlogo == true){
					$("#header, #hauptnavigation").stop().animate({"opacity": "1.0"}, anim_speed);
				}
				if (mouseondata == true){
					$("#content, #refcontainer, #footer").stop().animate({"opacity": "1.0"}, anim_speed);
				}
			}		
		}
		// ausblenden
		else
		{
			if ($.browser.msie && $.browser.version < 9.0) 
			{
				$("#refcontainer .refelement").stop().animate({"opacity": "0.1"}, anim_speed, function(){
					$("#refcontainer .refelement").addClass('reflow');
				});				
				$("#refwrapper ul.subcatnavi").stop().animate({"opacity": "0.1"}, anim_speed, function(){
					$("#refwrapper ul.subcatnavi").addClass('reflow');
				});				
								
				$("#map_route").stop().animate({"opacity": "0.1"}, anim_speed, function(){
					$("#map_route").addClass('reflow');
				});
				$("#otabs, #oldtabs").stop().animate({"opacity": "0.1"}, anim_speed, function(){
					$("#otabs, #oldtabs").addClass('reflow');
				});					

				$("#slidetop img, .bx-pager, #contenteinspalter").stop().animate({"opacity": "0.1"}, anim_speed);
			}			

			$("#content, #footer").stop().animate({"opacity": "0.1"}, anim_speed);
			$("#header, #hauptnavigation").stop().animate({"opacity": "0.3"}, anim_speed);
		}
	}
	
	// nur logo 
	if (pagefade=="4")
	{
		// einblenden
		if (mouseonlogo == true)
		{
			if ($.browser.msie && $.browser.version < 9.0) 
			{
				$("#header, #hauptnavigation").stop().animate({"opacity": ieopacity}, anim_speed);
			}
			else
			{
				$("#header, #hauptnavigation").stop().animate({"opacity": "1.0"}, anim_speed);
			}
		}
		// ausblenden
		else
		{
			$("#header, #hauptnavigation").stop().animate({"opacity": "0.3"}, anim_speed);
		}
	}

}




/*	ab hier SuperBGImage
***********************/
function superbgimage_hide(img) {
	
	$('#superbgimageshowinfo').fadeOut(anim_speed);

}

function superbgimage_show(img) {

	if ($('#refinfo div.refinfo' + img).length > 0)
	{
		$('div.bildinfoinhalt').html($('#refinfo div.refinfo' + img ).html());
		$('#superbgimagenav').fadeTo(anim_speed, '0.8');
		$('#superbgimageshowinfo').fadeTo(anim_speed, '0.8');
	}
	
}

$(document).ready(function(){

	// Options for SuperBGImage
	$.fn.superbgimage.options = {
		z_index: -1, // z-index for the container
		transition: 1, // 0-none, 1-fade, 2-slide down, 3-slide left, 4-slide top, 5-slide right, 6-blind horizontal, 7-blind vertical, 90-slide right/left, 91-slide top/down
		randomtransition: 0, // 0-none, 1-use random transition (0-7)
		slideshow: 1, // 0-none, 1-autostart slideshow
		slide_interval: 6000, // interval for the slideshow
		randomimage: 0, // 0-none, 1-random image
		speed: 1000, // animation speed
		onHide: superbgimage_hide,
		onShow: superbgimage_show
	};

	// bei neuen Projekten 
	if ($('#projectfullscreenslideshow').length>0)
	{
		$('#fullscreenslideshow').remove();
		$('#projectfullscreenslideshow').attr('id', 'fullscreenslideshow');
	}
  
	// initialize SuperBGImage
	//$('#fullscreenslideshow').superbgimage().hide();
	$('#fullscreenslideshow').superbgimage();
	if ($('#fullscreenslideshow a').length<2)
	{
		$('#fullscreenslideshow').hide();
	}
	else
	{
		$('#fullscreenslideshow').prepend('<a href="#" class="fullscreenstop">STOP</a>\n');
		$('#fullscreenslideshow').prepend('<a href="#" class="fullscreenstart">START</a>\n');
		$('.fullscreenstart').hide();
		$('.fullscreenstop').click(function() {
			$('#fullscreenslideshow').stopSlideShow();
			$('.fullscreenstop').hide();
			$('.fullscreenstart').show();
			return false;
		});
		$('.fullscreenstart').click(function() {
			$('#fullscreenslideshow').startSlideShow();
			$('#fullscreenslideshow').nextSlide();
			$('.fullscreenstart').hide();
			$('.fullscreenstop').show();
			return false;
		});
	}
	
	// prev slide
	$('a.bgimage-prev').click(function() {
		return $('#fullscreenslideshow').prevSlide();
	});

	// next slide
	$('a.bgimage-next').click(function() {
		return $('#fullscreenslideshow').nextSlide();
	});

	// start slideshow
	$('a.bgimage-start').click(function() {
		$('a.bgimage-start').hide();
		$('a.bgimage-stop').show();
		return $('#fullscreenslideshow').startSlideShow();
	});

	// stop slideshow
	$('a.bgimage-stop').click(function() {
		$('a.bgimage-start').show();
		$('a.bgimage-stop').hide();
		return $('#fullscreenslideshow').stopSlideShow();
	});
	
}); // ende document ready




$(document).ready(function(){

	var saveref = $("#refcontainer .refelement");

/*	Isotope
***************/	
	
	// Isotope initialisieren
	if ($('#refcontainer').length>0)
	{
		var $container = $('#refcontainer');
		var $iduration = 300;
		if ($.browser.msie && $.browser.version < 9.0){
			$iduration = 600;
		}
		$container.isotope({
			itemSelector: '.refelement',
			animationEngine: 'jquery',
			layoutMode : 'masonry',
			animationOptions: {
				duration: $iduration,
				easing: 'linear',
				queue: false
			}		
		});
		
		// filtern
		//alert($.cookie('kategorie'));
		$container.isotope({ filter: $.cookie('kategorie') });
	}
	
	// Hauptnavi, bei klick isotope filtern
	$('ul.subnavi a.refmain').click(function(){
		$('ul.subnavi li').removeClass('aktiv');
		$.cookie('kategorie', $(this).attr('rel'));
		var selector = $(this).attr('rel');
		$container.isotope({ filter: '*' });
		$container.isotope({ filter: selector });
		$(this).blur().parent().parent().addClass('aktiv');
		return false;
	});
	
	// Hauptnavi aktiven Menüpunkt
	//alert($.cookie('kategorie'));
	$('ul.subnavi a.refmain').each(function(){
		if (($(this).attr('rel') == '*') && ($.cookie('kategorie') == null))
		{
			$(this).parent().parent().addClass('aktiv');
		}	
		if ($(this).attr('rel') == $.cookie('kategorie'))
		{
			$(this).parent().parent().addClass('aktiv');
		}
	});

	// Subnavi, bei hover ausgewählte hervorheben
	$('ul.subcatnavi a.refsub').hover(function() {
		saveref.removeClass('refhigh').addClass('reflow2');
		$('#refcontainer '+$(this).attr('rel')).addClass('refhigh');
	},function() {
		saveref.removeClass('refhigh').removeClass('reflow2');
	});
	
	// Subnavi, click unterdrücken
	$('ul.subcatnavi a.refsub').click(function(event) {
		event.preventDefault();
		$(this).blur();
		return false;
	});	
	
	// Tooltip für Thumbnails
	if ($('#refcontainer').length>0)
	{
		tipoffset = 10;
		if ($.browser.msie && $.browser.version < 9.0)
		{
			tipoffset = 0;
		}
		$('#refcontainer a[title]').tipTip({
			maxWidth: "auto", 
			edgeOffset: tipoffset, 
			defaultPosition: "top", 
			fadeIn: 100,
			fadeOut: 0,
			delay: 100
		});
	}	
	
	// Hover-Effekt bei Referenzen, animation bei ie erst ab 9.0
	if ($('#refcontainer').length>0)
	{
		$(".refelement a").hover(function() {
			saveref.removeClass('refhigh').addClass('reflow');
			$(this).parent().addClass('refhigh').css({'z-index' : 999999999});
			if ($.browser.msie && $.browser.version < 9.0)
			{
				$(this).css({'z-index' : 999999999}).find('img').stop().css({'z-index' : 999999999});
			}
			else
			{
				$(this).css({'z-index' : 999999999}).find('img').stop().css({'z-index' : 999999999})
					.animate({
						marginTop: '-7px', 
						marginLeft: '-9px', 
						width: '168px', 
						height: '105px'
					}, 100);
			}
		} , function() {
			if ($.browser.msie && $.browser.version < 9.0)
			{
				$(this).css({'z-index' : '0'}).find('img').stop().css({'z-index' : '0'});
			}
			else
			{
				$(this).css({'z-index' : '0'}).find('img').stop().css({'z-index' : '0'})
					.animate({
						marginTop: '0', 
						marginLeft: '0',
						width: '150px', 
						height: '91px'
					}, 100);
			}
			saveref.removeClass('refhigh').removeClass('reflow').css({'z-index' : 0});
		});	
	}	

	// Tabs für neue Projekte
	$('#otabs').children().css('display', 'none');
	$('#otab1').show();
	//$('.projektnav-tab-new').find('a').click(function(event){
	$('.projektnav-tab-new').find('a').bind("click", function(event){
		event.preventDefault();
		if ($(this).parent().hasClass('aktiv'))
		{
			;
		}
		else 
		{
			$('.projektnav-tab-new').removeClass('aktiv');
			$(this).parent().addClass('aktiv');
			$('#otabs').children().css('display', 'none');
			$($(this).attr('href')).slideDown(anim_speed);
		}	
	});

	// Tabs für alte Projekte
	$('#oldtabs').children().css('display', 'none');
	$('#oldtab1').show();
	$('.projektnav-tab-old').find('a').click(function(event){
		event.preventDefault();
		if ($(this).parent().hasClass('aktiv'))
		{
			;
		}
		else 
		{
			$('.projektnav-tab-old').removeClass('aktiv');
			$(this).parent().addClass('aktiv');
			$('#oldtabs').children().css('display', 'none');
			jQuery('#otab1 div.infoblock1, #otab2 div.infoblock2, #otab3 div.infoblock3').equalHeight();
			$($(this).attr('href')).slideDown(anim_speed);
			jQuery('#otab1 div.infoblock1, #otab2 div.infoblock2, #otab3 div.infoblock3').equalHeight();
		}	
	});
	
}); // ende document ready

