var $j=jQuery.noConflict();

$j(document).ready(function() {	

	//select all the a tag with name equal to modal
	$j('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		
		//Get the A tag
		var id = $j(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = $j(document).height();
		var maskWidth = $j(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$j('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$j('#mask').fadeIn(100);	
		$j('#mask').fadeTo("slow",0.8);
		
	
		//Get the window height and width
		var winH = $j(window).height();
		var winW = $j(window).width();
              
		//Set the popup window to center
		$j(id).css('top',  winH/2-$j(id).height()/2);
		$j(id).css('left', winW/2-$j(id).width()/2);
	
		//transition effect
		$j(id).fadeIn(300); 
	
	});
	
	//if close button is clicked
	$j('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$j('#mask').hide();
		$j('.window').hide();
	});		
	
	$j('.close_modal').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$j('#mask').hide();
		$j('.window').hide();
	});	
	
	//if mask is clicked
	$j('#mask').click(function () {
		$j(this).hide();
		$j('.window').hide();
	});	
	
	
});


