$j(document).ready( function() {
  setupLinks();
  setupDialog();
});

// Setup links
function setupLinks() {
  $j('#meet-the-team-block a.window_link, .friend_component li a').click( function(e) {
    // prevent default link action
    e.preventDefault();

    // Hide the scrollbars
    $j('body').css('overflow', 'hidden');

    // clear the dialog content
    $j('#dialog-content').empty();
    // start loading the new content
    loadPage( $j(this).attr('href') );
    // open the new dialog
    var id = '#team-member-dialog';  

    //Get the screen height and width  
    var maskHeight = $j(document).height();  
    var maskWidth = $j(window).width();  

    //Set height and width to mask to fill up the whole screen  
    $j('#mask').css({'width':maskWidth,'height':maskHeight,'top':0,'left':0});  

    //transition effect       
    $j('#mask').fadeIn(500);      
    $j('#mask').fadeTo("slow",0.7);    
    
    //Get the window height and width  
    var winH = $j(window).height();  
    var winW = $j(window).width();

    //Set the popup window to center  
    $j(id).css('top', parseInt((winH/2-$j(id).height()/2) + $j(document).scrollTop()) );
    $j(id).css('left', winW/2-$j(id).width()/2);  

    //transition effect  
    $j(id).fadeIn(1000);
  });
}

// Setup Dialog
function setupDialog() {
  //if close button is clicked  
  $j('.window .close').click( function (e) {  
    //Cancel the link behavior  
    e.preventDefault();  
    $j('#mask, .window').hide();
    $j('body').css('overflow', 'auto');
  });       
  //if mask is clicked  
  $j('#mask').click( function () {  
    $j(this).hide();  
    $j('.window').hide();
    $j('body').css('overflow', 'auto');
  });
}

// Load a new page and place it in the dialog
function loadPage( page ) {
  $j('#dialog-content').load( page + ' #location_0 > *', function() { $j('#location_0');});
}
