
	var Crombie = {

		init : function() {

			Crombie.profiles_dropdown()
			Crombie.quick_form()
			Crombie.tweaks()
			Crombie.will_form()

		},	//	END init: function()

		profiles_dropdown : function() {

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

		},

		quick_form : function() {

			if ($('#quick_enquiry').get(0)) {
				quick_form = $('#quick_enquiry form')

				var labels = {};

				$(quick_form).find('input:text').each(function() {
					this_label = $(this).prev().html()
					this_input = $(this).attr('id')

					labels[this_input] = this_label.substr(0, this_label.length - 1)
				})

				$.each(labels, function(input, label) {
					$('label[for=' + input + ']').remove()

					$('input#' + input).val(label).css({color: '#BBB'}).focus(function() {
						if ($(this).val() == label) $(this).css({color: '#333'}).val('')
					}).blur(function() {
						if ($(this).val() == '') $(this).css({color: '#BBB'}).val(label)
					})
				})

				//	That's the labels and focus/blur rules defined.. Now let's define what
				//	happens when the form is submitted..
				quick_form.submit(function() {
					if ($('#quick_enquiry div.alert').get(0)) $('#quick_enquiry div.alert').slideUp()

					//	Prepare variables for submission
					name    = $('input#name').val()    != labels['name']    ? $('input#name').val()    : '';
					email   = $('input#email').val()   != labels['email']   ? $('input#email').val()   : '';
					enquiry = $('input#enquiry').val() != labels['enquiry'] ? $('input#enquiry').val() : '';
					sub_url = $('input[name=sub_url]').val()

					//	Submit via HTTP POST
					$.post('/incs/actions/quick_enquiry_submit.php', {
							'name'    : name,
							'email'   : email,
							'enquiry' : enquiry,
							'sub_url' : sub_url
						}, function(response) {

							//	Here's where we handle the results and decide WHAT?!
							//	If the response isn't the word 'win', then the response is an error report. Display that if
							//	there are errors, or replace the 'win' with a thank you message and hide the form.

							if (response == 'win') {
								//	Message sent successfully, let's do this!
								hide_form = true;
								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>';
							} else {
								hide_form = false;
							}

							if (hide_form) $('#quick_enquiry form').slideUp()

							setTimeout(function () { $(response).insertBefore('#quick_enquiry form').hide().slideDown() }, 1000)

						}, 'html'
					)	//	END $.post()

					//	And last of all, stop the browser actually firing its own submit event
					return false;
				})	//	quick_form.submit()
			}	//	if ($('#quick_enquiry').get(0))
		},	//	END quick_form: function()



		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')
					.hover(
						function() { $(this).addClass('hover') },
						function() { $(this).removeClass('hover') }
					)
					.focus(function() { $(this).addClass('focus') })
					.blur(function()  { $(this).removeClass('focus') })

				$('textarea')
					.hover(
						function() { $(this).addClass('hover') },
						function() { $(this).removeClass('hover') }
					)
					.focus(function() { $(this).addClass('focus') })
					.blur(function()  { $(this).removeClass('focus') })

				$('select')
					.hover(
						function() { $(this).addClass('hover') },
						function() { $(this).removeClass('hover') }
					)
					.focus(function() { $(this).addClass('focus') })
					.blur(function()  { $(this).removeClass('focus') })

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

				search_input = $('#search input')

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

			//	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').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()
					} else {
						$('.executors').hide()
					}
				}

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

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

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

				$('input[name=will_type]').click(function()         { check_joint_will() })
				$('input[name=has_children]').click(function()      { check_guardians() })
				$('input[name=nom_grandchildren]').click(function() { check_other_beneficiaries() })
				$('input[name=extra_copies]').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').click(function() {
					$(this).closest('.info_panel').addClass('closed').removeClass('open')
					
					return false;
				})

				$('a.info_trigger').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 = {}

	//	If we're using Firefox and the Firebug console function exists, load it.. Load it up real good!
	if (typeof window.loadFirebugConsole == 'function') window.loadFirebugConsole()

	//	Fix up, look sharp!
	$(function() { Crombie.init() })
