// Dropdown Jump menu controls
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// Disable the autoplay
function autoPlayDisable()
{	$('#btnPlayPause').removeClass( "btnPause" ).addClass( "btnPlay" ).attr("title","Play Slideshow");
	$("body").stopTime('controlled');
}
// Enable the autoplay
function autoPlayEnable()
{	$('#btnPlayPause').removeClass( "btnPlay" ).addClass( "btnPause" ).attr("title","Pause Slideshow");
	$("body").everyTime(5000, 'controlled', function() { swapNext(); });
}
// remove current image and add the one referenced by thisItem
function swapCurrent (thisItem)
{	// remove highlight from last selection and then remove the current class
	$('#gallery a.current').css("border-color", "#404040" );
	$('#gallery a.current').children().stop().animate({ opacity: 0.4 }, 400 );
	$('#gallery a.current').removeClass ('current');
	// add current class to this selection and make sure it's styled as active
	$(thisItem).addClass ('current');
	$(thisItem).css("border-color", "#606060" );
	$(thisItem).children().stop().animate({ opacity: 1 }, 200 );
	$(thisItem).children().each(function (i) {
		var appendImage = '<img src="'+$(this).attr("src")+'" alt="'+$(this).attr("alt")+'" title="'+$(this).attr("title")+'" border="0" />';
		var appendText = $(this).attr("title");
		$('#fullContainer')
			.animate({ opacity: 0 }, 500 )
			.queue(function () {	$(this).empty().dequeue();	})
			.queue(function () {	$(this).append( appendImage ).dequeue();	})
			.animate({ opacity: 1 }, 500 );
		$('#textContainer')
			.animate({ opacity: 0 }, 300 )
			.queue(function () {	$(this).empty().dequeue();	})
			.queue(function () {	$(this).animate({ opacity: 0 }, 500 ).dequeue();	})
			.queue(function () {	$(this).append( appendText ).dequeue();	})
			.queue(function () {	$(this).animate({ opacity: 1 }, 200 ).dequeue();	})
	});
}
// Go to the first slide in the gallery if we're not already there
function swapFirst ()
{	if ( $('#gallery a.current').parent().is(':first-child') )	{	/* Already there*/	}
	else	{	swapCurrent ( $('#gallery a.current').parent().siblings(':first-child').children("a") );	}	}
// Go to the previous slide in the gallery, if we're at the beginning then go to the last
function swapPrev ()
{	if ( $('#gallery a.current').parent().is(':first-child') )	{	var swapToThis = $('#gallery a.current').parent().siblings(':last-child').children("a");	}
	else	{	var swapToThis = $('#gallery a.current').parent().prev().children("a");	}
	swapCurrent ( swapToThis );	}
// Go to the next slide in the gallery, if we're at the end start over
function swapNext ()
{	if ( $('#gallery a.current').parent().is(':last-child') )	{	var swapToThis = $('#gallery a.current').parent().siblings(':first-child').children("a");	}
	else	{	var swapToThis = $('#gallery a.current').parent().next().children("a");	}
	swapCurrent ( swapToThis );	}
// Go to the last slide in the gallery if we're not already there
function swapLast ()
{	if ( $('#gallery a.current').parent().is(':last-child') )	{	/* Already there*/	}
	else	{	swapCurrent ( $('#gallery a.current').parent().siblings(':last-child').children("a") );	}	}

$(document).ready(function()
{	// Set a slideshow tracker
	var active = true;
	// auto scroll the thumbnails on the X axis only
	$('#thumbs').autoscroll(AUTOSCROLL_X);
	// make all thumbnails semitransparent on load
	$('#thumbs a img').css( "opacity", 0.4 ); 
	// make sure anything that's marked current has the proper styles
	$('#thumbs a.current').css( "border-color", "#606060" ); 
	$('#thumbs a.current img').css( "opacity", 1 );
	// Thumbnail rollover styling
	$("#thumbs a").hover(
		function () { if ( $(this).attr('class') != "current")	{	$(this).css("border-color", "#606060" );	$(this).children().stop().animate({ opacity: 1 }, 200 );	}	}, 
		function () { if ( $(this).attr('class') != "current")	{	$(this).css("border-color", "#404040" );	$(this).children().stop().animate({ opacity: 0.4 }, 400 );	}	}	);
	// Trigger the swapCurrent on the clicked thumbnail
	$('#thumbs a').click(function() {	swapCurrent ( $(this) );	active = false;	autoPlayDisable();	return false;	});
	// Trigger the swapCurrent on the clicked button
	$('#btnFirst').click(function() {	swapFirst();	active = false;	autoPlayDisable();	return false;	});
	$('#btnPrev').click(function() {	swapPrev();		active = false;	autoPlayDisable();	return false;	});
	$('#btnNext').click(function() {	swapNext();		active = false;	autoPlayDisable();	return false;	});
	$('#btnLast').click(function() {	swapLast();		active = false;	autoPlayDisable();	return false;	});
	// Trigger the slideshow on load and toggle it onclick of btnPlayPause 
	$('#btnPlayPause').click(function() {
		if ( active ) { active = false;	autoPlayDisable();	}
		else {			active = true;	autoPlayEnable();	}
		return false;
	});
	$("body").everyTime(5000, 'controlled', function() { swapNext(); });
});