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

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

function setupLinks() {
  $j('#linkHolder ul 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 = '#content-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(300);      
    $j('#mask').fadeTo("fast",0.8);    
 
    //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(500);
  });
}

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');
  });
}

