function copyInput(){
    	// 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'));
				el.addClass('inactive');
			}
		}

		// 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', '');
				el.removeClass('inactive');
			}
		});

		// initialise
		sticky();
	});
}

$(document).ready(function() {
	copyInput();

	// external links
	$('a[rel="external"]').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});

	// 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 > 0) {
		load();
	}

	$("#callback-form").validate();
	
	if ($.cookie('admin')){
	    $('li#edit-link').css('display','inline');
	}
	
	function addMega(){
	    $(this).find("ul").not("#nav > ul > li > ul > li > ul").slideDown('fast');
	}

	function removeMega(){
	    $(this).find("ul").not("#nav > ul > li > ul > li > ul").slideUp('fast');
	}

	var megaConfig = {
	    interval: 200,
	    sensitivity: 7,
	    over: addMega,
	    timeout: 500,
	    out: removeMega
	};
	$('#nav > ul > li').hoverIntent(megaConfig);
	$('#home-products ul li:first').addClass('top');

	// list active link toggler
	$('.active-link-toggle:has(a)').each(function(el) {
		$(el).find('a').click(function() {
			$(el).find('a.active').removeClass('active');
			$(this).addClass('active');
			var id = $('#' + $(this).attr('href').replace(/\#/i, '') + '');
			var originalBackground = id.css('background-color');
			id.css('background-color', '#E4E5E6').animate({backgroundColor: originalBackground}, 1500);
		});
	});

	$('#home-products li').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});

	// toggle hidden elements
	if ($('.toggle').length > 0) {
		$('.toggle').each(function() {
			var hidden = $(this);
			
			// hide by default
			hidden.hide();

			// add toggle handler
			$('#' + hidden.attr('id') + '-toggle').click(function() {
				// toggle hidden content
				hidden.toggle('slow');
				
				// return false to prevent link
				return false;
			});
		});
	}

	//apply border radius for IE
	$("#private-banner, #park-banner, #dealer-banner, #subnav, #contact-us, #call-back-request, #renewal, #newsletter, #rm-banner, #home-products, #home-news, #home-banner, #rm-nav a, #sme-nav a, #private-nav a, #park-nav a, #dealer-nav a, #heading").borderRadius();
});