$(document).ready(function() {
	//select all the a tag with name equal to modal
	if($('a[name=modal]').click(function(e) {

		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');	
		if(id == "#IE6") var mask=1; else var mask=0;
		
		launchWindow(id,mask);
	}));

	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('#mask, .window').fadeOut(400);
	});		

	//if mask is clicked
	$('#mask').click(function () {
		$(this).fadeOut(400);
		$('.window').fadeOut(400);
	});			
});

function launchWindow(id,mask) {
	
	if(mask == 1) { // Only show if requested
		//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,'opacity':0.5});

		//transition effect		
		$('#mask').fadeIn(300);	
	}
	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();
		  
	//Set the popup window to center
	$(id).css('top',  winH/2-$(id).height()/2-50);
	$(id).css('left', winW/2-$(id).width()/2);

	//transition effect
	$('.close').click();
	$(id).fadeIn(300); 
	//$(window).scrollTop(0);
}

