// JavaScript Document
$(document).ready(function() {	
	$('a[name=modal]').click(function(e) {
		$('body').append("<div id='mask'></div>");
		$('.boxes').appendTo('body');
		e.preventDefault();
		
		var id = $(this).attr('href');
	
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
		
		var offset = parseInt($(document).scrollTop());
		
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		$('#mask').fadeIn(200);
		$('#mask').fadeTo("fast",0.8);	
		
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
		
		$(id).css('top',parseInt(winH/2-$(id).height()/2+offset)+'px');
		$(id).css('left', parseInt(winW/2-$(id).width()/2)+'px');
		$(id).fadeIn(200); 
	});
	
	$('.window .close').click(function (e) {
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	
});