/**
 * hovvaccordion - An accordion that expands on hover
 *
 * @param {Object} childSelector - the child elecment to expand
 */
$.fn.hovvaccordion = function (hoverItem,childSelector)
{
	/* prevent elem has no properties error */
	if (this.length == 0) {
		return(this);
	};

	var childSelector = childSelector || function() { };
	var hoverItem = hoverItem || function() { };

	return this.hover(

		function()
		{
			// register hover events on the hoverItems

			$(hoverItem).hover(

				function ()
				{
					// N.B. This reassigned to hoverItem
					$(this).parents('ul').parent().find(childSelector).hide();
					$(this).find(childSelector).show();
				}
				,
				function () {}
			);
		}
		,
		function ()
		{
			// hide all childSelectors when  you've moved out of the parent
			$(this).find(childSelector).hide();
		}

	);
}
	
	

$(document).ready(function(){
	$(".accordionCluster .description").css('display','none');

	$(".accordionCluster li h3").hover(
		function()
		{
			$(this).css('text-decoration','underline');
			$(this).css('color','#c00');
		},
		function(){
			$(this).css('text-decoration','none');
			$(this).css('color','#00c');

		}
	);

	$(".accordionCluster h3").click(
		function()
		{
			var thisItemIsExpanded = ( $(this).siblings('.description').css("display") ) == 'none' ? false : true;
						
			if (thisItemIsExpanded)
			{
				$(this).parent().css("list-style-image","url('/media/design/icon_plus.gif')");
				$(this).siblings().find('.flashPlayer').remove(); // remove any flash mp3 player
			} 
			else
			{
				$(this).parent().css("list-style-image","url('/media/design/icon_minus.gif')");
				// collapse siblings
				// var otherListItems = $(this).parent().siblings();
				var otherListItems = $(this).parents('.accordionCluster').find('li');

				otherListItems.each(
					function()
					{
						if ( $(this).children('.description').css("display") != "none")
						{
							$(this).children('.description').hide(); // BlindUp(300, null, null);
							$(this).css("list-style-image","url('/media/design/icon_plus.gif')");
						}
						$(this).find('.flashPlayer').remove(); // remove any flash mp3 player
					}
				);
				
				$(this).siblings().find("a[@href$='.mp3']").each(
					function(i)
					{
						var podcastUrl = $(this).attr('href');
	
						var playerBaseUrl = '//my.nottingham.ac.uk/media/design';
						
						var flashPlayerHtml =	'<p class="flashPlayer"><object type="application/x-shockwave-flash"  data="' + playerBaseUrl + '/player.swf" width="290" height="24" ><param name="movie" value="' + playerBaseUrl + '/player.swf" /><param name="FlashVars" value="bg=0xf8f8f8&amp;leftbg=0xC3E1FE&amp;lefticon=0x03406F&amp;rightbg=0xC3E1FE&amp;rightbghover=0x03406F&amp;righticon=0x03406F&amp;righticonhover=0xC3E1FE&amp;text=0x666666&amp;slider=0x666666&amp;track=0xFFFFFF&amp;border=0x666666&amp;loader=0xC3E1FE&amp;soundFile='
										+ podcastUrl +'" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="bgcolor" value="#ffffff" /></object></p>';
						
						$(this).parent().before(flashPlayerHtml);
					}
				);				
			}
			$(this).siblings('.description').toggle(); // BlindToggleVertically(300, null, null);
		}
	);
	
	// hovvaccordion - An accordion that expands on hover
	$('.hovvaccordion').hovvaccordion('li', '.infoBox');
});