/* ******************** */	
// create listing display
function get_listing(topic,sort_type,sort_page,sort_per_page,featured_ocid_list,expand_list) {
	var listing_proxy = new listingproxy();
	// retrieve data via ajax
	listing_result = listing_proxy.buildListing(topic,sort_type,sort_page,sort_per_page,featured_ocid_list,expand_list);
	// build display
	$('#listing_header').html(listing_result.HEADER);
	$('#listing_text').html(listing_result.HEADER_TEXT);
	$('#categories_other').html(listing_result.SUBHEADER_RIGHT);
	// determine if there is a sort for the display
	if (listing_result.SORT.length > 0)
		{ $('#listing-utilities-sort').html(listing_result.SORT); }
	else
		{
		// code transplanted from hcm.js; insert "show all" link
		$("#categories").before("<p><a style='text-decoration:underline;' id='show_all' href='#' >Show All Products</a></p>");			
		}
	// determine if there is a result set for the display
	if (listing_result.RESULT_INFO.length > 0)
		{
		$('#listing-utilities').html(listing_result.RESULT_INFO);
		$('#listing-utilities-bottom').html(listing_result.RESULT_INFO_BOTTOM);

		$(document).ready(function() {
			// sync both select boxes for items per page
			$("#page-items-bottom").change(function () {				
				var selected = $("#page-items-bottom option:selected");    
				$("#page-items option").each(function() {
					if (selected.val() == $(this).val())
						{ $(this).attr("selected",true); }
				});				
			})
			$("#page-items").change(function () {				
				var selected = $("#page-items option:selected");    
				$("#page-items-bottom option").each(function() {
					if (selected.val() == $(this).val())
						{ $(this).attr("selected",true); }
				});				
			})			
		});
		
		}
	// main content area
	$('#categories').html(listing_result.DISPLAY);
}
/* ******************** */	
// sort listing of products
function sort_listing(topic,sort_type,sort_page,featured_ocid_list) {
	if (sort_type == "")
		{ sort_type = $('#sort-by').val(); }
	// call function to create sorted display
	get_listing(topic,sort_type,sort_page,$('#page-items').val(),featured_ocid_list,"")	
}