jQuery(function() {
/*
		$("#slider_bar").slider({
			value: 50,
			min: 0,
			max: 250,
			step: 25,
     		slide: function(e,ui){
     			$('#survey_amount').text(ui.value + ' miles');
			},
			change: function(event, ui) { // here's your AJAX request whenever someone moves the slider
				$.ajax({
				type: "POST",
				url: "some.php",
				data: "name=John&location=Boston",
				success: function(msg){
				alert( "Data Saved: " + msg );
					}
				});
			}
		});		$('#tell_a_friend1').hide();	$('#tell_a_friend1').show();
		$("#survey_amount").html($("#slider_bar").slider("value") + ' miles');
*/
		
		$('#event_header_text .more_artists').hide();
		$('#event_header_text a.more').click(function(){
			$(this).text($(this).text() == 'More...' ? 'Close...' : 'More...');
			$('#event_header_text .more_artists').toggle();
			return false;
		});
		
		$('#tab_div div.event_inner').hide();
		$('#event_tabs div.corner.left_top').hide();
		$('#tab_div div:first').show();
		$('ul#tab_menu li:first').addClass('selected'); 
		
		$('ul#tab_menu li a:first').click(function(){
			$('ul#tab_menu li').removeClass('selected'); 
			$('#event_tabs div.corner.left_top').hide();
			$(this).parent().addClass('selected');
			
			var currentTab = $(this).attr('href');
			
			$('#tab_div div.event_inner').hide();
			$(currentTab).show();
			return false;
		});
		
		$('ul#tab_menu li a:not(:first)').click(function(){
			$('ul#tab_menu li').removeClass('selected'); 
			$('#event_tabs div.corner.left_top').show();
			$(this).parent().addClass('selected');
			
			var currentTab = $(this).attr('href');
			
			$('#tab_div div.event_inner').hide();
			$(currentTab).show();
			return false;
		});
		
		$('ul#event_info_buttons li a.tell_a_friend').click(function(){
			$('#tell_a_friend2').show();
			return false;
		});
		
		
		$('ul#event_info_buttons li a.attending').click(function(){
			$('#remind_me').show();
			return false;
		});
		
		

		$('a#tell_a_friend_close').click(function(){
			$('#tell_a_friend2').hide();
		
			return false;
		});

		$('ul.event_images').galleria({
			history   : false, 
			clickNext : true,
			insert    : '#event_image_header',
			onImage   : function(image,caption,thumb) {
				
				// fade in the image & caption
				image.css('display','none').fadeIn(1000);
				caption.css('display','none').fadeIn(1000);
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				// add a title for the clickable image
				image.attr('title','Next');
			},
			onThumb : function(thumb) { // thumbnail effects go here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
				)
			}
		});


	// if has class 'autoscroll' then start auto scrolling
	if ($('.event_images').hasClass('autoscroll')) {
		var cycleTimer = setInterval(function () {
		$.galleria.next();
		}, 5000);
	}

	// select some trigger elements to stop the auto-cycle
	var $stopTriggers = $('#event_image_header, #menu_prev, #menu_next, .image_thumb, #slider_bar, .ui-slider-handle') // tab headers and next/prev buttons
	
	// this is the function that will stop the auto-cycle
	function stopCycle() {
	   // remove the no longer needed stop triggers
	   $stopTriggers.unbind('click.cycle');
	   clearInterval(cycleTimer);          // stop the auto-cycle itself
	   //$buttons.show();                       // show the navigation buttons
	}
	
	// bind stop cycle function to the click event using namespaces
	$stopTriggers.bind('click.cycle', stopCycle);
		
	});
