/* Based on plugin from http://www.queness.com/post/77/simple-jquery-modal-window-tutorial */

$(document).ready(function() {    

	$('#mask').css({opacity:'0.75'});
	
	//select all the tag with class pop-btn  
		$('.pop_btn').click(function(e) {  
			e.preventDefault();
	
			//Get the id from the name tag  
			var id = $(this).attr('rel');
	
			//detach the id content from #pop-hide and put it in #pop-load  
			$(id).detach().appendTo('#pop_load');

			//find the youtube videos and refresh the source 
			//*fixes the continuing ie streaming bug when the window closes 
			$(id).find('iframe').attr('title','YouTube video player').each( function (){
				var ytsrc = $(this).attr('src');
				$(this).attr('src', function(){
					$(this).attr('src', ytsrc);
				});
		    });
			
			//transition effect for mask       
			$('#mask').fadeIn(1000, function() {
				//transition effect of popup window  
				$('#pop_load').fadeIn(1500);
		});      

		//Get the window height and width  
        var winH = $(window).height();  
        var winW = $(window).width();  
        var idH = $(id).outerHeight(true);  
        var idW = $(id).outerWidth(true);  
        var ploadT = (winH-idH)/2  
        var ploadL = (winW-idW)/2  
                
        //Set the popup window to center  
        $('#pop_load').css('top',  ploadT);  
        $('#pop_load').css('left', ploadL);  

	});  
      
    //if close button is clicked  
    $('.close_btn').click(function() {  

		//Get the id from the name tag  
        var id = $(this).attr('rel');

		//transition effect of popup window  
        $('#pop_load').fadeOut(1500, function() {
			//detach the id content from #pop-load and put it back in #pop-hide   
			$(id).detach().appendTo('#pop_hide');
			//transition effect of popup window  
	        $('#mask').fadeOut(1000);

		});

   });       
});
