$(document).ready(function(){

	// fancybox
	$('a[href$=.jpg],a[href$=.png],a[href$=.gif]').fancybox({
		'titleShow' : true,
		'titlePosition' : 'over',
		'centerOnScroll' : true,
		'padding' :	5,
		'overlayColor' :'#F1F1ED'
	}); 
	
	$('a.iframe').fancybox({
		'titleShow' : false,
		'width' : '80%',
		'height' : '80%',
		'padding' :	5,
		'overlayColor' :'#F1F1ED'
	});
	
	$(".newsletter").fancybox({
		'type' : 'iframe',
		'width' : '72%',
		'height' : '70%'
	}); 
	
	$("a#inline").fancybox({
		'hideOnContentClick': false
	});
	
	
	// shows the tooltip layer and displays the title attribute
	$('[rel="tooltip"], .tooltip').tipsy({
		live: true,
		gravity: 's'
	});	
		
	// open links with rel=external in a new window
	$('a[class*=external]').click( function() {
		window.open(this.href);
		return false;
	});
	
	// smooth scrolling
	$("a.smoothscroll").click(function() {
		var elementClicked = $(this).attr("href");
		var destination = $(elementClicked).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 1000 );
		return false;
	});
	
	
	// öffnet alle Links vom Typ PDF in einem neuen Fenster
	$('a[href$=pdf]')
	  .attr({ target: '_blank' });
		
	
	// der inline-gallery die klasse .clearfix übergeben
	$('.gallery').addClass('clearfix');
	
	
	// allen Links der inline-gallery ein class="thickbox" und rel="currentStream" hinzufuegen
	$('.gallery-icon a').attr('class','fancybox');
	$('.gallery-icon a').attr('rel','currentStream');
	
	
	// liest den title von Inputfeldern aus und setzt ihn dynamisch als value
	function switchText()
	{
		if ($(this).val() == $(this).attr('title'))
			$(this).val('').removeClass('exampleText');
		else if ($.trim($(this).val()) == '')
			$(this).addClass('exampleText').val($(this).attr('title'));
	}
	
	$('input[type=text][title!=""]').each(function() {
		if ($.trim($(this).val()) == '') $(this).val($(this).attr('title'));
		if ($(this).val() == $(this).attr('title')) $(this).addClass('exampleText');
	}).focus(switchText).blur(switchText);
	
	$('form').submit(function() {
		$(this).find('input[type=text][title!=""]').each(function() {
			if ($(this).val() == $(this).attr('title')) $(this).val('');
		});
	});
	
	// adds table classes
	$('.profile tr td:nth-child(1)').addClass('firstTd');
	$('.data tr td:nth-child(2)').addClass('secondTd');
	
	
	// Internet Explorer: insert an image to the external links
	if ($.browser.msie) {
		$('a.external').before(' <img src="/lib/framework/icon_external.png" alt="external link"/>');
	}


});









