$(document).ready(function() {
	// external links
	$('a.external').click(function() {
		window.open($(this).attr('href'), 'blank');
	
		return false;
	});
	
	// copy input title content into value only if value is empty (allows for fields to be pre-populated e.g. from php)
	$('input[title], textarea[title]').each(function() {
		var el = $(this);
		
		function sticky() {
			if (el.attr('value').length == 0) {
				el.attr('value', el.attr('title'));
			}
		}
		
		// reset on mouse out
		$(this).blur(function() {
			sticky();
		});
		
		// clear on mouse in
		$(this).focus(function() {
			if (el.attr('title') == el.attr('value')) {
				el.attr('value', '');
			}
		});
		
		// initialise
		sticky();
	});
	
	// clean junk on form submit
	$('form').submit(function() {
		$(this).find('input[title], textarea[title]').each(function() {
			if ($(this).attr('title') == $(this).attr('value')) $(this).attr('value', '');
		});
	});
	
	// google map
	if ($('#map').length) {
		load();
	}
	
	// Tabs
	$('.tabs').tabs();
	// select enquiry form tab
	$('#contact .tabs').tabs('select', 1);
	
	// Expanding menu
	$('#left-column li:has(ul)').each(function() {
		$(this).find('a:eq(0)').click(function() {
			// toggle display
			$('#left-column li:not(.active) ul:visible').slideUp('slow');
			$(this).parent().find('ul').slideDown('slow');
			
			// disable link clicks on expansion items
			return false;
		});
	});
	
	// hide by default
	$('#left-column li:not(.active) ul').hide();
	
	// IE6 fixing
	if ($.browser.msie && ~$.browser.version < 7) {
		// width issues
		$('ul.black-bar li, div.testimonial, div.testimonial *, div.dual-content').each(function() {
			$(this).width($(this).width());
		});
		
		// PNG fix
		jQuery.ifixpng(url + 'images/blank.gif');
		jQuery('img[src$=.png], .bg-png').ifixpng();
		
		// fix for the fix applied to pngs
		$('#left-column ul.navigation li a').css({
			'position': 'relative',
			'z-index': 999
		});
	}
});