jQuery(document).ready(function($) {
	$('form.surgeform').iPhorm();
	
	// Tooltip settings

	if ($.isFunction($.fn.qtip)) {
		$('.surgeform-tooltip').qtip({
			content: {
				text: false
			},
show: {
            delay: 0,
            solo: true,
            when: {
                target: false,
                event: 'mouseover'
            },
            effect: function() {
                $(this).stop(true, true).show();
            }
        },
        hide: {
            fixed: true,
            delay: 0,
            when: {
                target: false,
                event: 'mouseout'
            },
            effect: function() {
                $(this).stop(true, true).hide();
            }
        },

			style: { 
      width: 200,
      padding: 5,
      background: '#4b4c51',
      color: 'white',
      textAlign: 'center',
      border: {
         width: 0,
         radius: 5,
         color: '#4b4c51'
      },
      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];
}
