
// Mailmask

jQuery.fn.noSpam = function() {
	at = '@';
	return this.each(function(){
		e = null;
		jQuery(this).find('span').replaceWith(at);
		e = jQuery(this).text();
		jQuery(this).attr('href', 'mailto:' + e);
	});
};


jQuery.fn.topLink = function(settings) {
	settings = jQuery.extend({fadeSpeed: 200}, settings);
	var scroll_timer;
	var displayed = false;
	var $message = jQuery(this);
	var $window = jQuery(window);
	var top = jQuery(document.body).children(0).position().top;
	$window.scroll(function () {
		window.clearTimeout(scroll_timer);
		scroll_timer = window.setTimeout(function () {
			if($window.scrollTop() <= top)
			{
				displayed = false;
				$message.fadeOut(settings.fadeSpeed);
			}
				else if(displayed == false) 
			{
				displayed = true;
				$message.stop(true, true).fadeIn(settings.fadeSpeed).click(function () { $message.fadeOut(settings.fadeSpeed); });
			}
		}, 100);
	});
};

jQuery(document).ready(function(){
	jQuery('a.escape').noSpam();
	jQuery('.gototop').topLink({fadeSpeed: 500});
	jQuery('a[rel=lightbox]').colorbox({maxHeight:'90%'});
	jQuery('a[rel=gbuch]').colorbox({iframe:true, innerWidth:600, innerHeight:450, maxHeight:'90%'});
	jQuery('.branding').fadeTo(500, 1.0); // This sets the opacity of the thumbs to fade down to 30% when the page loads
	jQuery('.branding').hover(function(){
			jQuery(this).stop(true, true).fadeTo(600, 1.0); // This should set the opacity to 100% on hover
		},function(){
		jQuery(this).fadeTo(900, 1.0); // This should set the opacity back to 30% on mouseout
	});
	
	jQuery('a[href*=#]').click(function(){
		if(location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname){
			var $target = jQuery(this.hash);
			$target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');
			if($target.length){
				var targetOffset = $target.offset().top;
				jQuery('html,body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});
});


