/**
 * Video Channel JS
 * JS Specific to the video channel
 * This won't be useful for any other channel.
 *
 * @package agdistis
 * @version $Id: video_channel.js,v 1.4 2007/12/11 20:40:03 tpeters Exp $
 */

 
// DIV ID of the parent category list
var VPJS_MENU_PARENTS_UL      = 'vich_synacor_categories_ul';
var VPJS_CATEGORIES_TITLE_DIV = 'vich_vendor_categories_list';
var VPJS_OPEN_VENDOR_CATS     = new Object;



/**
 * Hides the parent categories DIV based on the state of brows_ids.
 *
 * @param object sheep - Sheep listening to vpjs_browse_ids.
 */
function vpjs_menu_vendors_handler(sheep)
{
	var vendor_ids = vpjs_get_vendor_ids();

	// Try to hide any open categories
	for (var vendor_id in VPJS_OPEN_VENDOR_CATS)
	{
		vpjs_block_hide('vendcat_' + vendor_id);
		delete VPJS_OPEN_VENDOR_CATS[vendor_id];
	}
	
	// Show any vendor specific categories.
	var vendcats_shown = false;
	if (vendor_ids.length == 1)
	{
		var status = vpjs_block_show('vendcat_' + vendor_ids[0])
		if (status)
		{
			vendcats_shown = true;
			VPJS_OPEN_VENDOR_CATS[vendor_ids[0]] = true;
		}
	}

	// Hide or show the parent categories
	var title_div_parent = document.getElementById(VPJS_CATEGORIES_TITLE_DIV);
	if (vendor_ids.length)
	{
		if (vendcats_shown)
		{
			vpjs_block_hide(VPJS_MENU_PARENTS_UL);
			vpjs_block_show(title_div_parent.id, true);
		}
		else
		{
			vpjs_block_hide(title_div_parent.id, true);
		}
	}
	else
	{
		vpjs_block_show(VPJS_MENU_PARENTS_UL);
		vpjs_block_hide(title_div_parent.id, true);
		if (old_selected && vpjs_off_class)
		{
			old_selected.className = vpjs_off_class;
			old_selected = '';
		}
	}
};





/**
 * Displays a loading message while changing body contents
 * @param string target
 * @return void
 */
function vpjs_vich_listings_loading(target)
{
	var id = document.getElementById(target);
	if (!id)
	{
		return;
	}

	id.innerHTML = '<div class="vich_listings_loading">Loading . . .</div>';
} 



/**
 * Overrides the toggleUl menu handler in the header.
 * Allows us to add functionality to when the menu is clicked.
 *
 * @return void
 */
function vpjs_toggleUl_override()
{
	if (typeof window.toggleUl == 'function')
	{
		window.vpjs_old_toggleUl = window.toggleUl;
		window.toggleUl = window.vpjs_toggleUl_overrider;
	}
}

/**
 * This is the new toggleUl function that is called
 *
 * @param string element
 * @return void
 */
function vpjs_toggleUl_overrider(element)
{
	if (typeof window.vpjs_old_toggleUl == 'function')
	{
		window.vpjs_old_toggleUl(element);
	}

	var theUl = document.getElementById(element);
	if (theUl.style.display == 'none')
	{
		pldv_hide_overlay();
	}
	else
	{
		pldv_show_overlay();
	}
}



/**
 * Hides the overlay.
 *
 * @return void
 */
function pldv_hide_overlay()
{
	if ((pldv_status == 3) && wmpl_object && !isIE)
	{
		pldv_id.style.visibility = 'hidden';
	}
}


/**
 * Shows the overlay.
 *
 * @return void
 */
function pldv_show_overlay()
{
	if ((pldv_status == 3) && wmpl_object && !isIE)
	{
            pldv_id.style.visibility = 'visible';
	}
}
