$(document).ready(function()
{		
	$('a[name=modal]').click(function(e)	//select all the a tag with name equal to modal
	{
		e.preventDefault();	//Cancel the link behavior
		
		var id = $(this).attr('href');	//Get the A tag
		// alert(id);
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		$('#mask').css({'width':maskWidth,'height':maskHeight});	//Set heigth and width to mask to fill up the whole screen
		
		//transition effect		
		// $('#mask').fadeIn(1000);	
		// $('#mask').fadeTo("slow",0.8);	
		
		// Get the window scrolled amounts
		var scroll_arr = getScrollXY();
		var scrollH = parseInt(scroll_arr[1]);
		var scrollW = parseInt(scroll_arr[0]);

		// alert('scrollH: '+scrollH+', scrollW: '+scrollW);
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
		
		// alert('winH: '+winH+', winW: '+winW);

		// Get the div height and width
		var divH = $(id).height();
		var divW = $(id).width();
		
		// Get the Top and Left offsets
		var offset_top = (winH-divH)/2 + scrollH;
		var offset_left = (winW-divW)/2 + scrollW;

		// alert('offset_top: '+offset_top+', offset_left: '+offset_left);
		
		//Set the popup window to center
		$(id).css('top', offset_top);
		$(id).css('left', offset_left);
	
		$(id).fadeIn(2000);	//transition effect
	}); // * /
	
	// $('.window .close').click(function (e)	//if close button is clicked
	$('b[name=modalclose]').click(function(e)	//select all the a tag with name equal to modal
	{
		e.preventDefault();	//Cancel the link behavior
		
		$('#mask').hide();
		$('.window').hide();
	});		

	$('a[name=modalclose]').click(function(e)	//select all the a tag with name equal to modal
	{
		e.preventDefault();	//Cancel the link behavior
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	$('#mask').click(function ()	//if mask is clicked
	{
		$(this).hide();
		$('.window').hide();
	});
}); // */

function CloseDialog()
{
	$('#mask').hide();
	$('.window').hide();
}

function getScrollXY() 
{
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) //Netscape compliant
	{
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} 
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) //DOM compliant
	{
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} 
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) //IE6 standards compliant mode
	{
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	
	return [ scrOfX, scrOfY ];
}
