$(function(){
	//modify the image divs to center images
	$("span.catalogue_list_image img, span.catalogue2_image img").each( function(){
		if( $(this).width() > $(this).parent().width() )
		{
			var w = $(this).width()/2 - ($(this).parent().width()/2);
			if( w > 0 ) w = w*-1;
			$(this).css("left",w);
		}
	});

	$('ul.accordion').accordion({
		active: ".selected",
		autoHeight: false,
		header: ".opener",
		collapsible: true,
		event: "click"
	});
	$('ul.accordion2').accordion({
		autoHeight: false,
		header: ".opener",
		collapsible: true,
		fillSpace: true,
		event: "click"
	});
	
	//connect hash change events to select the active menu
	$(window).bind( 'hashchange', function( event ) {
		var hash_str = event.fragment,
		param_obj = event.getState(),
		param_val = parseInt( event.getState( 'accordion' ) ),
		param_val_coerced = event.getState( 'param_name', true );
		$('ul.accordion').accordion("activate",param_val);	
		$('ul.accordion2').accordion("activate",param_val);	
	});
	//if a hash is passed in teh url, use it to select active state
	index = parseInt( $.deparam.fragment().accordion );
	$('ul.accordion').accordion("activate",index);
	$('ul.accordion2').accordion("activate",index);

	//finally, add the correct hash to the urls
	$("div.slide").each(
		function(index)
		{
			$(this).find("a").each(
				function()
				{
					$(this).attr("href",$(this).attr("href")+"#accordion="+index);
				}
			);
		}
	);

});

