	
$j(window).load(function() {
	var h1 = $j('#sidelinks').height();
	var h2 = $j('#subcontent').height();
	console.log("h1 = " + h1 +" , h2 = " + h2);
	if(h1 > h2) {
		$j('#subcontent').height(h1);
	} else {
		$j('#sidelinks').height(h2);
	}
});


$j(document).ready(function() {
		$j('.hov p:first-child').css("border-bottom","1px solid white");
		$j('.hov a:first-child').css("border-bottom","1px solid white");

		$j('#c1_new').addClass('headsel');

		$j.ajaxSetup({ cache: true });
		$j.getScript("http://www.cap-press.com/myjs/wz_tooltip.js", function() {

			$j('.lse_info').hover(
			function() {
				Tip("Law faculty may view this book instantly as an ebook on Law School Exchange.",WIDTH,-350);
			}, function() {
				UnTip();
			});

			$j('.authhov, .bhov').hover(
			function() {
				var cl = $j(this).attr("class");
				var val_id = 0;
				var h_type = 0;

				if($j(this).hasClass("authhov")) {
					val_id = _getHoverClassAid(cl);
					authHovers[val_id] = 1;
					h_type = AUTH;
				} else {
					val_id = _getHoverClassBid(cl);
					bookHovers[val_id] = 1;
					h_type = BOOK;
				}
				
				if(!(val_id > 0))
					return;
				$j.ajax({
				url: "/authhov.php",
				data: "val=" + val_id + "&type=" + h_type,
				success: function(html) {
					if(h_type == AUTH) {
						if(authHovers[val_id] == 1)
							Tip(html,WIDTH,-350);
					} else if(h_type == BOOK) {
						if(bookHovers[val_id] == 1)
							Tip(html,WIDTH,-650);
					} else {
					}
				},
				error: function(request,error) {
				}
				});
			}, function() {
				var h_type;
				var val_id;
				var cl = $j(this).attr("class");

				if($j(this).hasClass("authhov")) {
					h_type = AUTH;
					val_id = _getHoverClassAid(cl);
				}
				else if($j(this).hasClass("bhov")) {
					h_type = BOOK;
					val_id = _getHoverClassBid(cl);
				}

				if(h_type == AUTH) {
					authHovers[val_id] = 0;
					UnTip();
				} else {
					bookHovers[val_id] = 0;
					UnTip();
				}
			});

		});
		$j.ajaxSetup({ cache: false });

		new Ajax.Autocompleter("stext", "stext_choices", "/search_auto.php", {minChars: 2, frequency: 0.1, updateElement: function(li) { document.getElementById('sform').submit(); }, afterUpdateElement: function(text,li) { }});

	});

	// hover buttons
	// lookin.gif -> lookin-over.gif
	$j('.hb').hover(function() {
		this.src = this.src.replace('.gif','-over.gif');
	},
	function() {
		this.src = this.src.replace('-over.gif','.gif');
	});


	// side link hovers
	$j('li.hov').hover(
	function() {
		this.firstChild.style.borderBottom = '1px solid #037885';
		this.style.listStyleImage = 'url(/front_images/leaf.png)';
	},
	function() {
		this.firstChild.style.borderBottom = '1px solid white';
		this.style.listStyleImage = 'url(/front_images/blank.png)';
	});

	bbs_hover = 0;
	// 0 = no hover, 1 =  over "Browse by Subject", 2=over the ul

function b() {
	if(bbs_hover == 0) {
		$j('#bbs').removeClass('subjhov');
		$j('#subjs').hide();
	}
}

	$j('#bbs').hover(function() {
		$j(this).addClass('subjhov');
		$j('#subjs').fadeIn();
		bbs_hover |= 1;
	}, function() {
		bbs_hover ^= 1;
		var t = setTimeout(b,10);
	});

	$j('#subjs').hover(function() {
		bbs_hover |= 2;
	}, function() {
		bbs_hover ^= 2;
		var t = setTimeout(b,10);
	});

	$j('#c1_new').click(
	function() {
		$j('#c1div_forth').hide('slow');
		$j('#c1div_new').show('slow');
		$j('#c1_new').addClass('headsel');
		$j('#c1_forth').removeClass('headsel');
	});
	$j('#c1_forth').click(
	function() {
		$j('#c1div_new').hide('slow');
		$j('#c1div_forth').show('slow');
		$j('#c1_forth').addClass('headsel');
		$j('#c1_new').removeClass('headsel');
	});

var authHovers = new Array();
var bookHovers = new Array();

var AUTH = 1;
var BOOK = 2;

function _getHoverClassAid(cl)
{
	return _getHoverClassVal("aid_",cl);
}
function _getHoverClassBid(cl)
{
	return _getHoverClassVal("bid_",cl);
}

function _getHoverClassVal(prefix,cl)
{
	var val_id = 0;
	var classes = cl.split(" ");
	for(var i=0; i<classes.length; i++) {
		var re = new RegExp("^" + prefix + "([0-9]+)$");
		var m = classes[i].match(re);
		if(m) {
			val_id = m[1];
			return val_id;
		}
	}

	return 0;
}

