$(document).ready(function(){
	var slideshowOn = true;
	$('#panel2').cycle({
		timeout: 6000,
		delay: 5000,
		speed: 1000,
		next:    '.nextbutton',
		prev:'.prevbutton',
		before:  onBefore,
		after: onAfter
	});

	$("#panel2 li").css({"visibility":"visible"});

	$("#panel2 a").each(function(intIndex){
		$(this).attr("id", "link"+intIndex)
	})

	$("#panel2-start").toggle(
		function(){$(this).text("Play");$('#panel2').cycle('pause');updateSlideshow(0);},
		function(){$(this).text("Pause");$('#panel2').cycle('resume');updateSlideshow(1);}
	);

	$("#panel2 a").each(function(intIndex){
		$(this).attr({
		id: 'link'+intIndex,
		rel:'slides'
		})
	})
		$("#panel2 a").unbind().colorbox({rel:'slides', slideshow:true,slideshowAuto:true});

});

function updateSlideshow(a){
	
	if(a==0){
		slideshowOn = true;
		$("#panel2 a").unbind().colorbox({rel:'slides', slideshow:true,slideshowAuto:false});

		}else{
		$("#panel2 a").unbind().colorbox({rel:'slides', slideshow:true,slideshowAuto:true});
		slideshowOn = false;
	}
}


function onAfter(curr,next,opts) {
	var caption = (opts.currSlide + 1) + ' of ' + opts.slideCount;
	$('span.caption2').html(caption);
}

function onBefore(curr,next,opts) {
    $("#enlarge").attr({title:"Slide "+opts.currSlide})
		.unbind()
		.click(function(){
				$("#link"+opts.currSlide).click();
				return false;
		});
}
