//Initalise page
$(document).ready(function(){
	initialiseExpanders();
	addSelectors();
});

function initialiseExpanders() {
	//hide all "QuestionText" divs, and create buttons to trigger them
	$('.QuestionText .detail').hide();
	$('.QuestionText .brief').append(' <a href="#" onClick="showDetail(this); return false;">Find out more</a>');
	$('.QuestionText .detail').append(' <a href="#" onClick="hideDetail(this); return false;">Close</a>');
	$('#London').addClass(' hidden');
	$('#York').addClass(' hidden');
	$('#Newcastle').addClass(' hidden');
	$('#closeFooter').addClass(' hidden');
}


function showNewcastle(e)
{
	$('#London').addClass(' hidden');
	$('#York').addClass(' hidden');
	$('#Newcastle').removeClass(' hidden');
	$('#LeftCompForm').addClass(' hidden');
	$('#closeFooter').removeClass(' hidden');
}

function showLondon(e)
{
	$('#Newcastle').addClass(' hidden');
	$('#York').addClass(' hidden');
	$('#London').removeClass(' hidden');
	$('#LeftCompForm').addClass(' hidden');
	$('#closeFooter').removeClass(' hidden');
}
function showYork(e)
{
	$('#London').addClass(' hidden');
	$('#York').removeClass(' hidden');
	$('#Newcastle').addClass(' hidden');
	$('#LeftCompForm').addClass(' hidden');
	$('#closeFooter').removeClass(' hidden');
}
function showForm(e)
{
	$('#London').addClass(' hidden');
	$('#York').addClass(' hidden');
	$('#Newcastle').addClass(' hidden');
	$('#LeftCompForm').removeClass(' hidden');
	$('#closeFooter').addClass(' hidden');
}


function showDetail(e) {
	//show "QuestionText" details
	$(e).hide();
	$(e).parent().parent().find('.detail a').fadeIn();
	$(e).parent().parent().find('.detail').slideDown();
}

function hideDetail(e) {
	//hide "QuestionText" details
	$(e).hide();
	$(e).parent().parent().find('.brief a').fadeIn();
	$(e).parent().parent().find('.detail').slideUp();
}

function addSelectors() {
	//add events to "QuestionRadio" buttons to collapse each section
	$('#Hotels .QuestionRadio').click( function() {
		var selectionText = $(this).parent().find('.QuestionText strong').text();
		selectionText = "<strong>" + selectionText.substring(0, (selectionText.length - 1)) + "</strong>";
		$('#Hotels div:first').slideUp();
		$('#Hotels .selected').remove();
		$('#Hotels').prepend('<span class="selected">You have selected ' + selectionText + '<a href="#" onClick="showSection(this); return false;">Change</a></span>');
		$('#Hotels').prepend('<img class="tick" src="/gner/images/multievents/1ticked.png" alt="" />');
	});
	$('#Experiences .QuestionRadio').click( function() {
		var selectionText = $(this).parent().find('.QuestionText strong').text();
		selectionText = "<strong>" + selectionText.substring(0, (selectionText.length - 1)) + "</strong>";
		$('#Experiences div:first').slideUp();
		$('#Experiences .selected').remove();
		$('#Experiences').prepend('<span class="selected">You have selected ' + selectionText + '<a href="#" onClick="showSection(this); return false;">Change</a></span>');
		$('#Experiences').prepend('<img class="tick" src="/gner/images/multievents/2ticked.png" alt="" />');
	});
	$('#Indulges .QuestionRadio').click( function() {
		var selectionText = $(this).parent().find('.QuestionText strong').text();
		selectionText = "<strong>" + selectionText.substring(0, (selectionText.length - 1)) + "</strong>";
		$('#Indulges div:first').slideUp();
		$('#Indulges .selected').remove();
		$('#Indulges').prepend('<span class="selected">You have selected ' + selectionText + '<a href="#" onClick="showSection(this); return false;">Change</a></span>');
		$('#Indulges').prepend('<img class="tick" src="/gner/images/multievents/3ticked.png" alt="" />');
	});
	
}

function showSection(e) {
	//open collapsed section
	$(e).parent().parent().find('div').slideDown();
	$(e).remove();
}