/* 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() {  

        //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');
		
		//transition effect for mask       
        $('#mask').fadeIn(800, function() {
	        //transition effect of popup window  
	        $('#pop-load').fadeIn(800);
		});      

		//Get the window height and width  
        var winH = $(window).height();  
        var winW = $(window).width();  
                
        //Set the popup window to center  
        $('#pop-load').css('top',  winH/2-$(id).height()/2);  
        $('#pop-load').css('left', winW/2-$(id).width()/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(800);
		});
   });       

	//if close-fp button is clicked  
    $('.close-video-btn').click(function() {  

		//Get the id from the name tag  
        var id = $(this).attr('name');
		
		//Safely removes the flowplayer  
		$('a.myPlayer:visible').flowplayer(0).unload();

		//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(800);
		});
   });       

});
