jQuery(document).ready(function($) {
	/* initialize jScrollPane */
	if ($(".scrollPane .scrollPaneWrapper").length > 0) {
		$(".scrollPane .scrollPaneWrapper").jScrollPane({
			scrollbarWidth : 4,
			showArrows : false,
			arrowSize : 0,
			dragMinHeight : 62,
			dragMaxHeight : 62,
			maintainPosition: true
		});
	}
	
	$(".accordionInner").accordion({
		active: false, 
		selectedClass: "accordionInner-selected",
		alwaysOpen: false,
		header: ".accordionInner-header",
		collapsible: true,
		autoHeight:false
	}).bind("change.ui-accordion", function(){
		//console.debug(this, arguments);
		$(this).closest(".scrollPaneWrapper").jScrollPane({
			scrollbarWidth : 4,
			showArrows : false,
			arrowSize : 0,
			dragMinHeight : 62,
			dragMaxHeight : 62,
			maintainPosition: true
		});
	});
	
	$(".accordionRoot").accordion({
		selectedClass: "accordion-selected",
		alwaysOpen: false,
		active: false,
		header: ".accordion-header",
		collapsible: true,
		autoHeight:false
	});
	
	/*
	$('a[rel*=lightbox]').lightBox({
		overlayBgColor: 		'#26576a',		// (string) Background color to overlay; inform a hexadecimal value like: #RRGGBB. Where RR, GG, and BB are the hexadecimal values for the red, green, and blue values of the color.
		overlayOpacity:			0.8,		// (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9
		// Configuration related to navigation
		fixedNavigation:		false,		// (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface.
		// Configuration related to images
		imageLoading:			'images/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
		imageBtnPrev:			'images/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
		imageBtnNext:			'images/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
		imageBtnClose:			'images/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
		imageBlank:				'images/lightbox-blank.gif'			// (string) Path and the name of a blank image (one pixel)
	}); // Select all links that contains lightbox in the attribute rel
	*/
	
	//$('.menu#top li:last').addClass('last');
	/* Menu hover action */
	/*$('#content .inner').css('padding-top','32px');
	$('.menu#top li').mouseover(function() {
		$(this).children().show();
	})
	$('.menu#top li').mouseout(function() {
		$('.menu#top .sub-menu').delay(500).hide();
		$('.current-menu-parent .sub-menu').show();
	});*/
	
	/* top menu */
	(function(){
		function hideCurrent() {
			var el = $(this);
			
			$(">.current-menu-item", el).removeClass("current-menu-item").find(">ul").hide();
		};
		
		
		$('.menu#top').each(function(){
			var el = $(this),
				items = $(">.menu-item", el),
				active = null, current = null,
				hideTimeout = null;
				
			function clearHideTimeout() {
				if (hideTimeout) {
					window.clearTimeout(hideTimeout);
					hideTimeout = null;
				}
			};
				
			function setHideTimeout() {
				clearHideTimeout();
				hideTimeout = window.setTimeout(function(){
					hideCurrent.call(el);
					if (current) {
						//current.addClass("current-menu-item");
						//$(">ul", current).show();
					}
				}, 400);
			};
				
			current = items.filter(".current-menu-item");
			active = null;
			
			items.bind("mouseover", function(event) {
				var ul = $(">ul", this), item = $(this);
				
				clearHideTimeout();
				
				if (!item.is(".current-menu-item")) {
					hideCurrent.call(el);
				}
				
				item.addClass("current-menu-item");
				if (ul.length > 0) {
					ul.show();
				}
			});
			
			items.bind("mouseout", function(event){
				setHideTimeout();
			});
		});
	})($);
	
	// something about this is causing a "f is undefined" error with jquery
	//$("#sort").msDropDown();
	$('#sort').change(function () {
		$(location).attr('href',this.value);
	});
	
	$('.bib_search #s').css('color','#AAA');
	$('.bib_search #s').focus(function() {
		$(this).css('color','#333');
		if($(this).val()=='Author, Title, or Genre') {
			$(this).val('');
		}
	});
	$('.bib_search #s').blur(function() {
		$(this).css('color','#AAA');
		if($(this).val()=='') {
			$(this).val('Author, Title, or Genre');
		}
	});
});
