$(document).ready(function() {

	//select all the a tag with name equal to modal
	$('a[name=modal],ba[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();

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		$(id).css("font-size",(14*winH/1024)+"px")

		//Set heigth and width to mask to fill up the whole screen
//		if($(id).height()+80<maskHeight)
		$('#mask').css({'width':maskWidth,'height':maskHeight});
//		else
//			$('#mask').css({'width':maskWidth,'height':$(id).height()+winH/4});

		//transition effect
		$('#mask').fadeIn(500);
		$('#mask').fadeTo("medium",0.5);


		//if($(id).height()+80<$(window).height())
		//	$(id).css('height',  $(window).height()-140);

		//Set the popup window to center
		if($(id).height()+80<$(window).height())
			$(id).css('top', winH/2-$(id).height()/2-20);
		else
			$(id).css('top', 10);
		$(id).css('left', winW/2-$(id).width()/2);

		//transition effect
		$(id).fadeIn(500);

		$(id).draggable();

	});

	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();

		$('#mask').fadeOut(500);
/*		$('#mask').hide();*/
/*		$('.window').hide();*/
		$('.window').fadeOut(600);
	});

	//if mask is clicked
	$('#mask').click(function () {
		/*$(this).hide();
		$('.window').hide();*/
		$(this).fadeOut(500);
		$('.window').fadeOut(500);
	});

});

