$(document).ready(function() {

	posFooter();

	// Shadowbox initialisieren
	Shadowbox.init({
		counterType: 'skip',
	    onOpen: function() { 
			$('#sb-nav-close').appendTo($('#sb-wrapper-inner'));
			$('#sb-nav-previous').prependTo($('#sb-info-inner'));
			$('#sb-nav-next').appendTo($('#sb-info-inner'));
			$('#sb-nav').remove();
		},
	    onFinish: function() { 
			$('<span>|</span>').insertAfter('#sb-counter a:not(:last)');
		}
	});
	
	// Suchformularaktionen
	$('#suche .text').click(function() {
		if (this.value == this.defaultValue)
		{
			this.value = '';
		}
		else
		{
			this.select();
		}
	});
	$('#suche .text').blur(function() {
		if (this.value == '')
		{
			this.value = this.defaultValue;
		}
	});
	
	// Wenn auf der Suchergebnisseite -> letzten Suchbegriff in das Suchformular eintragen
	if ($('body.suchergebnisse').length!=0)
	{
		var inputText = $('div.suchergebnisse p.header strong').html();
		$('input.keywords').val(inputText);
	}
	
	// Fading bei Seitenwechsel
	$('a:not(a[href="#"], a.galleryLink, #sb-container a, a.extern, a[href^=mailto])').live('click', function(event) {
		event.preventDefault();
		var url = this.href;
		$('#fadeOverlay').css('height', getBrowserHeight()+20);
		$('#fadeOverlay').fadeIn(500);
		var load = setTimeout(function() {
			window.location.href = url;
		}, 300);
	});
	
	$(window).load(function() {
		$('#fadeOverlay').css('height', getBrowserHeight()+20);
		$('#fadeOverlay').show();
		$('#fadeOverlay').fadeOut(500);
	});

	// FF fix to fire load-event even if history.back() is called
	$(window).unload(function() {});
		
	// Zeige/Verstecke Projektdaten und Link bei Mouseenter/Mouseleave Projektbild
	$('.projektPic a.pfeil').mouseenter(function()
	{
		$(this).parent('.projektPic').children('a.text').css('display','none');
		$(this).parent('.projektPic').children('a.text').appendTo($(this).parent('.projektPic'));
		$(this).parent('.projektPic').children('a.text').fadeIn(100);
	});
	$('.projektPic a.text').mouseleave(function()
	{
		$(this).fadeOut(100);
	});

});

// Footer bei Browser-Resize neu positionieren
var timer=0;
$(window).resize(function() {
	clearTimeout(timer)
	timer=setTimeout(function() {
		posFooter();
	},150);
	
});

/* * * * * * *
 *
 * FUNCTIONS
 *
 * * * * * * */
function getBrowserHeight() {
	myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}

// Footer nach unten schieben, wenn der Seiteninhalt die Seite nicht füllt
function posFooter() {
	var hoeheBrowser = getBrowserHeight();
	var hoeheContent = $('#header').outerHeight() + $('#container').outerHeight() + 125;
	var rest = 0;
	if (hoeheContent < hoeheBrowser)
	{
		rest = hoeheBrowser - hoeheContent;
	}
	$('#wrapper').css(
		'height',hoeheContent+rest-125 + "px"
	);
}

// Zeigt das entsprechende Großbild aus dem Teamgruppenfoto
function showPic(cssIdent)
{
	$('#_4 .inhalt .ce_image:not(.'+cssIdent+')').hide(300);
	$('#_2 .inhalt a.text:not(.'+cssIdent+')').hide();
	$('#_4 .inhalt .ce_image.'+cssIdent).show(300);
	$('#_2 .inhalt a.text.'+cssIdent).show();
}
