$(document).ready(function(){
	$(".hideme").css('display', 'none');
        $("#tellafriend_form").attr('action', 'http://www.cyclingcityyork.org.uk/subpages/emailAFriend/');
        $("#tellus_form").attr('action', 'http://www.cyclingcityyork.org.uk/subpages/tellUs/');
	$("a[rel='tellafriend']").colorbox({inline:true, href:"#tellafriend", rel:"nofollow", scrolling:false});
	$("a[rel='tellus']").colorbox({inline:true, href:"#tellus", rel:"nofollow", scrolling:false});
	$("a[rel='colorboxgallery']").colorbox();
	$("a[rel='colorboximages']").colorbox();

    $("#tellUsSubmit").live('click', function(e) {
            pageTracker._trackPageview('/pages/feedback/completed');
    });

	$('#tellafriend_form').ajaxForm({
		success: friendResponse,
		clearForm: 'false'
	});
	
	$('#tellus_form').ajaxForm({
		success: tellusResponse,
		clearForm: 'false'
	});

	function friendResponse(responseText, statusText)  {
		$('#tellafriend').html(responseText);
		$("a[href='#close']").click(function(){
			$.fn.colorbox.close()
		});
		$('#tellafriend_form').ajaxForm({
			success: friendResponse,
			clearForm: 'false'
		});
		$("#tellafriend_form").attr('action', 'http://www.cyclingcityyork.org.uk/subpages/emailAFriend/');
	};

	function tellusResponse(responseText, statusText)  {
		$('#tellus').html(responseText);

		$("a[href='#close']").click(function(){
			$.fn.colorbox.close()
		});
		$('#tellus_form').ajaxForm({
			success: tellusResponse,
			clearForm: 'false'
		});
		$("#tellus_form").attr('action', 'http://www.cyclingcityyork.org.uk/subpages/tellUs/');
	};
});
