 $(document).ready(function(){
    
    //get the height and width of the page
    var window_width = $(window).width();
    var window_height = $(window).height();
    
    //vertical and horizontal centering of modal window(s)
    /*we will use each function so if we have more then 1 
    modal window we center them all*/
    $('.popup_window').each(function(){
        
        //get the height and width of the modal
        var popup_height = $(this).outerHeight();
        var popup_width = $(this).outerWidth();
        
        //calculate top and left offset needed for centering
        var top = (window_height-popup_height)/2;
        var left = (window_width-popup_width)/2;
        
        //apply new top and left css values 
        $(this).css({'top' : top , 'left' : left});
        
    });

        
        $('.activate_popup').click(function(){
                
              //get the id of the modal window stored in the name of the activating element       
              var popup_id = $(this).attr('name');
              
              //use the function to show it
              show_popup(popup_id);
              
        });
        
        $('.close_popup').click(function(){
            
            //use the function to close it
            close_popup();
            
        });
        
    });
    
    //THE FUNCTIONS
    
    function close_popup(){
        
        //hide the mask
        $('#mask').fadeOut(500);
        
        //hide modal window(s)
        $('.popup_window').fadeOut(500);
        
    }
    function show_popup(popup_id){
    
        //set display to block and opacity to 0 so we can use fadeTo
        $('#mask').css({ 'display' : 'block', opacity : 0});
        
        //fade in the mask to opacity 0.8 
        $('#mask').fadeTo(500,0.8);
         
         //show the modal window
        $('#'+popup_id).fadeIn(500);
        
    }