 $.fn.centerInClient = function(options) {

    var opt = { forceAbsolute: false,
                container: window,    // selector of element to center in
                completeHandler: null
              };
    $.extend(opt, options);
   
    return this.each(function(i) {
        var el = $(this);
        var jWin = $(opt.container);
        var isWin = opt.container == window;

        // force to the top of document to ENSURE that 
        // document absolute positioning is available
        if (opt.forceAbsolute) {
            if (isWin)
                el.remove().appendTo("body");
            else
                el.remove().appendTo(jWin.get(0));
        }

        // have to make absolute
        el.css("position", "absolute");

        // height is off a bit so fudge it
        var heightFudge = isWin ? 2.0 : 1.8;

        var x = (isWin ? jWin.width() : jWin.outerWidth()) / 2 - el.outerWidth() / 2;
        var y = (isWin ? jWin.height() : jWin.outerHeight()) / heightFudge - el.outerHeight() / 2;

        el.css("left", x + jWin.scrollLeft());
        el.css("top", y + jWin.scrollTop());

        // if specified make callback and pass element
        if (opt.completeHandler)
            opt.completeHandler(this);
    });
}

/*
$(document) .ready(function () {
    var right_page = $('#right-sidebar'). height();
    
    var new_height = right_page + 250;
    
    $('body').css({'min-height' : + right_page});
    
});*/

$(document) .ready(function () {
   
   $("#accordion").accordion({ header: "h3" });
    
});

/*Prevents Right Click Context Menu
$(document) .ready(function () {
   
  $(this).bind("contextmenu", function(e) {
                e.preventDefault();
            });
    
});
*/

$(document) .ready(function () {
    
    $('.reveal_divtools') .click(function () {
	$('div#div_tools').slideDown();
});
});

$(document) .ready(function () {
    
    $('.hide_divtools') .click(function () {
	$('div#div_tools').slideUp();
});
});

$(document) .ready(function () {

    $('#right-sidebar h6') .toggle(function () {
    
    if ($(this).next().is(":hidden") == true) {
    $(this).next().slideDown();
    }
    else {
    $(this).next().slideUp();
    }

    },
    function () {
    
   if ($(this).next().is(":hidden") == true) {
    $(this).next().slideDown();
    }
    else {
    $(this).next().slideUp();
    }

});
});


/* top drawers */
$(document) .ready(function () {
    
    $('#options_menu') .click(function () {

                  $('#caxton_drawer').hide();
                  $('#winchester_drawer').hide();
                   $('#search_drawer').hide();
                   $('#options_drawer').show();
                  $('#top_drawer').slideDown('slow');
                    
                  
                    
    });
});

   $(document) .ready(function () {
              
              $('#options_close a') .click(function () {
                  $('#top_drawer') .slideUp();
                  $('#options_drawer').hide();
                  });
                  });
                  
                  
                  $(document) .ready(function () {
    
    $('#caxton_menu') .click(function () {

                  $('#options_drawer').hide();
                  $('#winchester_drawer').hide();
                   $('#search_drawer').hide();
                  $('#caxton_drawer').show();
                  $('#top_drawer').slideDown();
                
    });
});


              $(document) .ready(function () {
              
              $('#caxton_close a') .click(function () {
                  $('#top_drawer') .slideUp();
                  $('#caxton_drawer').hide();
                  
                  });
                  });
                  
                  $(document) .ready(function () {
    
    $('#winchester_menu ') .click(function () {

                  $('#options_drawer').hide();
                  $('#caxton_drawer').hide();
                   $('#search_drawer').hide();
                  $('#winchester_drawer').show();
                  $('#top_drawer').slideDown();
                
    });
});


              $(document) .ready(function () {
              $('#winchester_close a') .click(function () {
                  $('#top_drawer') .slideUp();
                  $('#winchester_drawer').hide(); 
                  });
                  });
                  
                  $(document) .ready(function () {
                   $('#search_menu') .click(function () {
                  $('#options_drawer').hide();
                  $('#caxton_drawer').hide();
                  $('#winchester_drawer').hide();
                  $('#search_drawer').show();
                  $('#top_drawer').slideDown();        
    });
});


              $(document) .ready(function () {
              $('#search_close a') .click(function () {
                  $('#top_drawer') .slideUp();
                  $('#search_drawer').hide();
                  });
                  });
                  
                    $(document) .ready(function () {
                   $('#search_menu') .click(function () {
                  $('#options_drawer').hide();
                  $('#caxton_drawer').hide();
                  $('#winchester_drawer').hide();
                  $('#search_drawer').show();
                  $('#top_drawer').slideDown();        
    });
});

/* toc note */
$(document) .ready(function () {
    
    $('#toc_note') .click(function () {
    
            
               $('#bubble_contents') .fadeIn('slow');
                  
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
                               
               $("#bubble_contents").centerInClient({ container: window, forceAbsolute: true });
                  
            //   $("#bubble_contents").draggable({ handle: '#xray_contents'});
                  
               //$("#bubble_contents").resizable({ minWidth: '500px' });
                  
               $('#ajax_note').show();
                  
               $('#ajax_note').empty();
               
               var win_toc_note = $(this).attr('note');
               
               $('#ajax_note').html('<span class="popup_title">Textual Note</span><p> ' + win_toc_note + '</p>');
             
               $("#close_bubble a").bind("click", function(){
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
               $('#bubble_contents') .hide();
             });
    
    });
});

/* markup key */
$(document) .ready(function () {
    
    $('#markup_key') .click(function () {
    
            
               $('#bubble_contents') .fadeIn('slow');
                  
               $("#bubble_contents").css({'width' : '60%', 'min-height' : '400px'});
                               
               $("#bubble_contents").centerInClient({ container: window, forceAbsolute: true });
                  
            //   $("#bubble_contents").draggable({ handle: '#xray_contents'});
                  
               //$("#bubble_contents").resizable({ minWidth: '500px' });
                  
               $('#ajax_note').show();
                  
               $('#ajax_note').empty();
               
               var markup_vol = $(this).attr('vol');
               
               $('#ajax_note').html('<span class="popup_title">' + markup_vol + ' - Key to Markup</span><br />');
             
               $("#close_bubble a").bind("click", function(){
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
               $('#bubble_contents') .hide();
             });
    
    });
});

/* markup key */
$(document) .ready(function () {
    
    $('#page_contents') .click(function () {
    
            
               $('#bubble_contents_toc') .fadeIn('slow');
                  
               $("#bubble_contents_toc").css({'width' : '60%', 'min-height' : '400px'});
                               
               $("#bubble_contents_toc").centerInClient({ container: window, forceAbsolute: true });
                  
               $('#ajax_note_toc').show();
                  
               $('#ajax_note_toc').empty();
               
               var contents_vol = $(this).attr('vol');
               
               $('#ajax_note_toc').html('<br /><span class="popup_title">' + contents_vol + ' - Page Contents</span>');
             
               $("#close_bubble_toc a").bind("click", function(){
               $("#bubble_contents_toc").css({'width' : '40%', 'min-height' : '20px'});
               $('#bubble_contents_toc') .hide();
             });
    
    });
});

/* page damage popup */
$(document) .ready(function () {
    
    $('#damage a') .click(function () {
    
            
               $('#bubble_contents') .fadeIn('slow');
                  
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
                               
               $("#bubble_contents").centerInClient({ container: window, forceAbsolute: true });
                  
               $("#bubble_contents").draggable({ handle: '#xray_contents'});
                  
               //$("#bubble_contents").resizable({ minWidth: '500px' });
                  
               $('#ajax_note').show();
                  
               $('#ajax_note').empty();
               
               var type = $(this).attr('type');
               
               if (type == 'hole') {
               $('#ajax_note').html('Physical damage to the page. There is a ' + type + ' on the page.');
               }
               else if (type == 'torn') {
               $('#ajax_note').html('Physical damage to the page. Part of the page is ' + type);
               }
               else if (type == 'missing') {
               $('#ajax_note').html('Physical damage to the page. The whole page is ' + type);
               }
               else {
               $('#ajax_note').empty();
               }
                
               $("#close_bubble a").bind("click", function(){
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
               $('#bubble_contents') .hide();
             });
    
    });
});

/* options switches */

$(document) .ready(function () {

    $('#all_notes a') .toggle(function () {

    $("span.caxton_note") .show();
    $("span.winchester_note") .show();
    $('#all_notes a'). html('Hide All Notes');
    },
    function () {
    
      $("span.caxton_note") .hide();
    $("span.winchester_note") .hide();
    $('#all_notes a'). html('Show All Notes');

});
});

$(document) .ready(function () {

    $('#palaeography_notes a') .toggle(function () {

    //$("span.caxton_note") .show();
    $("span [type='paleography']") .show();
    $('#palaeography_notes a'). html('Hide Palaeography');
    },
    function () {
    
      $("span.caxton_note") .hide();
      $("span.winchester_note") .hide();
   // $("span [type='paleography']") .hide();
    $('#palaeography_notes a'). html('Show Palaeography');

});
});

$(document) .ready(function () {

    $('#correction_notes a') .toggle(function () {

    //$("span.caxton_note") .show();
    $("span [type='correction']") .show();
    $('#correction_notes a'). html('Hide Correction');
    },
    function () {
    
      $("span.caxton_note") .hide();
       $("span.winchester_note") .hide();
    //$("span [type='correction']") .hide();
    $('#correction_notes a'). html('Show Correction');

});
});

$(document) .ready(function () {

    $('#textual_notes a') .toggle(function () {

    //$("span.caxton_note") .show();
    $("span [type='textual']") .show();
    $('#textual_notes a'). html('Hide Textual');
    },
    function () {
    
       $("span.winchester_note") .hide();
      $("span.caxton_note") .hide();
  //  $("span [type='textual']") .hide();
    $('#textual_notes a'). html('Show Textual');

});
});

$(document) .ready(function () {

    $('#others_notes a') .toggle(function () {

    //$("span.caxton_note") .show();
    $("span [type='others']") .show();
    $('#others_notes a'). html('Hide Others');
    },
    function () {
    
       $("span.winchester_note") .hide();
      $("span.caxton_note") .hide();
    //$("span [type='others']") .hide();
    $('#others_notes a'). html('Show Others');

});
});

$(document) .ready(function () {

    $('#ink_notes a') .toggle(function () {

    //$("span.caxton_note") .show();
    $("span [type='ink']") .show();
    $('#ink_notes a'). html('Hide Ink');
    },
    function () {
    
       $("span.winchester_note") .hide();
      $("span.caxton_note") .hide();
    //$("span [type='ink']") .hide();
    $('#ink_notes a'). html('Show Ink');

});
});


/* notes loader */

$(document) .ready(function () {
    
    $('.winchester_note a') .click(function () {
    
            
               $('#bubble_contents') .fadeIn('slow');
                  
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
                               
               $("#bubble_contents").centerInClient({ container: window, forceAbsolute: true });
                  
               $("#bubble_contents").draggable({ handle: '#xray_contents'});
                  
               //$("#bubble_contents").resizable({ minWidth: '500px' });
                  
               $('#ajax_note').show();
                  
               $('#ajax_note').empty();
               
               var win_type = $(this).attr('type');
               var win_text = $(this).next().text();
               
               $('#ajax_note').html('<p><span class="popup_title">Winchester Note</span></p>Type = ' + win_type + '<br />Note = ' + win_text + '<br />');
                
               $("#close_bubble a").bind("click", function(){
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
               $('#bubble_contents') .hide();
             });
             
                     this.blur();
                      return false;
    
    });
});

$(document) .ready(function () {
    
    $('.caxton_note a') .click(function () {
    
            
               $('#bubble_contents') .fadeIn('slow');
                  
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
                               
               $("#bubble_contents").centerInClient({ container: window, forceAbsolute: true });
                  
               $("#bubble_contents").draggable({ handle: '#xray_contents'});
                  
               //$("#bubble_contents").resizable({ minWidth: '500px' });
                  
               $('#ajax_note').show();
                  
               $('#ajax_note').empty();
               
               var cax_type = $(this).attr('resp');
               var cax_text = $(this).next().text();
               
               $('#ajax_note').html('<p><span class="popup_title">Caxton Note</span></p>Type = ' + cax_type + '<br />Note = ' + cax_text +'<br />');
                
               $("#close_bubble a").bind("click", function(){
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
               $('#bubble_contents') .hide();
             });
             
                     this.blur();
                      return false;
    
    });
});


/* corrections */

$(document) .ready(function () {

    $('#reg_corrections a') .toggle(function () {

    //$("span.caxton_note") .show();
    $("#corr .ie_reg") .hide();
    $('#reg_corrections a'). html('Show Reg');
    },
    function () {
    
      //$("span.caxton_note") .hide();
    $("#corr .ie_reg") .show();
    $('#reg_corrections a'). html('Hide Reg');

});
});

$(document) .ready(function () {

    $('#sic_corrections a') .toggle(function () {

    //$("span.caxton_note") .show();
    $("span.sic") .show();
    $('#deletions_highlighter').show();
    $('#sic_corrections a'). html('Hide Sic');
    },
    function () {
    
      //$("span.caxton_note") .hide();
    $("span.sic") .hide();
    $('#deletions_highlighter').hide();
    $('#sic_corrections a'). html('Show Sic');

});
});

$(document) .ready(function () {

$('span.sic'). mouseover(function () {

 $('#bubble_contents') .fadeIn('slow');
                  
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
                               
               $("#bubble_contents").centerInClient({ container: window, forceAbsolute: true });
                  
               $("#bubble_contents").draggable({ handle: '#xray_contents'});
                  
               //$("#bubble_contents").resizable({ minWidth: '500px' });
                  
               $('#ajax_note').show();
                  
               $('#ajax_note').empty();
               
               var sic_rend = $(this).parent().attr('rend');
               var sic_n = $(this).parent().attr('n');
               
               $('#ajax_note').html('<p><span class="popup_title">Scribal Correction</span></p>' + sic_rend + '; ' + sic_n +'<br />');
                
               $("#close_bubble a").bind("click", function(){
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
               $('#bubble_contents') .hide();
             });
             
                     this.blur();
                      return false;

}). mouseout(function () {

});

});

/* deletions */

$(document) .ready(function () {

    $('#all_deletions a') .toggle(function () {
    //$('div #del').show();
    $('span #del').addClass('highlight');
     $('span.ie_deletion').addClass('highlight');
    $('#all_deletions a') .html('Remove Highlights');
    },
    function () {
   // $('div #del').hide();
    $('span #del').removeClass('highlight');
    $('span.ie_deletion').removeClass('highlight');
    $('#all_deletions a') .html('All Deletions');
});
});

$(document) .ready(function () {

    $('#all_additions a') .toggle(function () {
    //$('div #del').show();
    $('div #add').addClass('highlight2');
    $('span.ie_addition').addClass('highlight2');
    $('#all_additions a') .html('Remove Highlights');
    },
    function () {
   // $('div #del').hide();
    $('div #add').removeClass('highlight2');
    $('span.ie_addition').removeClass('highlight2');
    $('#all_additions a') .html('All Additions');
});
});

/* image text options */

$(document) .ready(function () {

    $('span.page_break b') .toggle(function () {
    $(this).next().show();
   // $(this) .html(' hide images ');
    },
    function () {
   // $('div #del').hide();
    $(this).next().hide(); 
   // $('#meta_hide') .html(' - ');
});
});


/* switch to page view - book nav */
$(document) .ready(function () {

    $('#div_switch') .toggle(function () {
 
    $("#previous").hide();
    $("#first").hide();
 
    $('#test_pad').empty();
    
    var intro_div = $('div #winchester_div:first').attr('number');
    
    if (intro_div = 'intro') {
    	$('div #winchester_div:first').hide();
    } else {
    	
    }
    
    var current_div = $('div.winchester_div:visible').attr('number');
    
    $('#test_pad').html('Current Div = ' + current_div);

    $("#div_nav") .slideDown('slow');
 
     $('#winchester_div').next().nextAll().hide();
    $('#div_switch'). html('Switch to Full Text View');
    },
    function () {
    
    $("#div_nav") .slideUp('slow');
    $('div #winchester_div:first').show();
    $('#winchester_div').nextAll().show();
    $('#div_switch'). html('Switch to Div View');

});
});

/* div nav buttons */
/* switch to page view - book nav */
$(document) .ready(function () {

    $('#div_next') .click(function () {
   
   var last_div = $('div #winchester_div:last').attr('number');
   var div_visible = $('div.winchester_div:visible').next().attr('number');
   
   var div_visible2 = $('div.winchester_div:visible');
   
    $('#test_pad').empty();
   
   $('#test_pad').html('Current Div = ' + div_visible);
    
     if (div_visible == last_div) {
    $('#next').hide();
    $('#last').hide();
    $('#previous').show();
    $('#first').show();
    } else {
    $('#next').show();
    $('#last').show();
    $('#previous').show();
    $('#first').show();
    }
    
    $('div.winchester_div:visible').next('#winchester_div').show();
    
    $(div_visible2).hide();
    
});
});

$(document) .ready(function () {

    $('#div_previous') .click(function () {
   
   var first_div = $('div #winchester_div:first').next().attr('number');
   var div_visible_prev = $('div.winchester_div:visible').prev().attr('number');
   
   var div_visible_prev2 = $('div.winchester_div:visible');
   
    $('#test_pad').empty();
   
   $('#test_pad').html('Current Div = ' + div_visible_prev);
    
     if (div_visible_prev == first_div) {
    $('#next').show();
    $('#last').show();
    $('#previous').hide();
    $('#first').hide();
    } else {
    $('#next').show();
    $('#last').show();
    $('#previous').show();
    $('#first').show();
    }
    
    $('div.winchester_div:visible').prev('#winchester_div').show();
    
    $(div_visible_prev2).hide();
    
});
});

/*
$(document) .ready(function () {

 $("div.winchester_div:visible").click(function () {
      $(this).css("background", "yellow");
    });
});
*/


$(document) .ready(function () {
    $('#div_first') .click(function () {
    
	$('#next').show();
    $('#last').show();
    $('#previous').hide();
    $('#first').hide();
    $('#winchester_div').nextAll('#winchester_div').hide();
    $('#winchester_div').show();
     $('#winchester_div').next('#winchester_div').show();
     
      var intro_div = $('div #winchester_div:first').attr('number');
    
    if (intro_div = 'intro') {
    	$('div #winchester_div:first').hide();
    } else {
    	
    }
    
     var div_visible_first = $('div.winchester_div:visible').attr('number');
   
     $('#test_pad').empty();
     
     $('#test_pad').html('Current Div = ' + div_visible_first);
    
});
});

$(document) .ready(function () {

    $('#div_last') .click(function () {
	$('#next').hide();
    $('#last').hide();
    $('#previous').show();
    $('#first').show();
    $('#winchester_div').nextAll('#winchester_div').hide();
    $('#winchester_div').hide();
    $('div #winchester_div:last').show();
    
    
      var last_div = $('div #winchester_div:last').attr('number');
      
    $('#test_pad').empty();
     
     $('#test_pad').html('Current Div = ' + last_div);
     
});
});

/* toggle individual div visibility */

/* toggle individual div visibility */

$(document) .ready(function () {

    $('span.div_title') .click(function () {
    
     if ($(this).nextAll().is(":visible") == true) {
 			 
        $(this).nextAll().hide();
 	 }
 	 else {
 	 	 	$(this).nextAll().show();
        $('span.milestone_title').hide();
 	 }
    
    });
    });


/* toggle all div visibility */
$(document) .ready(function () {

    $('#div_collapseall') .toggle(function () {
 
	$('span.div_title').nextAll().hide();
	$('#div_collapseall') .html('Expand All Divs');
    },
    function () {
    $('span.div_title').nextAll().show();
    $('span.milestone_title').hide();
	$('#div_collapseall') .html('Collapse All Divs');
});
});

/* milestone tools */

$(document) .ready(function () {

    $('#show_milestones') .toggle(function () {
 
	$('span.milestone_title').show();
	$('#show_milestones').html('Hide Milestones');
    },
    function () {
$('span.milestone_title').hide();
$('#show_milestones').html('Show Milestones');
});
});

/* toggle individual milestone visibility */
$(document) .ready(function () {

    $('span.milestone_title') .toggle(function () {
 
	$(this).next().slideUp();
    },
    function () {
    $(this).next().slideDown();

});
});

/* toggle all div visibility */
$(document) .ready(function () {

    $('#milestones_collapseall') .toggle(function () {
 
	$('span.milestone_title').nextAll().slideUp();
	$('#milestones_collapseall') .html('Expand All Milestones');
    },
    function () {
    $('span.milestone_title').nextAll().slideDown();
	$('#milestones_collapseall') .html('Collapse All Milestones');
});
});
		
/*
$(document).ready(function() {
			$("a.winchester-thumbs").fancybox({
			
			'zoomSpeedIn':    100,
			'zoomSpeedOut':   100,
			'imageScale':     true,
			'centerOnScroll': false,
			});
		});
	*/
	
		$(document).ready(function() {
			$("a.zoom").fancybox();

			$("a.zoom1").fancybox({
				'overlayOpacity'	:	0.2,
				'overlayColor'		:	'#dedede'
			});

			$("a.zoom2").fancybox({
				'zoomSpeedIn'		:	500,
				'zoomSpeedOut'		:	500
			});
		});

/* folio index loader */
$(document) .ready(function () {

    $('#win_folio_index li a') .click(function () {
    
    	  var sectionName = $(this).text();
    	  var galleryID = $(this).attr('galleryid');
    	  var galleryName = $(this).attr('galleryname');
    
 		var load_div = $('#folio_right_div');
 		
 		var link_position = $(this).position();
 		
    $.get('includes/folio_index.inc.php', {section_name: sectionName, gallery_id: galleryID, gallery_name: galleryName}, function (data) { 
    $(load_div).html(data);
   });
 		
 		$('#win_folio_index li a').css({'text-decoration' : 'none', 'color' : '#779eab'});
 		$(this).css({'text-decoration' : 'underline', 'color' : '#555555'});
 		
		
    });
    });
    
    /* folio index loader */
$(document) .ready(function () {

    $('#cax_sig_index li a') .click(function () {
    
    	  var sectionName = $(this).text();
    	  var galleryID = $(this).attr('galleryid');
    	  var galleryName = $(this).attr('galleryname');
    
 		var load_div = $('#sig_right_div');
 		
 		var link_position = $(this).position();
 		
    $.get('includes/folio_index.inc.php', {section_name: sectionName, gallery_id: galleryID, gallery_name: galleryName}, function (data) { 
    $(load_div).html(data);
   });
 		
 		$('#cax_sig_index li a').css({'text-decoration' : 'none', 'color' : '#779eab'});
 		$(this).css({'text-decoration' : 'underline', 'color' : '#555555'});
 		
		
    });
    });
    
    /* win toc modal */
    
    $(document) .ready(function () {
    
    $('#toc_bubble a') .click(function () {
    
            
               $('#bubble_contents') .fadeIn('slow');
                  
               $("#bubble_contents").css({'width' : '95%', 'min-height' : '400px'});
                               
               $("#bubble_contents").centerInClient({ container: window, forceAbsolute: true });
                  
               $('#ajax_note').show();
                  
               $('#ajax_note').empty();
               
               var win_toc1 = $(this).text();
               var galleryID = $(this).attr('galleryid');
               var galleryName = $(this).attr('gallery');
               var winchester = $(this).attr('version');
               
               var load_div = $('#ajax_note');
 		
			    $.get('includes/folio_index.inc.php', {section_name: win_toc1, gallery_id: galleryID, gallery_name: galleryName, version_name: winchester}, function (data) { 
    				$(load_div).html(data);
   				});
             
               $("#close_bubble a").bind("click", function(){
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
               $('#bubble_contents') .hide();
             });
    
    });
});

    /* win toc modal */
    
    $(document) .ready(function () {
    
    $('#cax_toc_bubble a') .click(function () {
    
            
               $('#bubble_contents') .fadeIn('slow');
                  
               $("#bubble_contents").css({'width' : '95%', 'min-height' : '400px'});
                               
               $("#bubble_contents").centerInClient({ container: window, forceAbsolute: true });
                  
               $('#ajax_note').show();
                  
               $('#ajax_note').empty();
               
               var toc1 = $(this).text();
               var galleryID = $(this).attr('galleryid');
               var galleryName = $(this).attr('gallery');
               var caxton = $(this).attr('version');
               
               var load_div = $('#ajax_note');
 		
			    $.get('includes/folio_index.inc.php', {section_name: toc1, gallery_id: galleryID, gallery_name: galleryName, version_name: caxton}, function (data) { 
    				$(load_div).html(data);
   				});
             
               $("#close_bubble a").bind("click", function(){
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
               $('#bubble_contents') .hide();
             });
    
    });
});


$(document) .ready(function () {

    $('#folio_fulltext a') .toggle(function () {
    
    var pagenumber = $(this).attr("page");
    var load_div = $('#folio_full');
 
	$('div#folio_single').hide();
	$('#winchester_div').hide();
	$(this).text('Return to Single Folio');
	$('#folio_parallel').hide();
	$.get('includes/win_xml_loader.php', function (data) { 
	
    $(load_div).html(data);
    
    $(load_div).show();

     // var div_height = document.getElementById(pagenumber);
    // var div_height = $('div#Folio 96r');
			//var h = div_height.scrollHeight;
//			var h = div_height.height();
			//var h = document.body.scrollHeight;
//			alert('Height ' + pagenumber + h);
//			self.scrollTo(0,h);

                                            var div_height = $('div#' + pagenumber);
			//var h = div_height.scrollHeight;
			var position = div_height.position();
			//var h = document.body.scrollHeight;
			var position_top = position.top;
			//alert('Height3 ' + position_top);
			self.scrollTo(0,position_top);

		$('#bubble_contents') .fadeIn('slow');
                  
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '150px'});
                               
               $("#bubble_contents").centerInClient({ container: window, forceAbsolute: true });
                  
               $('#ajax_note').show();
                  
               $('#ajax_note').empty();
		
	       $('#ajax_note').append('<p><span class="popup_title">Winchester Full Text</span></p><p>You are now viewing the single folio within the context of the full text.</p><p>Textual Options are still available for this text</p><p>To view a Quick View Image for each folio simply select the required link from the Folio page number.</p>');

$("#close_bubble a").bind("click", function(){
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
               $('#bubble_contents') .hide();
             });

   });
	$('div#div_tools').slideDown();

	
	//if ($("#folio_full").length)
            //{
              //    location.href = location.href + anchor;
           // }
			
			//humanMsg.displayMsg('<strong>You are now viewing:</strong> <span class="indent"> \''+page2+'\'. This is the current page within the context of Time Passes.</span>');
			
	


	
    },
    function () {
    
    var div_switch_text = $('#div_switch'). text();
    var div_collapseall_text = $('#div_collapseall').text();
    
    if (div_switch_text == 'Switch to Div View') {
    //$('div#folio_single').append(div_switch_text);
    }
    else {
   //  $("#div_nav") .slideUp('slow');
   // $('#div_switch'). html('Switch to Div View');
    $('#div_switch').trigger('click');
    }
    
    if (div_collapseall_text == 'Collapse All Divs') {
    
    }
    else {
    $('#div_collapseall').trigger('click');
    }
    
  $('div#folio_full').empty();
  $('div#folio_single').show();
  $('#winchester_div').show();
  $(this).text('View Full Text');
  $('#folio_parallel').show();
  $('div#div_tools').slideUp();
});
});

$(document) .ready(function () {

    $('#folio_parallel a') .toggle(function () {
    
    var folio_no = $(this).attr('caption');
    var load_div2 = $('#folio_right_div2');
    
		$(this).text('Return to Single Folio');
		$('#folio_fulltext').hide();
		$('#sig_fulltext').hide();
		$('div.switch_close').trigger('click');
		
		  $.get('includes/image_fader.inc.php', {folio: folio_no}, function (data2) { 
    				$(load_div2).html(data2);
   				});
   				
   				$('body').css({'minWidth' : '1230px'});
		
    },
    function () {
    $('#folio_right_div2').empty();
    $('body').css({'minWidth' : '980px'});
    $('div.switch_open').trigger('click');
   $(this).text('View Image Parallel');
   $('#folio_fulltext').show();
   $('#sig_fulltext').show();
});
});


/* Caxton Full Text Loader */
$(document) .ready(function () {

    $('#sig_fulltext a') .toggle(function () {
    
   var pagenumber2 = $(this).attr("page");
    var load_div = $('#folio_full');
 
	$('div#folio_single').hide();
	$('#winchester_div').hide();
	$(this).text('Return to Single Sig.');
	$('#folio_parallel').hide();
	$.get('includes/caxton_xml_loader.php', function (data) { 
	
    $(load_div).html(data);
    
    $(load_div).show();

   
                var div_height2 = $('div#' + pagenumber2);
             //  var div_height = $('div#Sigi7v');
             //  alert(div_height2);
		var position = div_height2.position();
		var position_top = position.top;
		self.scrollTo(0,position_top);

		$('#bubble_contents') .fadeIn('slow');
                  
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '150px'});
                               
               $("#bubble_contents").centerInClient({ container: window, forceAbsolute: true });
                  
               $('#ajax_note').show();
                  
               $('#ajax_note').empty();
		
	       $('#ajax_note').append('<p><span class="popup_title">Caxton Full Text</span></p><p>You are now viewing the single signature within the context of the full text.</p><p>Textual Options are still available for this text</p><p>To view a Quick View Image for each signature simply select the required link from the Sig. page number.</p>');

$("#close_bubble a").bind("click", function(){
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
               $('#bubble_contents') .hide();
             });

   });
	$('div#div_tools').slideDown();

    },
    function () {
    
    var div_switch_text = $('#div_switch'). text();
    var div_collapseall_text = $('#div_collapseall').text();
    
    if (div_switch_text == 'Switch to Div View') {
 
    }
    else {

    $('#div_switch').trigger('click');
    }
    
    if (div_collapseall_text == 'Collapse All Divs') {
    
    }
    else {
    $('#div_collapseall').trigger('click');
    }
    
  $('div#folio_full').empty();
  $('div#folio_single').show();
  $('#winchester_div').show();
  $(this).text('View Full Text');
  $('#folio_parallel').show();
  $('div#div_tools').slideUp();
});
});


$(document) .ready(function () {

    $('.bib_entry span.expand_entry') .click(function () {
 
	if ($(this).prev().is(":hidden") == true) {
	$(this).prev().slideDown();
	$(this).html('<a>Hide Full Entry</a>');
	}
	else {
	$(this).prev().slideUp();
	$(this).html('<a>Show Full Entry</a>');
	}
});
});


$(document) .ready(function () {

    $('#all_entries a') .toggle(function () {

	$('div.bib_expand').each(function () {

	if ($(this).is(":hidden") == true) {
	$(this).slideDown();
	$('.bib_entry span.expand_entry').html('<a>Hide Full Entry</a>');
	    }
	else {
	
	}
	});

	$(this).html('<a>Hide All Entries</a>');

	},
	function () {

	$('div.bib_expand').each(function () {
		if ($(this).is(":hidden") == false) {
	$(this).slideUp();
	$('.bib_entry span.expand_entry').html('<a>Show Full Entry</a>');
	    }
	else {
	
	}
	});

	$(this).html('<a>Show All Entries</a>');

});
});

/* bibliography tags filter */
$(document) .ready(function () {

    $('.bib_tags a') .click(function () {
 
	
	$('#bib_listing_full').hide();
	//$('#bib_listing_filter').empty();
	$('#bib_listing_filter').show();

	     var tag_id = $(this).attr('tag_id');
	     var tag_name = $(this).text();
               
               var load_div = $('#bib_listing_filter');
 		
			    $.get('includes/bib_filter.inc.php', {tagID: tag_id, tagName: tag_name}, function (data) 					{ 
    				$(load_div).html(data);
   				});

		$('#bib_sidebar_tags li a').css({'text-decoration' : 'none', 'color' : '#779eab'});
 		$(this).css({'text-decoration' : 'underline', 'color' : '#555555'});
    
});
});

/* bibliography sidebar tags filter */
$(document) .ready(function () {

    $('#bib_sidebar_tags li a') .click(function () {
 
	
	$('#bib_listing_full').hide();
	//$('#bib_listing_filter').empty();
	$('#bib_listing_filter').show();

	     var tag_id = $(this).attr('tag_id');
	     var tag_name = $(this).text();
               
               var load_div = $('#bib_listing_filter');
 		
			    $.get('includes/bib_filter.inc.php', {tagID: tag_id, tagName: tag_name}, function (data) 					{ 
    				$(load_div).html(data);
   				});

		$('#bib_sidebar_tags li a').css({'text-decoration' : 'none', 'color' : '#779eab'});
 		$(this).css({'text-decoration' : 'underline', 'color' : '#555555'});
		$('#bib_sidebar_categories li a').css({'text-decoration' : 'none', 'color' : '#779eab'});
    
});
});

/* bibliography sidebar categories filter */
$(document) .ready(function () {

    $('#bib_sidebar_categories li a') .click(function () {
 
	
	$('#bib_listing_full').hide();
	//$('#bib_listing_filter').empty();
	$('#bib_listing_filter').show();

	     var cat_id = $(this).attr('cat_id');
	     var cat_name = $(this).text();
               
               var load_div = $('#bib_listing_filter');
 		
			    $.get('includes/bib_catfilter.inc.php', {catID: cat_id, catName: cat_name}, function (data) 					{ 
    				$(load_div).html(data);
   				});

		$('#bib_sidebar_categories li a').css({'text-decoration' : 'none', 'color' : '#779eab'});
 		$(this).css({'text-decoration' : 'underline', 'color' : '#555555'});
		$('#bib_sidebar_tags li a').css({'text-decoration' : 'none', 'color' : '#779eab'});
    
});
});


/* Caxton Description expander */
$(document) .ready(function () {

    $('div.description_title') .click(function () {
 
	if ($(this).next().is(":hidden") == true) {
	$(this).next().slideDown();
	$(this).css({'font-weight' : 'bold', 'color' : '#555555', 'border-bottom' : '1px solid #555555'});
	//$(this).html('<a>Hide Full Entry</a>');
	}
	else {
	$(this).next().slideUp();
	$(this).css({'font-weight' : 'normal', 'color' : '#779eab', 'border-bottom' : '1px solid #ededed'});
	//$(this).html('<a>Show Full Entry</a>');
	}
});
});