$(function(){

$('#Overlay').css('opacity', 0.5);
$('#Overlay').height($(document).height());	
	
$('.ManagementTeam li').each(function(index){
	$(this).find('a').click(function(){
		$('#Overlay').fadeIn();							
		$('#DialogueBox').fadeIn();
		$('#DialogueContent').addClass('Profile');
		$('#DialogueContent').html($('.ManagementTeam .Profile').eq(index).html());
		return false;
	})
})

$('#DialogueBox').find('.CloseButton').click(function(){												   
		$('#Overlay').fadeOut();
		$('#DialogueBox').fadeOut();
		$("#DialogueBox").removeAttr("style");
})

$('#Overlay').click(function(){												   
		$('#Overlay').fadeOut();
		$('#DialogueBox').fadeOut();
		$("#DialogueBox").removeAttr("style");
})



$('.Awards a').each(function(index){
	$(this).click(function(){
		$('#Overlay').fadeIn();							
		$('#DialogueBox').fadeIn();
		$('#DialogueContent').addClass('Details');
		$('#DialogueContent').html($('.Awards .Details').eq(index).html());
		return false;
	})
})

$('#photos a').each(function(index){
	$(this).click(function(){
		var loadImage = new Image();
			loadImage.src = $(this).attr('href');
			var newImage = '';
				newImage = "<img src='"+ $(this).attr('href') +"' alt='' style='border:4px solid #000;' />";
			$('#DialogueContent').html(newImage);
			
			loadImage.onload  = function(){	
			
			$('#Loader').fadeOut();
			
				var imageWidth = loadImage.width;
				var imageLeftmargin = -loadImage.width/2;
		
				if(imageWidth === 0){
					$('#DialogueBox').css({ 'text-align' : 'center' });
				}else {			
					$('#DialogueBox').css({
						'text-align' : 'center',
						'width' : imageWidth,
						'margin-left' : imageLeftmargin
					});
				}
				
				if(loadImage.height > 600){
					$('#DialogueBox').css({ 'top' : '24px' });
				}
									
				$('#DialogueBox').fadeIn();
			}
			$('#Overlay').fadeIn();
			$('#Loader').fadeIn();
			
		return false;
	})
})

$('#suckerfishnav').find('>li:last').addClass('ContactNav');

})
