
	var Crombie = {

		init : function() {

			Crombie.profiles_dropdown();
			Crombie.tweaks();
			Crombie.will_form();

		},	//	END init: function()

		profiles_dropdown : function() {

			$('#profiles_dropdown select').change(function() {
				window.location = $(this).val();
			})

		},

		tweaks : function () {
			//	Hide stuff
			$('.hide_inner').each(function() { $(this).removeClass('hide_inner').wrapInner('<span class="hide_this"></span>') });

			//	Remove stuff
			$('.remove_this').each(function() { $(this).remove() });

			//	Prepare forms and such, seeing as though IE6 has no idea what you're talking about if you use pseudo-selectors
			$('input')
				.bind( 'mouseenter mouseleave', function() {
					$( this ).toggleClass( 'hover' );
				})
				.bind( 'focus blur', function() {
					$( this ).toggleClass( 'focus' );
				});

			$('textarea')
				.bind( 'mouseenter mouseleave', function() {
					$( this ).toggleClass( 'hover' );
				})
				.bind( 'focus blur', function() {
					$( this ).toggleClass( 'focus' );
				});

			$('select')
				.bind( 'mouseenter mouseleave', function() {
					$( this ).toggleClass( 'hover' );
				})
				.bind( 'focus blur', function() {
					$( this ).toggleClass( 'focus' );
				});

			if (!$('#search').val()) {
				initial_value = 'Type and hit Enter';

				$('#search input')
					.val(initial_value)
					.css({color: '#BBB'})
					.bind( 'focus', function() {
						if ( $(this).val() == initial_value) $(this).css({color: '#333'}).val('')
					})
					.bind( 'blur', function() {
						if ( $(this).val() == '') $(this).css({color: '#BBB'}).val(initial_value)
					})
			}	//	END	if (!$('#search').val())

            $('form.default').submit( function() {
                $(this).find('button').html('Please Wait');
                return true;
            });

			//	Tweak CSS using jQuery to take advantage of
			//	CSS selectors that IE doesn't understand.
			$('ul.header_links li:last').css({textIndent: 0})
			$('#navigation li:last a').css({marginRight: 0, width: 156})
			$('#sub_nav li:last').css({border : 'none'})
			$('#content .staff_intro ul li:last').css({marginRight: 0})
			$('#content .org:last').css({ border : 0 })
			$('#content .partner:last').css({ border : 0 })
			$('#footer p.foot_logos a:last').css({ border : 0 })
		},	//	END	tweaks : function ()



		will_form : function() {
			if ($('#will_form').get(0)) {
				$('#will_form fieldset').bind( 'click', function() {
					$('#will_form fieldset').removeClass('focus')
					$(this).addClass('focus')
				})

				$('input:checkbox').css({ border : 0 })
				$('input:radio').css({ border : 0 })

				function check_num_copies() {
					extra_copies = $('input[name=extra_copies]:checked').val()

					if (extra_copies == 'yes') {
						$('.num_copies_input').show()
					} else {
						$('.num_copies_input').hide()
					}
				}

				function check_other_beneficiaries() {
					nom_grandchildren = $('input[name=nom_grandchildren]:checked').val()

					if (nom_grandchildren == 'no') {
						$('.other_beneficiaries').show()
					} else {
						$('.other_beneficiaries').hide()
					}
				}

				function check_guardians() {
					has_children = $('input[name=has_children]:checked').val()

					if (has_children == 'yes') {
						$('.guardians').show()
					} else {
						$('.guardians').hide()
					}
				}

				function check_executors() {
					nominate_spouse = $('input[name=nominate_spouse]:checked').val()

					if (nominate_spouse == 'no') {
						$('.executors').show();
						$('.alternative_options').hide();
					} else {
						$('.executors').hide();
						$('.alternative_options').show();
					}
				}

				function check_joint_will() {
					joint_will = $('input[name=will_type]:checked').val()

					if (joint_will == 'joint') {
						$('.joint_options').show()
						$('.alternative_options').show();
						$('.executors').hide()

						$('input[name=nominate_spouse]').bind( 'click', function() { check_executors() })
						check_executors()
					} else {
						$('.joint_options').hide()
						$('.alternative_options').hide()
						$('.executors').show()
					}
				}

				$('input[name=will_type]').bind( 'click', function() { check_joint_will(); });
				$('input[name=has_children]').bind( 'click', function() { check_guardians(); });
				$('input[name=nom_grandchildren]').bind( 'click', function() { check_other_beneficiaries(); });
				$('input[name=extra_copies]').bind( 'click', function() { check_num_copies(); });

				check_joint_will();
				check_guardians();
				check_other_beneficiaries();
				check_num_copies();

				$('.info_panel')
					.addClass('closed')
					.append('<div class="close"><a href="#">Close this</a></span>')

				$('div.close a').bind( 'click', function() {
					$(this).closest('.info_panel').addClass('closed').removeClass('open')

					return false;
				})

				$('a.info_trigger').bind( 'click', function() {
					info_panel = $(this).attr('id').split('_')[2];

					if ($('.info_' + info_panel).hasClass('open')) {
						$('.info_panel').addClass('closed').removeClass('open')
					}
					else {
						$('.info_panel').addClass('closed').removeClass('open')
						$('.info_' + info_panel).addClass('open').removeClass('closed')
					}

					return false;
				})
			}
		}
	};	//	END	var Crombie = {}



	//	Fix up, look sharp!
	$(function() {

		Crombie.init();

		$.fn.quick_form = function() {

			return this.each(function() {

				var form, labels;

				form   = $( this );
				labels = {};

				form.find('input:visible').each(function() {
					var input, input_id, label, label_text;

					input    = $( this );
					input_id = input.attr('id');

					label      = input.prev();
					label_text = label.text();
					label_text = label_text.substr(0, label_text.length - 1);

					labels[input_id] = label_text;

					label.remove(labels[input_id]);

					input
						.val( label_text )
						.css({ color: '#BBB' })
						.bind( 'focus', function() {
							if ( $( this ).val() == label_text ) {
								$( this ).css({ color: '#333' }).val( '' );
							}
						})
						.bind( 'blur', function() {
							if ( $( this ).val() == '') {
								$( this ).css({ color: '#BBB' }).val( label_text );
							}
						});

				});

				form.bind( 'submit', function() {
					var name, email, enquiry, sub_url, response;

					if ($('#quick_enquiry_wrap div.alert').get(0)) $('#quick_enquiry_wrap div.alert').slideUp();

					name    = $('input#quick_name').val()    != labels.quick_name    ? $('input#quick_name').val()    : '';
					email   = $('input#quick_email').val()   != labels.quick_email   ? $('input#quick_email').val()   : '';
					enquiry = $('input#quick_enquiry').val() != labels.quick_enquiry ? $('input#quick_enquiry').val() : '';
					sub_url = $('input[name=sub_url]').val();

					$.ajax({
						url: '/incs/actions/quick_enquiry_submit.php',
						data: {
							name    : name,
							email   : email,
							enquiry : enquiry,
							sub_url : sub_url
						},
						success: function( response ) {
							if (response == 'win') {
								$('#quick_enquiry_wrap form').slideUp();
								response  = '<div class="clearfix alert"><h4>Thank you</h4><p>Your message was sent successfully. We will get back to you soon as we can!</p></div>';
							}

							$( response ).insertBefore('#quick_enquiry_wrap form').hide().slideDown();
						},
						dataType: 'html',
						type: 'POST'
					});

					return false;
				});

			});

		};

		$('#quick_enquiry_wrap form').quick_form();

	});

