$(document).ready(function()
{
	$('#booknow_lightbox_background').fadeTo(1, 0);
	function showBookingLightbox() {
		$('#booknow_lightbox_background').show();
		$('#booknow_lightbox_background').fadeTo(500, 0.75);
		$('#booknow_lightbox').fadeIn(500);
	}

    function formUpdate(ret, status)
    {
		if(status == 'success')
		{
			if(ret.ok)
			{
				$('.copy').html('<h1>'+ret.thankyou_header+'</h1><p>'+ret.thankyou_message+'</p>');
				return;
			}
					
			$('.input_error').removeClass('input_error');
			
			$.each(ret.error,function(i,val) { if(val) $("[name='"+i+"']").addClass('input_error'); });
			if(ret.output)
			{
				if(ret.output.error.length)
				{
					$('.tpl_formElement_error').empty();
					$.each(ret.output.error,function(i,val)
					{
					$('.tpl_formElement_error').append(val+'<br />');
					});
					$('.tpl_formElement_error').show();
				}
			}
			else $('.tpl_formElement_error').hide();
		}
    }
    $("#tpl_form").submit(function()
    {
		var options = 
		{ 
			success:		formUpdate,
			url:		'application.php',
			type:		'post',
			dataType:		'json'
		}; 
		$(this).ajaxSubmit(options);
		return false;
    });
	var weblinks = {
	    en: 'https://www.rciholidaynetwork.co.uk/WEBLink/TLCWorldForFreeUK',
	    fr: 'https://www.rciholidaynetwork.co.uk/WEBLink/TLCWorldForFreeFrance',
	    de: 'https://www.rciholidaynetwork.co.uk/WEBLink/TLCWorldForFreeGermany',
	    it: 'https://www.rciholidaynetwork.co.uk/WEBLink/TLCWorldForFreeItaly',
	    es: 'https://www.rciholidaynetwork.co.uk/WEBLink/TLCWorldForFreeSpain',
	    us: 'https://www.rciholidaynetwork.co.uk/WEBLink/TLCWorldForFreeUSA',
	    ca: 'https://www.rciholidaynetwork.co.uk/WEBLink/TLCWorldForFreeUSA',
	    za: 'https://www.rciholidaynetwork.co.uk/WEBLink/TLCWorldForFreeUSA',
	    ru: 'https://www.rciholidaynetwork.co.uk/WEBLink/TLCWorldForFreeUSA'
	};
    $("#tpl_form2").submit(function()
    {
		var tmp = 0;
		$('.input_error').removeClass('input_error');
		$(":checkbox").each(function()
		{
			if(!$(this).is(':checked'))
			{
				tmp = 1;
				$(this).parent().addClass('input_error');
			}
		});
		if(tmp == 0)
		{
			var lang = $("input[name='lang']").val();
			
			if (lang == 'sg') {
				showBookingLightbox();
			} else {
				if(!weblinks[lang]) lang = 'en';
				top.location = weblinks[lang];
			}
		}
		return false;
    });

	$('#continue_button').click(function() {
		var lang = $("input[name='lang']").val();

		if(!weblinks[lang]) lang = 'en';
		top.location = weblinks[lang];
	});

    $('.select').click(function()
    {
		if($('#selectSite').is(':visible')) $('#selectSite').hide();
		else $('#selectSite').slideDown('fast');
    });
    $('#selectSite').mouseout(function()
    {
		if($(this).is(':visible'))
		{
			$(this).hide();
		}
    }).mouseover(function()
    {
        $(this).show();
    });
    $('.select').html('<p>'+$('.'+$('.select').attr('id')).html()+'</p>');
    
    $('.ul_mainMenu > li > a').hover(
		function() { if(!$(this).hasClass('on')) $(this).css('background-position','0px 0px'); },
		function() { if(!$(this).hasClass('on')) $(this).css('background-position','0px -32px'); }
    );
    
    $('.ul_mainMenu > li > a').each(function() { if($(this).hasClass('on')) $(this).css('background-position','0px -36px'); });
    
	$('div.golf').hide();
	$('div.horse').hide();	
	$('div.football').hide();
	$('div.activities ').hide();
	
	$('#aActivities').click(function()
	{
		$('div.golf').hide();
		$('div.horse').hide();
		$('div.football').hide();
		$('div.activities').fadeIn();
	 	return false;
	});
	
	$('#aGolf').click(function()
	{
		$('div.golf').fadeIn();
		$('div.horse').hide();
		$('div.football').hide();
		$('div.activities').hide();
	 	return false;
	});
	
	$('#aHorse').click(function()
	{
		$('div.golf').hide();
		$('div.horse').fadeIn();
		$('div.football').hide();
		$('div.activities').hide();
	 	return false;
	});

	$('#aFootball').click(function()
	{
		$('div.golf').hide();
		$('div.horse').hide();
		$('div.football').fadeIn();
		$('div.activities').hide();
	 	return false;
	});

      $('div#copy > h2').click(function() {
										
      $(this).next().slideToggle('slow');
      $(this).toggleClass('active');
										});


	$('#copyright_link').click(function() {
		$('#copyright').slideToggle(250);
	});

	$('#copyright_close').click(function() {
		$('#copyright').slideUp(250);
	});
});

