$(document).ready(function()
{
	// Creating custom :external selector
	$.expr[':'].external = function(obj){
		return !obj.href.match(/^mailto\:/)
				&& !obj.href.match(/^javascript\:/) 
				&& !obj.href.match(/recaptcha\.net/) 
				&& (obj.hostname != location.hostname);
	};
	
	// Add 'external' CSS class to all external links
	$('a:external').addClass('external');	
	$('a.external img').parent().addClass('image');
	
	$('.external').click(function() {
		var link = $(this).attr('href');
	
		$('<div><p>You are currently leaving our site, and headed towards:</p><p><strong>'+(link)+'</strong></p><p>Are you sure you want to proceed?</p>').dialog({
				title: "External Link",
				modal : true,
				overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				'Okay': function() {
					$(this).dialog('close').remove();
					window.open(link);
				},
				'Cancel': function() {
					$(this).dialog('close').remove();
					return false;
				}
			}
		});
	
		return false;
	});
	
	$('a.quote').click(function(e) {
		e.preventDefault();
		
		var title = 'Quote request';
		var $this = $(this);
		
		if( $(this).is('.consult') )
			title = 'On-site consultation request';
		
		$('<iframe id="quoteFrame" src="' + this.href + '" />').dialog({
			title: title,
			autoOpen: true,
			width: 660,
			height: 600,
			modal: true,
			resizable: true,
			autoResize: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			}
		});	
	});
	
	// hide product menu if not on a product page
	/*
	if( !$('body').is('.products') )
		$('#nav-products ul').hide();
	*/
	
	/*
	$('#nav-products a:first').click(function(e) {
		e.preventDefault();
		$('#nav-products ul').toggle();
	});
	*/
	
	/* 
	$('#nav-usedproducts span').hide();
	
	$('#nav-usedproducts a:first').click(function(e) {
		e.preventDefault();
		if( $('#nav-usedproducts span').is(':hidden') ) {
			$('#nav-usedproducts span').show();
			$('#content').css('min-height','961px');
		}
		else {
			$('#nav-usedproducts span').hide();
			$('#content').css('min-height','869px');
		}
	});
	*/ 
	$("#enquiryform").validate();
	$("#subscribe form").validate();
	$("#postalsubscribe").validate();
	$("form.quote").validate();
});
