$(function(){
	$('body').removeClass('js-disabled').addClass('js-enabled');
	
	$('#options_bar>ul').append('<li class="print"><a href="javascript:window.print()">Print</a></li>');
	
	contactForms();
	
	$('#questions li a').boxy({
		modal:true,
		closeText: '<img src="/images/button_close.gif" alt="Close this dialog" />'
	});
	
	$('#button_calculate').spinner();
	
});

function contactForms() {
	var forms = $('#body_contact .formbox');
	if (forms.length>1) {
		var initialValue = $.jget['form'] || 0; // pull the form index from the querystring
		if (initialValue > forms.length) initialValue = 0;

		$('<div id="selector"><label for="nature">The nature of your enquiry:</label><select id="nature"></select>').insertBefore(forms[0]);
		forms.each(function(){
			var index = forms.index(this);
			var option = $('<option></option>').text($('h2.title', this).text()).attr({value:index});
			if (index == initialValue) option.attr({selected:'selected'});
			$('#nature').append(option);
		});
		
		forms.hide();
		$(forms.get(initialValue)).show();

		$('#nature').change(function(){
			forms.hide();
			$(forms.get($(this).attr('value'))).show();
			document.body.className += ''; // force IE6 to reflow the page to fix rendering issues
		});

	}
}

jQuery.fn.spinner = function() {
	return this.each(function(){
		var spinnerImage = new Image();
		spinnerImage.src = '/images/ajax-loader.gif';
		spinnerImage.alt = 'Calculating…';
		spinnerImage.className = 'submit';
		
		$(this).click(function(){
			$(this).after(spinnerImage).hide();
		});
	});
}

function hideEmail()
{

	showit('email');
	hideit('a1');
	hideit('a2');
	hideit('a3');
	hideit('a4');
	hideit('a5');
	showit('f1');
	showit('f2');
	showit('f3');
	showit('f4');
	showit('f5');
	showit('f6');
	
	hideit('fpost');
	showit('femail');



	document.body.className += ''; // force IE6 to reflow the page to fix rendering issues
}

function hidePost()
{

	hideit('email');
	showit('a1');
	showit('a2');
	showit('a3');
	showit('a4');
	showit('a5');
	showit('f1');
	showit('f2');
	showit('f3');
	showit('f4');
	showit('f5');
	showit('f6');

	showit('fpost');
	hideit('femail');
	
	document.body.className += ''; // force IE6 to reflow the page to fix rendering issues
}

function showit(obj)
{
	var el = document.getElementById(obj);
		el.style.display = '';
}

function hideit(obj)
{
	var el = document.getElementById(obj);
	el.style.display = 'none';
}



function toggle(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}
