/**
 * @author mraichelson
 */

var URL_images = 'http://media.charlotteobserver.com/static/design/'; // URL of where the blank.gif image will live.

$(document).ready(function(){
	// set up active slide and first panel to display
	$('div#multimediabar2 div.mm-links li:first').addClass('active');
	// set up all slideshows
	$('div#multimediabar2 div.mm-panelset').each(function(i){
		var thePanelset = i+1;
		$('div.mm-panels',this).cycle(
			{
				fx:'scrollHorz',
				speed:500,
				timeout:7500,
				next:'#mm-panelset'+thePanelset+' .mm-right a', 
				prev:'#mm-panelset'+thePanelset+' .mm-left a',
				pager:'#mm-panelset'+thePanelset+' .mm-pagination',
				pagerAnchorBuilder:function(idx,slide){
					return '<a href="#"><img src="'+URL_images+'blank.gif" alt=""><\/a>';
				}
			}
		);
	});
	$('#multimediabar2 .mm-pagination a').focus(function(){ this.blur(); });
	$('#multimediabar2 .mm-left a, #multimediabar2 .mm-right a').focus(function(){ this.blur(); });
	// pause all except the first panelset
	$('div#multimediabar2 div.mm-panelset:not(#mm-panelset1) div.mm-panels').cycle('pause');

	// make tabs switch panelsets
	$('div#multimediabar2 div.mm-links a').click(function(){
		$(this).parents('ul').find('.active').removeClass('active');
		$(this).parent('li').addClass('active');
		$('div#multimediabar2 div.mm-panels').cycle('stop');
		var nextPanelset = '#'+$(this).attr('class');
		$('.mm-panelset:not('+nextPanelset+')').fadeOut(
			'animspeed',
			function(){
				$(nextPanelset).fadeIn(
					animspeed,
					function(){
						$(nextPanelset+' div.mm-panels').cycle('resume');
						$(nextPanelset+' div.mm-pagination a:first').trigger('click');
					}
				);
			}
		);
		this.blur();
		return false;
	});
});
