jQuery(document).ready(function($) {
	$('form.iphorm').iPhorm();

	// Tooltip settings
	if ($.isFunction($.fn.qtip)) {
		$('.iphorm-tooltip').qtip({
			content: {
				text: false
			},
			style: {
			width: 200,
			padding: 5,
			background: '#01224F',
			color: '#ffffff',
			textAlign: 'center',
			'font-size': 12,
			border: {
			   width: 7,
			   radius: 5,
			   color: '#01224F'
			},
			tip: 'leftMiddle',
			name: 'dark' // Inherit the rest of the attributes from the preset dark style
			},
			position: {
				corner: {
					target: 'rightMiddle',
					tooltip: 'leftMiddle'
				}
			}
		});
	}

	// Changes subject to a text field when 'Other' is chosen
	var subjectHtml = $('.subject-input-wrapper').html();
	$('#subject').live('change', function () {
		if ($(this).val() == 'Other') {
			$('.subject-input-wrapper').empty();
			newHtml = $('<input name="subject" type="text" id="subject" value="" />');
			$('.subject-input-wrapper').html(newHtml);
			$cancelOther = $('<a>').click(function () {
				$('.subject-input-wrapper').empty();
				$('.subject-input-wrapper').append(subjectHtml);
				$(this).remove();
				return false;
			}).attr('href', '#').addClass('cancel-button').attr('title', 'Cancel');
			newHtml.after($cancelOther);
		}
	});
}); // End document ready

//Image preloader
var images = new Array(
	'contact-form/images/close.png',
	'contact-form/images/success.png'
);
var imageObjs = new Array();
for (var i in images) {
	imageObjs[i] = new Image();
	imageObjs[i].src = images[i];
}
