$(document).ready(function() {
	
	Cufon.replace('h1, h2, h3, h4, h5, h6');
	Cufon.replace('#closeup .node-text h2', {
		textShadow: '1px 1px #444'
	});
	
	/* Teasers */
	
	var speed = 500;
	
	var scrollSettings = {
		'axis' : 'y',
		'easing' : 'easeInOutExpo',
		'duration' : (speed / 2)
	}
	
	var setTeaserState = function($elem, state) {
	
		$elem.fadeOut(speed / 3, function() {
			
			if (state) {		
				$(this).removeClass('inactive');
			} else {
				$(this).addClass('inactive');
			}
			
			Cufon.replace('h1, h2, h3, h4, h5, h6');
			Cufon.replace('#teasers .inactive h2');
			Cufon.replace('#closeup .node-text h2', {
				textShadow: '1px 1px #444'
			});
			
			$(this).fadeIn(speed / 3) 
		});
	};
	
	$('#teasers .read-more-link, #teasers .teaser h2 a').click(function() {
		
		/* Make sure Google Analytics sees this */
		pageTracker._trackPageview('/' + $(this).attr('href').substr(1) + '/');
		
		var elemID = '#page-' + $(this).attr('href').substr(1);
		var $article = $(elemID);
		var $teaser = $(this).closest('div.teaser');
				
		$('#articles .article:not(' + elemID + ')').slideUp(speed, function() {
			$article.slideDown(speed, function() {
				
				$('#teasers div.teaser').unbind('click');
				
				$teaser.one('click', function() {
					
					$article.slideUp(speed, function() {
						
						setTeaserState($teaser, true);
						
						$.scrollTo($('#content'), scrollSettings);
					});
					
					return false;
				});
				
				$.scrollTo(($('#closeup').height() - 20), scrollSettings);
			});
		});
		
		setTeaserState($teaser, false);
		$teaser.siblings().removeClass('inactive');
		
		//return false;
	});
	
	/* Go directly to article */
	if (window.location.hash) {
		$('#' + window.location.hash.substr(1) + '-teaser a.read-more-link').click();
		
		
	}
});