jQuery(document).ready(function($){
	var page=document.location.href;
	page=page.replace("#","");

	$('.getphotogroup').live('change',function(){
		// get the photo group for display on photos page
		var sg=$(this).val();
		$.post(page,
			{
				'ajaxrequest':'callfile_public-photos-slide-show_getphotogroups',
				'sg':sg
			},
			function (data){
				var content=decodeString(data);
				$('#thumbnailredirect').attr('href',"/photos.php?sg=" + sg + "&viewchoice=thumbnail");
								
				// do something with returned data
				$('.customslideshow').cycle('destroy');

				$('#customshowdisplay').html(content);

				function onAfter() {
				
					thealt=decodeString(this.alt);// changelog 2011/10/25 added rawurlencoding in public-photo-show (the source file for photos called via ajax)
					$('#customslidedescription').html(thealt);
					var slideid=$('.activeSlide').index();
					var containeroffset=$('#snavcontainer').offset();
							
					// get a count of how many slides
					var snavcount=$("#snav > a").size();
					var maxcount=snavcount-20;
					if(maxcount>0){
						if(slideid==snavcount-1){
							// this is the last slide, so reset the navigation
							$('#snav').offset({top:containeroffset.top,left:containeroffset.left});
						}
						else if(slideid>5){
							var offset=$('#snav').offset();
							var newleft=offset.left-20;
							$('#snav').offset({top:offset.top,left:newleft});
							$('#snavcontainer').offset({top:containeroffset.top,left:containeroffset.left});
						}
					}

				}	
					
				$('.customslideshow').fadeIn('slow').before("<div id='snavcontainer'><div id='snav'>").cycle({
					fx:
					'fade',
					randomizeEffects:1,
					autostop:0,
					pause:1,
					pager:'#snav',
					after:onAfter
				});
			});
		
	});

	// code to produce scrolling list of club names
	if($('.scrolllist').length>0){
		$('.scrolllist').fadeIn('slow').vTicker({
			speed: 500,
			pause: 3000,
			showItems: 5,
			animation: 'fade',
			mousePause: false,
			height: 0,
			direction: 'up'
		});

		$('.scrolllist,.scrolllisttitle').click(
			function(){
				if($('#clublist').length==0){
					$("<div id='clublist' style='position:absolute;top:50px;right:300px;width:500px;background-color:#FFFFFF;padding:10px;border:1px solid #000066;z-index:50' class='corners-10 shadows-10'></div>").insertBefore(this);
					$.post(page,{
					   'ajaxrequest':'getclublist'
					   },
					   function(data){
						da=data.split('%%');
						if(da[0]=='success'){
							$('#clublist').html("<div id='closeclublist'>Click on a club name to view or click here to close</div>" + da[1]);
							$('.slideshow').fadeOut('slow');
						}
					   });
				}
				else{
					$('#clublist').fadeIn('slow');
					$('.slideshow').fadeOut('slow');
				}
			}
		);

	$('#closeclublist').live('click',function(){
		$('#clublist').fadeOut('slow').remove();
		$('.slideshow').fadeIn('slow');
	});

	}
	// end code to produce club names

	if($('#mastheadslides').length>0){
		function mycarousel_initCallback(carousel)
		{
		    // Disable autoscrolling if the user clicks the prev or next button.
		    carousel.buttonNext.bind('click', function() {
		        carousel.startAuto(0);
		    });

		    carousel.buttonPrev.bind('click', function() {
		        carousel.startAuto(0);
		    });

		    // Pause autoscrolling if the user moves with the cursor over the clip.
		    carousel.clip.hover(function() {
		        carousel.stopAuto();
		    }, function() {
		        carousel.startAuto();
		    });
		}


		$('#mastheadslides').jcarousel({
        // Configuration goes here
			visible:3,
			vertical:0,
			size:3,
			scroll:1,
			auto:2,
	        wrap: 'last',
	        initCallback: mycarousel_initCallback

   		});
	}

});
