function slideSwitch() {
    var $active = $('#slideshow li.active');

    if ( $active.length == 0 ) $active = $('#slideshow li:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow li:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

jQuery(document).ready(function() {
	
	 setInterval( "slideSwitch()", 5000 );
	
    jQuery('#mycarousel').jcarousel({
        auto: 10,
		scroll: 1,
		animation: 'slow',
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });

	// Setup Google Map result
	$('#region li').click(function(){
		var this_id = $(this).attr("id");
		var seePrev = $(this).prev();
		var prev_id = seePrev.attr("id");
		
		if(this_id =="reg_11"){
			$('ul#church li').show();
		}
		else if((this_id =="reg_3")||(this_id =="reg_9")){
			$('ul#church li').hide();
			$('ul#church li.'+this_id).show();
			$('ul#church li.'+prev_id).show();
		}else{
		$('ul#church li').hide();
		$('ul#church li.'+this_id).show();
		}
	});
	
	// Setup Fancybox
	$(".gallery-item a").fancybox();
	
	// Setup anglican_site_tab
	function angTab(){
		
		var child_id ="";
		
	$('.anglican_sites_tab div').mouseover(function(){
		child_id = $(this).attr("id");
		
		
		$('#'+child_id+'_name').show();
	}).mouseout(function(){
		child_id = $(this).attr("id");
		
		$('.anglican_sites_name div').mouseover(function(){
			$(this).addClass('showDiv');
			$('#'+child_id+'_name').show();
		}).mouseout(function(){
			$(this).removeClass('showDiv');
			$('#'+child_id+'_name').hide();
		});
		
		if($('#'+child_id+'_name').hasClass('showDiv')){
			return false;
		}else{
			$('.anglican_sites_tab div').mouseout(function(){
				$('#'+child_id+'_name').hide();
			});
		}
		
	});

	
	}
	
	angTab();

});