 $.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 content_height = $('#inner_wrapper').height();
//$('#right-sidebar').css({'height' : content_height});
//$('#sidebar_tray').css({'height' : content_height});

//});

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

   // $('#sidebar_switch') .toggle(function () {
    
    //	 $('#sidebar_content').hide();
       // $("#right-sidebar").animate({width: 1}, 10);
      //  $('#content').css({'margin-right' : '15px'});
	//	$('#sidebar_switch').css({'background' : 'url(assets/images/open_aqua.gif) no-repeat right top'});
		

   // },
   // function () {

    //	$('#sidebar_switch').css({'background' : 'url(assets/images/close_aqua.gif) no-repeat right top'});
   // 	$('#content').css({'margin-right' : '250px'});
     //   $("#right-sidebar").animate({width: 240}, 100);
      //  $('#sidebar_content').show();
//});
//});

$(document) .ready(function() {

              $("#accordion").accordion({
			autoHeight: true
		});

              
            });


$(document) .ready(function () {

    $('div.switch_close') .click(function () {
    
    		$('div.switch_close').hide();
    	  $('div.switch_open').show();
    	 $('#sidebar_content').hide();
        $("#right-sidebar").animate({width: 1}, 10);
        $('#content').css({'margin-right' : '15px'});
		//$('#sidebar_switch').css({'background' : 'url(assets/images/open_aqua.gif) no-repeat right top'});
		
    });
    });
    
    
    $(document) .ready(function () {

    $('div.switch_open') .click(function () {
		
		$('div.switch_open').hide();
		$('div.switch_close').show();
    //	$('#sidebar_switch').css({'background' : 'url(assets/images/close_aqua.gif) no-repeat right top'});
    	$('#content').css({'margin-right' : '220px'});
        $("#right-sidebar").animate({width: 210}, 100);
        $('#sidebar_content').show();
});
});

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

    $('#volume_loader') .toggle(function () {
    
 		$('#sidebar_volumes').slideDown();
 		$('#volume_loader').html('Volumes - ');
    },
    function () {
    
 	    $('#sidebar_volumes').slideUp();
 		$('#volume_loader').html('Volumes + ');
});
});

$(document) .ready(function () {

    $('#issue_loader') .toggle(function () {
    
 		$('#sidebar_issues').slideDown();
 		$('#issue_loader').html('Issues - ');
    },
    function () {
    
 	    $('#sidebar_issues').slideUp();
 		$('#issue_loader').html('Issues + ');
});
});

$(document) .ready(function () {

    $('#subtitle_loader') .toggle(function () {
    
 		$('#sidebar_subtitles').slideDown();
 		$('#subtitle_loader').html('Subtitles - ');
    },
    function () {
    
 	    $('#sidebar_subtitles').slideUp();
 		$('#subtitle_loader').html('Subtitles + ');
});
});

$(document) .ready(function () {

    $('#editor_loader') .toggle(function () {
    
 		$('#sidebar_editors').slideDown();
 		$('#editor_loader').html('Editors - ');
    },
    function () {
    
 	    $('#sidebar_editors').slideUp();
 		$('#editor_loader').html('Editors + ');
});
});

$(document) .ready(function () {

    $('#publisher_loader') .toggle(function () {
    
 		$('#sidebar_publishers').slideDown();
 		$('#publisher_loader').html('Publishers - ');
    },
    function () {
    
 	    $('#sidebar_publishers').slideUp();
 		$('#publisher_loader').html('Publishers + ');
});
});

$(document) .ready(function () {

    $('#location_loader') .toggle(function () {
    
 		$('#sidebar_locations').slideDown();
 		$('#location_loader').html('Locations - ');
    },
    function () {
    
 	    $('#sidebar_locations').slideUp();
 		$('#location_loader').html('Locations + ');
});
});

$(document) .ready(function () {

    $('#month_loader') .toggle(function () {
    
 		$('#sidebar_months').slideDown();
 		$('#month_loader').html('Months - ');
    },
    function () {
    
 	    $('#sidebar_months').slideUp();
 		$('#month_loader').html('Months + ');
});
});

$(document) .ready(function () {

    $('#year_loader') .toggle(function () {
    
 		$('#sidebar_years').slideDown();
 		$('#year_loader').html('Years - ');
    },
    function () {
    
 	    $('#sidebar_years').slideUp();
 		$('#year_loader').html('Years + ');
});
});

$(document) .ready(function () {

    $('#price_loader') .toggle(function () {
    
 		$('#sidebar_prices').slideDown();
 		$('#price_loader').html('Prices - ');
    },
    function () {
    
 	    $('#sidebar_prices').slideUp();
 		$('#price_loader').html('Prices + ');
});
});

$(document) .ready(function () {

    $('#note_loader') .toggle(function () {
    
 		$('#sidebar_notes').slideDown();
 		$('#note_loader').html('Notes - ');
    },
    function () {
    
 	    $('#sidebar_notes').slideUp();
 		$('#note_loader').html('Notes + ');
});
});

$(document) .ready(function () {

    $('#size_loader') .toggle(function () {
    
 		$('#sidebar_sizes').slideDown();
 		$('#size_loader').html('Sizes - ');
    },
    function () {
    
 	    $('#sidebar_sizes').slideUp();
 		$('#size_loader').html('Sizes + ');
});
});

$(document) .ready(function () {

    $('#pdf_loader') .toggle(function () {
    
 		$('#sidebar_pdfs').slideDown();
 		$('#pdf_loader').html('PDFs - ');
    },
    function () {
    
 	    $('#sidebar_pdfs').slideUp();
 		$('#pdf_loader').html('PDFs + ');
});
});


$(document) .ready(function () {

    $('#toc_loader') .toggle(function () {
    
 		$('#sidebar_toc').slideDown();
 		$('#toc_loader').html('Table of Contents - ');
    },
    function () {
    
 	    $('#sidebar_toc').slideUp();
 		$('#toc_loader').html('Table of Contents + ');
});
});

$(document) .ready(function () {
		$("#tabs").tabs();
	});


/* magazines list expander */

$(document) .ready(function () {

    $('#magazine_expander li a') .click(function () {
    
    var magazineName = $(this).text();
    
 	//	$('div#magazine_right').show();
 		var load_div = $('#magazine_right');
 	//	$(load_div).empty();
 		
 		var link_position = $(this).position();
 		
    $.get('includes/magazine_details.php', {gallery: magazineName}, function (data) { 
    $(load_div).html(data);
   });
 		
 		$('#magazine_expander li a').css({'text-decoration' : 'none'});
 		$(this).css({'text-decoration' : 'underline'});
 		
    });
});

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

    $('#article_expander li a') .click(function () {
    
    var articleID = $(this).attr('article_id');
    var gallery_title = $(this).attr('gallery');
    
 	//	$('div#article_right').show();
 		var load_div = $('#article_right');
 	//	$(load_div).empty();
 		
 		var link_position = $(this).position();
 		
    $.get('includes/article_details.php', {article: articleID, gallery: gallery_title}, function (data) { 
    $(load_div).html(data);
   });
 		
 		$('#article_expander li a').css({'text-decoration' : 'none'});
 		$(this).css({'text-decoration' : 'underline'});
 		
    });
});

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

    $('#author_expander li a') .click(function () {
    
    var authorID = $(this).attr('author_id');
    var gallery_magazine = $(this).attr('gallery');
    var galleryID = $(this).attr('gallery_id'); 
    
 	//	$('div#author_right').show();
 		var load_div = $('#author_right');
 		//$(load_div).empty();
 		
 		var link_position = $(this).position();
 		
 		if (!gallery_magazine) {
    $.get('includes/author_details.php', {author: authorID, gallery_id:galleryID}, function (data) { 
    $(load_div).html(data);
   });
   }
   else {
     $.get('includes/author_details.php', {author: authorID, gallery:gallery_magazine}, function (data) { 
    $(load_div).html(data);
   });
   }
 		
 		$('#author_expander li a').css({'text-decoration' : 'none'});
 		$(this).css({'text-decoration' : 'underline'});
 		
    });
});

/* catalogue expander */
/* authors expander */
$(document) .ready(function () {

    $('#catalogue_author li a') .click(function () {
    
    var authorID = $(this).attr('author_id');
 
 		var load_div = $('#author_right');
 		
 		var link_position = $(this).position();
 		
     $.get('includes/catalogue_author_details.php', {author: authorID}, function (data) { 
    $(load_div).html(data);
   });
 		
 		$('#catalogue_author li a').css({'text-decoration' : 'none'});
 		$(this).css({'text-decoration' : 'underline'});
 		
    });
});


$(document) .ready(function () {

    $('#catalogue_article li a') .click(function () {
    
    var articleID = $(this).attr('article_id');
 
 		var load_div = $('#article_right');
 		
 		var link_position = $(this).position();
 		
     $.get('includes/catalogue_article_details.php', {article: articleID}, function (data) { 
    $(load_div).html(data);
   });
 		
 		$('#catalogue_article li a').css({'text-decoration' : 'none'});
 		$(this).css({'text-decoration' : 'underline'});
 		
    });
});


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

    $('li#tab_magazines') .toggle(function () {
    
 		$(this).next().slideDown();
 		$(this).html('Volumes - ');
    },
    function () {
    
 	    $(this).next().slideUp();
 		$(this).html('Volumes + ');
});
});

/* image rotation */
$(document) .ready(function () {
 $('#rotate_left') .click(function () {
    
    	$('div.switch_close').hide();
    	  $('div.switch_open').show();
    	 $('#sidebar_content').hide();
        $("#right-sidebar").animate({width: 1}, 10);
        $('#content').css({'margin-right' : '15px'});
    
    $('div#image_full img').rotateRight(90);
	$('#rotate_left').hide();
	$('#rotate_right').show();
    
    });
    });
    
$(document) .ready(function () {
 $('#rotate_right') .click(function () {
    
        	$('div.switch_close').hide();
    	  $('div.switch_open').show();
    	 $('#sidebar_content').hide();
        $("#right-sidebar").animate({width: 1}, 10);
        $('#content').css({'margin-right' : '15px'});
    
    $('div#image_full canvas').rotateRight(90);
    
    });
    });
    
    /* timeline drag */
    $(document) .ready(function () {
    
        $("div#timeline_content").draggable({ containment: 'div#timeline_frame', scroll: false, axis: 'x' });
    
    });
    
    /* image zoomer */
    
    $(document) .ready(function () {

    $('#zoom_in') .click(function () {
    
         			$("div#image_full img").draggable({ containment: 'div#image_full', scroll: false });
         			$("div#image_full canvas").draggable({ containment: 'div#image_full', scroll: false });
    
    				$('#image_zoomer').addClass('zoom_on');
    				$('#image_zoomer').removeClass('zoom_off');
 				    $('#image_full').addClass('full_zoom');
    				$('#image_full').removeClass('normal_zoom');
    				
   			     $('#zoom_in').hide();
   			      $('#rotate_buttons').hide();
   			      $('#zoom_out').show();
   			      $('#zoom_notice').fadeIn();
   			      
    });
    });
    
    
   $(document) .ready(function () {

    $('#zoom_out') .click(function () {
    
    
       			//   $('div#image_full img').draggable('option', 'revert', true);
       			$('div#image_full img').draggable('destroy');
    					$('div#image_full canvas').draggable('destroy');
    					
    				$('#image_zoomer').removeClass('zoom_on');
        			$('#image_zoomer').addClass('zoom_off');
 				    $('#image_full').addClass('normal_zoom');
    				$('#image_full').removeClass('full_zoom');
    				
    				$("div#image_full img").animate({top: 0, left:0}, 700);
    				$("div#image_full canvas").animate({top: 0, left:0}, 700);
    				
    				$('#zoom_out').hide();
   			      $('#zoom_in').show();
   			       $('#rotate_buttons').show();

 				$('#zoom_notice').hide();
});
});

$(document) .ready(function () {
    
    $('#editor_bubble') .click(function () {
    
            
               $('#bubble_contents') .fadeIn('slow');
                  
               $("#bubble_contents").css({'width' : '40%', 'min-height' : '20px'});
                               
               $("#bubble_contents").centerInClient({ container: window, forceAbsolute: true });
                  
              $("#bubble_contents").draggable({ containment: 'div#inner_wrapper', scroll: false });
                  
               //$("#bubble_contents").resizable({ minWidth: '500px' });
                  
               $('#ajax_note').show();
                  
               $('#ajax_note').empty();
                              
               var editorID = $(this).attr('editor_id');
               var editorName = $(this).attr('editor');
               var load_div = $('#ajax_note');
               
               
                 $.get('includes/editor_gallery_details.php', {editor: editorName, editor_id: editorID}, 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 () {
    
    $('div#sidebar_carousel').draggable({ axis: 'x' });
    
    });
    
    
    /* alphabetical sorter */
    $(document) .ready(function() {

                $('#demoOne').listnav({
                
                //initLetter: 'a',
                includeAll: true,
                noMatchText: 'No Magazines.'
                
                });
            
            });
            
            $(document) .ready(function() {

                $('#demoTwo').listnav({
                
               // initLetter: 'a',
                includeAll: true,
                noMatchText: 'No Authors.'
                
                });
            
            });
            
                $(document) .ready(function() {

                $('#demoThree').listnav({
                
               // initLetter: 'a',
                includeAll: true,
                noMatchText: 'No Articles.'
                
                });
            
            });
            
               $(document) .ready(function() {

                $('#demoFour').listnav({
                
               // initLetter: 'a',
                includeAll: true,
                noMatchText: 'No Types.'
                
                });
            
            });


/** search list **/
 
 
 $(document) .ready(function() {
  
  	$('#slider h3') .toggle(function () {
  
  		$(this).next().show();
  		
  		$(this).css({'color' : '#666666', 'font-weight' : 'bold'});
  		
  		  },
    function () {
  		
  		$(this).removeClass('open_background');
  
  		$(this).next().hide();
  		
  		$(this).css({'color' : '#779eab', 'font-weight' : 'normal'});
  		
  	});
  
  });
  
  
 /** authors list **/
  $(document) .ready(function() {
  
  	$('#authors_list a') .click(function () {
  	
  		var letter_no = $(this).text();
  		var load_div = $('#author_left');
  		
  		$('#authors_list a').css({'background-color' : '#ffffff', 'color' : '#4e7093'});
 		$(this).css({'background-color' : '#666666', 'color' : '#ffffff'});
  	
  			$('#author_right').empty();
  			//$('#author_left').append(letter_no);
  			
  			$.get('includes/catalogues_author_listing2_inc.php', {letter: letter_no}, function (data) { 
    $(load_div).html(data);
   });
  		
  	});
  
  });
  
   /** articles list **/
  $(document) .ready(function() {
  
  	$('#articles_list a') .click(function () {
  	
  		var letter_no2 = $(this).text();
  		var load_div = $('#article_left');
  		
  		$('#articles_list a').css({'background-color' : '#ffffff', 'color' : '#4e7093'});
 		$(this).css({'background-color' : '#666666', 'color' : '#ffffff'});
  	
  			$('#article_right').empty();
  			//$('#author_left').append(letter_no);
  			
  			$.get('includes/catalogues_article_listing2_inc.php', {letter: letter_no2}, function (data) { 
    $(load_div).html(data);
   });
  		
  	});
  
  });
  
 
  /** expand type listing **/
  $(document) .ready(function() {
  
  	$('#typelisting_expand') .toggle(function () {
  
  	$('#searchtype_listing').slideDown();
  	$('#searchtype_listing2').slideDown();
  	$('#typelisting_expand a').text('Select a new Image Type - ');
  		
  		  },
    function () {
  		
  	$('#searchtype_listing').slideUp();
  	$('#searchtype_listing2').slideUp();
  		$('#typelisting_expand a').text('Select a new Image Type + ');
  		
  	});
  
  });
  
  
    /** expand type listing **/
  $(document) .ready(function() {
  
  	$('#copyright_notice ul li') .toggle(function () {
  
  		$(this).next().slideDown();
  		
  		  },
    function () {
  		
  			$(this).next().hide();
  	
  	});
  
  });
