$(document).ready(function() {


// Swap form field values when focused
	$('#site-search input[type=text], #map-search input[type=text]').each(function() {
	    var default_value = this.value;
	    $(this).focus(function() {
	        if(this.value == default_value) {this.value = '';}
	    });
	    $(this).blur(function() {
	        if(this.value == '') {this.value = default_value;}
	    });
	});
	
	
// Keep top nav item "active" while dropdown is visible
	/* Add id to current page so it stays active for below function */
	$('#site-nav li').children('a.current-page-item').attr('id','current');
	
	/* Keep nav item active when it's hovered */
	$('#site-nav > li').hover(function() {
		$(this).children().addClass('current-page-item');
	}, function() {		
		$(this).children().removeClass('current-page-item');
		$('#site-nav li a#current').addClass('current-page-item');
	});
	
	
// Configure the slideshow on homepage
	$('#home #slides').cycle({
		fx: 'fade',
		timeout: 8000,
		speed: 850,
		pager: '#home #thumbnail-group',
		activePagerClass: 'active',
		pagerAnchorBuilder: function(idx, slide) { return '#thumbnail-group li:eq(' + idx + ') a'; }
	});

	
// Pause the slideshow if thumbnails are hovered
	$('#home #thumbnail-group').hover(function() {
		$('#home #slides').cycle('pause');
	}, function() {
		$('#home #slides').cycle('resume');
	});
	

// Links with class="external" opens new tab
	$('a[class*=external]').click(function() {
		$(this).attr('target','_blank');
	});


// Apply first/last class on sub navigation
	$('#left-sidebar ul.sub-nav li:first').addClass('first');
	$('#left-sidebar ul.sub-nav li:last').addClass('last');
	
	
// Find events form toggle
	$('#events-alldates').change(function() {
		var isChecked = $(this).attr('checked');
		
		if(isChecked == true) {
			$('#events-from-to').slideUp();
		} else {
			$('#events-from-to').slideDown();
		}
	});
	

// Set or change cookie for each text size
	$('#text-resize ul li.small a').click(function() {
		$('body').css('font-size','100%');
		$.cookie('text-size', 'small', { path: '/', expires: 30 });
	});
	
	$('#text-resize ul li.medium a').click(function() {
		$('body').css('font-size','125%');
		$.cookie('text-size', 'medium', { path: '/', expires: 30 });
	});
	
	$('#text-resize ul li.large a').click(function() {
		$('body').css('font-size','150%');
		$.cookie('text-size', 'large', { path: '/', expires: 30 });
	});
	
	if ($.cookie('text-size') == 'small') { $('body').css('font-size','100%'); }
	if ($.cookie('text-size') == 'medium') { $('body').css('font-size','125%'); }
	if ($.cookie('text-size') == 'large') { $('body').css('font-size','150%'); }


// Loads Neighbourhood Map
	if( $('#gmap').length != 0){
		wtb_prepare();
	}
	
	// Loads Neighbourhood Map
	if( $('#gmap_2').length != 0){
		wtb_prepare_green();
	}
	
	
// Loads Gallery
	if( $('#photo-gallery').length != 0){
		gallery_prepare();
	}


}); // End of document ready
