/*
	Author: mbarry
*/

(function() {
	var highlightImages = $(".highlight_image");
	var html = $('html');
	var win = $(window);
	
	highlightImages.each(function() {
		var highlightImage = $(this);
		highlightImage.data('start_height', highlightImage.height());
		highlightImage.data('start_width', highlightImage.width());
		highlightImage.after("<span class=\"highlight_image_button\"></span>")
	});
	
	win.bind("resize", function() {
		highlightImages.each(function() {
			var highlightImage = $(this);
			var startHeight = highlightImage.data('start_height');
			var startWidth = highlightImage.data('start_width');
			var ratio = startWidth / startHeight;
			var newHeight = html.width() / ratio;
			
			if (newHeight < startHeight) {
				return;
			}
			highlightImage.height(newHeight).width(html.width()).css({
				top: -(newHeight - startHeight) / 2
			});
		});
		
	}).triggerHandler('resize');
	
	// Patient Education Human graphic popups
	$('#wrapper').click(function(event){
		if($('.popout').is(':visible')){
			$('.popout').hide();
		}
	});
	
	$('.anatomy-text').click(function(event){
		event.stopPropagation();
		$('.popout').hide().removeClass('active-popout');
		$('.popout', this).addClass('active-popout').fadeToggle(100);
	});
		
})();
