/* Based on plugin from http://www.queness.com/post/77/simple-jquery-modal-window-tutorial */

$(document).ready(function() {    


	//UN-COMMENT Set to show a popup on initial page load  

	/*	
    //Define the pop-up id  
    var id = $('#pop-1');
		
	//detach the id content from #pop-hide and put it in #pop-load  
    $(id).detach().appendTo('#pop-load');

	//Get the window height and width  
	var winH = $(window).height();  
	var winW = $(window).width();  
			
	//Set the popup window to center and make display
	$('#pop-load').css('top',  winH/2-$(id).height()/2);  
	$('#pop-load').css('left', winW/2-$(id).width()/2);  
	$('#pop-load').css('display', 'block');  

	//Set the mask to display
	$('#mask').css('display', 'block');  
	*/

	//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('name');
	
			//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(600, function() {
				//transition effect of popup window  
				$('#pop-load').fadeIn(800);
		});      

		//Get the window height and width  
        var winH = $(window).height();  
        var winW = $(window).width();
        var popH = $(id).height();  
        var popW = $(id).width();
        //var popPADL = $(id).padding-left();
        //var popPADR = $(id).padding-right();
		
                
        //Set the popup window to center  
        $('#pop-load').css('top',  (winH/2)-(popH/2) );  
        $('#pop-load').css('left', (winW/2)-(popW/2) );  

	});  
      
    //if close button is clicked  
    $('.close-btn').click(function() {  

		//Get the id from the name tag  
        var id = $(this).attr('name');

		//transition effect of popup window  
        $('#pop-load').fadeOut(800, 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(600);

		});

   });       
});
