$(document).ready(
	function() {
		// extending textareas
		$('<a href="#expand" class="extend-link">Expand textarea</a>').appendTo('dd.extend').click(
			function() {
				var $ta = $(this).prev('textarea.extend');
				$ta.animate({
					height: $ta.innerHeight()+150
				}, 'slow');
				$(this).get(0).blur();
				return false;
			}
		);
		
		$('#content-primary > h3 + p').addClass('introduction');
		
		$('ol li:first-child, ul li:first-child').addClass('f');
		$('ol li:last-child, ul li:last-child').addClass('l');

		$('#branding-strapline').flash({
			src: '/css/images/tagline.swf',
			width: 305,
			height: 51
		});
		
		// duplicate the navigation, append to footer
		$('#navigation-main > ul').clone().insertAfter('#footer h2').parent().find('ul').addClass('footer-navigation').find('li > ul').remove();
		
		
		// add link to google maps via postcode
		/*
		$('.adr .postal-code').each(function() {
			$('<a>').attr('title','View our location on Google Maps').attr('href','http://maps.google.co.uk/?q='+$(this).text()).addClass('map').html('Location map').insertAfter($(this).parents('.adr'));
		});
		*/
		

		function quick_fading() {
			// BIND the mouseover (quick_fading) event on the anchor
			// MOUSEOVER the link, activate the SHOW effect
			// UNBIND the mouseover event on the anchor
			
			// BIND the mouseover (quick_fading) event to the anchor WHEN MOUSEOUT on the anchor
			// MOUSEOVER the link, activate the HIDE effect
			// UNBIND the mouseover event on the anchor.		
			$('#quick-link-anchor').one('mouseout', function() {
				$(this).unbind('mouseout').one('mouseover', quick_fading);
			}).click(function(){
				$(this).get(0).blur();
				return false;
			});
			if($(this).parent().is('.hidden')) {
				$('#quick-links-navigation').fadeIn('slow', function() {
					$('#quick-links').removeClass('hidden').addClass('shown').find('#close-interested').bind('click',quick_fading);
				});
			}
			else {
				$('#quick-links-navigation').fadeOut('slow', function() {
					$('#quick-links').removeClass('shown').addClass('hidden');
				});
			}
			// if clicked, no need to show the anchor in the URL
			$('#close-interested').blur();
			return false;
		}
		if($('body').not('.admin').length>0) {
			$.ajax({
				type: 'POST',
				url: '/_compile/a_interested.php',
				data: 'interested=get',
				dataType: 'html',
				success: function(return_text) {
					$('div#footer').before('<div id="quick-links" class="hidden"><a href="#quick-links" id="quick-link-anchor">I am interested in...</a></div>');
					$('#quick-links').append('<div id="quick-links-navigation">'+return_text+'</div>');
					$('#quick-link-anchor').one('mouseover', quick_fading);
				}
			});
		}
	
		
		$('table.vcalendar').find('tr').hover(
			function() {
				$(this).next('address.adr').addClass('hover');
			},
			function() {
				$(this).next('address.adr').removeClass('hover');
			}
			).find('td.location strong').hover(
			function() {
				//$(this).next('address.adr').addClass('show');
				//$(this).next('address.adr').css('top','15px').css('left','15px');
			},
			function() {
				//$(this).next('address.adr').removeClass('show');
			}
		);
	}
);