$(document).ready(function() {	

	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set height and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(500);	
		$('#mask').fadeTo("slow",0.5);	
	
		//Get the window height and width
		var scrolledX =0;
		var scrolledY =0;
	
		scrolledX = document.body.scrollLeft || document.documentElement.scrollLeft || self.pageXOffset;
		scrolledY = document.body.scrollTop || document.documentElement.scrollTop || self.pageYOffset;
		
		if(scrolledX==null){scrolledX=0;}
		if(scrolledY==null){scrolledY=0;}
		
		var screenWidth = document.body.clientWidth || document.documentElement.clientWidth || self.innerWidth;
		var screenHeight = document.body.clientHeight || document.documentElement.clientHeight || self.innerHeight;
		

		var left = scrolledX + (screenWidth - $(id).width())/2;
		//var top = (scrolledY+$(id).height() - screenHeight/5);
		var top = $(window).scrollTop() + (($(window).height() - $(id).width())/2);
		

		//Set the popup window to center
    	$(id).css({"position": "absolute","top": top,"left": left});

		//transition effect
		$(id).fadeIn(1000); 
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('#mask, .window').hide();
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			
	
});
