// START

var rl;
$(document).ready(function(e) 
{
	rl = new AH();
	rl.init();
});


function AH()
{
	this.init =  function()
	{
		initTitle();
		initImages();
	}
	
	/**********************
	*	TITLE
	**********************/
	
	function initTitle()
	{
		$('article header').each(function() 
		{
			var target = $(this);
			
			var hwidth = $(this).find('h2').width();
			var imgwidth = 0;
			var hx = Math.round((904 - imgwidth - hwidth) / 2) + 'px';
			
			target.css('margin-left', hx);

			if($('a img', target).length > 0)
			{
				$('a img', target).imagesLoaded(function(e) 
				{
					imgwidth = $(this).width(); 
					hx = Math.round((904 - imgwidth - hwidth) / 2) + 'px';
					
					target.css({'margin-left' : hx, 'visibility' : 'visible'});
				});
			}
			else
			{
				target.css({'visibility' : 'visible'});
			}
		});
	}
	

	
	/**********************
	*	IMAGES
	**********************/

	function initImages()
	{
		$('.images img').click(clickImage);
	}
	
	function clickImage()
	{
		$(this).parent().append($(this));
	}
		

}



	/**********************
	*	F A D E I N
	**********************/
	

$(document).ready(function() {
	
	$("body").css("display", "none");

    $("body").fadeIn(300);
    
	$("a.transition").click(function(event){
		event.preventDefault();
		linkLocation = this.href;
		$("body").fadeOut(200, redirectPage);		
	});		
	function redirectPage() {
		window.location = linkLocation;
	}
	
});

