$(document).ready(function() {
	//initialize tabs
	$('#booklisttabs').tabs();
	
	//enable course selection button if a section is selected
	$('#sectionlb').click(function() {$('#Button1').removeAttr('disabled');$('#Button1').removeAttr('class');});
	
	//gray backdrop for 2nd row of tabs, only show if there's a second row.
	if ($('#booklisttabs ul.tabs-nav').length > 0)
	{
	if($('#booklisttabs ul.tabs-nav').height() > 30)
		$('#booklisttabs ul.tabs-nav').attr("style","background: transparent url(skins/skin_1/images/booklist/tab2ndrowbg.gif) repeat-x right bottom;");
	}
	
	//Highlight row when New/Used/eBook clicked
	$('.addcartform input').click(function() {	
		selectRow(this);
	});
	//Highlight row when New/Used/eBook preselected.
	$('.addcartform input:checked').each(function() {	
		selectRow(this);
	});
	
	//Row remove link
	$('.unselect a').click(function(){
		var row = $(this).closest('tr');
		$(row).find('.addcartform input').removeAttr('checked');
		$(row).attr('class',$(row).attr("class").replace(" selected",""));
		return false;
	});
	
	//details rollover
	$('#bodyWrapper .info').hover(
		function()
		{
			$(this).addClass("infobackdrop");
			$(this).find('.productoverlay').fadeIn('fast');
		},
		function()
		{
			var info = this;
			$(this).find('.productoverlay').fadeOut('fast',function(){$(info).removeClass("infobackdrop");});
		}
	
	);
	
	//rollover close link
	$('.productoverlay a.close').click(function() {
		$(this).closest('.productoverlay').fadeOut('fast',function(){
			$(this).closest(".info").removeClass("infobackdrop");
		});
		return false;
	});
	
	//Automatically show subs overlay if the link to it is tagged with the "autoload" css class.
	if ($('a#ShowOverlay.autoload').length > 0)
	{
		
		if(imgLoader == undefined) //just in case thickbox.js isn't initialized.
		{
		imgLoader = new Image();// preload image
		imgLoader.src = tb_pathToImage;
		}
		tb_show("",$('a#ShowOverlay.autoload').attr("href"),"");
		
	}
	

	
	//Select All links
	$('a.selectall').click(function() {
		var type = $(this).attr("type"); // attribute type="new" or type="used" in the link.
	
		$(this).closest('table').find(".addcartform input."+type).click();
		return false;
	});
	
	$('.booklistright #pnlStudentLogin .title').click( function() {
		$(this).next('.inner').slideDown("fast");
	});
	

});

function selectRow(radio)
{
	
	var name = $(radio).attr('name');
	$(".addcartform input[name='"+name+"']").closest('tr').removeClass('selected');
	$(radio).closest('tr').addClass('selected');
}

function setSub(value)
{
	tb_remove();
	if (value=="1" || value=="0")
	{
		$('.subs input').attr("checked","");
		$('.subs input[value='+value+']').attr("checked","checked");
	}
	return false;
}