$(document).ready(function(){

	$('#contrastLow a, #contrastHigh a').click( function() {
		toggleAccessibility();
	});
	
	bindGalleryToggle();
	
	$('#selectNavigation select').change( function() {
		window.location = $(this).val();
	});
	
    if ( $('#add_block_localMh').length > 0) {
    
    	if ( $('#add_block_localMh li').length > 1 ) setInterval( "slideSwitchInternal()", 20000 );
    
    	$('#add_block_localMh').hoverIntent( function() {
    		$('#add_block_localMh span').animate({opacity: 1}, 1000);
    	}, function() {
    		$('#add_block_localMh span').animate({opacity: 0}, 1000);
    	});

    }
	
});


function toggleAccessibility() {

	if ( $.cookie('accessible') ) {
		$('#wrapper').removeClass( 'accessible' );
		$.cookie('accessible', null);
	} else {
		$('#wrapper').addClass( 'accessible' );
		$.cookie('accessible', true, 1, '/');
	}

};


function bindGalleryToggle() {

	$('#galleryToggle').bind( 'click', function( e ) {
		e.preventDefault();
		toggleGallery();
	});


}

function toggleGallery( galleryLink ) {

	var state = $('#galleryToggle').html()
	
	
	$('#galleryBar').slideToggle('slow', function() {
		$('#galleryToggle').html( ((state == 'Show Gallery') ? 'Hide Gallery' : 'Show Gallery' ));
	});

}


function slideSwitchInternal() {

    var $active = $('#add_block_localMh li.active');
    var $next = $active.next();

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

    var $next =  $active.next().length ? $active.next()
        : $('#add_block_localMh li:first');

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

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

