function show_fam(id) {
	$('#family-'+id).click();
}

function lb_is_admin() {
	url = "admin_action.php?a=isadmin";
	$.post(url,function(data) {
		if(parseInt(data) == 1)
			overlay_admin();
		return parseInt(data);
	});
}

function show_lbox(title) {
	$("#prod-fam-content").dialog("open");
}

$(document).ready(function() {
	$("#prod-fam-content").dialog({
		modal: true,
		title: "Product Family",
		overlay: {
			opacity: 0.5,
			background: "black"
		},
		width: "800px",
		height: "600px",
		autoOpen: false,
		resizable: false
	});
	$("#prod-fam-content").show();

/* set all of the family related menu items to open the appropriate family in the lightbox */
	$('.family-menu-item').click(function(){
		$("#prods-in-fam").empty();
		$("#prod-fam-content").dialog("open");
		$.ajax({
			type: "GET",
			url: "prods_in_family.php",
			data: 'fid='+$(this).attr('rid')+'&mid='+$(this).attr('mid')+'&sort=l&order=asc',
			success: function(msg){
				$("#prods-in-fam").empty().append(msg);
			}
		});

		//$('#prods-in-fam').load('prods_in_family.php?fid='+$(this).attr('rid')+'&mid='+$(this).attr('mid')+'&sort=l&order=asc', {}, function() { show_lbox($(this).text()); }); 
		//$('#prod-fam-admin').attr('href','admin.php?p=family&fid='+$(this).attr('rid'));
	});
	
	$('.page-menu-item').click(function() {
	document.location.href = $(this).attr('href');
	});
	
	$('.product-menu-item').click(function() {
	document.location.href = $(this).attr('href');
	});
   
/* when the page completely loads, fade in (fade out the black screen)    */
	$(window).load(function() { 
		$('#black-overlay').hide();//fadeOut('fast'); 
	});
})

function change_sort(options, sortby) {
	order = $('#sort_'+sortby).val();
	if(order == '' || order == 0) order = 'asc';
	else if(order == 'asc') order = 'desc';
	else if(order == 'desc') order = '';
	$('#sort_'+sortby).val(order);

	$.ajax({
		type: "GET",
		url: "prods_in_family.php",
		data: options+'&ajax=1&sort='+sortby+'&order='+order,
		success: function(msg){
			$("#prod-list-table").replaceWith(msg);
		}
	});
	return false;
}
