﻿$(document).ready(function(){
	var window_width = $(window).width();
	var window_height = $(window).height();

	$('.modWindow').each(function(){	
		var modal_height = $(this).outerHeight();
		var modal_width = $(this).outerWidth();
		var top = (window_height-modal_height)/2;
		var left = (window_width-modal_width)/2;
		$(this).css({'top' : top , 'left' : left});		
	});
	
	$('.openModal').click(function(){   
		var modal_id = $(this).attr('name');
		show_modal(modal_id);		  
	});
	
	$('.close_modal').click(function(){		
		close_modal();		
	});
	
	$(document).keypress(function(e){
		if(e.keyCode==27){
			close_modal();
		}
	});
	
	$(".closeModal").click(function(){
		close_modal();
	});		
});
    
//Functions

function close_modal(){
	$('#mask').fadeOut('slow');
	$('.modWindow').fadeOut('slow');
}

function show_modal(modal_id){
	$('#mask').css({ 'display' : 'block', opacity : 0});
	$('#mask').fadeTo('slow',0.5);
	$('#'+modal_id).fadeIn('slow');
	
}
