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(400);	
		$j('#mask').fadeTo("fast",0.6);
		
		//Get the window height and width
		var winW = $j(window).width();
		var winH = $j(window).height();
              
		//Set the popup window to center
		$j(id).css('left', winW/2-$j(id).width()/2);
		$j(id).css('top', winH/2-$j(id).height()/2);

		//transition effect
		$j(id).fadeIn(1000); 
		
		//Hide Flash Objects
		$j('object').css('visibility', 'hidden');
		$j('#youtube_vids').css('visibility', 'hidden');
	
	});
	
	//Center and Scroll Modal
	$j(window).scroll(function(){
	       $j(".window")
	          .stop()
	          .animate({"marginTop": ($j(window).scrollTop()) + "px"}, "slow" );
	});
	
	//if close button is clicked
	$j('.window .close, .window_home .close, #mask').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$j('#mask').hide();
		$j('.window').hide();
		$j('.window_home').hide();
		$j('object').css('visibility', 'visible');
		$j('#youtube_vids').css('visibility', 'visible');
	});
	
});
