jQuery(document).ready(function(){
	Cufon.replace('h2')('h3',{fontSize:'19px'})('h4',{fontSize:'19px'})('h5',{fontSize:'17px'})('.adress');
	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;
			}
		}
	});
	
	jQuery('a.escape').noSpam();
	
	jQuery('.gototop').topLink({fadeSpeed: 500});
	jQuery('a[rel=lightbox]').colorbox({maxHeight:'90%'});
	
	jQuery('.branding').fadeTo(500, 1.0);
	jQuery('.branding').hover(function(){
		jQuery(this).stop(true, true);
		jQuery(this).fadeTo(600, 0.6);
	},function(){
		jQuery(this).fadeTo(900, 1.0); 
	});
});

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);
		});
};
